plugins: rtl 13 fixes for tests

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-10-13 13:11:15 +02:00
parent 0935b0d60f
commit 80a79cc1e7
27 changed files with 371 additions and 403 deletions
@@ -34,8 +34,12 @@ const apis = TestApiRegistry.from(
);
describe('Incidents', () => {
beforeEach(() => {
jest.useFakeTimers();
});
afterEach(() => {
jest.resetAllMocks();
jest.useRealTimers();
});
it('Renders an empty state when there are no incidents', async () => {
@@ -47,13 +51,10 @@ describe('Incidents', () => {
<Incidents readOnly={false} refreshIncidents={false} team="test" />
</ApiProvider>,
);
await waitFor(() => !screen.queryByTestId('progress'));
await waitFor(
() =>
expect(
screen.getByText('Nice! No incidents found!'),
).toBeInTheDocument(),
{ timeout: 2000 },
jest.advanceTimersByTime(2000);
await waitFor(() => expect(screen.queryByTestId('progress')).toBe(null));
await waitFor(() =>
expect(screen.getByText('Nice! No incidents found!')).toBeInTheDocument(),
);
});
@@ -66,15 +67,14 @@ describe('Incidents', () => {
<Incidents readOnly={false} team="test" refreshIncidents={false} />
</ApiProvider>,
);
await waitFor(() => !screen.queryByTestId('progress'));
await waitFor(
() =>
expect(
screen.getByText('user', {
exact: false,
}),
).toBeInTheDocument(),
{ timeout: 2000 },
jest.advanceTimersByTime(2000);
await waitFor(() => expect(screen.queryByTestId('progress')).toBe(null));
await waitFor(() =>
expect(
screen.getByText('user', {
exact: false,
}),
).toBeInTheDocument(),
);
expect(screen.getByText('test-incident')).toBeInTheDocument();
expect(screen.getByTitle('Acknowledged')).toBeInTheDocument();
@@ -93,15 +93,14 @@ describe('Incidents', () => {
<Incidents readOnly team="test" refreshIncidents={false} />
</ApiProvider>,
);
await waitFor(() => !screen.queryByTestId('progress'));
await waitFor(
() =>
expect(
screen.getByText('user', {
exact: false,
}),
).toBeInTheDocument(),
{ timeout: 2000 },
jest.advanceTimersByTime(2000);
await waitFor(() => expect(screen.queryByTestId('progress')).toBe(null));
await waitFor(() =>
expect(
screen.getByText('user', {
exact: false,
}),
).toBeInTheDocument(),
);
expect(screen.getByText('test-incident')).toBeInTheDocument();
expect(screen.getByLabelText('Status warning')).toBeInTheDocument();
@@ -127,15 +126,14 @@ describe('Incidents', () => {
<Incidents readOnly={false} team="test" refreshIncidents={false} />
</ApiProvider>,
);
await waitFor(() => !screen.queryByTestId('progress'));
await waitFor(
() =>
expect(
screen.getByText(
'Error encountered while fetching information. Error occurred',
),
).toBeInTheDocument(),
{ timeout: 2000 },
jest.advanceTimersByTime(2000);
await waitFor(() => expect(screen.queryByTestId('progress')).toBe(null));
await waitFor(() =>
expect(
screen.getByText(
'Error encountered while fetching information. Error occurred',
),
).toBeInTheDocument(),
);
});
});