From 45a7c9aca76c1604f9e3300cda74dbfd09428fd5 Mon Sep 17 00:00:00 2001 From: Lars Olav Torvik Date: Mon, 2 Dec 2024 10:50:39 +0100 Subject: [PATCH] Fix for radio not being populated with values from mellomlagring or in byggeren --- .../radio/mellomlagring-radio.json | 35 ++++++++++ mocks/mocks/routes/innsending-api.js | 9 +++ .../fyllut/cypress/e2e/components/radio.cy.ts | 64 ++++++++++++++----- .../src/components/radio/Radio.tsx | 2 +- 4 files changed, 92 insertions(+), 18 deletions(-) create mode 100644 mocks/mocks/data/innsending-api/radio/mellomlagring-radio.json diff --git a/mocks/mocks/data/innsending-api/radio/mellomlagring-radio.json b/mocks/mocks/data/innsending-api/radio/mellomlagring-radio.json new file mode 100644 index 000000000..922ca5d6a --- /dev/null +++ b/mocks/mocks/data/innsending-api/radio/mellomlagring-radio.json @@ -0,0 +1,35 @@ +{ + "brukerId": "19876898104", + "skjemanr": "radio-test", + "tittel": "Radio test", + "tema": "AAP", + "spraak": "nb", + "hoveddokument": {}, + "hoveddokumentVariant": { + "vedleggsnr": "radio-test", + "tittel": "Radio test", + "label": "Radio test", + "pakrevd": false, + "mimetype": "application/json", + "document": { + "language": "nb-NO", + "data": { + "data": { + "simple": "nei", + "withDescription": "first" + }, + "metadata": {}, + "state": "submitted" + } + } + }, + "innsendingsId": "62a75280-2a85-4e56-9de2-84faa63a2111", + "status": "Opprettet", + "vedleggsListe": [], + "kanLasteOppAnnet": true, + "fristForEttersendelse": 14, + "endretDato": "2024-06-17T13:21:09.17675+02:00", + "skalSlettesDato": "2024-07-15T11:21:09.166405Z", + "skjemaPath": "radiotest", + "visningsType": "fyllUt" +} diff --git a/mocks/mocks/routes/innsending-api.js b/mocks/mocks/routes/innsending-api.js index e5b6751a8..c7b45ca9f 100644 --- a/mocks/mocks/routes/innsending-api.js +++ b/mocks/mocks/routes/innsending-api.js @@ -24,6 +24,7 @@ const activitesFuture = require('../data/innsending-api/activities/activities-fu const prefillData = require('../data/innsending-api/prefill-data/prefill-data.json'); const prefillDataUsa = require('../data/innsending-api/prefill-data/prefill-data-usa.json'); const mellomlagringSelectBoxes = require('../data/innsending-api/select-boxes/mellomlagring-select-boxes.json'); +const mellomlagringRadio = require('../data/innsending-api/radio/mellomlagring-radio.json'); const mellomlagringMonthPicker = require('../data/innsending-api/month-picker/mellomlagring-month-picker.json'); const objectToByteArray = (obj) => Array.from(new TextEncoder().encode(JSON.stringify(obj))); @@ -227,6 +228,14 @@ module.exports = [ body: convertToInnsendingApiResponse(mellomlagringSelectBoxes), }, }, + { + id: 'success-radio', + type: 'json', + options: { + status: 200, + body: convertToInnsendingApiResponse(mellomlagringRadio), + }, + }, { id: 'container123-complete', type: 'json', diff --git a/packages/fyllut/cypress/e2e/components/radio.cy.ts b/packages/fyllut/cypress/e2e/components/radio.cy.ts index 1572dbc90..f842c80a7 100644 --- a/packages/fyllut/cypress/e2e/components/radio.cy.ts +++ b/packages/fyllut/cypress/e2e/components/radio.cy.ts @@ -3,31 +3,61 @@ */ describe('Radio', () => { + before(() => { + cy.configMocksServer(); + }); + beforeEach(() => { cy.defaultIntercepts(); - cy.visit('/fyllut/radiotest/veiledning?sub=paper'); - cy.defaultWaits(); + cy.mocksRestoreRouteVariants(); }); - it('should render simple radio correctly', () => { - cy.findAllByRole('group', { name: 'Simple' }).within(() => { - cy.findAllByRole('radio', { name: 'Ja' }).should('exist'); - cy.findAllByRole('radio', { name: 'Nei' }).should('exist'); + describe('Paper', () => { + beforeEach(() => { + cy.visit('/fyllut/radiotest/veiledning?sub=paper'); + cy.defaultWaits(); + }); + + it('should render simple radio correctly', () => { + cy.findAllByRole('group', { name: 'Simple' }).within(() => { + cy.findAllByRole('radio', { name: 'Ja' }).should('exist'); + cy.findAllByRole('radio', { name: 'Nei' }).should('exist'); + }); + }); + + it('should render radio with decriptions correctly', () => { + // Description for each radio option + cy.findAllByRole('group', { name: 'With description' }).within(() => { + cy.findAllByRole('radio', { name: 'First This is the first option' }).should('exist'); + cy.findAllByRole('radio', { name: 'Second This is the second option' }).should('exist'); + cy.findAllByRole('radio', { name: 'Third' }).should('exist'); + }); + + // Normal and extended description + cy.findByText('Normal description').should('exist'); + cy.findByRole('button', { name: 'Extended description header' }).should('exist'); + cy.findByRole('button', { name: 'Extended description header' }).click(); + cy.findByText('Extended description').should('exist'); }); }); - it('should render radio with decriptions correctly', () => { - // Description for each radio option - cy.findAllByRole('group', { name: 'With description' }).within(() => { - cy.findAllByRole('radio', { name: 'First This is the first option' }).should('exist'); - cy.findAllByRole('radio', { name: 'Second This is the second option' }).should('exist'); - cy.findAllByRole('radio', { name: 'Third' }).should('exist'); + describe('Digital', () => { + beforeEach(() => { + cy.defaultInterceptsMellomlagring(); + cy.mocksUseRouteVariant('get-soknad:success-radio'); + cy.visit('/fyllut/radiotest/veiledning?sub=digital&innsendingsId=62a75280-2a85-4e56-9de2-84faa63a2111'); + cy.defaultWaits(); + cy.wait('@getMellomlagring'); }); - // Normal and extended description - cy.findByText('Normal description').should('exist'); - cy.findByRole('button', { name: 'Extended description header' }).should('exist'); - cy.findByRole('button', { name: 'Extended description header' }).click(); - cy.findByText('Extended description').should('exist'); + it('should populate values from "mellomlagring"', () => { + cy.findAllByRole('group', { name: 'Simple' }).within(() => { + cy.findAllByRole('radio', { name: 'Nei' }).should('be.checked'); + }); + + cy.findAllByRole('group', { name: 'With description' }).within(() => { + cy.findAllByRole('radio', { name: /^First/ }).should('be.checked'); + }); + }); }); }); diff --git a/packages/shared-components/src/components/radio/Radio.tsx b/packages/shared-components/src/components/radio/Radio.tsx index 7c6b77a3c..e5679a94e 100644 --- a/packages/shared-components/src/components/radio/Radio.tsx +++ b/packages/shared-components/src/components/radio/Radio.tsx @@ -23,7 +23,7 @@ const Radio = forwardRef(