Skip to content

Commit

Permalink
Migrate existing puppeteer scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Nov 14, 2022
1 parent a92833a commit e1136dc
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 516 deletions.
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: 210 additions & 5 deletions e2e/basic.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +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('homepage has title and links to intro page', async ({ page }) => {
await page.goto('http://localhost:9000/standalone/full/');

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 });

// Expect a title "to contain" a substring.
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

0 comments on commit e1136dc

Please sign in to comment.