fix(editor): ask only the top refusing layer, safe retry notes
This commit is contained in:
1 parent
f8be0ad01a
commit
ee86a3a659
5 files changed
+92
-15
No files matched your search
@@ -57,6 +57,18 @@ export async function passwordToken(account: SandboxAccount): Promise<string> {
|
|||||||
return body.access_token
|
return body.access_token
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Records a retry on the running test; outside a test (the global setup) it goes to the
|
||||||
|
* console, where `test.info()` would throw.
|
||||||
|
*/
|
||||||
|
function noteRetry(type: string, description: string): void {
|
||||||
|
try {
|
||||||
|
test.info().annotations.push({ type, description })
|
||||||
|
} catch {
|
||||||
|
console.log(`${type}: ${description}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A verified TOTP factor enrolled by the account itself through the GoTrue
|
* A verified TOTP factor enrolled by the account itself through the GoTrue
|
||||||
* API (as its authenticator app would be set up); resolves with its secret.
|
* API (as its authenticator app would be set up); resolves with its secret.
|
||||||
@@ -70,8 +82,10 @@ export async function enrolVerifiedFactor(
|
|||||||
if (!enrolment.factor) throw new Error(`sandbox enrol: ${refusal(enrolment)}`)
|
if (!enrolment.factor) throw new Error(`sandbox enrol: ${refusal(enrolment)}`)
|
||||||
let verified = await verifyTotp(token, enrolment.factor)
|
let verified = await verifyTotp(token, enrolment.factor)
|
||||||
// The HTTP 500 of the sweep (see `STEP_UP_ATTEMPTS`) is tried once more.
|
// The HTTP 500 of the sweep (see `STEP_UP_ATTEMPTS`) is tried once more.
|
||||||
if (verified.status >= 500)
|
if (verified.status >= 500) {
|
||||||
|
noteRetry('verify retried', `HTTP ${verified.status} from GoTrue verify`)
|
||||||
verified = await verifyTotp(token, enrolment.factor)
|
verified = await verifyTotp(token, enrolment.factor)
|
||||||
|
}
|
||||||
if (verified.status !== 200)
|
if (verified.status !== 200)
|
||||||
throw new Error(`sandbox verify: ${refusal(verified)}`)
|
throw new Error(`sandbox verify: ${refusal(verified)}`)
|
||||||
return enrolment.factor.secret
|
return enrolment.factor.secret
|
||||||
@@ -151,10 +165,10 @@ export async function stepUpAdmin(page: Page, dict: Dict, secret: string) {
|
|||||||
for (let attempt = 1; ; attempt += 1) {
|
for (let attempt = 1; ; attempt += 1) {
|
||||||
const unavailable = await sendStepUpCode(page, dict, secret)
|
const unavailable = await sendStepUpCode(page, dict, secret)
|
||||||
if (!unavailable || attempt === STEP_UP_ATTEMPTS) break
|
if (!unavailable || attempt === STEP_UP_ATTEMPTS) break
|
||||||
test.info().annotations.push({
|
noteRetry(
|
||||||
type: 'step-up retried',
|
'step-up retried',
|
||||||
description: `attempt ${attempt}: GoTrue verify failed on the server`,
|
`attempt ${attempt}: GoTrue verify failed on the server`,
|
||||||
})
|
)
|
||||||
await page.reload()
|
await page.reload()
|
||||||
}
|
}
|
||||||
await expect(stepUpHeading(page, dict)).toBeHidden()
|
await expect(stepUpHeading(page, dict)).toBeHidden()
|
||||||
|
|||||||
@@ -9,8 +9,9 @@ import { FINGERPRINT_PATTERN, fingerprintOf, randomHex } from './fingerprint'
|
|||||||
* entries and the left-draft flag carry instead of the account id. It is kept in this
|
* entries and the left-draft flag carry instead of the account id. It is kept in this
|
||||||
* tab's sessionStorage with a fingerprint of the account id salted with the tag, reused
|
* tab's sessionStorage with a fingerprint of the account id salted with the tag, reused
|
||||||
* only for the account whose fingerprint it holds, and rotated on sign-out and on any
|
* only for the account whose fingerprint it holds, and rotated on sign-out and on any
|
||||||
* other account (the flags of the old tag cleared). Resolved at once, on any origin (http included). A storage
|
* other account (the flags of the old tag cleared). Resolved at once, on any origin
|
||||||
* that refuses keeps it in memory only: a reload then restores nothing.
|
* (http included). A storage that refuses keeps it in memory only: a reload then
|
||||||
|
* restores nothing.
|
||||||
*/
|
*/
|
||||||
const STORAGE_KEY = 'faunosteo:editor:session-tag'
|
const STORAGE_KEY = 'faunosteo:editor:session-tag'
|
||||||
const TAG_PATTERN = /^[0-9a-f]{32}$/
|
const TAG_PATTERN = /^[0-9a-f]{32}$/
|
||||||
|
|||||||
@@ -233,8 +233,8 @@ function leavingLayers(from: EditorView, to: EditorView): LayerName[] {
|
|||||||
/**
|
/**
|
||||||
* Whether a POP must not be followed, and which layer refused it: a modal that is no
|
* Whether a POP must not be followed, and which layer refused it: a modal that is no
|
||||||
* layer is open (its place-scoped state is not in the history, every layer is asked), or
|
* layer is open (its place-scoped state is not in the history, every layer is asked), or
|
||||||
* a dirty layer would be removed. Only the layers the POP removes are asked, top down, so
|
* a dirty layer would be removed. Only the layers the POP removes are asked, top down, and
|
||||||
* a dirty form shows its own confirmation and a layer the POP keeps is never asked.
|
* the first to refuse stops the walk: a lower dirty layer's question is never left pending.
|
||||||
*/
|
*/
|
||||||
function refusal(
|
function refusal(
|
||||||
ctx: PopContext,
|
ctx: PopContext,
|
||||||
@@ -246,9 +246,7 @@ function refusal(
|
|||||||
return 'modal'
|
return 'modal'
|
||||||
}
|
}
|
||||||
const leaving = leavingLayers(view, entry?.view ?? ctx.defaultView)
|
const leaving = leavingLayers(view, entry?.view ?? ctx.defaultView)
|
||||||
const answers = leaving.map((layer) => nav.guards.ask(layer, false).allowed)
|
return leaving.find((layer) => !nav.guards.ask(layer, false).allowed) ?? null
|
||||||
const index = answers.indexOf(false)
|
|
||||||
return index < 0 ? null : leaving[index]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The view under the finding dialog's sheet: what lies over it is clean, it goes. */
|
/** The view under the finding dialog's sheet: what lies over it is clean, it goes. */
|
||||||
|
|||||||
@@ -86,8 +86,10 @@ export function stepHistory(
|
|||||||
const state = api.get()
|
const state = api.get()
|
||||||
const preview = editablePreview(state)
|
const preview = editablePreview(state)
|
||||||
if (typeof preview === 'string') return blocked(preview)
|
if (typeof preview === 'string') return blocked(preview)
|
||||||
const move = direction === 'undo' ? stepBack : stepForward
|
const step = (direction === 'undo' ? stepBack : stepForward)(
|
||||||
const step = move(historyOf(state), state.documentText)
|
historyOf(state),
|
||||||
|
state.documentText,
|
||||||
|
)
|
||||||
if (!step) return blocked('empty')
|
if (!step) return blocked('empty')
|
||||||
const replaced = preview.replaceDocument(step.text)
|
const replaced = preview.replaceDocument(step.text)
|
||||||
if (!replaced.ok) return replaced
|
if (!replaced.ok) return replaced
|
||||||
|
|||||||
@@ -1066,7 +1066,7 @@ describe('the citations sheet over a dirty edit form (final review rev 4, item 1
|
|||||||
draftKept()
|
draftKept()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('after the cascade keeps the form, one Back reopens the sheet (docs, limit 6)', async () => {
|
it('after the cascade keeps the form, one Back reopens the sheet (docs, limit 5)', async () => {
|
||||||
const user = await sheetOverDirtyForm()
|
const user = await sheetOverDirtyForm()
|
||||||
const sheet = within(panelOpen()!)
|
const sheet = within(panelOpen()!)
|
||||||
const head = sheet.getByRole('button', { name: /^Alpha/ })
|
const head = sheet.getByRole('button', { name: /^Alpha/ })
|
||||||
@@ -1099,6 +1099,68 @@ describe('the citations sheet over a dirty edit form (final review rev 4, item 1
|
|||||||
draftKept()
|
draftKept()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/** The reference Alpha's edit dialog opened from the sheet; `dirty` types in it. */
|
||||||
|
async function referenceOverSheet(user: User, dirty: boolean) {
|
||||||
|
const sheet = within(panelOpen()!)
|
||||||
|
const head = sheet.getByRole('button', { name: /^Alpha/ })
|
||||||
|
if (head.getAttribute('aria-expanded') === 'false') await user.click(head)
|
||||||
|
const tile = within(head.closest('li')!)
|
||||||
|
await user.click(tile.getByRole('button', { name: 'Modifier' }))
|
||||||
|
await waitFor(() => expect(refForm()).toBeDefined())
|
||||||
|
if (dirty)
|
||||||
|
await user.type(within(refForm()!).getByLabelText('Citation'), ' x')
|
||||||
|
}
|
||||||
|
|
||||||
|
it('a jump of three entries asks the dirty reference only, nothing stays pending under it', async () => {
|
||||||
|
const user = await sheetOverDirtyForm()
|
||||||
|
await referenceOverSheet(user, true)
|
||||||
|
await act(async () => navigate(-3))
|
||||||
|
await waitFor(() => expect(screen.queryAllByText(question)).toHaveLength(1))
|
||||||
|
expect(refForm()!.contains(screen.getByText(question))).toBe(true)
|
||||||
|
await user.click(
|
||||||
|
within(refForm()!).getByRole('button', { name: 'Abandonner' }),
|
||||||
|
)
|
||||||
|
await waitFor(() => expect(refForm()).toBeUndefined())
|
||||||
|
// The refused jump is dropped: the sheet stays, and no question comes up unasked.
|
||||||
|
expect(panelOpen()).not.toBeNull()
|
||||||
|
expect(screen.queryByText(question)).toBeNull()
|
||||||
|
draftKept()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('a clean reference over the sheet over a dirty form: a Back asks the form in view', async () => {
|
||||||
|
const user = await sheetOverDirtyForm()
|
||||||
|
await referenceOverSheet(user, false)
|
||||||
|
await act(async () => navigate(-3))
|
||||||
|
await waitFor(() => expect(panelOpen()).toBeNull())
|
||||||
|
await waitFor(() => expect(refForm()).toBeUndefined())
|
||||||
|
expect(inDialog().getByText(question)).toBeVisible()
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(findingDialog()!.contains(document.activeElement)).toBe(true),
|
||||||
|
)
|
||||||
|
draftKept()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('a clean reference over the sheet over a dirty form: a leave out asks the form in view', async () => {
|
||||||
|
const user = await sheetOverDirtyForm()
|
||||||
|
await referenceOverSheet(user, false)
|
||||||
|
const url = new URL('/app/admin/sheets', window.location.origin).href
|
||||||
|
const event = Object.assign(new Event('navigate', { cancelable: true }), {
|
||||||
|
navigationType: 'traverse',
|
||||||
|
destination: { url, key: 'list', sameDocument: true },
|
||||||
|
})
|
||||||
|
act(() => {
|
||||||
|
api.dispatchEvent(event)
|
||||||
|
})
|
||||||
|
expect(event.defaultPrevented).toBe(true)
|
||||||
|
await waitFor(() => expect(panelOpen()).toBeNull())
|
||||||
|
await waitFor(() => expect(refForm()).toBeUndefined())
|
||||||
|
expect(inDialog().getByText(question)).toBeVisible()
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(findingDialog()!.contains(document.activeElement)).toBe(true),
|
||||||
|
)
|
||||||
|
draftKept()
|
||||||
|
})
|
||||||
|
|
||||||
it('a jump out of the editor closes the sheet, then the form asks in view', async () => {
|
it('a jump out of the editor closes the sheet, then the form asks in view', async () => {
|
||||||
await sheetOverDirtyForm()
|
await sheetOverDirtyForm()
|
||||||
const url = new URL('/app/admin/sheets', window.location.origin).href
|
const url = new URL('/app/admin/sheets', window.location.origin).href
|
||||||
|
|||||||
Reference in new issue
Block a user