|
3 | 3 | * SPDX-License-Identifier: AGPL-3.0-or-later |
4 | 4 | */ |
5 | 5 |
|
6 | | -import { type CDPSession, expect, mergeTests } from '@playwright/test' |
| 6 | +import { expect, mergeTests } from '@playwright/test' |
| 7 | +import { test as editorTest } from '../support/fixtures/editor' |
| 8 | +import { test as offlineTest } from '../support/fixtures/offline' |
7 | 9 | import { test as randomUserTest } from '../support/fixtures/random-user' |
8 | 10 | import { test as uploadFileTest } from '../support/fixtures/upload-file' |
9 | 11 |
|
10 | | -const test = mergeTests(randomUserTest, uploadFileTest) |
| 12 | +const test = mergeTests(editorTest, offlineTest, randomUserTest, uploadFileTest) |
11 | 13 |
|
12 | | -const setOnline = async (client: CDPSession, online: boolean): Promise<void> => { |
13 | | - if (online) { |
14 | | - await client.send('Network.emulateNetworkConditions', { |
15 | | - offline: false, |
16 | | - latency: 0, |
17 | | - downloadThroughput: -1, |
18 | | - uploadThroughput: -1, |
19 | | - }) |
20 | | - await client.send('Network.disable') |
21 | | - } else { |
22 | | - await client.send('Network.enable') |
23 | | - await client.send('Network.emulateNetworkConditions', { |
24 | | - offline: true, |
25 | | - latency: 0, |
26 | | - downloadThroughput: 0, |
27 | | - uploadThroughput: 0, |
28 | | - }) |
29 | | - } |
30 | | -} |
| 14 | +// As we switch on and off the network |
| 15 | +// we cannot run tests in parallel. |
| 16 | +test.describe.configure({ mode: 'serial' }) |
31 | 17 |
|
32 | | -test.beforeEach(async ({ page, file }) => { |
33 | | - await page.goto(`f/${file.fileId}`) |
| 18 | +test.beforeEach(async ({ file }) => { |
| 19 | + await file.open() |
34 | 20 | }) |
35 | 21 |
|
36 | | -test.describe('Offline', () => { |
37 | | - test('Offline state indicator', async ({ context, page }) => { |
38 | | - await expect(page.locator('.session-list')).toBeVisible() |
39 | | - await expect(page.locator('.offline-state')).not.toBeVisible() |
| 22 | +test('Offline state indicator', async ({ editor, setOffline }) => { |
| 23 | + await expect(editor.sessionList).toBeVisible() |
| 24 | + await expect(editor.offlineState).not.toBeVisible() |
40 | 25 |
|
41 | | - const client = await context.newCDPSession(page) |
42 | | - await setOnline(client, false) |
| 26 | + await setOffline() |
43 | 27 |
|
44 | | - await expect(page.locator('.session-list')).not.toBeVisible() |
45 | | - await expect(page.locator('.offline-state')).toBeVisible() |
46 | | - |
47 | | - await setOnline(client, true) |
48 | | - }) |
| 28 | + await expect(editor.sessionList).not.toBeVisible() |
| 29 | + await expect(editor.offlineState).toBeVisible() |
| 30 | +}) |
49 | 31 |
|
50 | | - test('Disabled upload and link file when offline', async ({ context, page }) => { |
51 | | - await page.locator('[data-text-action-entry="insert-link"]').click() |
52 | | - await expect( |
53 | | - page.locator('[data-text-action-entry="insert-link-file"] button'), |
54 | | - ).toBeEnabled() |
55 | | - await page.locator('[data-text-action-entry="insert-link"]').click() |
56 | | - await expect( |
57 | | - page.locator('[data-text-action-entry="insert-attachment"] button'), |
58 | | - ).toBeEnabled() |
| 32 | +test('Disabled upload and link file when offline', async ({ |
| 33 | + editor, |
| 34 | + setOffline, |
| 35 | +}) => { |
| 36 | + const linkToFile = editor.getMenu('insert-link-file') |
| 37 | + await editor.withOpenMenu('insert-link', () => expect(linkToFile).toBeEnabled()) |
| 38 | + await expect(editor.getMenu('insert-attachment')).toBeEnabled() |
59 | 39 |
|
60 | | - const client = await context.newCDPSession(page) |
61 | | - await setOnline(client, false) |
| 40 | + await setOffline() |
62 | 41 |
|
63 | | - await page.locator('[data-text-action-entry="insert-link"]').click() |
64 | | - await expect( |
65 | | - page.locator('[data-text-action-entry="insert-link-file"] button'), |
66 | | - ).toBeDisabled() |
67 | | - await page.locator('[data-text-action-entry="insert-link"]').click() |
68 | | - await expect( |
69 | | - page.locator('[data-text-action-entry="insert-attachment"] button'), |
70 | | - ).toBeDisabled() |
| 42 | + await editor.withOpenMenu('insert-link', () => expect(linkToFile).toBeDisabled()) |
| 43 | + await expect(editor.getMenu('insert-attachment')).toBeDisabled() |
| 44 | +}) |
71 | 45 |
|
72 | | - await setOnline(client, true) |
73 | | - }) |
| 46 | +test('typing offline and coming back online', async ({ |
| 47 | + editor, |
| 48 | + setOffline, |
| 49 | + setOnline, |
| 50 | +}) => { |
| 51 | + await expect(editor.locator).toBeVisible() |
| 52 | + await setOffline() |
| 53 | + await editor.typeHeading('Hello world') |
| 54 | + await setOnline() |
| 55 | + await expect(editor.offlineState).not.toBeVisible() |
| 56 | + await expect(editor.saveIndicator).toHaveAttribute('title', /Unsaved changes/) |
74 | 57 | }) |
0 commit comments