Skip to content

Commit

Permalink
Rewrite e2e paste to avoid javascript APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Xon committed Aug 29, 2024
1 parent 9e70971 commit 652a4b6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 10 deletions.
19 changes: 15 additions & 4 deletions test-e2e/test-suit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,23 @@ export class TestSuit {

async pasteText(text: string, _locator?: Locator): Promise<void> {
const locator = _locator || this.input;
await locator.focus();
await this.advanceClock();

await this.page.evaluate(() => {
if (!document.querySelector('textarea#pasteTarget')) {
document.body.insertAdjacentHTML('afterbegin', "<textarea id='pasteTarget'></textarea>");
}
});

const target = this.page.locator('textarea#pasteTarget');
await target.fill(''); // empty any value
await target.fill(text);

await this.crossProcessLock(async () => {
await this.page.evaluate(`navigator.clipboard.writeText('${text}')`);
await this.advanceClock();
await target.selectText(); // Focus & Ctrl+a
await this.ctrlC(target);

await this.selectByClick();

await this.ctrlV(locator);
});

Expand Down
25 changes: 22 additions & 3 deletions test-e2e/tests/select-multiple.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ describe(`Choices - select multiple`, () => {
describe('on paste', () => {
// playwright lacks clipboard isolation, so use serial mode to try to work around it.
// https://github.com/microsoft/playwright/issues/13097
describe.configure({ mode: 'serial' });
describe.configure({ mode: 'serial', timeout: 2000 });

describe('searching by label', () => {
test('displays choices filtered by inputted value', async ({ page, bundle }) => {
Expand Down Expand Up @@ -681,25 +681,44 @@ describe(`Choices - select multiple`, () => {
const choice = suite.selectableChoices.first();
await expect(choice).toHaveText(city);
});

test(`filters choices - ${city}`, async ({ page, bundle }) => {
const suite = new SelectTestSuit(page, bundle, testUrl, testId);
await suite.startWithClick();
await suite.typeText(city);
await suite.expectVisibleDropdown();

const choice = suite.selectableChoices.first();
await expect(choice).toHaveText(city);
});
});
});

describe('on paste', () => {
// playwright lacks clipboard isolation, so use serial mode to try to work around it.
// https://github.com/microsoft/playwright/issues/13097
describe.configure({ mode: 'serial' });
describe.configure({ mode: 'serial', timeout: 30000 });

cities.forEach(({ country, city }) => {
test(`filters choices - ${country} = ${city}`, async ({ page, bundle }) => {
const suite = new SelectTestSuit(page, bundle, testUrl, testId);
await suite.startWithClick();
await suite.expectVisibleDropdown();

await suite.pasteText(country);

const choice = suite.selectableChoices.first();
await expect(choice).toHaveText(city);
});

test(`filters choices - ${city}`, async ({ page, bundle }) => {
const suite = new SelectTestSuit(page, bundle, testUrl, testId);
await suite.startWithClick();

await suite.pasteText(city);

const choice = suite.selectableChoices.first();
await expect(choice).toHaveText(city);
});
});
});
});
Expand Down
25 changes: 22 additions & 3 deletions test-e2e/tests/select-one.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe(`Choices - select one`, () => {
describe('on paste', () => {
// playwright lacks clipboard isolation, so use serial mode to try to work around it.
// https://github.com/microsoft/playwright/issues/13097
describe.configure({ mode: 'serial' });
describe.configure({ mode: 'serial', timeout: 30000 });

describe('searching by label', () => {
test('displays choices filtered by inputted value', async ({ page, bundle }) => {
Expand Down Expand Up @@ -556,25 +556,44 @@ describe(`Choices - select one`, () => {
const choice = suite.selectableChoices.first();
await expect(choice).toHaveText(city);
});

test(`filters choices - ${city}`, async ({ page, bundle }) => {
const suite = new SelectTestSuit(page, bundle, testUrl, testId);
await suite.startWithClick();
await suite.typeText(city);
await suite.expectVisibleDropdown();

const choice = suite.selectableChoices.first();
await expect(choice).toHaveText(city);
});
});
});

describe('on paste', () => {
// playwright lacks clipboard isolation, so use serial mode to try to work around it.
// https://github.com/microsoft/playwright/issues/13097
describe.configure({ mode: 'serial' });
describe.configure({ mode: 'serial', timeout: 30000 });

cities.forEach(({ country, city }) => {
test(`filters choices - ${country} = ${city}`, async ({ page, bundle }) => {
const suite = new SelectTestSuit(page, bundle, testUrl, testId);
await suite.startWithClick();
await suite.expectVisibleDropdown();

await suite.pasteText(country);

const choice = suite.selectableChoices.first();
await expect(choice).toHaveText(city);
});

test(`filters choices - ${city}`, async ({ page, bundle }) => {
const suite = new SelectTestSuit(page, bundle, testUrl, testId);
await suite.startWithClick();

await suite.pasteText(city);

const choice = suite.selectableChoices.first();
await expect(choice).toHaveText(city);
});
});
});
});
Expand Down

0 comments on commit 652a4b6

Please sign in to comment.