✨(frontend) pad persistance
This commit manage the persistance of the pad. We save the pad in different ways: - when the user close the tab or the browser - when the user leave the page (go to another pad by example) - every 1 minute ---- - We save the pad only if the pad has been modified. - Pads are collaborative, to not save multiple times the same pad, we save the pad only if the user is the last to have modified the pad. ---- Because of the collaborative aspect of the pads, the best way to store our pad is to save the Y.Doc, to do so the recommended way is to convert the Y.Doc to a Uint8Array and then to a string (base64). Our pad are saved as a string in a object in a Minio bucket.
This commit is contained in:
@@ -138,4 +138,63 @@ test.describe('Pad Editor', () => {
|
||||
await expect(page.getByText('Hello World Pad 2')).toBeHidden();
|
||||
await expect(page.getByText('Hello World Pad 1')).toBeVisible();
|
||||
});
|
||||
|
||||
test('it saves the doc when we change pages', async ({
|
||||
page,
|
||||
browserName,
|
||||
}) => {
|
||||
const [pad] = await createPad(page, 'pad-save-page', browserName, 1);
|
||||
|
||||
const panel = page.getByLabel('Pads panel').first();
|
||||
|
||||
// Check the first pad
|
||||
await panel.getByText(pad).click();
|
||||
await expect(page.locator('h2').getByText(pad)).toBeVisible();
|
||||
await page.locator('.ProseMirror.bn-editor').click();
|
||||
await page
|
||||
.locator('.ProseMirror.bn-editor')
|
||||
.fill('Hello World Pad persisted 1');
|
||||
await expect(page.getByText('Hello World Pad persisted 1')).toBeVisible();
|
||||
|
||||
await panel
|
||||
.getByRole('button', {
|
||||
name: 'Add a pad',
|
||||
})
|
||||
.click();
|
||||
|
||||
const card = page.getByLabel('Create new pad card').first();
|
||||
await expect(
|
||||
card.getByRole('heading', {
|
||||
name: 'Name the pad',
|
||||
level: 3,
|
||||
}),
|
||||
).toBeVisible();
|
||||
|
||||
await page.goto('/');
|
||||
|
||||
await panel.getByText(pad).click();
|
||||
|
||||
await expect(page.getByText('Hello World Pad persisted 1')).toBeVisible();
|
||||
});
|
||||
|
||||
test('it saves the doc when we quit pages', async ({ page, browserName }) => {
|
||||
const [pad] = await createPad(page, 'pad-save-quit', browserName, 1);
|
||||
|
||||
const panel = page.getByLabel('Pads panel').first();
|
||||
|
||||
// Check the first pad
|
||||
await panel.getByText(pad).click();
|
||||
await expect(page.locator('h2').getByText(pad)).toBeVisible();
|
||||
await page.locator('.ProseMirror.bn-editor').click();
|
||||
await page
|
||||
.locator('.ProseMirror.bn-editor')
|
||||
.fill('Hello World Pad persisted 2');
|
||||
await expect(page.getByText('Hello World Pad persisted 2')).toBeVisible();
|
||||
|
||||
await page.goto('/');
|
||||
|
||||
await panel.getByText(pad).click();
|
||||
|
||||
await expect(page.getByText('Hello World Pad persisted 2')).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user