Skip to content

Commit 49b7120

Browse files
committed
fix(offline): autosave with disconnects
Signed-off-by: Max <max@nextcloud.com>
1 parent 7df4e02 commit 49b7120

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

playwright/e2e/autosave.spec.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
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'
9+
import { test as uploadFileTest } from '../support/fixtures/upload-file'
10+
11+
const test = mergeTests(editorTest, offlineTest, uploadFileTest)
12+
13+
// As we switch on and off the network
14+
// we cannot run tests in parallel.
15+
test.describe.configure({ mode: 'serial' })
16+
17+
test.beforeEach(async ({ open }) => {
18+
await open()
19+
})
20+
21+
test('saves after 30 seconds', async ({ editor, page }) => {
22+
await page.clock.install()
23+
await expect(editor.el).toBeVisible()
24+
await editor.typeHeading('Hello world')
25+
await expect(editor.saveIndicator).toHaveAccessibleName(/Unsaved changes/)
26+
await page.clock.fastForward(30_000)
27+
await expect(editor.saveIndicator).not.toHaveAccessibleName(/Unsaved changes/)
28+
// TODO: Why does this not work? await expect(await file.getContent()).toBe('## Hello world')
29+
})
30+
31+
test('saves after being disconnected for 20 sec.', async ({
32+
editor,
33+
page,
34+
setOffline,
35+
setOnline,
36+
}) => {
37+
await page.clock.install()
38+
await expect(editor.el).toBeVisible()
39+
await editor.typeHeading('Hello world')
40+
await expect(editor.saveIndicator).toHaveAccessibleName(/Unsaved changes/)
41+
setOffline()
42+
await page.clock.fastForward(20_000)
43+
setOnline()
44+
await page.clock.fastForward(20_000)
45+
await expect(editor.saveIndicator).not.toHaveAccessibleName(/Unsaved changes/)
46+
// TODO: Why does this not work? await expect(await file.getContent()).toBe('## Hello world')
47+
})
48+
49+
test('saves after being disconnected for 2 minutes', async ({
50+
editor,
51+
page,
52+
setOffline,
53+
setOnline,
54+
}) => {
55+
await page.clock.install()
56+
await expect(editor.el).toBeVisible()
57+
await editor.typeHeading('Hello world')
58+
await expect(editor.saveIndicator).toHaveAccessibleName(/Unsaved changes/)
59+
setOffline()
60+
await page.clock.fastForward(120_000)
61+
setOnline()
62+
await page.clock.fastForward(40_000)
63+
await expect(editor.saveIndicator).not.toHaveAccessibleName(/Unsaved changes/)
64+
// TODO: Why does this not work? await expect(await file.getContent()).toBe('## Hello world')
65+
})

src/services/SaveService.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ class SaveService {
9696
_autosave() {
9797
return this.save({ manualSave: false }).catch((error) => {
9898
logger.error('Failed to autosave document.', { error })
99+
// retry in 30 seconds
100+
this.autosave()
99101
})
100102
}
101103
}

0 commit comments

Comments
 (0)