|
1 |
| -import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest' |
2 |
| -import { fireEvent, render, screen, waitFor } from '@testing-library/react' |
| 1 | +import { render, screen, waitFor } from '@testing-library/react' |
3 | 2 | import { BestillingProgresjon } from '@/components/bestilling/statusListe/BestillingProgresjon/BestillingProgresjon'
|
4 | 3 | import React from 'react'
|
5 |
| -import { http, HttpResponse } from 'msw' |
6 |
| -import { setupServer } from 'msw/node' |
7 |
| -import { uferdigBestillingMock } from '#/mocks/BasicMocks' |
8 | 4 | import { TestComponentSelectors } from '#/mocks/Selectors'
|
| 5 | +import { dollyTest } from '../vitest.setup' |
| 6 | +import { userEvent } from '@vitest/browser/context' |
| 7 | +import { uferdigBestillingMock } from '#/mocks/BasicMocks' |
| 8 | +import { worker } from './mocks/browser' |
| 9 | +import { http, HttpResponse } from 'msw' |
9 | 10 |
|
10 |
| -describe('BestillingProgresjon', () => { |
11 |
| - const server = setupServer( |
12 |
| - http.get('/dolly-backend/api/v1/bestilling/1', () => { |
13 |
| - return HttpResponse.json(bestillinger?.[0]) |
14 |
| - }), |
15 |
| - ) |
16 |
| - |
| 11 | +dollyTest('renders Bestillingprogresjon and cancel removes the element', async () => { |
17 | 12 | const bestillinger = [uferdigBestillingMock]
|
18 | 13 |
|
19 |
| - beforeAll(() => server.listen()) |
20 |
| - afterEach(() => server.resetHandlers()) |
21 |
| - afterAll(() => server.close()) |
| 14 | + const { rerender } = render( |
| 15 | + <BestillingProgresjon |
| 16 | + bestillingID={bestillinger?.[0]?.id} |
| 17 | + cancelBestilling={() => bestillinger.pop()} |
| 18 | + onFinishBestilling={() => null} |
| 19 | + />, |
| 20 | + ) |
22 | 21 |
|
23 |
| - test('renders', async () => { |
24 |
| - render( |
25 |
| - <BestillingProgresjon |
26 |
| - bestillingID={'1'} |
27 |
| - cancelBestilling={() => bestillinger.pop()} |
28 |
| - erOrganisasjon={false} |
29 |
| - onFinishBestilling={() => null} |
30 |
| - />, |
31 |
| - ) |
| 22 | + await waitFor(() => expect(screen.getByText('Bestillingsstatus')).toBeDefined(), { |
| 23 | + timeout: 2000, |
| 24 | + }) |
32 | 25 |
|
33 |
| - await waitFor(() => expect(screen.queryByText('Bestillingsstatus')).toBeDefined()) |
| 26 | + worker.use( |
| 27 | + // override the initial uferdigBestillling request handler to return empty |
| 28 | + http.get('/dolly-backend/api/v1/bestilling/2', () => { |
| 29 | + return new HttpResponse(null, { status: 404 }) |
| 30 | + }), |
| 31 | + ) |
34 | 32 |
|
35 |
| - const avbrytButton = screen.getByTestId(TestComponentSelectors.BUTTON_AVBRYT_BESTILLING) |
36 |
| - fireEvent.click(avbrytButton) |
| 33 | + const avbrytButton = screen.getByTestId(TestComponentSelectors.BUTTON_AVBRYT_BESTILLING) |
| 34 | + await userEvent.click(avbrytButton) |
37 | 35 |
|
38 |
| - await waitFor(() => expect(screen.queryByText('Bestillingsstatus')).toBeNull()) |
39 |
| - }) |
| 36 | + rerender( |
| 37 | + <BestillingProgresjon |
| 38 | + onFinishBestilling={() => null} |
| 39 | + bestillingID={null} |
| 40 | + cancelBestilling={() => bestillinger.pop()} |
| 41 | + />, |
| 42 | + ) |
| 43 | + |
| 44 | + expect(screen.queryByText('Bestillingsstatus')).toBeNull() |
40 | 45 | })
|
0 commit comments