| index b5318ed..892f586 100644 |
| --- a/fixtures/engines/share-pop.mjs |
| +++ b/fixtures/engines/share-pop.mjs |
| @@ -94,6 +94,84 @@ for (const engine of [chromium, webkit]) { |
| await context.close() |
| } |
| |
| + // One request at a time (review on #106): while a switch's POST is held |
| + // back, flipping the other switch puts it straight back and sends |
| + // nothing; past 500ms the waiting switch says aria-busy; the answer |
| + // redraws the panel. Then a POST that fails: the switch goes back and |
| + // the panel says so. |
| + { |
| + const context = await browser.newContext({ viewport: { width: 1280, height: 900 }, deviceScaleFactor: 1 }) |
| + await context.addCookies(config.cookies.map((c) => ({ name: c.Name, value: c.Value, url: config.origin, httpOnly: c.HttpOnly, sameSite: 'Lax' }))) |
| + const page = await context.newPage() |
| + await page.goto(config.origin + '/d/' + config.docs.simple.shift()) |
| + await page.waitForSelector('[docs-text][contenteditable="true"]', { timeout: 30000 }) |
| + let mode = 'slow' |
| + let posts = 0 |
| + let finished = 0 |
| + page.on('requestfinished', (r) => { if (r.method() === 'POST') finished++ }) |
| + page.on('requestfailed', (r) => { if (r.method() === 'POST') finished++ }) |
| + await page.route('**/share/**', async (route) => { |
| + if (route.request().method() !== 'POST') return route.continue() |
| + posts++ |
| + if (mode === 'abort') return route.abort() |
| + await pause(1500) |
| + return route.continue() |
| + }) |
| + await page.click('[estilo-bar-actions] a[href$="/share"]') |
| + await until(async () => (await page.locator('[docs-share-pop] [docs-share-panel]').count()) === 1) |
| + const rung = (i) => page.locator('[docs-share-rung]').nth(i) |
| + const checked = (i) => rung(i).locator('input[type=checkbox]').isChecked() |
| + const team = await checked(0) |
| + const link = await checked(1) |
| + const t0 = Date.now() |
| + await rung(0).locator('[rst-switch]').click() |
| + await pause(150) |
| + await rung(1).locator('[rst-switch]').click() |
| + await pause(100) |
| + if ((await checked(1)) !== link) fail('a second switch moved while the first one\'s request was in flight') |
| + await pause(Math.max(0, 750 - (Date.now() - t0))) |
| + if ((await page.locator('[docs-share-rung] input[aria-busy="true"]').count()) !== 1) fail('the waiting switch did not say aria-busy after 500ms') |
| + const settled = await until(async () => finished === 1 && (await page.locator('[docs-share-pop] [aria-busy="true"]').count()) === 0 && (await checked(0)) !== team, 5000) |
| + if (!settled) fail('the held request did not land and redraw the panel') |
| + if (posts !== 1) fail(`${posts} requests were sent for one switch and one refused flip, want 1`) |
| + if ((await checked(1)) !== link) fail('the refused flip took effect after all') |
| + |
| + mode = 'abort' |
| + const before = await checked(0) |
| + await rung(0).locator('[rst-switch]').click() |
| + const reverted = await until(async () => (await page.locator('[docs-share-error]').count()) === 1 && (await checked(0)) === before) |
| + if (!reverted) fail(`a failed request: error shown ${await page.locator('[docs-share-error]').count()}, switch ${await checked(0)} (want back at ${before})`) |
| + await context.close() |
| + } |
| + |
| + // The first load failing (review on #106): nothing is drawn, so Share |
| + // goes to the share page, which handles a lost session and a 404 |
| + // itself. A refused panel request, then an expired session. |
| + { |
| + const context = await browser.newContext({ viewport: { width: 1280, height: 900 }, deviceScaleFactor: 1 }) |
| + await context.addCookies(config.cookies.map((c) => ({ name: c.Name, value: c.Value, url: config.origin, httpOnly: c.HttpOnly, sameSite: 'Lax' }))) |
| + const page = await context.newPage() |
| + const doc = config.docs.simple.shift() |
| + await page.goto(config.origin + '/d/' + doc) |
| + await page.waitForSelector('[docs-text][contenteditable="true"]', { timeout: 30000 }) |
| + await page.route((u) => u.searchParams.get('panel') === '1', (route) => route.abort()) |
| + await Promise.all([ |
| + page.waitForURL(config.origin + '/d/' + doc + '/share', { timeout: 8000 }).catch(() => {}), |
| + page.click('[estilo-bar-actions] a[href$="/share"]'), |
| + ]) |
| + if (page.url() !== config.origin + '/d/' + doc + '/share') fail(`a failed first load left the page at ${page.url()}, want the share page`) |
| + await page.unroute((u) => u.searchParams.get('panel') === '1') |
| + await page.goto(config.origin + '/d/' + doc) |
| + await page.waitForSelector('[docs-text][contenteditable="true"]', { timeout: 30000 }) |
| + await context.clearCookies() |
| + await Promise.all([ |
| + page.waitForURL((u) => u.pathname.startsWith('/signin'), { timeout: 8000 }).catch(() => {}), |
| + page.click('[estilo-bar-actions] a[href$="/share"]'), |
| + ]) |
| + if (!new URL(page.url()).pathname.startsWith('/signin')) fail(`with the session gone, Share left the page at ${page.url()}, want sign-in`) |
| + await context.close() |
| + } |
| + |
| // Phone: Share is a row in estilo's Menu sheet; a modal sheet. |
| { |
| const context = await browser.newContext({ viewport: { width: 390, height: 844 }, deviceScaleFactor: 1, hasTouch: true }) |