Skip to content

Commit 6ee7c8d

Browse files
authored
Merge branch 'master' into bugfix/publish-workflow
2 parents 124a3f0 + d118d7d commit 6ee7c8d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1511
-527
lines changed

.github/workflows/app.dolly-frontend.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ on:
1414
- "libs/security-core/**"
1515
- "apps/dolly-frontend/**"
1616
- ".github/workflows/app.dolly-frontend.yml"
17-
- ".github/workflows/common.playwright.yml"
17+
- ".github/workflows/common.playwright-vitest.yml"
1818

1919
jobs:
2020
playwright:
21-
uses: ./.github/workflows/common.playwright.yml
21+
uses: ./.github/workflows/common.playwright-vitest.yml
2222
permissions:
2323
packages: write
2424
id-token: write

.github/workflows/common.playwright.yml .github/workflows/common.playwright-vitest.yml

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Playwright Tests
1+
name: Playwright/Vitest Tests
22
on:
33
workflow_call:
44
inputs:
@@ -17,8 +17,8 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
shardIndex: [ 1, 2, 3 ]
21-
shardTotal: [ 3 ]
20+
shardIndex: [ 1, 2, 3, 4 ]
21+
shardTotal: [ 4 ]
2222
env:
2323
NODE_AUTH_TOKEN: ${{ secrets.READER_TOKEN }}
2424
steps:
@@ -44,6 +44,11 @@ jobs:
4444
name: blob-report-${{ matrix.shardIndex }}
4545
path: ${{ inputs.working-directory }}/src/main/js/blob-report
4646
retention-days: 1
47+
48+
- name: Run Vitest/RTL tests
49+
if: ${{ matrix.shardIndex == 1 }}
50+
working-directory: ${{ inputs.working-directory }}/src/main/js
51+
run: npm run test:vitest-run
4752

4853
merge-reports:
4954
if: ${{ !cancelled() }}

apps/dolly-frontend/settings.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ includeBuild "../../libs/reactive-session-security"
1515
includeBuild "../../libs/security-core"
1616
includeBuild "../../libs/security-core"
1717
includeBuild "../../libs/testing"
18+
includeBuild '../../.github/workflows'
1819

