Skip to content

Commit 51f9a0f

Browse files
committed
Add e2e test for #1281
1 parent 0acba2b commit 51f9a0f

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

public/test/select-multiple/index.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,27 @@ <h2>Select multiple inputs</h2>
11071107
</script>
11081108
</div>
11091109

1110+
<div data-test-hook="clear-on-add">
1111+
<label for="choices-clear-on-add">Clear choices on add item</label>
1112+
<select
1113+
class="form-control"
1114+
name="choices-clear-on-add"
1115+
id="choices-clear-on-add"
1116+
multiple
1117+
>
1118+
<option value="Choice 1">Choice 1</option>
1119+
<option value="Choice 2">Choice 2</option>
1120+
</select>
1121+
<script>
1122+
document.addEventListener('DOMContentLoaded', function() {
1123+
const choices = new Choices('#choices-clear-on-add', {});
1124+
choices.passedElement.element.addEventListener("addItem", function () {
1125+
choices.clearChoices()
1126+
choices.hideDropdown()
1127+
})
1128+
});
1129+
</script>
1130+
</div>
11101131

11111132
</div>
11121133
</div>

public/test/select-one/index.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,27 @@ <h2>Select one inputs</h2>
11081108
</script>
11091109
</div>
11101110

1111+
<div data-test-hook="clear-on-add">
1112+
<label for="choices-clear-on-add">Clear choices on add item</label>
1113+
<select
1114+
class="form-control"
1115+
name="choices-clear-on-add"
1116+
id="choices-clear-on-add"
1117+
>
1118+
<option value="Choice 1">Choice 1</option>
1119+
<option value="Choice 2">Choice 2</option>
1120+
</select>
1121+
<script>
1122+
document.addEventListener('DOMContentLoaded', function() {
1123+
const choices = new Choices('#choices-clear-on-add', {});
1124+
choices.passedElement.element.addEventListener("addItem", function () {
1125+
choices.clearChoices()
1126+
choices.hideDropdown()
1127+
})
1128+
});
1129+
</script>
1130+
</div>
1131+
11111132
</div>
11121133
</div>
11131134
</body>

test-e2e/tests/select-multiple.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,5 +1034,27 @@ describe(`Choices - select multiple`, () => {
10341034
await suite.expectVisibleNoticeHtml('No choices to choose from');
10351035
});
10361036
});
1037+
1038+
describe('Clear choices on add item', () => {
1039+
const testId = 'clear-on-add';
1040+
test('Expected items', async ({ page, bundle }) => {
1041+
const suite = new SelectTestSuit(page, bundle, testUrl, testId);
1042+
await suite.startWithClick();
1043+
await suite.expectChoiceCount(2);
1044+
1045+
await suite.choices.first().click();
1046+
await suite.advanceClock();
1047+
await suite.expectHiddenDropdown();
1048+
await suite.expectedItemCount(1);
1049+
1050+
await suite.wrapper.click();
1051+
await suite.advanceClock();
1052+
await suite.expectVisibleNoticeHtml('No choices to choose from', false);
1053+
1054+
await suite.keyPress('Backspace');
1055+
await suite.expectedItemCount(0);
1056+
await suite.expectChoiceCount(1);
1057+
});
1058+
});
10371059
});
10381060
});

test-e2e/tests/select-one.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,5 +977,19 @@ describe(`Choices - select one`, () => {
977977
await suite.expectVisibleNoticeHtml('No choices to choose from');
978978
});
979979
});
980+
981+
describe('Clear choices on add item', () => {
982+
const testId = 'clear-on-add';
983+
test('Expected items', async ({ page, bundle }) => {
984+
const suite = new SelectTestSuit(page, bundle, testUrl, testId);
985+
await suite.startWithClick();
986+
await suite.expectChoiceCount(2);
987+
988+
await suite.choices.last().click();
989+
await suite.advanceClock();
990+
await suite.expectedItemCount(1);
991+
await suite.expectChoiceCount(1);
992+
});
993+
});
980994
});
981995
});

0 commit comments

Comments
 (0)