Skip to content

Commit 1b969b4

Browse files
committed
Add e2e test for #1278
1 parent 51f9a0f commit 1b969b4

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed

public/test/select-multiple/index.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,33 @@ <h2>Select multiple inputs</h2>
11291129
</script>
11301130
</div>
11311131

1132+
<div data-test-hook="set-choices-preserve">
1133+
<label for="choices-set-choices-preserve">setChoices example</label>
1134+
<select
1135+
class="form-control"
1136+
name="choices-set-choices-preserve"
1137+
id="choices-set-choices-preserve"
1138+
multiple
1139+
>
1140+
<option value="Choice 1">Choice 1</option>
1141+
<option value="Choice 2" selected>Choice 2</option>
1142+
</select>
1143+
<script>
1144+
document.addEventListener('DOMContentLoaded', function() {
1145+
const choices = new Choices('#choices-set-choices-preserve', {});
1146+
choices.setChoices(
1147+
[
1148+
{ value: 'Choice 1', label: 'Choice 1' },
1149+
{ value: 'Choice 2', label: 'Choice 2' }
1150+
],
1151+
'value',
1152+
'label',
1153+
true,
1154+
);
1155+
});
1156+
</script>
1157+
</div>
1158+
11321159
</div>
11331160
</div>
11341161
</body>

public/test/select-one/index.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,32 @@ <h2>Select one inputs</h2>
11291129
</script>
11301130
</div>
11311131

1132+
<div data-test-hook="set-choices-preserve">
1133+
<label for="choices-set-choices-preserve">setChoices example</label>
1134+
<select
1135+
class="form-control"
1136+
name="choices-set-choices-preserve"
1137+
id="choices-set-choices-preserve"
1138+
>
1139+
<option value="Choice 1">Choice 1</option>
1140+
<option value="Choice 2" selected>Choice 2</option>
1141+
</select>
1142+
<script>
1143+
document.addEventListener('DOMContentLoaded', function() {
1144+
const choices = new Choices('#choices-set-choices-preserve', {});
1145+
choices.setChoices(
1146+
[
1147+
{ value: 'Choice 1', label: 'Choice 1' },
1148+
{ value: 'Choice 2', label: 'Choice 2' }
1149+
],
1150+
'value',
1151+
'label',
1152+
true,
1153+
);
1154+
});
1155+
</script>
1156+
</div>
1157+
11321158
</div>
11331159
</div>
11341160
</body>

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,5 +1056,19 @@ describe(`Choices - select multiple`, () => {
10561056
await suite.expectChoiceCount(1);
10571057
});
10581058
});
1059+
1060+
describe('setChoices', () => {
1061+
const testId = 'set-choices-preserve';
1062+
test('Expected selected to be preserved', async ({ page, bundle }) => {
1063+
const suite = new SelectTestSuit(page, bundle, testUrl, testId);
1064+
await suite.start();
1065+
await suite.advanceClock();
1066+
1067+
await suite.expectHiddenDropdown();
1068+
await suite.expectedValue('Choice 2');
1069+
await suite.expectedItemCount(1);
1070+
await suite.expectChoiceCount(2);
1071+
});
1072+
});
10591073
});
10601074
});

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,5 +991,18 @@ describe(`Choices - select one`, () => {
991991
await suite.expectChoiceCount(1);
992992
});
993993
});
994+
995+
describe('setChoices', () => {
996+
const testId = 'set-choices-preserve';
997+
test('Expected selected to be preserved', async ({ page, bundle }) => {
998+
const suite = new SelectTestSuit(page, bundle, testUrl, testId);
999+
await suite.start();
1000+
1001+
await suite.expectHiddenDropdown();
1002+
await suite.expectedValue('Choice 2');
1003+
await suite.expectedItemCount(1);
1004+
await suite.expectChoiceCount(3);
1005+
});
1006+
});
9941007
});
9951008
});

0 commit comments

Comments
 (0)