-
Notifications
You must be signed in to change notification settings - Fork 91
test(e2e): add editor smoke tests for typing, formulas and slides #197
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
Open
juliusknorr
wants to merge
2
commits into
main
Choose a base branch
from
test/e2e-editor-smoke-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { test, expect } from '@playwright/test'; | ||
| import { openNewEditor, editorApi } from './helpers'; | ||
|
|
||
| test.describe('Document editor - typing and formatting', () => { | ||
| test('type text and apply bold/italic', async ({ page }) => { | ||
| const { editorPage, frame } = await openNewEditor(page, 'a.try-editor.word', /\.docx/); | ||
|
|
||
| await editorPage.keyboard.type('Hello world'); | ||
| await editorPage.keyboard.press('Control+A'); | ||
| await editorPage.keyboard.press('Control+b'); | ||
| await editorPage.keyboard.press('Control+i'); | ||
|
|
||
| // The edit registered: the undo button is no longer disabled. | ||
| await expect(frame.locator('#slot-btn-undo button').first()).not.toHaveClass(/disabled/); | ||
|
|
||
| // The typed text round-trips through the automation API. | ||
| const text = await editorApi(editorPage, (api) => api.asc_GetSelectedText()); | ||
| expect(text).toContain('Hello world'); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import { Page, expect } from '@playwright/test'; | ||
|
|
||
| const EDITOR_IFRAME = 'iframe[name="frameEditor"]'; | ||
|
|
||
| /** | ||
| * Open the example page, create a new document of the requested type, and wait | ||
| * until the editor iframe has finished loading. Returns the editor tab (a new | ||
| * page) and a frameLocator scoped to the editor iframe. | ||
| */ | ||
| export async function openNewEditor(page: Page, selector: string, urlExt: RegExp) { | ||
| await page.goto('/example/'); | ||
| await expect(page).toHaveTitle(/ONLYOFFICE|euro-office/i); | ||
|
|
||
| const newPagePromise = page.context().waitForEvent('page'); | ||
| await page.click(selector); | ||
| const editorPage = await newPagePromise; | ||
|
|
||
| await editorPage.waitForURL(/\/example\/editor/); | ||
| await editorPage.waitForLoadState('domcontentloaded'); | ||
| await expect(editorPage).toHaveURL(urlExt); | ||
|
|
||
| const editorIframe = editorPage.locator(EDITOR_IFRAME); | ||
| await expect(editorIframe).toBeAttached({ timeout: 15_000 }); | ||
|
|
||
| const frame = editorPage.frameLocator(EDITOR_IFRAME); | ||
| await expect(frame.locator('#loading-mask')).toBeHidden({ timeout: 30_000 }); | ||
|
|
||
| await frame.locator('#editor_sdk').click(); | ||
| return { editorPage, frame }; | ||
| } | ||
|
|
||
| /** | ||
| * Evaluate a function against the editor's automation API (window.Asc.editor) | ||
| * inside the editor iframe. The function is serialized, so it must be | ||
| * self-contained (no closures over test scope). | ||
| */ | ||
| export async function editorApi<T>(editorPage: Page, fn: (api: any) => T): Promise<T> { | ||
| const handle = await editorPage.locator(EDITOR_IFRAME).elementHandle(); | ||
| if (!handle) throw new Error('editor iframe not found'); | ||
| const frame = await handle.contentFrame(); | ||
| if (!frame) throw new Error('editor iframe has no content frame'); | ||
|
|
||
| return frame.evaluate((body) => { | ||
| const w = window as unknown as { Asc?: { editor?: unknown } }; | ||
| const api = w.Asc?.editor; | ||
| if (!api) throw new Error('window.Asc.editor not available'); | ||
| // eslint-disable-next-line no-new-func | ||
| return new Function('api', `return (${body})(api);`)(api); | ||
| }, fn.toString()); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { test, expect } from '@playwright/test'; | ||
| import { openNewEditor, editorApi } from './helpers'; | ||
|
|
||
| const slideCount = (p: import('@playwright/test').Page) => | ||
| editorApi(p, (api) => api.getCountPages()); | ||
|
|
||
| test.describe('Presentation editor - building a deck', () => { | ||
| test('create a deck of 3 slides', async ({ page }) => { | ||
| const { editorPage, frame } = await openNewEditor(page, 'a.try-editor.slide', /\.pptx/); | ||
|
|
||
| // A fresh presentation starts with a single slide. | ||
| expect(await slideCount(editorPage)).toBe(1); | ||
|
|
||
| // The Ctrl+M shortcut only fires when the slide-thumbnail panel is focused | ||
| // and toolbar button ids are renamed in this build, so drive slide creation | ||
| // through the automation API (AddSlide) instead. | ||
| await editorApi(editorPage, (api) => { api.AddSlide(); api.AddSlide(); }); | ||
|
|
||
| await expect.poll(() => slideCount(editorPage)).toBe(3); | ||
|
|
||
| // The document was mutated: undo is enabled. | ||
| await expect(frame.locator('#slot-btn-undo button').first()).not.toHaveClass(/disabled/); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { test, expect } from '@playwright/test'; | ||
| import { openNewEditor, editorApi } from './helpers'; | ||
|
|
||
| const cellText = (editorPage: import('@playwright/test').Page) => | ||
| editorApi(editorPage, (api) => { | ||
| const info = api.asc_getCellInfo(); | ||
| return info && info.asc_getText ? info.asc_getText() : null; | ||
| }); | ||
|
|
||
| test.describe('Spreadsheet editor - numbers and formulas', () => { | ||
| test('enter numbers and a formula', async ({ page }) => { | ||
| const { editorPage, frame } = await openNewEditor(page, 'a.try-editor.cell', /\.xlsx/); | ||
| const nameBox = frame.locator('#ce-cell-name'); | ||
| const select = async (cell: string) => { | ||
| await nameBox.fill(cell); | ||
| await nameBox.press('Enter'); | ||
| }; | ||
|
|
||
| // Ctrl+Home guarantees the grid has keyboard focus at A1 (the helper's | ||
| // canvas click can leave an arbitrary cell selected). | ||
| await editorPage.keyboard.press('Control+Home'); | ||
| await editorPage.keyboard.type('5'); | ||
| await editorPage.keyboard.press('Enter'); | ||
| await editorPage.keyboard.type('10'); | ||
| await editorPage.keyboard.press('Enter'); | ||
| await editorPage.keyboard.type('=A1+A2'); | ||
| await editorPage.keyboard.press('Enter'); | ||
|
|
||
| // Operands landed in A1/A2. | ||
| await select('A1'); | ||
| expect(await cellText(editorPage)).toBe('5'); | ||
| await select('A2'); | ||
| expect(await cellText(editorPage)).toBe('10'); | ||
|
|
||
| // The formula was accepted into A3. asc_getText() returns the formula | ||
| // string, not the computed value. | ||
| await select('A3'); | ||
| expect(await cellText(editorPage)).toBe('=A1+A2'); | ||
|
|
||
| // TODO: verify the *computed* value (15). asc_getCellInfo().asc_getText() | ||
| // returns the formula, and pluginMethod_GetSelectedText() returns "" for | ||
| // cell selections, so neither reflects the result. The clipboard route | ||
| // (select A3 -> Ctrl+C -> navigator.clipboard.readText() === '15') works | ||
| // but needs clipboard-read/write permissions wired into the project config. | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commented these lines and the test still passed.
maybe we can test these two bold/italic actions with
Tested it locally, fails commenting line 10-11 and passes with them uncommented.