Skip to content

Commit dd15ef6

Browse files
committed
Merge branch 'master' into nav-select-submission-value-removed-from-values
2 parents 7af0e43 + 8aad8b8 commit dd15ef6

File tree

9 files changed

+64
-30
lines changed

9 files changed

+64
-30
lines changed

.github/workflows/build-and-test.yaml

+8-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,14 @@ jobs:
2929
run: yarn check-types
3030
- name: 'Build'
3131
run: yarn build
32-
- name: 'Test'
33-
run: yarn test
32+
- name: 'Test bygger'
33+
run: yarn test:bygger
34+
- name: 'Test fyllut'
35+
run: yarn test:fyllut
36+
- name: 'Test shared-components'
37+
run: yarn test:shared-components
38+
- name: 'Test shared-domain'
39+
run: yarn test:shared-domain
3440

3541
package-and-push-bygger:
3642
if: github.ref == 'refs/heads/master'

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
"preview:bygger": "yarn workspace @navikt/bygger-backend preview",
2929
"preview:fyllut": "yarn workspace @navikt/fyllut-backend preview",
3030
"test": "concurrently \"yarn workspace @navikt/bygger-frontend test\" \"yarn workspace @navikt/bygger-backend test\" \"yarn workspace @navikt/fyllut-frontend test\" \"yarn workspace @navikt/fyllut-backend test\" \"yarn workspace @navikt/skjemadigitalisering-shared-domain test\" \"yarn workspace @navikt/skjemadigitalisering-shared-components test\"",
31+
"test:bygger": "concurrently \"yarn workspace @navikt/bygger-frontend test\" \"yarn workspace @navikt/bygger-backend test\"",
32+
"test:fyllut": "concurrently \"yarn workspace @navikt/fyllut-frontend test\" \"yarn workspace @navikt/fyllut-backend test\"",
33+
"test:shared-domain": "yarn workspace @navikt/skjemadigitalisering-shared-domain test",
34+
"test:shared-components": "yarn workspace @navikt/skjemadigitalisering-shared-components test",
3135
"test:coverage": "yarn workspaces run test:coverage",
3236
"cypress:bygger": "yarn workspace @navikt/bygger-frontend cypress",
3337
"cypress:fyllut": "yarn workspace @navikt/fyllut-frontend cypress",

packages/bygger/src/components/NavFormBuilder.test.jsx

