mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-15 07:34:42 -04:00
Note Loading Boundary: Replace redirect with refetch from API (#2275)
This commit is contained in:
parent
fa53bccb03
commit
f2ed9d4453
6 changed files with 54 additions and 28 deletions
|
@ -62,41 +62,49 @@ describe('create non existing note hint', () => {
|
|||
|
||||
it('renders an button as initial state', async () => {
|
||||
mockCreateNoteWithPrimaryAlias()
|
||||
const view = render(<CreateNonExistingNoteHint></CreateNonExistingNoteHint>)
|
||||
const onNoteCreatedCallback = jest.fn()
|
||||
const view = render(<CreateNonExistingNoteHint onNoteCreated={onNoteCreatedCallback}></CreateNonExistingNoteHint>)
|
||||
await screen.findByTestId('createNoteMessage')
|
||||
expect(onNoteCreatedCallback).not.toBeCalled()
|
||||
expect(view.container).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('renders a waiting message when button is clicked', async () => {
|
||||
mockCreateNoteWithPrimaryAlias()
|
||||
const view = render(<CreateNonExistingNoteHint></CreateNonExistingNoteHint>)
|
||||
const onNoteCreatedCallback = jest.fn()
|
||||
const view = render(<CreateNonExistingNoteHint onNoteCreated={onNoteCreatedCallback}></CreateNonExistingNoteHint>)
|
||||
const button = await screen.findByTestId('createNoteButton')
|
||||
act(() => {
|
||||
button.click()
|
||||
})
|
||||
await screen.findByTestId('loadingMessage')
|
||||
expect(onNoteCreatedCallback).not.toBeCalled()
|
||||
expect(view.container).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('redirects when the note has been created', async () => {
|
||||
it('shows success message when the note has been created', async () => {
|
||||
mockCreateNoteWithPrimaryAlias()
|
||||
const view = render(<CreateNonExistingNoteHint></CreateNonExistingNoteHint>)
|
||||
const onNoteCreatedCallback = jest.fn()
|
||||
const view = render(<CreateNonExistingNoteHint onNoteCreated={onNoteCreatedCallback}></CreateNonExistingNoteHint>)
|
||||
const button = await screen.findByTestId('createNoteButton')
|
||||
act(() => {
|
||||
button.click()
|
||||
})
|
||||
await screen.findByTestId('redirect')
|
||||
await screen.findByTestId('noteCreated')
|
||||
expect(onNoteCreatedCallback).toBeCalled()
|
||||
expect(view.container).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it("shows an error message if note couldn't be created", async () => {
|
||||
mockFailingCreateNoteWithPrimaryAlias()
|
||||
const view = render(<CreateNonExistingNoteHint></CreateNonExistingNoteHint>)
|
||||
const onNoteCreatedCallback = jest.fn()
|
||||
const view = render(<CreateNonExistingNoteHint onNoteCreated={onNoteCreatedCallback}></CreateNonExistingNoteHint>)
|
||||
const button = await screen.findByTestId('createNoteButton')
|
||||
act(() => {
|
||||
button.click()
|
||||
})
|
||||
await screen.findByTestId('failedMessage')
|
||||
expect(onNoteCreatedCallback).not.toBeCalled()
|
||||
expect(view.container).toMatchSnapshot()
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue