diff --git a/_develop/scripts/puppeteer.sh b/_develop/scripts/puppeteer.sh deleted file mode 100755 index aa040fe7eb..0000000000 --- a/_develop/scripts/puppeteer.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -npm start & -sleep 20 -./node_modules/.bin/jasmine test/functional/epic.js -EXIT_CODE=$? - -FOREMAN_PID=$(pgrep foreman) -kill -s SIGINT $FOREMAN_PID - -exit $EXIT_CODE diff --git a/_develop/wdio.config.js b/_develop/wdio.config.js deleted file mode 100644 index f6eab1d481..0000000000 --- a/_develop/wdio.config.js +++ /dev/null @@ -1,34 +0,0 @@ -exports.config = { - specs: ['./test/functional/epic.js'], - exclude: [], - - reporters: ['spec'], - - maxInstances: 10, - capabilities: [ - { - browserName: 'chrome', - }, - ], - - sync: true, - logLevel: 'error', - coloredLogs: true, - - baseUrl: `http://localhost:${process.env.npm_package_config_ports_proxy}`, - - waitforTimeout: 10000, - connectionRetryTimeout: 90000, - connectionRetryCount: 3, - - framework: 'jasmine', - jasmineNodeOpts: { - defaultTimeoutInterval: 10000, - expectationResultHandler: passed => { - if (passed) return; - this.saveScreenshot( - `./wd-${this.desiredCapabilities.browserName}-error.png`, - ); - }, - }, -}; diff --git a/e2e/basic.spec.ts b/e2e/basic.spec.ts index 1f66ede25d..048a13a412 100644 --- a/e2e/basic.spec.ts +++ b/e2e/basic.spec.ts @@ -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('

The Whale

'); + + await page.keyboard.press('Enter'); + expect(await quillPage.editorHTML()).toEqual('

The Whale


'); + + 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( + [ + '

The Whale

', + '


', + `

\t${P1}

`, + '


', + `

${P2}

`, + ].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( + [ + '

The Whale

', + '


', + `

${CHAPTER}

`, + '


', + `

\t${P1}

`, + '


', + `

${P2}

`, + ].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( + [ + '

Whale

', + '


', + `

${CHAPTER}

`, + '


', + `

\t${P1}

`, + '


', + `

${P2}

`, + ].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( + [ + '


', + '


', + `

${CHAPTER}

`, + '


', + `

\t${P1}

`, + '


', + `

${P2}

`, + ].join(''), + ); + + await page.keyboard.press('Delete'); + expect(await quillPage.editorHTML()).toEqual( + [ + '


', + `

${CHAPTER}

`, + '


', + `

\t${P1}

`, + '


', + `

${P2}

`, + ].join(''), + ); + + await page.click('.ql-toolbar .ql-bold'); + await page.click('.ql-toolbar .ql-italic'); + expect(await quillPage.editorHTML()).toEqual( + [ + '

\uFEFF

', + `

${CHAPTER}

`, + '


', + `

\t${P1}

`, + '


', + `

${P2}

`, + ].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( + [ + '

Moby Dick

', + `

${CHAPTER}

`, + '


', + `

\t${P1}

`, + '


', + `

${P2}

`, + ].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( + [ + '

Moby Dick

', + `

${CHAPTER}

`, + '


', + `

\t${P1}

`, + '


', + `

${P2}

`, + ].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( + [ + '

Moby Dick

', + `

${CHAPTER}

`, + '


', + `

\t${P1}

`, + '


', + `

${P2}

`, + ].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( + 'ABCDA', + ); + const selection = await page.evaluate(getSelectionInTextNode); + expect(selection).toBe('["DA",1,"DA",1]'); }); diff --git a/e2e/utils/QuillPage.ts b/e2e/utils/QuillPage.ts new file mode 100644 index 0000000000..ed1b809372 --- /dev/null +++ b/e2e/utils/QuillPage.ts @@ -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; diff --git a/e2e/utils/fixtures.ts b/e2e/utils/fixtures.ts new file mode 100644 index 0000000000..20a0e7aa84 --- /dev/null +++ b/e2e/utils/fixtures.ts @@ -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.'; diff --git a/e2e/utils/index.ts b/e2e/utils/index.ts new file mode 100644 index 0000000000..f136df2582 --- /dev/null +++ b/e2e/utils/index.ts @@ -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, + ]); +} diff --git a/package-lock.json b/package-lock.json index a2db117ed9..130932b1e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -49,7 +49,6 @@ "mini-css-extract-plugin": "^2.6.1", "npm-run-all": "^4.1.5", "prettier": "^2.7.1", - "puppeteer": "^19.0.0", "style-loader": "^3.3.1", "stylus": "^0.59.0", "stylus-loader": "^7.0.0", @@ -5117,18 +5116,6 @@ "node": ">=8.9" } }, - "node_modules/agent-base": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", - "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", - "dev": true, - "dependencies": { - "debug": "4" - }, - "engines": { - "node": ">= 6.0.0" - } - }, "node_modules/ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -8588,12 +8575,6 @@ "node": ">=10.0.0" } }, - "node_modules/devtools-protocol": { - "version": "0.0.1045489", - "resolved": "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.1045489.tgz", - "integrity": "sha512-D+PTmWulkuQW4D1NTiCRCFxF7pQPn0hgp4YyX4wAQ6xYXKOadSWPR3ENGDQ47MW/Ewc9v2rpC/UEEGahgBYpSQ==", - "dev": true - }, "node_modules/devtools/node_modules/agent-base": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-5.1.1.tgz", @@ -13953,19 +13934,6 @@ "node": ">=10.19.0" } }, - "node_modules/https-proxy-agent": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", - "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", - "dev": true, - "dependencies": { - "agent-base": "6", - "debug": "4" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/human-signals": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", @@ -19281,44 +19249,6 @@ "node": ">=8" } }, - "node_modules/puppeteer": { - "version": "19.1.1", - "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-19.1.1.tgz", - "integrity": "sha512-nyIytOp1mYagiVeKkWODuMAGJoeQkcGNy7utkm2BN2d2r90n1ezO1tM4ld2V3vpP4u2kGk20obqv/Lj0Icd3KA==", - "dev": true, - "hasInstallScript": true, - "dependencies": { - "cosmiconfig": "7.0.1", - "https-proxy-agent": "5.0.1", - "progress": "2.0.3", - "proxy-from-env": "1.1.0", - "puppeteer-core": "19.1.1" - }, - "engines": { - "node": ">=14.1.0" - } - }, - "node_modules/puppeteer-core": { - "version": "19.1.1", - "resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-19.1.1.tgz", - "integrity": "sha512-jV26Ke0VFel4MoXLjqm50uAW2uwksTP6Md1tvtXqWqXM5FyboKI6E9YYJ1qEQilUAqlhgGq8xLN5+SL8bPz/kw==", - "dev": true, - "dependencies": { - "cross-fetch": "3.1.5", - "debug": "4.3.4", - "devtools-protocol": "0.0.1045489", - "extract-zip": "2.0.1", - "https-proxy-agent": "5.0.1", - "proxy-from-env": "1.1.0", - "rimraf": "3.0.2", - "tar-fs": "2.1.1", - "unbzip2-stream": "1.4.3", - "ws": "8.9.0" - }, - "engines": { - "node": ">=14.1.0" - } - }, "node_modules/qjobs": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/qjobs/-/qjobs-1.2.0.tgz", @@ -28335,15 +28265,6 @@ "regex-parser": "^2.2.11" } }, - "agent-base": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", - "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", - "dev": true, - "requires": { - "debug": "4" - } - }, "ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -31033,12 +30954,6 @@ } } }, - "devtools-protocol": { - "version": "0.0.1045489", - "resolved": "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.1045489.tgz", - "integrity": "sha512-D+PTmWulkuQW4D1NTiCRCFxF7pQPn0hgp4YyX4wAQ6xYXKOadSWPR3ENGDQ47MW/Ewc9v2rpC/UEEGahgBYpSQ==", - "dev": true - }, "di": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/di/-/di-0.0.1.tgz", @@ -34938,16 +34853,6 @@ "resolve-alpn": "^1.0.0" } }, - "https-proxy-agent": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", - "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", - "dev": true, - "requires": { - "agent-base": "6", - "debug": "4" - } - }, "human-signals": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", @@ -38748,37 +38653,6 @@ "escape-goat": "^2.0.0" } }, - "puppeteer": { - "version": "19.1.1", - "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-19.1.1.tgz", - "integrity": "sha512-nyIytOp1mYagiVeKkWODuMAGJoeQkcGNy7utkm2BN2d2r90n1ezO1tM4ld2V3vpP4u2kGk20obqv/Lj0Icd3KA==", - "dev": true, - "requires": { - "cosmiconfig": "7.0.1", - "https-proxy-agent": "5.0.1", - "progress": "2.0.3", - "proxy-from-env": "1.1.0", - "puppeteer-core": "19.1.1" - } - }, - "puppeteer-core": { - "version": "19.1.1", - "resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-19.1.1.tgz", - "integrity": "sha512-jV26Ke0VFel4MoXLjqm50uAW2uwksTP6Md1tvtXqWqXM5FyboKI6E9YYJ1qEQilUAqlhgGq8xLN5+SL8bPz/kw==", - "dev": true, - "requires": { - "cross-fetch": "3.1.5", - "debug": "4.3.4", - "devtools-protocol": "0.0.1045489", - "extract-zip": "2.0.1", - "https-proxy-agent": "5.0.1", - "proxy-from-env": "1.1.0", - "rimraf": "3.0.2", - "tar-fs": "2.1.1", - "unbzip2-stream": "1.4.3", - "ws": "8.9.0" - } - }, "qjobs": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/qjobs/-/qjobs-1.2.0.tgz", diff --git a/package.json b/package.json index a4db4f866d..af679931f1 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,6 @@ "mini-css-extract-plugin": "^2.6.1", "npm-run-all": "^4.1.5", "prettier": "^2.7.1", - "puppeteer": "^19.0.0", "style-loader": "^3.3.1", "stylus": "^0.59.0", "stylus-loader": "^7.0.0", @@ -98,7 +97,7 @@ "website:develop": "npm run develop -w website -- --port $npm_package_config_ports_gatsby", "test": "npm run test:unit; npm run test:random", "test:all": "npm run test:unit; npm run test:functional; npm run test:random", - "test:functional": "./_develop/scripts/puppeteer.sh", + "test:e2e": "npx playwright test", "test:unit": "npm run build; karma start _develop/karma.config.js", "test:unit:ci": "npm run build; karma start _develop/karma.config.js --reporters dots,saucelabs", "test:random": "ts-node --preferTsExts -O '{\"module\":\"commonjs\"}' ./node_modules/.bin/jasmine test/random.ts", diff --git a/playwright.config.ts b/playwright.config.ts index d0f6036a4a..edd7709124 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,108 +1,28 @@ import type { PlaywrightTestConfig } from '@playwright/test'; import { devices } from '@playwright/test'; -/** - * Read environment variables from file. - * https://github.com/motdotla/dotenv - */ -// require('dotenv').config(); - -/** - * See https://playwright.dev/docs/test-configuration. - */ const config: PlaywrightTestConfig = { testDir: './e2e', testMatch: '*.spec.ts', - /* Maximum time one test can run for. */ timeout: 30 * 1000, expect: { - /** - * Maximum time expect() should wait for the condition to be met. - * For example in `await expect(locator).toHaveText();` - */ timeout: 5000, }, - /* Run tests in files in parallel */ fullyParallel: true, - /* Fail the build on CI if you accidentally left test.only in the source code. */ forbidOnly: !!process.env.CI, - /* Retry on CI only */ retries: process.env.CI ? 2 : 0, - /* Opt out of parallel tests on CI. */ workers: process.env.CI ? 1 : undefined, - /* Reporter to use. See https://playwright.dev/docs/test-reporters */ reporter: 'list', - /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ use: { - /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */ actionTimeout: 0, - /* Base URL to use in actions like `await page.goto('/')`. */ - // baseURL: 'http://localhost:3000', - - /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: 'on-first-retry', }, - - /* Configure projects for major browsers */ projects: [ - { - name: 'chromium', - use: { - ...devices['Desktop Chrome'], - }, - }, - - { - name: 'firefox', - use: { - ...devices['Desktop Firefox'], - }, - }, - - { - name: 'webkit', - use: { - ...devices['Desktop Safari'], - }, - }, - - /* Test against mobile viewports. */ - // { - // name: 'Mobile Chrome', - // use: { - // ...devices['Pixel 5'], - // }, - // }, - // { - // name: 'Mobile Safari', - // use: { - // ...devices['iPhone 12'], - // }, - // }, - - /* Test against branded browsers. */ - // { - // name: 'Microsoft Edge', - // use: { - // channel: 'msedge', - // }, - // }, - // { - // name: 'Google Chrome', - // use: { - // channel: 'chrome', - // }, - // }, + { name: 'Chrome', use: { ...devices['Desktop Chrome'] } }, + { name: 'Firefox', use: { ...devices['Desktop Firefox'] } }, + { name: 'Safari', use: { ...devices['Desktop Safari'] } }, + { name: 'Edge', use: { channel: 'msedge' } }, ], - - /* Folder for test artifacts such as screenshots, videos, traces, etc. */ - // outputDir: 'test-results/', - - /* Run your local dev server before starting the tests */ - // webServer: { - // command: 'npm run start', - // port: 3000, - // }, }; export default config; diff --git a/test/functional/epic.js b/test/functional/epic.js deleted file mode 100644 index 4ba99ab084..0000000000 --- a/test/functional/epic.js +++ /dev/null @@ -1,254 +0,0 @@ -const puppeteer = require('puppeteer'); - -jasmine.DEFAULT_TIMEOUT_INTERVAL = 100000; - -const SHORTKEY = process.platform === 'darwin' ? 'Meta' : 'Control'; - -const CHAPTER = 'Chapter 1. Loomings.'; -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.'; -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.'; - -describe('quill', function () { - it('compose an epic', async function () { - const browser = await puppeteer.launch({ - headless: false, - }); - const page = await browser.newPage(); - - await page.goto('http://localhost:9000/standalone/full/'); - await page.waitForSelector('.ql-editor', { timeout: 10000 }); - const title = await page.title(); - expect(title).toEqual('Full Editor - Quill Rich Text Editor'); - - await page.type('.ql-editor', 'The Whale'); - let html = await page.$eval('.ql-editor', e => e.innerHTML); - expect(html).toEqual('

The Whale

'); - - await page.keyboard.press('Enter'); - html = await page.$eval('.ql-editor', e => e.innerHTML); - expect(html).toEqual('

The Whale


'); - - 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); - html = await page.$eval('.ql-editor', e => e.innerHTML); - expect(html).toEqual( - [ - '

The Whale

', - '


', - `

\t${P1}

`, - '


', - `

${P2}

`, - ].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'); - html = await page.$eval('.ql-editor', e => e.innerHTML); - expect(html).toEqual( - [ - '

The Whale

', - '


', - `

${CHAPTER}

`, - '


', - `

\t${P1}

`, - '


', - `

${P2}

`, - ].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'); - html = await page.$eval('.ql-editor', e => e.innerHTML); - expect(html).toEqual( - [ - '

Whale

', - '


', - `

${CHAPTER}

`, - '


', - `

\t${P1}

`, - '


', - `

${P2}

`, - ].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'); - html = await page.$eval('.ql-editor', e => e.innerHTML); - expect(html).toEqual( - [ - '


', - '


', - `

${CHAPTER}

`, - '


', - `

\t${P1}

`, - '


', - `

${P2}

`, - ].join(''), - ); - - await page.keyboard.press('Delete'); - html = await page.$eval('.ql-editor', e => e.innerHTML); - expect(html).toEqual( - [ - '


', - `

${CHAPTER}

`, - '


', - `

\t${P1}

`, - '


', - `

${P2}

`, - ].join(''), - ); - - await page.click('.ql-toolbar .ql-bold'); - await page.click('.ql-toolbar .ql-italic'); - html = await page.$eval('.ql-editor', e => e.innerHTML); - expect(html).toEqual( - [ - '

\uFEFF

', - `

${CHAPTER}

`, - '


', - `

\t${P1}

`, - '


', - `

${P2}

`, - ].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'); - html = await page.$eval('.ql-editor', e => e.innerHTML); - expect(html).toEqual( - [ - '

Moby Dick

', - `

${CHAPTER}

`, - '


', - `

\t${P1}

`, - '


', - `

${P2}

`, - ].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); - html = await page.$eval('.ql-editor', e => e.innerHTML); - expect(html).toEqual( - [ - '

Moby Dick

', - `

${CHAPTER}

`, - '


', - `

\t${P1}

`, - '


', - `

${P2}

`, - ].join(''), - ); - - await page.keyboard.press('ArrowLeft'); - await page.keyboard.press('ArrowUp'); - await page.click('.ql-toolbar .ql-header[value="1"]'); - html = await page.$eval('.ql-editor', e => e.innerHTML); - expect(html).toEqual( - [ - '

Moby Dick

', - `

${CHAPTER}

`, - '


', - `

\t${P1}

`, - '


', - `

${P2}

`, - ].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'); - html = await page.$$eval('.ql-editor p', paras => paras[2].innerHTML); - expect(html).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'); - html = await page.$$eval('.ql-editor p', paras => paras[2].innerHTML); - expect(html).toBe('ABCDA'); - const selection = await page.evaluate(getSelectionInTextNode); - expect(selection).toBe('["DA",1,"DA",1]'); - - // await page.waitFor(1000000); - await browser.close(); - }); -}); - -function getSelectionInTextNode() { - const { anchorNode, anchorOffset, focusNode, focusOffset } = - document.getSelection(); - return JSON.stringify([ - anchorNode.data, - anchorOffset, - focusNode.data, - focusOffset, - ]); -}