Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Playwright for E2E tests #3695

Merged
merged 3 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/_e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: E2E Tests
on:
workflow_call:
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: |
npm start &
sleep 120
npx playwright test
2 changes: 1 addition & 1 deletion .github/workflows/test.yml → .github/workflows/_unit.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Unit Tests
on:
workflow_call:

jobs:
test:
runs-on: ubuntu-latest
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ concurrency:
cancel-in-progress: true

jobs:
test:
uses: ./.github/workflows/test.yml
unit:
uses: ./.github/workflows/_unit.yml
e2e:
uses: ./.github/workflows/_e2e.yml
6 changes: 4 additions & 2 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ on:
branches: [develop]

jobs:
test:
uses: ./.github/workflows/test.yml
unit:
uses: ./.github/workflows/_unit.yml
e2e:
uses: ./.github/workflows/_e2e.yml
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ test/random.js

core.js
quill.js
/test-results/
/playwright-report/
/playwright/.cache/
11 changes: 0 additions & 11 deletions _develop/scripts/puppeteer.sh

This file was deleted.

34 changes: 0 additions & 34 deletions _develop/wdio.config.js

This file was deleted.

215 changes: 215 additions & 0 deletions e2e/full.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
import { test, expect } from '@playwright/test';
import { getSelectionInTextNode, SHORTKEY } from './utils';
import { CHAPTER, P1, P2 } from './utils/fixtures';
import QuillPage from './utils/QuillPage';

test('compose an epic', async ({ page }) => {
await page.goto('http://localhost:9000/standalone/full');
const quillPage = new QuillPage(page);
await page.waitForSelector('.ql-editor', { timeout: 10000 });
await expect(page).toHaveTitle('Full Editor - Quill Rich Text Editor');

await page.type('.ql-editor', 'The Whale');
expect(await quillPage.editorHTML()).toEqual('<p>The Whale</p>');

await page.keyboard.press('Enter');
expect(await quillPage.editorHTML()).toEqual('<p>The Whale</p><p><br></p>');

await page.keyboard.press('Enter');
await page.keyboard.press('Tab');
await page.type('.ql-editor', P1);
await page.keyboard.press('Enter');
await page.keyboard.press('Enter');
await page.type('.ql-editor', P2);
expect(await quillPage.editorHTML()).toEqual(
[
'<p>The Whale</p>',
'<p><br></p>',
`<p>\t${P1}</p>`,
'<p><br></p>',
`<p>${P2}</p>`,
].join(''),
);

// More than enough to get to top
await Promise.all(
Array(40)
.fill(0)
.map(() => page.keyboard.press('ArrowUp')),
);
await page.keyboard.press('ArrowDown');
await page.keyboard.press('Enter');
await page.type('.ql-editor', CHAPTER);
await page.keyboard.press('Enter');
expect(await quillPage.editorHTML()).toEqual(
[
'<p>The Whale</p>',
'<p><br></p>',
`<p>${CHAPTER}</p>`,
'<p><br></p>',
`<p>\t${P1}</p>`,
'<p><br></p>',
`<p>${P2}</p>`,
].join(''),
);

// More than enough to get to top
await Promise.all(
Array(20)
.fill(0)
.map(() => page.keyboard.press('ArrowUp')),
);
await page.keyboard.press('ArrowRight');
await page.keyboard.press('ArrowRight');
await page.keyboard.press('ArrowRight');
await page.keyboard.press('ArrowRight');
await page.keyboard.press('Backspace');
await page.keyboard.press('Backspace');
await page.keyboard.press('Backspace');
await page.keyboard.press('Backspace');
expect(await quillPage.editorHTML()).toEqual(
[
'<p>Whale</p>',
'<p><br></p>',
`<p>${CHAPTER}</p>`,
'<p><br></p>',
`<p>\t${P1}</p>`,
'<p><br></p>',
`<p>${P2}</p>`,
].join(''),
);

await page.keyboard.press('Delete');
await page.keyboard.press('Delete');
await page.keyboard.press('Delete');
await page.keyboard.press('Delete');
await page.keyboard.press('Delete');
expect(await quillPage.editorHTML()).toEqual(
[
'<p><br></p>',
'<p><br></p>',
`<p>${CHAPTER}</p>`,
'<p><br></p>',
`<p>\t${P1}</p>`,
'<p><br></p>',
`<p>${P2}</p>`,
].join(''),
);

await page.keyboard.press('Delete');
expect(await quillPage.editorHTML()).toEqual(
[
'<p><br></p>',
`<p>${CHAPTER}</p>`,
'<p><br></p>',
`<p>\t${P1}</p>`,
'<p><br></p>',
`<p>${P2}</p>`,
].join(''),
);

await page.click('.ql-toolbar .ql-bold');
await page.click('.ql-toolbar .ql-italic');
expect(await quillPage.editorHTML()).toEqual(
[
'<p><strong><em><span class="ql-cursor">\uFEFF</span></em></strong></p>',
`<p>${CHAPTER}</p>`,
'<p><br></p>',
`<p>\t${P1}</p>`,
'<p><br></p>',
`<p>${P2}</p>`,
].join(''),
);
let bold = await page.$('.ql-toolbar .ql-bold.ql-active');
let italic = await page.$('.ql-toolbar .ql-italic.ql-active');
expect(bold).not.toBe(null);
expect(italic).not.toBe(null);

await page.type('.ql-editor', 'Moby Dick');
expect(await quillPage.editorHTML()).toEqual(
[
'<p><strong><em>Moby Dick</em></strong></p>',
`<p>${CHAPTER}</p>`,
'<p><br></p>',
`<p>\t${P1}</p>`,
'<p><br></p>',
`<p>${P2}</p>`,
].join(''),
);
bold = await page.$('.ql-toolbar .ql-bold.ql-active');
italic = await page.$('.ql-toolbar .ql-italic.ql-active');
expect(bold).not.toBe(null);
expect(italic).not.toBe(null);

await page.keyboard.press('ArrowRight');
await page.keyboard.down('Shift');
await Promise.all(
Array(CHAPTER.length)
.fill(0)
.map(() => page.keyboard.press('ArrowRight')),
);
await page.keyboard.up('Shift');
bold = await page.$('.ql-toolbar .ql-bold.ql-active');
italic = await page.$('.ql-toolbar .ql-italic.ql-active');
expect(bold).toBe(null);
expect(italic).toBe(null);

await page.keyboard.down(SHORTKEY);
await page.keyboard.press('b');
await page.keyboard.up(SHORTKEY);
bold = await page.$('.ql-toolbar .ql-bold.ql-active');
expect(bold).not.toBe(null);
expect(await quillPage.editorHTML()).toEqual(
[
'<p><strong><em>Moby Dick</em></strong></p>',
`<p><strong>${CHAPTER}</strong></p>`,
'<p><br></p>',
`<p>\t${P1}</p>`,
'<p><br></p>',
`<p>${P2}</p>`,
].join(''),
);

await page.keyboard.press('ArrowLeft');
await page.keyboard.press('ArrowUp');
await page.click('.ql-toolbar .ql-header[value="1"]');
expect(await quillPage.editorHTML()).toEqual(
[
'<h1><strong><em>Moby Dick</em></strong></h1>',
`<p><strong>${CHAPTER}</strong></p>`,
'<p><br></p>',
`<p>\t${P1}</p>`,
'<p><br></p>',
`<p>${P2}</p>`,
].join(''),
);
const header = await page.$('.ql-toolbar .ql-header.ql-active[value="1"]');
expect(header).not.toBe(null);

await page.keyboard.press('ArrowDown');
await page.keyboard.press('ArrowDown');
await page.keyboard.press('Enter');
await page.keyboard.press('Enter');
await page.keyboard.press('ArrowUp');
await page.type('.ql-editor', 'AA');
await page.keyboard.press('ArrowLeft');
await page.keyboard.down(SHORTKEY);
await page.keyboard.press('b');
await page.keyboard.press('b');
await page.keyboard.up(SHORTKEY);
await page.type('.ql-editor', 'B');
expect(await quillPage.root.locator('p').nth(2).innerHTML()).toBe('ABA');
await page.keyboard.down(SHORTKEY);
await page.keyboard.press('b');
await page.keyboard.up(SHORTKEY);
await page.type('.ql-editor', 'C');
await page.keyboard.down(SHORTKEY);
await page.keyboard.press('b');
await page.keyboard.up(SHORTKEY);
await page.type('.ql-editor', 'D');
expect(await quillPage.root.locator('p').nth(2).innerHTML()).toBe(
'AB<strong>C</strong>DA',
);
const selection = await page.evaluate(getSelectionInTextNode);
expect(selection).toBe('["DA",1,"DA",1]');
});
15 changes: 15 additions & 0 deletions e2e/utils/QuillPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Page } from '@playwright/test';

