Fix remaining act-related warningsin tests

This commit is contained in:
Alejandro Celaya 2023-12-31 20:16:06 +01:00
parent 2ad0daaed5
commit e7fab8c2d6
2 changed files with 13 additions and 16 deletions

View file

@ -1,4 +1,4 @@
import { act, render, screen, waitFor } from '@testing-library/react'; import { act, render, screen } from '@testing-library/react';
import { fromPartial } from '@total-typescript/shoehorn'; import { fromPartial } from '@total-typescript/shoehorn';
import { MemoryRouter } from 'react-router-dom'; import { MemoryRouter } from 'react-router-dom';
import { AppFactory } from '../../src/app/App'; import { AppFactory } from '../../src/app/App';
@ -23,7 +23,7 @@ describe('<App />', () => {
fetchServers={() => {}} fetchServers={() => {}}
servers={{}} servers={{}}
settings={fromPartial({})} settings={fromPartial({})}
appUpdated appUpdated={false}
resetAppUpdate={() => {}} resetAppUpdate={() => {}}
/> />
</MemoryRouter>, </MemoryRouter>,
@ -36,9 +36,6 @@ describe('<App />', () => {
expect(screen.getByText('MainHeader')).toBeInTheDocument(); expect(screen.getByText('MainHeader')).toBeInTheDocument();
expect(screen.getByText('ShlinkVersions')).toBeInTheDocument(); expect(screen.getByText('ShlinkVersions')).toBeInTheDocument();
await waitFor(() => screen.getByRole('alert'));
expect(screen.getByText('This app has just been updated!')).toBeInTheDocument();
}); });
it.each([ it.each([

View file

@ -1,4 +1,4 @@
import { screen } from '@testing-library/react'; import { act, screen } from '@testing-library/react';
import { fromPartial } from '@total-typescript/shoehorn'; import { fromPartial } from '@total-typescript/shoehorn';
import type { ServerData } from '../../../src/servers/data'; import type { ServerData } from '../../../src/servers/data';
import { DuplicatedServersModal } from '../../../src/servers/helpers/DuplicatedServersModal'; import { DuplicatedServersModal } from '../../../src/servers/helpers/DuplicatedServersModal';
@ -8,9 +8,9 @@ import { renderWithEvents } from '../../__helpers__/setUpTest';
describe('<DuplicatedServersModal />', () => { describe('<DuplicatedServersModal />', () => {
const onDiscard = vi.fn(); const onDiscard = vi.fn();
const onSave = vi.fn(); const onSave = vi.fn();
const setUp = (duplicatedServers: ServerData[] = []) => renderWithEvents( const setUp = (duplicatedServers: ServerData[] = []) => act(() => renderWithEvents(
<DuplicatedServersModal isOpen duplicatedServers={duplicatedServers} onDiscard={onDiscard} onSave={onSave} />, <DuplicatedServersModal isOpen duplicatedServers={duplicatedServers} onDiscard={onDiscard} onSave={onSave} />,
); ));
const mockServer = (data: Partial<ServerData> = {}) => fromPartial<ServerData>(data); const mockServer = (data: Partial<ServerData> = {}) => fromPartial<ServerData>(data);
it('passes a11y checks', () => checkAccessibility(setUp())); it('passes a11y checks', () => checkAccessibility(setUp()));
@ -21,8 +21,8 @@ describe('<DuplicatedServersModal />', () => {
[[mockServer(), mockServer()], 2], [[mockServer(), mockServer()], 2],
[[mockServer(), mockServer(), mockServer()], 3], [[mockServer(), mockServer(), mockServer()], 3],
[[mockServer(), mockServer(), mockServer(), mockServer()], 4], [[mockServer(), mockServer(), mockServer(), mockServer()], 4],
])('renders expected amount of items', (duplicatedServers, expectedItems) => { ])('renders expected amount of items', async (duplicatedServers, expectedItems) => {
setUp(duplicatedServers); await setUp(duplicatedServers);
expect(screen.queryAllByRole('listitem')).toHaveLength(expectedItems); expect(screen.queryAllByRole('listitem')).toHaveLength(expectedItems);
}); });
@ -45,8 +45,8 @@ describe('<DuplicatedServersModal />', () => {
discardBtn: 'Ignore duplicates', discardBtn: 'Ignore duplicates',
}, },
], ],
])('renders expected texts based on amount of servers', (duplicatedServers, assertions) => { ])('renders expected texts based on amount of servers', async (duplicatedServers, assertions) => {
setUp(duplicatedServers); await setUp(duplicatedServers);
expect(screen.getByRole('heading')).toHaveTextContent(assertions.header); expect(screen.getByRole('heading')).toHaveTextContent(assertions.header);
expect(screen.getByText(assertions.firstParagraph)).toBeInTheDocument(); expect(screen.getByText(assertions.firstParagraph)).toBeInTheDocument();
@ -61,8 +61,8 @@ describe('<DuplicatedServersModal />', () => {
mockServer({ url: 'url_1', apiKey: 'apiKey_1' }), mockServer({ url: 'url_1', apiKey: 'apiKey_1' }),
mockServer({ url: 'url_2', apiKey: 'apiKey_2' }), mockServer({ url: 'url_2', apiKey: 'apiKey_2' }),
]], ]],
])('displays provided server data', (duplicatedServers) => { ])('displays provided server data', async (duplicatedServers) => {
setUp(duplicatedServers); await setUp(duplicatedServers);
if (duplicatedServers.length === 0) { if (duplicatedServers.length === 0) {
expect(screen.queryByRole('listitem')).not.toBeInTheDocument(); expect(screen.queryByRole('listitem')).not.toBeInTheDocument();
@ -81,7 +81,7 @@ describe('<DuplicatedServersModal />', () => {
}); });
it('invokes onDiscard when appropriate button is clicked', async () => { it('invokes onDiscard when appropriate button is clicked', async () => {
const { user } = setUp(); const { user } = await setUp();
expect(onDiscard).not.toHaveBeenCalled(); expect(onDiscard).not.toHaveBeenCalled();
await user.click(screen.getByRole('button', { name: 'Discard' })); await user.click(screen.getByRole('button', { name: 'Discard' }));
@ -89,7 +89,7 @@ describe('<DuplicatedServersModal />', () => {
}); });
it('invokes onSave when appropriate button is clicked', async () => { it('invokes onSave when appropriate button is clicked', async () => {
const { user } = setUp(); const { user } = await setUp();
expect(onSave).not.toHaveBeenCalled(); expect(onSave).not.toHaveBeenCalled();
await user.click(screen.getByRole('button', { name: 'Save anyway' })); await user.click(screen.getByRole('button', { name: 'Save anyway' }));