Skip to content

Commit

Permalink
Fix select-multiple 'checking placeholder values' test
Browse files Browse the repository at this point in the history
  • Loading branch information
Xon committed Aug 21, 2024
1 parent 658658c commit f3ed0d0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
24 changes: 24 additions & 0 deletions test-e2e/select-test-suit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,30 @@ export class SelectTestSuit extends TestSuit {
await this.expectVisibleDropdown();
}

async delayData(): Promise<() => void> {
let stopJsonWaiting = (): void => {};
const jsonWaiting = new Promise<void>((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;
}
Expand Down
6 changes: 4 additions & 2 deletions test-e2e/tests/select-multiple.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
25 changes: 3 additions & 22 deletions test-e2e/tests/select-one.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>((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...');
Expand Down

0 comments on commit f3ed0d0

Please sign in to comment.