fix(app): R1 Escape layers with the page focused, twin keyboard framing, « Plus » field guard
This commit is contained in:
1 parent
90a5e7aa35
commit
132756eecd
7 files changed
+130
-8
No files matched your search
@@ -4,12 +4,14 @@ import {
|
||||
act,
|
||||
cleanup,
|
||||
fireEvent,
|
||||
render,
|
||||
screen,
|
||||
waitFor,
|
||||
within,
|
||||
} from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import type { Annotation } from '@faunosteo/core-wasm/types'
|
||||
import ModalDialog from '@/components/ui/ModalDialog'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { drawnText, insert, point } from '../helpers/editorFixtures'
|
||||
import { resetStore, serverHas, store } from '../helpers/editorHarness'
|
||||
@@ -202,6 +204,53 @@ describe('Escape leaves alone', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Escape with the focus on the page', () => {
|
||||
it('a delete dialog open: the selection is kept', async () => {
|
||||
const user = await mount()
|
||||
await select(user)
|
||||
await user.click(inPanel('Supprimer'))
|
||||
expect(document.querySelector('dialog[open]')).not.toBeNull()
|
||||
document.body.focus()
|
||||
escape(document.body)
|
||||
expect(panel()).toBeDefined()
|
||||
})
|
||||
|
||||
it('the references panel open: it closes, the selection is kept', async () => {
|
||||
const user = await mount()
|
||||
await select(user)
|
||||
const toggle = screen.getByRole('button', { name: 'Références' })
|
||||
await user.click(toggle)
|
||||
expect(toggle).toHaveAttribute('aria-expanded', 'true')
|
||||
escape(document.body)
|
||||
expect(toggle).toHaveAttribute('aria-expanded', 'false')
|
||||
expect(panel()).toBeDefined()
|
||||
})
|
||||
|
||||
it('a dialog outside the workspace open: the selection is kept', async () => {
|
||||
const user = await mount()
|
||||
await select(user)
|
||||
render(
|
||||
<ModalDialog onClose={() => undefined} label="Outside">
|
||||
<p>Outside</p>
|
||||
</ModalDialog>,
|
||||
)
|
||||
escape(document.body)
|
||||
expect(panel()).toBeDefined()
|
||||
})
|
||||
|
||||
it('« Plus » open, Escape in the twin filter: the menu and the field stay', async () => {
|
||||
const user = await mount(TWO(), 500)
|
||||
const more = screen.getByRole('button', { name: 'Plus' })
|
||||
await user.click(more)
|
||||
const filter = within(shown('[data-testid="annotation-overview"]')!)
|
||||
.getByRole('searchbox', { name: 'Filtrer par nom' })
|
||||
filter.focus()
|
||||
escape(filter)
|
||||
expect(more).toHaveAttribute('aria-expanded', 'true')
|
||||
expect(document.activeElement).toBe(filter)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Escape and the other layers', () => {
|
||||
it('closes the references panel from the tab row, the selection kept', async () => {
|
||||
const user = await mount()
|
||||
|
||||
@@ -21,6 +21,7 @@ import ReferencesPanel from '@/components/editor/references/ReferencesPanel'
|
||||
import AnnotationsTab from '@/components/editor/tabs/AnnotationsTab'
|
||||
import {
|
||||
FocusConsumedContext,
|
||||
isTextField,
|
||||
ownedBy,
|
||||
type FocusRequest,
|
||||
} from '@/editor/focusRequest'
|
||||
@@ -373,3 +374,28 @@ describe('a consumed request', () => {
|
||||
expect(document.activeElement?.getAttribute('data-focus-key')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('isTextField', () => {
|
||||
const input = (type: string) => {
|
||||
const element = document.createElement('input')
|
||||
element.type = type
|
||||
return element
|
||||
}
|
||||
|
||||
it('is true for what takes typed text', () => {
|
||||
for (const type of ['text', 'search', 'email']) {
|
||||
expect(isTextField(input(type))).toBe(true)
|
||||
}
|
||||
expect(isTextField(document.createElement('textarea'))).toBe(true)
|
||||
expect(isTextField(document.createElement('select'))).toBe(true)
|
||||
})
|
||||
|
||||
it('is false for a checkbox, a radio, a range, a button input', () => {
|
||||
for (const type of ['checkbox', 'radio', 'range', 'button', 'file']) {
|
||||
expect(isTextField(input(type))).toBe(false)
|
||||
}
|
||||
const off = document.createElement('div')
|
||||
off.setAttribute('contenteditable', 'false')
|
||||
expect(isTextField(off)).toBe(false)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user