fix(frontend): Await act calls in tests

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2022-11-21 16:55:49 +01:00
parent 2206349415
commit 614374768a
6 changed files with 11 additions and 11 deletions

View file

@ -40,7 +40,7 @@ describe('Copy to clipboard button', () => {
const view = render(copyToClipboardButton) const view = render(copyToClipboardButton)
expect(view.container).toMatchSnapshot() expect(view.container).toMatchSnapshot()
const button = await screen.findByTitle('renderer.highlightCode.copyCode') const button = await screen.findByTitle('renderer.highlightCode.copyCode')
act(() => { await act(() => {
button.click() button.click()
}) })
const tooltip = await screen.findByRole('tooltip') const tooltip = await screen.findByRole('tooltip')

View file

@ -61,7 +61,7 @@ describe('motd modal', () => {
expect(view.container).toMatchSnapshot() expect(view.container).toMatchSnapshot()
const button = await screen.findByTestId('motd-dismiss') const button = await screen.findByTestId('motd-dismiss')
act(() => { await act(() => {
button.click() button.click()
}) })
expect(view.container).toMatchSnapshot() expect(view.container).toMatchSnapshot()

View file

@ -77,7 +77,7 @@ describe('create non existing note hint', () => {
const onNoteCreatedCallback = jest.fn() const onNoteCreatedCallback = jest.fn()
const view = render(<CreateNonExistingNoteHint onNoteCreated={onNoteCreatedCallback}></CreateNonExistingNoteHint>) const view = render(<CreateNonExistingNoteHint onNoteCreated={onNoteCreatedCallback}></CreateNonExistingNoteHint>)
const button = await screen.findByTestId('createNoteButton') const button = await screen.findByTestId('createNoteButton')
act(() => { await act(() => {
button.click() button.click()
}) })
await screen.findByTestId('loadingMessage') await screen.findByTestId('loadingMessage')
@ -90,7 +90,7 @@ describe('create non existing note hint', () => {
const onNoteCreatedCallback = jest.fn() const onNoteCreatedCallback = jest.fn()
const view = render(<CreateNonExistingNoteHint onNoteCreated={onNoteCreatedCallback}></CreateNonExistingNoteHint>) const view = render(<CreateNonExistingNoteHint onNoteCreated={onNoteCreatedCallback}></CreateNonExistingNoteHint>)
const button = await screen.findByTestId('createNoteButton') const button = await screen.findByTestId('createNoteButton')
act(() => { await act(() => {
button.click() button.click()
}) })
await screen.findByTestId('noteCreated') await screen.findByTestId('noteCreated')
@ -103,7 +103,7 @@ describe('create non existing note hint', () => {
const onNoteCreatedCallback = jest.fn() const onNoteCreatedCallback = jest.fn()
const view = render(<CreateNonExistingNoteHint onNoteCreated={onNoteCreatedCallback}></CreateNonExistingNoteHint>) const view = render(<CreateNonExistingNoteHint onNoteCreated={onNoteCreatedCallback}></CreateNonExistingNoteHint>)
const button = await screen.findByTestId('createNoteButton') const button = await screen.findByTestId('createNoteButton')
act(() => { await act(() => {
button.click() button.click()
}) })
await screen.findByTestId('failedMessage') await screen.findByTestId('failedMessage')

View file

@ -47,7 +47,7 @@ describe('AliasesAddForm', () => {
const input = await screen.findByTestId('addAliasInput') const input = await screen.findByTestId('addAliasInput')
await testEvent.type(input, 'abc') await testEvent.type(input, 'abc')
expect(button).toBeEnabled() expect(button).toBeEnabled()
act(() => { await act(() => {
button.click() button.click()
}) })
expect(AliasModule.addAlias).toBeCalledWith('mock-note', 'abc') expect(AliasModule.addAlias).toBeCalledWith('mock-note', 'abc')

View file

@ -47,7 +47,7 @@ describe('AliasesListEntry', () => {
const view = render(<AliasesListEntry alias={testAlias} />) const view = render(<AliasesListEntry alias={testAlias} />)
expect(view.container).toMatchSnapshot() expect(view.container).toMatchSnapshot()
const button = await screen.findByTestId('aliasButtonRemove') const button = await screen.findByTestId('aliasButtonRemove')
act(() => { await act(() => {
button.click() button.click()
}) })
expect(AliasModule.deleteAlias).toBeCalledWith(testAlias.name) expect(AliasModule.deleteAlias).toBeCalledWith(testAlias.name)
@ -64,14 +64,14 @@ describe('AliasesListEntry', () => {
const view = render(<AliasesListEntry alias={testAlias} />) const view = render(<AliasesListEntry alias={testAlias} />)
expect(view.container).toMatchSnapshot() expect(view.container).toMatchSnapshot()
const buttonRemove = await screen.findByTestId('aliasButtonRemove') const buttonRemove = await screen.findByTestId('aliasButtonRemove')
act(() => { await act(() => {
buttonRemove.click() buttonRemove.click()
}) })
expect(AliasModule.deleteAlias).toBeCalledWith(testAlias.name) expect(AliasModule.deleteAlias).toBeCalledWith(testAlias.name)
await deletePromise await deletePromise
expect(NoteDetailsReduxModule.updateMetadata).toBeCalled() expect(NoteDetailsReduxModule.updateMetadata).toBeCalled()
const buttonMakePrimary = await screen.findByTestId('aliasButtonMakePrimary') const buttonMakePrimary = await screen.findByTestId('aliasButtonMakePrimary')
act(() => { await act(() => {
buttonMakePrimary.click() buttonMakePrimary.click()
}) })
expect(AliasModule.markAliasAsPrimary).toBeCalledWith(testAlias.name) expect(AliasModule.markAliasAsPrimary).toBeCalledWith(testAlias.name)

View file

@ -18,7 +18,7 @@ describe('Settings On-Off Button Group', () => {
const view = render(<OnOffButtonGroup value={value} onSelect={onSelect} />) const view = render(<OnOffButtonGroup value={value} onSelect={onSelect} />)
expect(view.container).toMatchSnapshot() expect(view.container).toMatchSnapshot()
const onButton = await screen.findByTestId('onOffButtonGroupOn') const onButton = await screen.findByTestId('onOffButtonGroupOn')
act(() => { await act(() => {
onButton.click() onButton.click()
}) })
expect(value).toBeTruthy() expect(value).toBeTruthy()
@ -26,7 +26,7 @@ describe('Settings On-Off Button Group', () => {
view.rerender(<OnOffButtonGroup value={value} onSelect={onSelect} />) view.rerender(<OnOffButtonGroup value={value} onSelect={onSelect} />)
expect(view.container).toMatchSnapshot() expect(view.container).toMatchSnapshot()
const offButton = await screen.findByTestId('onOffButtonGroupOff') const offButton = await screen.findByTestId('onOffButtonGroupOff')
act(() => { await act(() => {
offButton.click() offButton.click()
}) })
expect(value).toBeFalsy() expect(value).toBeFalsy()