Skip to content

Commit dc2e0f1

Browse files
authoredFeb 6, 2024
Merge pull request #1009 from navikt/test-radiopanel-legend-visibility
Test radiopanel legend visibility
2 parents c81c708 + 9a105d8 commit dc2e0f1

File tree

4 files changed

+114
-0
lines changed

4 files changed

+114
-0
lines changed
 

‎mocks/mocks/data/formio-api/custom-components-datagrid.json

+83
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,89 @@
8282
"input": true,
8383
"tableView": false,
8484
"navId": "ep9ghtd"
85+
},
86+
{
87+
"label": "Bor du i Norge?",
88+
"values": [
89+
{
90+
"value": "ja",
91+
"label": "Ja",
92+
"shortcut": ""
93+
},
94+
{
95+
"value": "nei",
96+
"label": "Nei",
97+
"shortcut": ""
98+
}
99+
],
100+
"validate": {
101+
"required": true,
102+
"onlyAvailableItems": false,
103+
"custom": "",
104+
"customPrivate": false,
105+
"strictDateValidation": false,
106+
"multiple": false,
107+
"unique": false
108+
},
109+
"key": "borDuINorge",
110+
"type": "radiopanel",
111+
"input": true,
112+
"tableView": false,
113+
"dataGridLabel": false,
114+
"inputType": "radio",
115+
"fieldSet": false,
116+
"placeholder": "",
117+
"prefix": "",
118+
"customClass": "",
119+
"suffix": "",
120+
"multiple": false,
121+
"defaultValue": null,
122+
"protected": false,
123+
"unique": false,
124+
"persistent": true,
125+
"hidden": false,
126+
"clearOnHide": true,
127+
"refreshOn": "",
128+
"redrawOn": "",
129+
"modalEdit": false,
130+
"labelPosition": "top",
131+
"description": "",
132+
"errorLabel": "",
133+
"tooltip": "",
134+
"hideLabel": false,
135+
"tabindex": "",
136+
"disabled": false,
137+
"autofocus": false,
138+
"dbIndex": false,
139+
"customDefaultValue": "",
140+
"calculateValue": "",
141+
"calculateServer": false,
142+
"widget": null,
143+
"attributes": {},
144+
"validateOn": "blur",
145+
"conditional": {
146+
"show": null,
147+
"when": null,
148+
"eq": ""
149+
},
150+
"overlay": {
151+
"style": "",
152+
"left": "",
153+
"top": "",
154+
"width": "",
155+
"height": ""
156+
},
157+
"allowCalculateOverride": false,
158+
"encrypted": false,
159+
"showCharCount": false,
160+
"showWordCount": false,
161+
"properties": {},
162+
"allowMultipleMasks": false,
163+
"addons": [],
164+
"fieldSize": "input--xxl",
165+
"dataSrc": "values",
166+
"id": "eadmph5",
167+
"keyModified": true
85168
}
86169
],
87170
"tableView": false,

‎packages/fyllut/cypress/cypress.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ declare global {
2828

2929
defaultInterceptsPrefillData(): Chainable<JQuery<HTMLElement>>;
3030

31+
shouldBeVisible(): Chainable<JQuery>;
32+
3133
/**
3234
* Configures the Mocks Server administration API client
3335
*/

‎packages/fyllut/cypress/e2e/custom-react-components.cy.ts

+25
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,34 @@ describe('Custom react components', () => {
187187
it('make sure you can add multiple select boxes in a DataGrid and edit them', () => {
188188
const labelSelect = 'Nedtrekksmeny';
189189
const labelDate = 'Dato (dd.mm.åååå)';
190+
const legendRadiopanel = 'Bor du i Norge?';
190191
const labelAdd = 'Legg til';
191192
cy.findAllByRole('combobox', { name: labelSelect }).eq(0).type('a{enter}');
192193
cy.findAllByRole('textbox', { name: labelDate }).eq(0).type('10.10.2000{esc}');
194+
cy.findAllByText(legendRadiopanel).should('have.length', 1).eq(0).shouldBeVisible();
195+
cy.findAllByRole('group', { name: legendRadiopanel })
196+
.eq(0)
197+
.within(() => {
198+
cy.findByLabelText('Ja').should('exist').click();
199+
});
193200
cy.findByRole('button', { name: labelAdd }).click();
194201
cy.findAllByRole('combobox', { name: labelSelect }).eq(1).type('b{enter}');
195202
cy.findAllByRole('textbox', { name: labelDate }).eq(1).type('11.10.2000{esc}');
203+
cy.findAllByText(legendRadiopanel).should('have.length', 2).eq(1).shouldBeVisible();
204+
cy.findAllByRole('group', { name: legendRadiopanel })
205+
.eq(1)
206+
.within(() => {
207+
cy.findByLabelText('Nei').should('exist').click();
208+
});
196209
cy.findByRole('button', { name: labelAdd }).click();
197210
cy.findAllByRole('combobox', { name: labelSelect }).eq(2).type('a{enter}');
198211
cy.findAllByRole('textbox', { name: labelDate }).eq(2).type('12.10.2000{esc}');
212+
cy.findAllByText(legendRadiopanel).should('have.length', 3).eq(2).shouldBeVisible();
213+
cy.findAllByRole('group', { name: legendRadiopanel })
214+
.eq(2)
215+
.within(() => {
216+
cy.findByLabelText('Nei').should('exist').click();
217+
});
199218

200219
cy.clickNextStep();
201220
cy.findByRole('heading', { name: 'Oppsummering' }).should('exist');
@@ -207,6 +226,8 @@ describe('Custom react components', () => {
207226
cy.get('dd').eq(0).contains('a');
208227
cy.get('dt').eq(1).contains(labelDate);
209228
cy.get('dd').eq(1).contains('10.10.2000');
229+
cy.get('dt').eq(2).contains(legendRadiopanel);
230+
cy.get('dd').eq(2).contains('Ja');
210231
});
211232

212233
cy.get('dl')
@@ -216,6 +237,8 @@ describe('Custom react components', () => {
216237
cy.get('dd').eq(0).contains('b');
217238
cy.get('dt').eq(1).contains(labelDate);
218239
cy.get('dd').eq(1).contains('11.10.2000');
240+
cy.get('dt').eq(2).contains(legendRadiopanel);
241+
cy.get('dd').eq(2).contains('Nei');
219242
});
220243

221244
cy.get('dl')
@@ -225,6 +248,8 @@ describe('Custom react components', () => {
225248
cy.get('dd').eq(0).contains('a');
226249
cy.get('dt').eq(1).contains(labelDate);
227250
cy.get('dd').eq(1).contains('12.10.2000');
251+
cy.get('dt').eq(2).contains(legendRadiopanel);
252+
cy.get('dd').eq(2).contains('Nei');
228253
});
229254
});
230255
});

‎packages/fyllut/cypress/support/commands.ts

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ Cypress.Commands.add('findByRoleWhenAttached', (role, options) => {
4545
.get('@elementWhenAttached');
4646
});
4747

48+
Cypress.Commands.add('shouldBeVisible', { prevSubject: true }, (subject) => {
49+
return cy.wrap(subject).should('be.visible').should('not.have.class', 'navds-sr-only');
50+
});
51+
4852
Cypress.Commands.add('clickNextStep', () => {
4953
return cy.findByRoleWhenAttached('button', { name: TEXTS.grensesnitt.navigation.next }).click();
5054
});

0 commit comments

Comments
 (0)
Please sign in to comment.