class QuillPage {
constructor(private page: Page) {}

get root() {
return this.page.locator('.ql-editor');
}

editorHTML() {
return this.root.innerHTML();
}
}

export default QuillPage;
5 changes: 5 additions & 0 deletions e2e/utils/fixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const CHAPTER = 'Chapter 1. Loomings.';
export const P1 =
'Call me Ishmael. Some years ago—never mind how long precisely-having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world. It is a way I have of driving off the spleen and regulating the circulation. Whenever I find myself growing grim about the mouth; whenever it is a damp, drizzly November in my soul; whenever I find myself involuntarily pausing before coffin warehouses, and bringing up the rear of every funeral I meet; and especially whenever my hypos get such an upper hand of me, that it requires a strong moral principle to prevent me from deliberately stepping into the street, and methodically knocking people’s hats off—then, I account it high time to get to sea as soon as I can. This is my substitute for pistol and ball. With a philosophical flourish Cato throws himself upon his sword; I quietly take to the ship. There is nothing surprising in this. If they but knew it, almost all men in their degree, some time or other, cherish very nearly the same feelings towards the ocean with me.';
export const P2 =
'There now is your insular city of the Manhattoes, belted round by wharves as Indian isles by coral reefs—commerce surrounds it with her surf. Right and left, the streets take you waterward. Its extreme downtown is the battery, where that noble mole is washed by waves, and cooled by breezes, which a few hours previous were out of sight of land. Look at the crowds of water-gazers there.';
12 changes: 12 additions & 0 deletions e2e/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const SHORTKEY = process.platform === 'darwin' ? 'Meta' : 'Control';

export function getSelectionInTextNode() {
const { anchorNode, anchorOffset, focusNode, focusOffset } =
document.getSelection();
return JSON.stringify([
(anchorNode as Text).data,
anchorOffset,
(focusNode as Text).data,
focusOffset,
]);
}
Loading