Skip to content

Commit

Permalink
Add e2e tests to interact with dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
jshjohnson committed Nov 3, 2018
1 parent 90a9265 commit f3c0abe
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 6 deletions.
38 changes: 37 additions & 1 deletion cypress/integration/select-multiple.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,42 @@ describe('Choices - select multiple', () => {
});
});
});

describe('interacting with dropdown', () => {
describe('opening dropdown', () => {
it('opens dropdown', () => {
cy.get('[data-test-hook=basic]')
.find('button.open-dropdown')
.focus()
.click();

cy.get('[data-test-hook=basic]')
.find('.choices__list--dropdown')
.should('be.visible');
});
});

describe('closing dropdown', () => {
beforeEach(() => {
// ensure dropdown is already open
cy.get('[data-test-hook=basic]')
.find('button.open-dropdown')
.focus()
.click();
});

it('closes dropdown', () => {
cy.get('[data-test-hook=basic]')
.find('button.close-dropdown')
.focus()
.click();

cy.get('[data-test-hook=basic]')
.find('.choices__list--dropdown')
.should('not.be.visible');
});
});
});
});

describe('remove button', () => {
Expand Down Expand Up @@ -501,7 +537,7 @@ describe('Choices - select multiple', () => {
describe('when data has loaded', () => {
describe('opening the dropdown', () => {
it('displays the loaded data', () => {
cy.wait(2000);
cy.wait(1000);
cy.get('[data-test-hook=remote-data]')
.find('.choices__list--dropdown .choices__list')
.children()
Expand Down
38 changes: 37 additions & 1 deletion cypress/integration/select-one.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,42 @@ describe('Choices - select one', () => {
});
});
});

describe('interacting with dropdown', () => {
describe('opening dropdown', () => {
it('opens dropdown', () => {
cy.get('[data-test-hook=basic]')
.find('button.open-dropdown')
.focus()
.click();

cy.get('[data-test-hook=basic]')
.find('.choices__list--dropdown')
.should('be.visible');
});
});

describe('closing dropdown', () => {
beforeEach(() => {
// ensure dropdown is already open
cy.get('[data-test-hook=basic]')
.find('button.open-dropdown')
.focus()
.click();
});

it('closes dropdown', () => {
cy.get('[data-test-hook=basic]')
.find('button.close-dropdown')
.focus()
.click();

cy.get('[data-test-hook=basic]')
.find('.choices__list--dropdown')
.should('not.be.visible');
});
});
});
});

describe('remove button', () => {
Expand Down Expand Up @@ -452,7 +488,7 @@ describe('Choices - select one', () => {
describe('when data has loaded', () => {
describe('opening the dropdown', () => {
it('displays the loaded data', () => {
cy.wait(2000);
cy.wait(1000);
cy.get('[data-test-hook=remote-data]')
.find('.choices__list--dropdown .choices__list')
.children()
Expand Down
4 changes: 4 additions & 0 deletions public/assets/styles/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ h6,
display: none;
}

.push-bottom {
margin-bottom: 24px;
}

.zero-bottom {
margin-bottom: 0;
}
Expand Down
2 changes: 1 addition & 1 deletion public/assets/styles/base.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion public/test/select-multiple.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
<h2>Select multiple inputs</h2>
<div data-test-hook="basic">
<label for="choices-basic">Basic</label>
<button class="open-dropdown push-bottom">Open dropdown</button>
<button class="close-dropdown push-bottom">Close dropdown</button>
<select class="form-control" name="choices-basic" id="choices-basic" multiple>
<option value="Choice 1">Choice 1</option>
<option value="Choice 2">Choice 2</option>
Expand Down Expand Up @@ -175,7 +177,15 @@ <h2>Select multiple inputs</h2>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
new Choices('#choices-basic');
const choicesBasic = new Choices('#choices-basic');

document.querySelector('button.open-dropdown').addEventListener('click', () => {
choicesBasic.showDropdown();
});

document.querySelector('button.close-dropdown').addEventListener('click', () => {
choicesBasic.hideDropdown();
});

new Choices('#choices-remove-button', {
removeItemButton: true,
Expand Down
12 changes: 11 additions & 1 deletion public/test/select-one.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
<h2>Select one inputs</h2>
<div data-test-hook="basic">
<label for="choices-basic">Basic</label>
<button class="open-dropdown push-bottom">Open dropdown</button>
<button class="close-dropdown push-bottom">Close dropdown</button>
<select class="form-control" name="choices-basic" id="choices-basic">
<option value="Choice 1">Choice 1</option>
<option value="Choice 2">Choice 2</option>
Expand Down Expand Up @@ -179,7 +181,15 @@ <h2>Select one inputs</h2>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
new Choices('#choices-basic');
const choicesBasic = new Choices('#choices-basic');

document.querySelector('button.open-dropdown').addEventListener('click', () => {
choicesBasic.showDropdown();
});

document.querySelector('button.close-dropdown').addEventListener('click', () => {
choicesBasic.hideDropdown();
});

new Choices('#choices-remove-button', {
removeItemButton: true,
Expand Down
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if (process.env.NODE_ENV !== 'production') {

setTimeout(() => {
res.status(200).send(fakeData);
}, 2000);
}, 1000);
});
}

Expand Down
4 changes: 4 additions & 0 deletions src/styles/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ h6,
display: none;
}

.push-bottom {
margin-bottom: $global-guttering;
}

.zero-bottom {
margin-bottom: 0;
}
Expand Down

0 comments on commit f3c0abe

Please sign in to comment.