Skip to content

Commit

Permalink
Update e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Xon committed Aug 25, 2024
1 parent d969bde commit 1f6415a
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 18 deletions.
29 changes: 23 additions & 6 deletions public/test/select-multiple/index-performance.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,43 @@
<body>
<div class="container">
<div class="section">
<h2>Select one inputs</h2>
<h2>Select multiple inputs</h2>
<div data-test-hook="basic">
<label for="choices-basic">Basic</label>
<select class="form-control" name="choices-basic" id="choices-basic" multiple>
<button class="disable push-bottom">Disable</button>
<button class="enable push-bottom">Enable</button>
<select
class="form-control"
name="choices-basic"
id="choices-basic"
multiple
>
</select>
<script>
document.addEventListener('DOMContentLoaded', function() {

const options = [...new Array(2000)].map((_, index) => ({
selected: !!(index % 2),
label: `Choice ${index + 1}`,
value: `Choice ${index + 1}`,
label: `Choice ${index + 1}$`,
value: `Choice ${index + 1}$`,
}));

const choices = new Choices('#choices-basic', {
allowHTML: true,
shouldSort: false,
removeItemButton: true,
choices: options
choices: options,
});
document
.querySelector('button.disable')
.addEventListener('click', () => {
choices.disable();
});

document
.querySelector('button.enable')
.addEventListener('click', () => {
choices.enable();
});
});
</script>
</div>
Expand Down
6 changes: 6 additions & 0 deletions test-e2e/test-suit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ export class TestSuit {
this.dropdown = this.group.locator('.choices__list.choices__list--dropdown');
}

logConsole(): void {
this.page.on('console', (msg) => {
console.log(msg);

Check warning on line 39 in test-e2e/test-suit.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
});
}

async start(textInput?: string): Promise<void> {
if (this.choicesBundle) {
await this.page.route('/assets/scripts/choices.js', (route) => route.continue({ url: this.choicesBundle }));
Expand Down
52 changes: 46 additions & 6 deletions test-e2e/tests/select-multiple-performance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { describe } = test;
const testUrl = '/test/select-multiple/index-performance.html';

describe(`Choices - select multiple (performance tests)`, () => {
test.setTimeout(30000);
// test.setTimeout(30000);

describe('scenarios', () => {
describe('basic', () => {
Expand Down Expand Up @@ -38,23 +38,63 @@ describe(`Choices - select multiple (performance tests)`, () => {
});

describe('selecting choices', () => {
const selectedChoiceText = 'Choice 1';
const selectedChoiceText = 'Choice 1$';

test('allows selecting choices from dropdown', async ({ page, bundle }) => {
const suite = new SelectTestSuit(page, bundle, testUrl, testId);
await suite.startWithClick();

await suite.choices.first().click();
await expect(suite.itemList.last()).toHaveText(selectedChoiceText);
await expect(suite.items.last()).toHaveText(selectedChoiceText);
});

test('does not remove selected choice from dropdown list', async ({ page, bundle }) => {
test('remove selected choice from dropdown list', async ({ page, bundle }) => {
const suite = new SelectTestSuit(page, bundle, testUrl, testId);
await suite.startWithClick();

await suite.choices.first().click();
await expect(suite.choices.first()).toHaveText(selectedChoiceText);
await expect(suite.itemList.last()).toHaveText(selectedChoiceText);
await expect(suite.choices.first()).not.toHaveText(selectedChoiceText);
await expect(suite.items.last()).toHaveText(selectedChoiceText);
});

test('multiple choices', async ({ page, bundle }) => {
const suite = new SelectTestSuit(page, bundle, testUrl, testId);
await suite.startWithClick();

await suite.expectedItemCount(1000);
await suite.expectChoiceCount(1000);
await suite.expectVisibleDropdown();

await suite.getChoiceWithText('Choice 1$').click();
await suite.expectedItemCount(1001);
await suite.expectChoiceCount(999);
await suite.expectVisibleDropdown();

await suite.getChoiceWithText('Choice 3$').click();
await suite.expectedItemCount(1002);
await suite.expectChoiceCount(998);
await suite.expectVisibleDropdown();
});

describe('slowly', () => {
test.setTimeout(30000);
test('all available choices', async ({ page, bundle }) => {
const suite = new SelectTestSuit(page, bundle, testUrl, testId);
await suite.startWithClick();

const itemCount = await suite.items.count();
const count = await suite.choices.count();

for (let i = 1; i < count + 1; i++) {
await suite.expectVisibleDropdown();
await suite.getChoiceWithText(`Choice ${i * 2 - 1}$`).click();
await suite.advanceClock();
await suite.expectedItemCount(itemCount + i);
await expect(suite.selectableChoices).toHaveCount(count - i);
}

await suite.expectVisibleNoticeHtml('No choices to choose from');
});
});
});

Expand Down
8 changes: 4 additions & 4 deletions test-e2e/tests/select-multiple.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe(`Choices - select multiple`, () => {
await suite.startWithClick();

await suite.choices.first().click();
await expect(suite.itemList.last()).toHaveText(selectedChoiceText);
await expect(suite.items.last()).toHaveText(selectedChoiceText);
});

test('remove selected choice from dropdown list', async ({ page, bundle }) => {
Expand All @@ -53,10 +53,10 @@ describe(`Choices - select multiple`, () => {

await suite.choices.first().click();
await expect(suite.choices.first()).not.toHaveText(selectedChoiceText);
await expect(suite.itemList.last()).toHaveText(selectedChoiceText);
await expect(suite.items.last()).toHaveText(selectedChoiceText);
});

test('selecting multiple choices', async ({ page, bundle }) => {
test('multiple choices', async ({ page, bundle }) => {
const suite = new SelectTestSuit(page, bundle, testUrl, testId);
await suite.startWithClick();

Expand All @@ -75,7 +75,7 @@ describe(`Choices - select multiple`, () => {
await suite.expectVisibleDropdown();
});

test('selecting all available choices', async ({ page, bundle }) => {
test('all available choices', async ({ page, bundle }) => {
const suite = new SelectTestSuit(page, bundle, testUrl, testId);
await suite.startWithClick();

Expand Down
4 changes: 2 additions & 2 deletions test-e2e/tests/select-one.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe(`Choices - select one`, () => {
await suite.startWithClick();

await suite.choices.first().click();
await expect(suite.itemList.last()).toHaveText(selectedChoiceText);
await expect(suite.items.last()).toHaveText(selectedChoiceText);
});

test('does not remove selected choice from dropdown list', async ({ page, bundle }) => {
Expand All @@ -53,7 +53,7 @@ describe(`Choices - select one`, () => {

await suite.choices.first().click();
await expect(suite.choices.first()).toHaveText(selectedChoiceText);
await expect(suite.itemList.last()).toHaveText(selectedChoiceText);
await expect(suite.items.last()).toHaveText(selectedChoiceText);
});
});

Expand Down

0 comments on commit 1f6415a

Please sign in to comment.