From 1f6415af0acca709da863cd605f08068e3fe584b Mon Sep 17 00:00:00 2001 From: Xon <635541+Xon@users.noreply.github.com> Date: Mon, 26 Aug 2024 02:43:43 +0800 Subject: [PATCH] Update e2e tests --- .../select-multiple/index-performance.html | 29 ++++++++--- test-e2e/test-suit.ts | 6 +++ .../tests/select-multiple-performance.spec.ts | 52 ++++++++++++++++--- test-e2e/tests/select-multiple.spec.ts | 8 +-- test-e2e/tests/select-one.spec.ts | 4 +- 5 files changed, 81 insertions(+), 18 deletions(-) diff --git a/public/test/select-multiple/index-performance.html b/public/test/select-multiple/index-performance.html index 4eb276a5..80f85222 100644 --- a/public/test/select-multiple/index-performance.html +++ b/public/test/select-multiple/index-performance.html @@ -55,26 +55,43 @@
-

Select one inputs

+

Select multiple inputs

-
diff --git a/test-e2e/test-suit.ts b/test-e2e/test-suit.ts index 50ed0704..0628ca04 100644 --- a/test-e2e/test-suit.ts +++ b/test-e2e/test-suit.ts @@ -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); + }); + } + async start(textInput?: string): Promise { if (this.choicesBundle) { await this.page.route('/assets/scripts/choices.js', (route) => route.continue({ url: this.choicesBundle })); diff --git a/test-e2e/tests/select-multiple-performance.spec.ts b/test-e2e/tests/select-multiple-performance.spec.ts index 428cd070..963f025e 100644 --- a/test-e2e/tests/select-multiple-performance.spec.ts +++ b/test-e2e/tests/select-multiple-performance.spec.ts @@ -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', () => { @@ -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'); + }); }); }); diff --git a/test-e2e/tests/select-multiple.spec.ts b/test-e2e/tests/select-multiple.spec.ts index 37296279..704d10f4 100644 --- a/test-e2e/tests/select-multiple.spec.ts +++ b/test-e2e/tests/select-multiple.spec.ts @@ -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 }) => { @@ -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(); @@ -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(); diff --git a/test-e2e/tests/select-one.spec.ts b/test-e2e/tests/select-one.spec.ts index 5f07a497..7e7b9fb5 100644 --- a/test-e2e/tests/select-one.spec.ts +++ b/test-e2e/tests/select-one.spec.ts @@ -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 }) => { @@ -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); }); });