oficina / docs Public

Share popover: a failed first load goes to the share page; test the in-flight guard

With nothing drawn yet (an expired session, a 404, a lost network) the
popover closes and Share goes where it goes with no script, the share
page, which handles sign-in and 404 itself; failed() stays for redraws
(review on #106, P2.1). share-pop.mjs gains two legs: a held POST, with
a second switch refused and one request sent, aria-busy past 500ms, and
an aborted POST reverting its switch with the error; and a refused panel
GET and an expired session, landing on the share page and sign-in. Seen
to fail without the redirect, the guard and the busy timer.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 37e6b8bbbffcb90a8d24d60cb3b071251fd168dc parent 0d2e8f8
3 files changed, +90 −2
  • fixtures/engines/share-pop.mjs +78 −0
  • internal/docs/brand/share-pop.js +10 −1
  • internal/docs/fonts_engines_browser_test.go +2 −1

CI cancelled — superseded by a newer push — run details

diff --git a/fixtures/engines/share-pop.mjs b/fixtures/engines/share-pop.mjs
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 })
diff --git a/internal/docs/brand/share-pop.js b/internal/docs/brand/share-pop.js
index 7298964..dee9190 100644
--- a/internal/docs/brand/share-pop.js
+++ b/internal/docs/brand/share-pop.js
@@ -148,7 +148,16 @@
var email = pop.querySelector('[docs-share-invite] input[type="email"]');
if (email) email.focus({ preventScroll: true });
})
- .catch(failed);
+ .catch(function () {
+ // Nothing drawn yet, so nothing to say a failure in and no close
+ // button (review on #106): an expired session (the sign-in page
+ // came back), a 404 or a lost network. Go to the share page,
+ // which is what Share is with no script, and which handles
+ // sign-in and 404 itself. failed() is for a redraw.
+ pop.removeAttribute("aria-busy");
+ close(false);
+ location.assign(href);
+ });
};
Array.prototype.forEach.call(links, function (a) {
diff --git a/internal/docs/fonts_engines_browser_test.go b/internal/docs/fonts_engines_browser_test.go
index 1b2d1cb..e0ea07d 100644
--- a/internal/docs/fonts_engines_browser_test.go
+++ b/internal/docs/fonts_engines_browser_test.go
@@ -107,9 +107,10 @@ func runEnginesApp(t *testing.T, script string) (string, *docs.App, error) {
}
// The richer-UI checks (richer.mjs): one simple document and one empty
// one per engine, and the list's search.
+ // The Share popover (share-pop.mjs): desk, busy, first load, phone.
if script == "share-pop.mjs" {
names = []string{"simple"}
- perName["simple"] = 2 * 2
+ perName["simple"] = 2 * 4
}
// The I2 layout (i2.mjs): a fresh simple document per leg, eight legs
// per engine.