Skip to content

Commit a0cfb56

Browse files
ARN-2197 OA Cypress tests (#590)
Co-authored-by: Lucas Cairns <lucas.cairns@gmail.com>
1 parent 8980dda commit a0cfb56

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1974
-129
lines changed

.eslintrc.json

+6
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@
5555
"printWidth": 120,
5656
"semi": false
5757
}
58+
],
59+
"no-plusplus": [
60+
"error",
61+
{
62+
"allowForLoopAfterthoughts": true
63+
}
5864
]
5965
}
6066
},

app/controllers/baseCollectionController.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ abstract class BaseCollectionController extends BaseController {
6262
const answerPairs = fields.map(it => [it.code, req.form.values[it.code]])
6363
const collectionEntry: FormWizard.CollectionEntry = Object.fromEntries(answerPairs)
6464

65-
const persistedCollection = (req.form.persistedAnswers[this.field.code] || []) as FormWizard.CollectionEntry[]
65+
const persistedCollection = [
66+
...((req.form.persistedAnswers[this.field.code] || []) as FormWizard.CollectionEntry[]),
67+
]
6668

6769
const entryId = Number.parseInt(req.params.entryId, 10)
6870

@@ -312,7 +314,7 @@ abstract class BaseCollectionController extends BaseController {
312314
}
313315

314316
if (this.getFormAction(req.url) === CollectionAction.Create) {
315-
const newEntryIndex = (req.form.persistedAnswers[this.field.code] || []).length - 1
317+
const newEntryIndex = (req.form.persistedAnswers[this.field.code] || []).length
316318
const updateUrl = `${this.field.collection.updateUrl}/${newEntryIndex}`
317319
const updatedErrors = Object.fromEntries(
318320
Object.entries(req.sessionModel.get('errors')).map(([key, error]) => [

app/form/v1_0/fields/offence-analysis.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ class OffenceAnalysisFieldsFactory extends FieldsFactory {
405405
}
406406

407407
offenceAnalysisVictimsCollection: FormWizard.Field = {
408-
text: 'Victim details',
408+
text: 'Victims',
409409
code: 'offence_analysis_victims_collection',
410410
type: FieldType.Collection,
411411
collection: {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
describe('Origin: /offence-analysis', () => {
2+
const destinations = {
3+
landingPage: '/offence-analysis',
4+
victimCreate: '/offence-analysis-victim/create',
5+
victimUpdate: '/offence-analysis-victim/edit',
6+
victimDelete: '/offence-analysis-victim/delete',
7+
victimsSummary: '/offence-analysis-victims-summary',
8+
othersInvolved: '/offence-analysis-others-involved',
9+
details: '/offence-analysis-details',
10+
summary: '/offence-analysis-complete',
11+
}
12+
13+
const sectionName = 'Offence analysis'
14+
15+
before(() => {
16+
cy.createAssessment()
17+
})
18+
19+
beforeEach(() => {
20+
cy.enterAssessment()
21+
})
22+
23+
describe(`Destination: ${destinations.othersInvolved}`, () => {
24+
it(`Victim is "Other" routes to "${destinations.othersInvolved}"`, () => {
25+
cy.visitStep(destinations.landingPage)
26+
27+
cy.getQuestion('Enter a brief description of the current index offence(s)').enterText('Test')
28+
cy.getQuestion('Did the current index offence(s) have any of the following elements?')
29+
.getCheckbox('Arson')
30+
.clickLabel()
31+
cy.getQuestion('Why did the current index offence(s) happen?').enterText('Test')
32+
cy.getQuestion('Did the current index offence(s) involve any of the following motivations?')
33+
.getCheckbox('Thrill seeking')
34+
.clickLabel()
35+
cy.getQuestion('Who was the victim?').getCheckbox('Other').clickLabel()
36+
cy.getQuestion('Who was the victim?').getCheckbox('Other').getConditionalQuestion().enterText('Test')
37+
38+
cy.assertResumeUrlIs(sectionName, destinations.landingPage)
39+
cy.saveAndContinue()
40+
cy.assertStepUrlIs(destinations.othersInvolved)
41+
cy.assertResumeUrlIs(sectionName, destinations.othersInvolved)
42+
})
43+
44+
describe(`Destination: ${destinations.details}`, () => {
45+
it(`Routes to "${destinations.details}"`, () => {
46+
cy.visitStep(destinations.othersInvolved)
47+
48+
cy.getQuestion('How many other people were involved with committing the current index offence(s)?')
49+
.getRadio('1')
50+
.clickLabel()
51+
52+
cy.assertResumeUrlIs(sectionName, destinations.othersInvolved)
53+
cy.saveAndContinue()
54+
cy.assertStepUrlIs(destinations.details)
55+
cy.assertResumeUrlIs(sectionName, destinations.details)
56+
})
57+
58+
describe(`Destination: ${destinations.summary}`, () => {
59+
it(`Routes to "${destinations.summary}"`, () => {
60+
cy.visitStep(destinations.details)
61+
62+
cy.getQuestion('Was Sam the leader in regard to committing the current index offence(s)?')
63+
.getRadio('No')
64+
.clickLabel()
65+
cy.getQuestion(
66+
'Does Sam recognise the impact or consequences on the victims or others and the wider community?',
67+
)
68+
.getRadio('No')
69+
.clickLabel()
70+
cy.getQuestion('Does Sam accept responsibility for the current index offence(s)?').getRadio('No').clickLabel()
71+
cy.getQuestion('What are the patterns of offending?').enterText('¯\\_(ツ)_/¯')
72+
cy.getQuestion('Is the current offence(s) an escalation in seriousness from previous offending?')
73+
.getRadio('No')
74+
.clickLabel()
75+
cy.getQuestion(
76+
'Is the current offence(s) linked to risk of serious harm, risks to the individual or other risks?',
77+
)
78+
.getRadio('No')
79+
.clickLabel()
80+
cy.getQuestion(
81+
'Is the current offence(s) linked to risk of serious harm, risks to the individual or other risks?',
82+
)
83+
.getRadio('No')
84+
.getConditionalQuestion()
85+
.enterText('¯\\_(ツ)_/¯')
86+
cy.getQuestion('Is there evidence that Sam has ever been a perpetrator of domestic abuse?')
87+
.getRadio('No')
88+
.clickLabel()
89+
cy.getQuestion('Is there evidence that Sam has ever been a victim of domestic abuse?')
90+
.getRadio('No')
91+
.clickLabel()
92+
93+
cy.assertResumeUrlIs(sectionName, destinations.details)
94+
cy.markAsComplete()
95+
cy.assertStepUrlIs(destinations.summary)
96+
cy.assertResumeUrlIs(sectionName, destinations.summary)
97+
cy.currentSectionMarkedAsComplete(sectionName)
98+
99+
// checkmark is removed on making a change
100+
cy.getSummary(
101+
'How many other people were involved with committing the current index offence(s)?',
102+
).clickChange()
103+
cy.assertStepUrlIs(destinations.othersInvolved)
104+
cy.getQuestion('How many other people were involved with committing the current index offence(s)?')
105+
.getRadio('2')
106+
.clickLabel()
107+
cy.saveAndContinue()
108+
109+
cy.assertStepUrlIs(destinations.details)
110+
cy.currentSectionNotMarkedAsComplete(sectionName)
111+
cy.markAsComplete()
112+
113+
cy.assertStepUrlIs(destinations.summary)
114+
cy.currentSectionMarkedAsComplete(sectionName)
115+
})
116+
})
117+
})
118+
})
119+
120+
describe(`Destination: ${destinations.victimCreate}`, () => {
121+
it(`Victim is "One or more person" routes to "${destinations.victimCreate}"`, () => {
122+
cy.visitStep(destinations.landingPage)
123+
124+
cy.getQuestion('Who was the victim?').getCheckbox('One or more person').clickLabel()
125+
126+
cy.assertResumeUrlIs(sectionName, destinations.landingPage)
127+
cy.saveAndContinue()
128+
cy.assertStepUrlIs(destinations.victimCreate)
129+
cy.assertResumeUrlIs(sectionName, destinations.victimsSummary)
130+
})
131+
132+
describe(`Destination: ${destinations.victimsSummary}`, () => {
133+
it(`routes to ${destinations.victimsSummary}`, () => {
134+
cy.visitStep(destinations.victimCreate)
135+
136+
cy.getQuestion("What is Sam's relationship to the victim?").getRadio('A stranger').clickLabel()
137+
cy.getQuestion("What is the victim's approximate age?").getRadio('0 to 4 years').clickLabel()
138+
cy.getQuestion("What is the victim's sex?").getRadio('Male').clickLabel()
139+
cy.getQuestion("What is the victim's race or ethnicity?").enterText('white{enter}')
140+
cy.saveAndContinue()
141+
cy.assertStepUrlIs(destinations.victimsSummary)
142+
cy.assertResumeUrlIs(sectionName, destinations.victimsSummary)
143+
})
144+
145+
describe(`Destination: ${destinations.othersInvolved}`, () => {
146+
it(`routes to ${destinations.othersInvolved}`, () => {
147+
cy.assertResumeUrlIs(sectionName, destinations.victimsSummary)
148+
149+
cy.visitStep(destinations.victimsSummary)
150+
cy.saveAndContinue()
151+
cy.assertStepUrlIs(destinations.othersInvolved)
152+
})
153+
154+
describe(`Destination: ${destinations.details}`, () => {
155+
it(`routes to ${destinations.details}`, () => {
156+
cy.assertResumeUrlIs(sectionName, destinations.details)
157+
158+
cy.visitStep(destinations.othersInvolved)
159+
cy.saveAndContinue()
160+
cy.assertStepUrlIs(destinations.details)
161+
})
162+
163+
describe(`Destination: ${destinations.summary}`, () => {
164+
it(`routes to ${destinations.summary}`, () => {
165+
cy.assertResumeUrlIs(sectionName, destinations.details)
166+
167+
cy.visitStep(destinations.details)
168+
cy.markAsComplete()
169+
cy.assertStepUrlIs(destinations.summary)
170+
cy.assertResumeUrlIs(sectionName, destinations.summary)
171+
})
172+
})
173+
})
174+
})
175+
})
176+
})
177+
})

cypress/e2e/v1.0/pages/accommodation/questions/livingWith.ts

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export default (stepUrl: string, summaryPage: string, positionNumber: number) =>
6565
})
6666
cy.checkAccessibility()
6767
})
68+
6869
Array.of(
6970
['Partner', 'Include name, age and gender.'],
7071
['Person under 18 years old', 'Include name, date of birth or age, gender and their relationship to Sam.'],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import whoWasTheLeader from './questions/whoWasTheLeader'
2+
import recogniseImpactOnVictims from './questions/recogniseImpactOnVictims'
3+
import acceptResponsibility from './questions/acceptResponsibility'
4+
import patternsOfOffending from './questions/patternsOfOffending'
5+
import escalationInSeriousness from './questions/escalationInSeriousness'
6+
import linkedToRiskOfSeriousHarm from './questions/linkedToRiskOfSeriousHarm'
7+
import perpetratorOfDomesticAbuse from './questions/perpetratorOfDomesticAbuse'
8+
import victimOfDomesticAbuse from './questions/victimOfDomesticAbuse'
9+
10+
describe('/offence-analysis-details', () => {
11+
const stepUrl = '/offence-analysis-details'
12+
const summaryPage = '/offence-analysis-complete'
13+
const questions = [
14+
whoWasTheLeader,
15+
recogniseImpactOnVictims,
16+
acceptResponsibility,
17+
patternsOfOffending,
18+
escalationInSeriousness,
19+
linkedToRiskOfSeriousHarm,
20+
perpetratorOfDomesticAbuse,
21+
victimOfDomesticAbuse,
22+
]
23+
24+
before(() => {
25+
cy.createAssessment().enterAssessment()
26+
cy.visitSection('Offence analysis')
27+
28+
cy.getQuestion('Enter a brief description of the current index offence(s)').enterText('¯\\_(ツ)_/¯')
29+
cy.getQuestion('Did the current index offence(s) have any of the following elements?')
30+
.getCheckbox('Arson')
31+
.clickLabel()
32+
cy.getQuestion('Why did the current index offence(s) happen?').enterText('¯\\_(ツ)_/¯')
33+
cy.getQuestion('Did the current index offence(s) involve any of the following motivations?')
34+
.getCheckbox('Thrill seeking')
35+
.clickLabel()
36+
cy.getQuestion('Who was the victim?').getCheckbox('Other').clickLabel()
37+
cy.getQuestion('Who was the victim?').getCheckbox('Other').getConditionalQuestion().enterText('¯\\_(ツ)_/¯')
38+
cy.saveAndContinue()
39+
40+
cy.getQuestion('How many other people were involved with committing the current index offence(s)?')
41+
.getRadio('There was no one else involved')
42+
.clickLabel()
43+
cy.saveAndContinue()
44+
45+
cy.assertStepUrlIs(stepUrl)
46+
cy.assertResumeUrlIs('Offence analysis', stepUrl)
47+
48+
cy.captureAssessment()
49+
})
50+
51+
beforeEach(() => {
52+
cy.cloneCapturedAssessment().enterAssessment()
53+
cy.visitStep(stepUrl)
54+
cy.assertQuestionCount(questions.length)
55+
cy.hasAutosaveEnabled()
56+
})
57+
58+
questions.forEach((questionTest, index) => {
59+
questionTest(stepUrl, summaryPage, index + 1)
60+
})
61+
62+
it('Should have no accessibility violations', () => {
63+
cy.checkAccessibility()
64+
})
65+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import othersInvolved from './questions/othersInvolved'
2+
3+
describe('/offence-analysis-others-involved', () => {
4+
const stepUrl = '/offence-analysis-others-involved'
5+
const summaryPage = '/offence-analysis-complete'
6+
const questions = [othersInvolved]
7+
8+
before(() => {
9+
cy.createAssessment().enterAssessment()
10+
cy.visitSection('Offence analysis')
11+
12+
cy.getQuestion('Enter a brief description of the current index offence(s)').enterText('¯\\_(ツ)_/¯')
13+
cy.getQuestion('Did the current index offence(s) have any of the following elements?')
14+
.getCheckbox('Arson')
15+
.clickLabel()
16+
cy.getQuestion('Why did the current index offence(s) happen?').enterText('¯\\_(ツ)_/¯')
17+
cy.getQuestion('Did the current index offence(s) involve any of the following motivations?')
18+
.getCheckbox('Thrill seeking')
19+
.clickLabel()
20+
cy.getQuestion('Who was the victim?').getCheckbox('Other').clickLabel()
21+
cy.getQuestion('Who was the victim?').getCheckbox('Other').getConditionalQuestion().enterText('¯\\_(ツ)_/¯')
22+
23+
cy.saveAndContinue()
24+
cy.assertStepUrlIs(stepUrl)
25+
cy.assertResumeUrlIs('Offence analysis', stepUrl)
26+
27+
cy.captureAssessment()
28+
})
29+
30+
beforeEach(() => {
31+
cy.cloneCapturedAssessment().enterAssessment()
32+
cy.visitStep(stepUrl)
33+
cy.assertQuestionCount(questions.length)
34+
cy.hasAutosaveEnabled()
35+
})
36+
37+
questions.forEach((questionTest, index) => {
38+
questionTest(stepUrl, summaryPage, index + 1)
39+
})
40+
41+
it('Should have no accessibility violations', () => {
42+
cy.checkAccessibility()
43+
})
44+
})

0 commit comments

Comments
 (0)