From f3ed0d094a4b981869ca0fa4afc98f91a4c2e765 Mon Sep 17 00:00:00 2001 From: Xon <635541+Xon@users.noreply.github.com> Date: Thu, 22 Aug 2024 00:55:05 +0800 Subject: [PATCH] Fix select-multiple 'checking placeholder values' test --- test-e2e/select-test-suit.ts | 24 ++++++++++++++++++++++++ test-e2e/tests/select-multiple.spec.ts | 6 ++++-- test-e2e/tests/select-one.spec.ts | 25 +++---------------------- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/test-e2e/select-test-suit.ts b/test-e2e/select-test-suit.ts index acaad83d..d288f2ff 100644 --- a/test-e2e/select-test-suit.ts +++ b/test-e2e/select-test-suit.ts @@ -25,6 +25,30 @@ export class SelectTestSuit extends TestSuit { await this.expectVisibleDropdown(); } + async delayData(): Promise<() => void> { + let stopJsonWaiting = (): void => {}; + const jsonWaiting = new Promise((f) => { + stopJsonWaiting = f; + }); + + await this.page.route('**/data.json', async (route) => { + await jsonWaiting; + + const fakeData = [...new Array(10)].map((_, index) => ({ + label: `Label ${index + 1}`, + value: `Value ${index + 1}`, + })); + + await route.fulfill({ + status: 200, + contentType: 'application/json', + body: JSON.stringify(fakeData), + }); + }); + + return stopJsonWaiting; + } + getWrappedElement(): Locator { return this.wrappedSelect; } diff --git a/test-e2e/tests/select-multiple.spec.ts b/test-e2e/tests/select-multiple.spec.ts index 7fab67f6..f37be291 100644 --- a/test-e2e/tests/select-multiple.spec.ts +++ b/test-e2e/tests/select-multiple.spec.ts @@ -477,13 +477,15 @@ describe(`Choices - select multiple`, () => { describe('remote data', () => { const testId = 'remote-data'; test('checking placeholder values', async ({ page, bundle }) => { - const jsonLoad = page.waitForResponse('**/data.json'); - const suite = new SelectTestSuit(page, bundle, testUrl, testId); + + const jsonLoad = page.waitForResponse('**/data.json'); + const stopJsonWaiting = await suite.delayData(); await suite.start(); await expect(suite.input).toHaveAttribute('placeholder', 'Loading...'); + stopJsonWaiting(); await jsonLoad; await suite.selectByClick(); diff --git a/test-e2e/tests/select-one.spec.ts b/test-e2e/tests/select-one.spec.ts index f6691a51..aaa3bb64 100644 --- a/test-e2e/tests/select-one.spec.ts +++ b/test-e2e/tests/select-one.spec.ts @@ -400,29 +400,10 @@ describe(`Choices - select one`, () => { describe('remote data', () => { const testId = 'remote-data'; test('checking placeholder values', async ({ page, bundle }) => { - const jsonLoad = page.waitForResponse('**/data.json'); - - let stopJsonWaiting = () => {}; - const jsonWaiting = new Promise((f) => { - stopJsonWaiting = f; - }); - - await page.route('**/data.json', async (route) => { - await jsonWaiting; - - const fakeData = [...new Array(10)].map((_, index) => ({ - label: `Label ${index + 1}`, - value: `Value ${index + 1}`, - })); - - await route.fulfill({ - status: 200, - contentType: 'application/json', - body: JSON.stringify(fakeData), - }); - }); - const suite = new SelectTestSuit(page, bundle, testUrl, testId); + + const jsonLoad = page.waitForResponse('**/data.json'); + const stopJsonWaiting = await suite.delayData(); await suite.start(); await expect(suite.itemList.first()).toHaveText('Loading...');