Skip to content

Commit

Permalink
Fix for radio not being populated with values from mellomlagring or i…
Browse files Browse the repository at this point in the history
…n byggeren
  • Loading branch information
lotorvik committed Dec 2, 2024
1 parent 0f67ddc commit 45a7c9a
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 18 deletions.
35 changes: 35 additions & 0 deletions mocks/mocks/data/innsending-api/radio/mellomlagring-radio.json
Original file line number Diff line number Diff line change
@@ -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"
}
9 changes: 9 additions & 0 deletions mocks/mocks/routes/innsending-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down Expand Up @@ -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',
Expand Down
64 changes: 47 additions & 17 deletions packages/fyllut/cypress/e2e/components/radio.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});
});
2 changes: 1 addition & 1 deletion packages/shared-components/src/components/radio/Radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const Radio = forwardRef<HTMLFieldSetElement, Props>(
<AkselRadioGroup
id={id}
legend={legend}
defaultValue={value}
value={value}
onChange={onChange}
ref={ref}
description={description}
Expand Down

0 comments on commit 45a7c9a

Please sign in to comment.