+23-22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NavFormioJs } from '@navikt/skjemadigitalisering-shared-components';
2-
import { render, screen, waitFor, within } from '@testing-library/react';
2+
import { cleanup, render, screen, waitFor, within } from '@testing-library/react';
33
import userEvent from '@testing-library/user-event';
44
import createMockImplementation, { DEFAULT_PROJECT_URL } from '../../test/backendMockImplementation';
55
import NavFormBuilder from './NavFormBuilder';
@@ -24,12 +24,17 @@ const DEFAULT_FORM_BUILDER_OPTIONS = {
2424
describe('NavFormBuilder', () => {
2525
beforeAll(() => {
2626
new NavFormioJs.Formio(DEFAULT_PROJECT_URL);
27+
});
28+
29+
beforeEach(() => {
2730
vi.spyOn(NavFormioJs.Formio, 'fetch').mockImplementation(createMockImplementation());
2831
});
2932

30-
afterEach(() => {
33+
afterEach(async () => {
3134
fetchMock.resetMocks();
32-
window.confirm = undefined;
35+
vi.restoreAllMocks();
36+
cleanup();
37+
await waitFor(() => expect(Object.keys(NavFormioJs.Formio.forms).length).toBe(0));
3338
});
3439

3540
describe('mounting', () => {
@@ -78,7 +83,7 @@ describe('NavFormBuilder', () => {
7883

7984
describe('remove button', () => {
8085
it('removes a component which no other component depends on', async () => {
81-
const checkbox = screen.queryByLabelText('Oppgi din favorittfarge');
86+
const checkbox = await screen.findByLabelText('Oppgi din favorittfarge');
8287
expect(checkbox).toBeInTheDocument();
8388

8489
const builderComponent = findClosestWithAttribute(checkbox, BUILDER_COMP_TESTID_ATTR);
@@ -92,7 +97,7 @@ describe('NavFormBuilder', () => {
9297

9398
it('prompts user when removing a component which other components depends on', async () => {
9499
window.confirm = vi.fn().mockImplementation(() => true);
95-
const fieldset = screen.queryByRole('group', { name: /Your favorite time of the year/ });
100+
const fieldset = await screen.findByRole('group', { name: /Your favorite time of the year/ });
96101
expect(fieldset).toBeInTheDocument();
97102

98103
const builderComponent = findClosestWithAttribute(fieldset, BUILDER_COMP_TESTID_ATTR);
@@ -106,15 +111,15 @@ describe('NavFormBuilder', () => {
106111

107112
it('does not remove component if user declines prompt', async () => {
108113
window.confirm = vi.fn().mockImplementation(() => false);
109-
const fieldset = screen.queryByRole('group', { name: /Your favorite time of the year/ });
114+
const fieldset = await screen.findByRole('group', { name: /Your favorite time of the year/ });
110115
expect(fieldset).toBeInTheDocument();
111116

112117
const builderComponent = findClosestWithAttribute(fieldset, BUILDER_COMP_TESTID_ATTR);
113118

114119
const removeComponentButton = await within(builderComponent).findByTitle('Slett');
115120
await userEvent.click(removeComponentButton);
116121

117-
expect(screen.queryByRole('group', { name: /Your favorite time of the year/ })).toBeInTheDocument();
122+
expect(await screen.findByRole('group', { name: /Your favorite time of the year/ })).toBeInTheDocument();
118123
expect(onChangeMock.mock.calls).toHaveLength(0);
119124

120125
expect(window.confirm.mock.calls).toHaveLength(1);
@@ -125,7 +130,7 @@ describe('NavFormBuilder', () => {
125130

126131
it('prompts user when removing component containing component which other components depends on', async () => {
127132
window.confirm = vi.fn().mockImplementation(() => true);
128-
const panel = screen.queryByText('Tilbakemelding');
133+
const panel = await screen.findByText('Tilbakemelding');
129134
expect(panel).toBeInTheDocument();
130135

131136
const builderComponent = findClosestWithAttribute(panel, BUILDER_COMP_TESTID_ATTR);
@@ -147,6 +152,7 @@ describe('NavFormBuilder', () => {
147152

148153
it('prompts user when removing attachment panel', async () => {
149154
window.confirm = vi.fn().mockImplementation(() => true);
155+
onReadyMock.mockReset();
150156
rerender(
151157
<NavFormBuilder
152158
form={{ ...testform, display: 'skjema' }}
@@ -155,12 +161,9 @@ describe('NavFormBuilder', () => {
155161
formBuilderOptions={DEFAULT_FORM_BUILDER_OPTIONS}
156162
/>,
157163
);
164+
await waitFor(() => expect(onReadyMock.mock.calls).toHaveLength(1));
158165

159-
const attachmentPanelLink = screen.queryByRole('link', { name: 'Vedlegg' });
160-
expect(attachmentPanelLink).toBeInTheDocument();
161-
await userEvent.click(attachmentPanelLink);
162-
163-
const attachmentPanel = screen.queryByRole('button', { name: 'Vedlegg' });
166+
const attachmentPanel = await screen.findByRole('button', { name: 'Vedlegg' });
164167
expect(attachmentPanel).toBeInTheDocument();
165168
const builderComponent = findClosestWithAttribute(attachmentPanel, BUILDER_COMP_TESTID_ATTR);
166169
const removeComponentButtons = await within(builderComponent).findAllByTitle('Slett');
@@ -177,6 +180,7 @@ describe('NavFormBuilder', () => {
177180

178181
it('does not remove attachment panel if user declines prompt', async () => {
179182
window.confirm = vi.fn().mockImplementation(() => false);
183+
onReadyMock.mockReset();
180184
rerender(
181185
<NavFormBuilder
182186
form={{ ...testform, display: 'skjema' }}
@@ -185,12 +189,9 @@ describe('NavFormBuilder', () => {
185189
formBuilderOptions={DEFAULT_FORM_BUILDER_OPTIONS}
186190
/>,
187191
);
192+
await waitFor(() => expect(onReadyMock.mock.calls).toHaveLength(1));
188193

189-
const attachmentPanelLink = screen.queryByRole('link', { name: 'Vedlegg' });
190-
expect(attachmentPanelLink).toBeInTheDocument();
191-
await userEvent.click(attachmentPanelLink);
192-
193-
const attachmentPanel = screen.queryByRole('button', { name: 'Vedlegg' });
194+
const attachmentPanel = await screen.findByRole('button', { name: 'Vedlegg' });
194195
expect(attachmentPanel).toBeInTheDocument();
195196
const builderComponent = findClosestWithAttribute(attachmentPanel, BUILDER_COMP_TESTID_ATTR);
196197
const removeComponentButtons = await within(builderComponent).findAllByTitle('Slett');
@@ -201,22 +202,22 @@ describe('NavFormBuilder', () => {
201202
'Du forsøker nå å slette vedleggspanelet. For å gjenopprette må et predefinert vedleggspanel trekkes inn. Vil du fremdeles slette panelet?',
202203
);
203204

204-
const attachmentPanelAfterNoDelete = screen.queryByRole('button', { name: 'Vedlegg' });
205+
const attachmentPanelAfterNoDelete = await screen.findByRole('button', { name: 'Vedlegg' });
205206
expect(attachmentPanelAfterNoDelete).toBeInTheDocument();
206207
});
207208
});
208209

209210
describe('conditional alert message in edit component', () => {
210211
it('is visible when component is depended upon by other components', async () => {
211-
const fieldset = screen.queryByRole('group', { name: /Your favorite time of the year/ });
212+
const fieldset = await screen.findByRole('group', { name: /Your favorite time of the year/ });
212213
expect(fieldset).toBeInTheDocument();
213214

214215
const builderComponent = findClosestWithAttribute(fieldset, BUILDER_COMP_TESTID_ATTR);
215216

216217
const editComponentButton = await within(builderComponent).findByTitle('Rediger');
217218
await userEvent.click(editComponentButton);
218219

219-
const conditionalAlert = screen.queryByRole('list', {
220+
const conditionalAlert = await screen.findByRole('list', {
220221
name: 'Følgende komponenter har avhengighet til denne:',
221222
});
222223
expect(conditionalAlert).toBeInTheDocument();
@@ -225,7 +226,7 @@ describe('NavFormBuilder', () => {
225226
});
226227

227228
it('is not visible when component is not depended upon by other components', async () => {
228-
const textInput = screen.queryByLabelText('Oppgi din favorittfarge');
229+
const textInput = await screen.findByLabelText('Oppgi din favorittfarge');
229230
expect(textInput).toBeInTheDocument();
230231

231232
const builderComponent = findClosestWithAttribute(textInput, BUILDER_COMP_TESTID_ATTR);

packages/bygger/src/setupTests.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import '@testing-library/jest-dom';
2+
import { cleanup } from '@testing-library/react';
23
import { Blob } from 'node:buffer';
34
import { URL } from 'node:url';
45
import { vi } from 'vitest';
@@ -13,3 +14,11 @@ fetchMock.enableMocks();
1314
globalThis.URL = URL;
1415
// @ts-ignore
1516
globalThis.Blob = Blob;
17+
18+
afterEach(() => {
19+
cleanup();
20+
});
21+
22+
afterAll(() => {
23+
vi.restoreAllMocks();
24+
});

packages/fyllut-backend/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"scripts": {
1010
"start": "cross-env-shell NODE_ENV=development vite",
1111
"build": "tsc && vite build",
12-
"preview": "cross-env-shell NODE_ENV=development NO_FORM_VALIDATION=true FYLLUT_BUILD_DIR=\"../../fyllut/dist\" PORT=3001 \"node bin/copyDotEnvTestToDist.js && cd dist && node server.mjs\"",
12+
"preview": "cross-env-shell NODE_ENV=development NO_DECORATOR=true NO_FORM_VALIDATION=true FYLLUT_BUILD_DIR=\"../../fyllut/dist\" PORT=3001 \"node bin/copyDotEnvTestToDist.js && cd dist && node server.mjs\"",
1313
"check-types": "tsc",
1414
"clean": "rimraf dist coverage node_modules",
1515
"test": "vitest --run",

packages/fyllut-backend/src/config/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const localDevelopmentConfig: DefaultConfig = {
5656
mockIdportenPid: process.env.MOCK_IDPORTEN_PID || '12345678911',
5757
mockIdportenJwt: process.env.MOCK_IDPORTEN_JWT || 'IDPORTEN_JWT',
5858
noFormValidation: process.env.NO_FORM_VALIDATION === 'true',
59-
noDecorator: process.env.NO_DECORATOR === 'false',
59+
noDecorator: process.env.NO_DECORATOR === 'true',
6060
tokenx: {
6161
...tokenx,
6262
wellKnownUrl:

packages/fyllut-backend/src/renderIndex.ts

-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const renderIndex = async (req: Request, res: Response, next: NextFunction) => {
1818
const qpForm = req.query.form;
1919
const qpInnsendingsId = req.query.innsendingsId;
2020
const qpSub = req.query.sub as QueryParamSub;
21-
const qbDisableDecorator = req.query.disableDecorator;
2221
let redirectUrl: string | undefined;
2322
let redirectParams: { [key: string]: any } = { ...req.query };
2423
if (qpForm) {
@@ -98,9 +97,6 @@ const renderIndex = async (req: Request, res: Response, next: NextFunction) => {
9897
httpStatusCode = 404;
9998
}
10099
}
101-
if (!config.isProduction && qbDisableDecorator === 'true') {
102-
return res.render('index.html', pageMeta);
103-
}
104100

105101
const decoratorFragments = await getDecorator(createRedirectUrl(req, res));
106102
res.status(httpStatusCode).render('index.html', {

packages/fyllut/src/setupTests.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
import '@testing-library/jest-dom';
2+
import { cleanup } from '@testing-library/react';
23
import { vi } from 'vitest';
34
import createFetchMock from 'vitest-fetch-mock';
45

56
const fetchMock = createFetchMock(vi);
67

78
fetchMock.enableMocks();
89
fetchMock.dontMock();
10+
11+
afterEach(() => {
12+
cleanup();
13+
});
14+
15+
afterAll(() => {
16+
vi.restoreAllMocks();
17+
});

packages/shared-components/src/setupTests.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import '@testing-library/jest-dom';
2+
import { cleanup } from '@testing-library/react';
23
import { vi } from 'vitest';
34
import createFetchMock from 'vitest-fetch-mock';
45

@@ -7,6 +8,14 @@ const fetchMock = createFetchMock(vi);
78
fetchMock.enableMocks();
89
fetchMock.dontMock();
910

11+
afterEach(() => {
12+
cleanup();
13+
});
14+
15+
afterAll(() => {
16+
vi.restoreAllMocks();
17+
});
18+
1019
Object.defineProperty(window, 'matchMedia', {
1120
writable: true,
1221
value: vi.fn().mockImplementation((query) => ({

0 commit comments

Comments
 (0)