Skip to content

Commit 3b3d54d

Browse files
committed
test(gdpr): Playwright coverage for deletion-token modal + delete-with-token
1 parent 10afa2b commit 3b3d54d

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import {expect, test} from '@playwright/test';
2+
import {goToNewPad, goToPad} from '../helper/padHelper';
3+
import {showSettings} from '../helper/settingsHelper';
4+
5+
test.describe('pad deletion token', () => {
6+
test.beforeEach(async ({context}) => {
7+
await context.clearCookies();
8+
});
9+
10+
test('creator sees a token modal exactly once and can dismiss it', async ({page}) => {
11+
await goToNewPad(page);
12+
const modal = page.locator('#deletiontoken-modal');
13+
await expect(modal).toBeVisible();
14+
15+
const tokenValue = await page.locator('#deletiontoken-value').inputValue();
16+
expect(tokenValue.length).toBeGreaterThanOrEqual(32);
17+
18+
await page.locator('#deletiontoken-ack').click();
19+
await expect(modal).toBeHidden();
20+
21+
const cleared = await page.evaluate(
22+
() => (window as any).clientVars.padDeletionToken);
23+
expect(cleared == null).toBe(true);
24+
});
25+
26+
test('second device can delete using the captured token', async ({page, browser}) => {
27+
const padId = await goToNewPad(page);
28+
const token = await page.locator('#deletiontoken-value').inputValue();
29+
await page.locator('#deletiontoken-ack').click();
30+
31+
const context2 = await browser.newContext();
32+
const page2 = await context2.newPage();
33+
await goToPad(page2, padId);
34+
await showSettings(page2);
35+
36+
await page2.locator('#delete-pad-with-token > summary').click();
37+
await page2.locator('#delete-pad-token-input').fill(token);
38+
page2.once('dialog', (d) => d.accept());
39+
await page2.locator('#delete-pad-token-submit').click();
40+
41+
await page2.waitForURL((url) => url.pathname === '/' || url.pathname.endsWith('/index.html'),
42+
{timeout: 10000});
43+
44+
await context2.close();
45+
});
46+
47+
test('wrong token keeps the pad alive and surfaces a shout', async ({page, browser}) => {
48+
const padId = await goToNewPad(page);
49+
await page.locator('#deletiontoken-ack').click();
50+
51+
const context2 = await browser.newContext();
52+
const page2 = await context2.newPage();
53+
await goToPad(page2, padId);
54+
await showSettings(page2);
55+
56+
await page2.locator('#delete-pad-with-token > summary').click();
57+
await page2.locator('#delete-pad-token-input').fill('bogus-token-value');
58+
// Accept the confirm() dialog, then capture the alert() the shout triggers.
59+
const dialogs: string[] = [];
60+
page2.on('dialog', async (d) => {
61+
dialogs.push(d.message());
62+
await d.accept();
63+
});
64+
await page2.locator('#delete-pad-token-submit').click();
65+
66+
await expect.poll(() => dialogs.length, {timeout: 10000}).toBeGreaterThanOrEqual(2);
67+
expect(dialogs.some((m) => /not the creator|cannot delete/i.test(m))).toBe(true);
68+
69+
// Pad must still exist for the original creator.
70+
await page.reload();
71+
await expect(page.locator('#editorcontainer.initialized')).toBeVisible();
72+
await context2.close();
73+
});
74+
});

0 commit comments

Comments
 (0)