Skip to content

Commit 0b14c92

Browse files
Reapeat multi field page controller
1 parent 9600dad commit 0b14c92

17 files changed

Lines changed: 1121 additions & 3844 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { Then, When } from "@badeball/cypress-cucumber-preprocessor";
2+
3+
Then("I see a summary card titled {string}", (cardTitle) => {
4+
cy.findByRole("heading", { name: cardTitle }).should("exist");
5+
});
6+
7+
Then(
8+
"the summary card {string} contains a row {string} with value {string}",
9+
(cardTitle, rowLabel, rowValue) => {
10+
cy.findByRole("heading", { name: cardTitle })
11+
.parents(".govuk-summary-card")
12+
.within(() => {
13+
cy.contains("dt", rowLabel).next("dd").should("contain.text", rowValue);
14+
});
15+
}
16+
);
17+
18+
Then(
19+
"the summary card {string} has a {string} link to {string}",
20+
(cardTitle, linkText, hrefFragment) => {
21+
cy.findByRole("heading", { name: cardTitle })
22+
.parents(".govuk-summary-card")
23+
.within(() => {
24+
cy.findAllByRole("link", { name: new RegExp(linkText, "i") })
25+
.first()
26+
.should("have.attr", "href")
27+
.and("include", hrefFragment);
28+
});
29+
}
30+
);
31+
32+
// Click the delete button on a specific card
33+
When("I delete the summary card {string}", (cardTitle) => {
34+
cy.findByRole("heading", { name: cardTitle })
35+
.parents(".govuk-summary-card")
36+
.within(() => {
37+
cy.findByRole("link", { name: /Delete/i }).click();
38+
});
39+
});
40+
41+
// Click the edit button on a specific card
42+
When("I edit the summary card {string}", (cardTitle) => {
43+
cy.findByRole("heading", { name: cardTitle })
44+
.parents(".govuk-summary-card")
45+
.within(() => {
46+
cy.findByRole("link", { name: /Change/i }).click();
47+
});
48+
});
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Feature: Repeating multi field - add multiple sections
2+
3+
Background:
4+
Given the form "repeat-multi-field" exists
5+
6+
Scenario: User can repeat sections with multiple fields
7+
When I enter "Alice" for "Your name"
8+
And I enter "French{enter}" for "Language"
9+
And I select the button "Continue"
10+
Then I see "You have selected these Interpreters"
11+
And I select the button "Add another"
12+
Then I don't see "French"
13+
Then I don't see "Alice"
14+
And I enter "Bob{enter}" for "Your name"
15+
And I enter "Italian" for "Language"
16+
And I select the button "Continue"
17+
Then I see "You have selected these Interpreters"
18+
Then I see a summary card titled "Item 1"
19+
And the summary card "Item 1" contains a row "Your name" with value "Alice"
20+
And the summary card "Item 1" contains a row "Language" with value "French"
21+
And the summary card "Item 1" has a "Change" link to "?view=0"
22+
And the summary card "Item 1" has a "Delete" link to "?remove=0"
23+
Then I see a summary card titled "Item 2"
24+
And the summary card "Item 2" contains a row "Your name" with value "Bob"
25+
And the summary card "Item 2" contains a row "Language" with value "Italian"
26+
And the summary card "Item 2" has a "Change" link to "?view=1"
27+
And the summary card "Item 2" has a "Delete" link to "?remove=1"
28+
And I edit the summary card "Item 2"
29+
And I enter "Robert{enter}" for "Your name"
30+
Then the summary card "Item 2" contains a row "Your name" with value "Robert"
31+
And I don't see "Bob"
32+
And the summary card "Item 2" has a "Delete" link to "?remove=1"
33+
And I delete the summary card "Item 2"
34+
And the summary card "Item 1" contains a row "Your name" with value "Alice"
35+
And the summary card "Item 1" contains a row "Language" with value "French"
36+
And I don't see "Robert"
37+
And I don't see "Delete"
38+
And I select the button "Continue"
39+
Then I see a summary card titled "Item 1"
40+
And I see "Check your answers"
41+
And the summary card "Item 1" contains a row "Your name" with value "Alice"
42+
And the summary card "Item 1" contains a row "Language" with value "French"
43+
And the summary card "Item 1" has a "Change" link to "?view=0"
44+
And the summary card "Item 1" has a "Delete" link to "?remove=0"
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"startPage": "/which-languages-do-you-translate-or-interpret",
3+
"pages": [
4+
{
5+
"title": "Check your answers",
6+
"path": "/summary",
7+
"controller": "./pages/summary.js",
8+
"components": [],
9+
"next": []
10+
},
11+
{
12+
"path": "/which-languages-do-you-translate-or-interpret",
13+
"title": "Select Interpreters",
14+
"controller": "RepeatedMultiFieldPageController",
15+
"options": {
16+
"sectionKey": "people_you_live_with",
17+
"summaryDisplayMode": {
18+
"samePage": false
19+
},
20+
"customText": {
21+
"separatePageTitle": "You have selected these Interpreters"
22+
}
23+
},
24+
"components": [
25+
{
26+
"name": "Name",
27+
"options": {
28+
"customValidationMessages": {
29+
"string.pattern.base": "Enter a valid first (given) name"
30+
}
31+
},
32+
"type": "TextField",
33+
"title": "Your name",
34+
"schema": {
35+
"regex": "(?=.*[A-Za-zÀ-ÖØ-öø-ÿ]{1}.*[A-Za-zÀ-ÖØ-öø-ÿ]{1}.*)^[\\sA-Za-zÀ-ÖØ-öø-ÿ'\\-,.]*$"
36+
}
37+
},
38+
{
39+
"name": "languagesProvided",
40+
"list": "languages",
41+
"type": "AutocompleteField",
42+
"title": "Language",
43+
"hint": "Start typing and select a language. Add each language separately. Include all the languages you provide a service in, apart from English.",
44+
"schema": {}
45+
}
46+
],
47+
"next": [
48+
{
49+
"path": "/summary"
50+
}
51+
]
52+
}
53+
],
54+
"lists": [
55+
{
56+
"title": "Languages",
57+
"name": "languages",
58+
"type": "string",
59+
"items": [
60+
{
61+
"value": "fr",
62+
"text": "French"
63+
},
64+
{
65+
"value": "es",
66+
"text": "Spanish; Castilian"
67+
},
68+
{
69+
"value": "it",
70+
"text": "Italian"
71+
}
72+
]
73+
}
74+
],
75+
"sections": [],
76+
"phaseBanner": {
77+
"phase": "beta"
78+
},
79+
"metadata": {
80+
"type": "translators-interpreters"
81+
},
82+
"fees": [],
83+
"outputs": [],
84+
"version": 2,
85+
"conditions": [],
86+
"skipSummary": false
87+
}

e2e/cypress/support/step_definitions/common/i_enter_string_for_string.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import { nanoid } from "nanoid";
22
import { When } from "@badeball/cypress-cucumber-preprocessor";
33

44
When("I enter {string} for {string}", (answer, label) => {
5-
cy.findByLabelText(label).type(answer);
5+
cy.findByLabelText(label).clear().type(answer);
66
});

model/src/data-model/types.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ export interface RepeatingFieldPage extends Page {
3737
};
3838
};
3939
}
40+
export interface RepeatingMultiFieldPage extends Page {
41+
controller: "RepeatedMultiFieldPageController";
42+
options: {
43+
sectionKey: string;
44+
summaryDisplayMode?: {
45+
samePage?: boolean;
46+
};
47+
customText?: {
48+
separatePageTitle?: string;
49+
customCardTitle?: string;
50+
};
51+
};
52+
}
4053
export interface CheckpointSummaryPage extends Page {
4154
controller: "CheckpointSummaryPageController";
4255
options: {

0 commit comments

Comments
 (0)