Note Loading Boundary: Replace redirect with refetch from API (#2275)

This commit is contained in:
Tilman Vatteroth 2022-08-13 14:32:19 +02:00 committed by GitHub
parent fa53bccb03
commit f2ed9d4453
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 54 additions and 28 deletions

View file

@ -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()
})
})