1920
develocity {
2021
buildScan {
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,45 @@
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'
32
import { BestillingProgresjon } from '@/components/bestilling/statusListe/BestillingProgresjon/BestillingProgresjon'
43
import React from 'react'
5-
import { http, HttpResponse } from 'msw'
6-
import { setupServer } from 'msw/node'
7-
import { uferdigBestillingMock } from '#/mocks/BasicMocks'
84
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'
910

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 () => {
1712
const bestillinger = [uferdigBestillingMock]
1813

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+
)
2221

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+
})
3225

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+
)
3432

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)
3735

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()
4045
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { render, screen } from '@testing-library/react'
2+
import { dollyTest } from '../vitest.setup'
3+
import { userEvent } from '@vitest/browser/context'
4+
import React from 'react'
5+
import { vi } from 'vitest'
6+
import { TestComponentSelectors } from '#/mocks/Selectors'
7+
import BestillingResultat from '@/components/bestilling/statusListe/BestillingResultat/BestillingResultat'
8+
9+
vi.useFakeTimers()
10+
11+
dollyTest('renders BestillingResultat and handles confetti appearance/disappearance', async () => {
12+
const lukkBestillingMock = vi.fn()
13+
14+
const successfulBestilling = {
15+
id: '123',
16+
ferdig: true,
17+
stoppet: false,
18+
antallIdenter: 1,
19+
antallLevert: 1,
20+
status: [{ statuser: [{ melding: 'OK' }] }],
21+
bruker: { brukerId: 'test123' },
22+
}
23+
24+
render(
25+
<BestillingResultat
26+
bestilling={successfulBestilling}
27+
lukkBestilling={lukkBestillingMock}
28+
erOrganisasjon={false}
29+
/>,
30+
)
31+
32+
const confettiComponent = screen.getByTestId('confetti')
33+
34+
expect(screen.getByText('Bestilling #123')).toBeInTheDocument()
35+
expect(confettiComponent).toBeInTheDocument()
36+
37+
const closeButton = screen.getByTestId(TestComponentSelectors.BUTTON_LUKK_BESTILLING_RESULTAT)
38+
await userEvent.click(closeButton)
39+
expect(lukkBestillingMock).toHaveBeenCalledWith('123')
40+
})
41+
42+
dollyTest('does not show confetti for unsuccessful bestillinger', async () => {
43+
const lukkBestillingMock = vi.fn()
44+
45+
const bestillingWithError = {
46+
id: '123',
47+
ferdig: true,
48+
stoppet: false,
49+
status: [{ statuser: [{ melding: 'Feil:random feil' }] }],
50+
bruker: { brukerId: 'test123' },
51+
}
52+
53+
const { rerender } = render(
54+
<BestillingResultat
55+
bestilling={bestillingWithError}
56+
lukkBestilling={lukkBestillingMock}
57+
erOrganisasjon={false}
58+
/>,
59+
)
60+
61+
expect(screen.queryByTestId('confetti')).not.toBeInTheDocument()
62+
63+
const stoppedBestilling = {
64+
id: '123',
65+
ferdig: true,
66+
stoppet: true,
67+
status: [{ statuser: [] }],
68+
bruker: { brukerId: 'test123' },
69+
}
70+
71+
rerender(
72+
<BestillingResultat
73+
bestilling={stoppedBestilling}
74+
lukkBestilling={lukkBestillingMock}
75+
erOrganisasjon={false}
76+
/>,
77+
)
78+
79+
expect(screen.queryByTestId('confetti')).not.toBeInTheDocument()
80+
81+
const incompleteBestilling = {
82+
id: '123',
83+
ferdig: false,
84+
stoppet: false,
85+
status: [{ statuser: [] }],
86+
bruker: { brukerId: 'test123' },
87+
}
88+
89+
rerender(
90+
<BestillingResultat
91+
bestilling={incompleteBestilling}
92+
lukkBestilling={lukkBestillingMock}
93+
erOrganisasjon={false}
94+
/>,
95+
)
96+
97+
expect(screen.queryByTestId('confetti')).not.toBeInTheDocument()
98+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { DollySelect } from '@/components/ui/form/inputs/select/Select'
2+
import { render, screen, waitFor } from '@testing-library/react'
3+
import { http, HttpResponse } from 'msw'
4+
import { dollyTest } from '../vitest.setup'
5+
import { worker } from './mocks/browser'
6+
import { userEvent } from '@vitest/browser/context'
7+
8+
dollyTest(
9+
'renders select with no options on empty list, and retries until options found',
10+
async () => {
11+
render(<DollySelect kodeverk={'test'} name={'test'} label={'Tester kodeverk'} />)
12+
13+
expect(screen.getByText('Tester kodeverk')).toBeInTheDocument()
14+
15+
expect(screen.getByText('Henter verdier ...')).toBeInTheDocument()
16+
17+
worker.use(
18+
// override the initial kodeverk request handler to return non-empty list
19+
http.get('/testnav-kodeverk-service/api/v1/kodeverk/test', () => {
20+
return HttpResponse.json({ koder: [{ value: 'kodeverk2', label: 'kodeverk2' }] })
21+
}),
22+
)
23+
24+
await waitFor(() => expect(screen.getByText('Velg ...')).toBeInTheDocument(), { timeout: 2000 })
25+
26+
const select = screen.getByRole('combobox')
27+
await userEvent.click(select)
28+
29+
await waitFor(() => expect(screen.getByText('kodeverk2')).toBeInTheDocument(), {
30+
timeout: 2000,
31+
})
32+
},
33+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { setupWorker } from 'msw/browser'
2+
import { handlers } from './handlers'
3+
4+
import '@navikt/ds-css'
5+
import '@/styles/main.less'
6+
7+
export const worker = setupWorker(...handlers) as any
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { http, HttpResponse } from 'msw'
2+
import { uferdigBestillingMock } from '#/mocks/BasicMocks'
3+
4+
const bestillinger = [uferdigBestillingMock]
5+
6+
export const handlers = [
7+
http.get('/testnav-kodeverk-service/api/v1/kodeverk/test', () => {
8+
return HttpResponse.json([])
9+
}),
10+
http.get('/dolly-backend/api/v1/bestilling/2', () => {
11+
return HttpResponse.json(bestillinger?.[0])
12+
}),
13+
]

0 commit comments

Comments
 (0)