fix(editor): Task 8 round 1, sync tag, cascaded leave ask
This commit is contained in:
1 parent
07bebbc855
commit
579d8afff4
10 files changed
+359
-83
No files matched your search
@@ -16,6 +16,7 @@ import {
|
||||
resolveSessionTag,
|
||||
} from '@/editor/history/sessionTag'
|
||||
import { useCitationDraft } from '@/editor/findings/citationDraft'
|
||||
import { useAuthStore } from '@/state/authStore'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { edit, insert } from '../helpers/editorFixtures'
|
||||
import { defaultView } from '@/editor/navigation'
|
||||
@@ -625,7 +626,10 @@ describe('final review: leaving the editor with a dirty dialog (criterion 17)',
|
||||
await openFinding(user, /Node A/)
|
||||
await modify(user)
|
||||
await user.type(nameField(), ' bis')
|
||||
act(() => forgetSessionTag())
|
||||
act(() => {
|
||||
forgetSessionTag()
|
||||
useAuthStore.setState({ user: null })
|
||||
})
|
||||
await waitFor(() => expect(findingDialog()).toBeNull())
|
||||
const flags = Object.keys(sessionStorage).filter((k) =>
|
||||
k.startsWith('faunosteo:editor:left-draft:'),
|
||||
@@ -666,11 +670,16 @@ describe('a jump of several entries out of the editor (criterion 23)', () => {
|
||||
})
|
||||
|
||||
/** A history jump to `pathname`, as Chromium dispatches it before it commits. */
|
||||
function traverse(pathname: string, key: string, cancelable = true) {
|
||||
function traverse(
|
||||
pathname: string,
|
||||
key: string,
|
||||
cancelable = true,
|
||||
sameDocument = true,
|
||||
) {
|
||||
const url = new URL(pathname, window.location.origin).href
|
||||
const event = Object.assign(new Event('navigate', { cancelable }), {
|
||||
navigationType: 'traverse',
|
||||
destination: { url, key, sameDocument: true },
|
||||
destination: { url, key, sameDocument },
|
||||
})
|
||||
act(() => {
|
||||
api.dispatchEvent(event)
|
||||
@@ -733,6 +742,33 @@ describe('a jump of several entries out of the editor (criterion 23)', () => {
|
||||
expect(sessionStorage.getItem(flagKey())).not.toBeNull()
|
||||
})
|
||||
|
||||
it('a failed jump closes the question and keeps the draft', async () => {
|
||||
const user = await dirtyDialog()
|
||||
api.traverseTo.mockImplementation(() => ({
|
||||
committed: Promise.reject(new Error('gone')),
|
||||
finished: Promise.reject(new Error('gone')),
|
||||
}))
|
||||
traverse('/app/admin/sheets', 'list')
|
||||
await user.click(inDialog().getByRole('button', { name: 'Abandonner' }))
|
||||
await waitFor(() =>
|
||||
expect(screen.queryByText('Abandonner les modifications ?')).toBeNull(),
|
||||
)
|
||||
expect(nameField()).toHaveValue('Node A bis')
|
||||
cleanup()
|
||||
expect(sessionStorage.getItem(flagKey())).not.toBeNull()
|
||||
})
|
||||
|
||||
it('a jump to another sheet is a leave; another document is not cancelled', async () => {
|
||||
await dirtyDialog()
|
||||
const other = '/app/admin/sheets/other-sheet/draft'
|
||||
expect(traverse('/app/admin', 'admin', true, false).defaultPrevented).toBe(
|
||||
false,
|
||||
)
|
||||
expect(screen.queryByText('Abandonner les modifications ?')).toBeNull()
|
||||
expect(traverse(other, 'other').defaultPrevented).toBe(true)
|
||||
expect(inDialog().getByText('Abandonner les modifications ?')).toBeVisible()
|
||||
})
|
||||
|
||||
it('a traversal inside the editor, or a clean dialog, is left alone', async () => {
|
||||
const user = await mount()
|
||||
await openFinding(user, /Node A/)
|
||||
|
||||
Reference in new issue
Block a user