Skip to content

Commit bf0b0cc

Browse files
committed
Reorganize cash transfer tests to share setup steps
1 parent 6f9d1b9 commit bf0b0cc

2 files changed

Lines changed: 150 additions & 121 deletions

File tree

cypress/e2e/cash-trasfer.cy.js

Lines changed: 134 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getProgramTerm } from '../support/utils';
22

3-
describe('Cash transfer workflows', () => {
3+
describe('Cash transfer program creation workflows', () => {
44
let testProgramNames = [];
55

66
beforeEach(function () {
@@ -34,68 +34,6 @@ describe('Cash transfer workflows', () => {
3434
cy.checkProgramFieldValuesInListView(programCode, programName, maxBeneficiaries, programType)
3535
})
3636

37-
it('Updates an individual program', function () {
38-
// Disable maker checker
39-
cy.loginAdminInterface()
40-
cy.setModuleConfig('social_protection', 'social-protection-config.json')
41-
42-
const programCode = 'E2EICPU'
43-
const programName = 'E2E Individual Cash Program Updated'
44-
const maxBeneficiaries = "100"
45-
const programType = "INDIVIDUAL"
46-
47-
cy.createProgram(programCode, programName, maxBeneficiaries, programType)
48-
49-
// Ensure the created program gets cleaned up later
50-
testProgramNames.push(programName);
51-
52-
const updatedProgramCode = 'E2EICP42'
53-
const updatedMaxBeneficiaries = "111"
54-
const updatedInstitution = "Social Protection Agency"
55-
const updatedDescription = "Foo bar baz"
56-
57-
// Go back into the list page to find the program & edit
58-
cy.visit('/front/benefitPlans');
59-
cy.contains('tfoot', 'Rows Per Page')
60-
cy.contains('td', programName)
61-
.parent('tr').within(() => {
62-
// click on edit button
63-
cy.get('a.MuiIconButton-root').click()
64-
})
65-
66-
cy.assertMuiInput('Code', programCode)
67-
cy.enterMuiInput('Code', updatedProgramCode)
68-
cy.assertMuiInput('Code', updatedProgramCode)
69-
70-
cy.enterMuiInput('Max Beneficiaries', updatedMaxBeneficiaries)
71-
72-
cy.enterMuiInput('Institution', updatedInstitution)
73-
74-
cy.enterMuiInput('Description', updatedDescription, 'textarea')
75-
76-
cy.get('[title="Save changes"] button').click()
77-
78-
// Wait for update to complete
79-
cy.get('ul.MuiList-root li div[role="progressbar"]').should('exist')
80-
cy.get('ul.MuiList-root li div[role="progressbar"]').should('not.exist')
81-
82-
// Check last journal message
83-
cy.get('ul.MuiList-root li').first().click()
84-
cy.contains(`Update ${getProgramTerm()}`).should('exist')
85-
cy.contains('Failed to update').should('not.exist')
86-
87-
// Check program field values are persisted
88-
cy.reload()
89-
cy.checkProgramFieldValues(
90-
updatedProgramCode,
91-
programName,
92-
updatedMaxBeneficiaries,
93-
programType,
94-
updatedInstitution,
95-
updatedDescription,
96-
)
97-
})
98-
9937
it('Creates and deletes an household program', function () {
10038
const programCode = 'E2EGCP'
10139
const programName = 'E2E Household Cash Program'
@@ -115,87 +53,162 @@ describe('Cash transfer workflows', () => {
11553
cy.visit('/front/benefitPlans');
11654
cy.checkProgramFieldValuesInListView(programCode, programName, maxBeneficiaries, programType)
11755
})
56+
})
11857

119-
it('Updates a household program', function () {
58+
describe('Cash transfer program update workflows', () => {
59+
before(() => {
12060
// Disable maker checker
12161
cy.loginAdminInterface()
12262
cy.setModuleConfig('social_protection', 'social-protection-config.json')
63+
cy.logoutAdminInterface()
64+
})
12365

124-
const programCode = 'E2EGCPU'
125-
const programName = 'E2E Household Cash Program Updated'
126-
const maxBeneficiaries = "200"
127-
const programType = "GROUP"
128-
129-
cy.createProgram(programCode, programName, maxBeneficiaries, programType)
130-
131-
// Ensure the created program gets cleaned up later
132-
testProgramNames.push(programName);
133-
134-
const updatedProgramCode = 'E2EGCP42'
135-
const updatedMaxBeneficiaries = "222"
136-
const updatedInstitution = "Family Support Services"
137-
const updatedDescription = "A functional program"
138-
139-
// Go back into the list page to find the program & edit
140-
cy.visit('/front/benefitPlans');
141-
cy.contains('tfoot', 'Rows Per Page')
142-
cy.contains('td', programName)
143-
.parent('tr').within(() => {
144-
// click on edit button
145-
cy.get('a.MuiIconButton-root').click()
146-
})
147-
148-
cy.assertMuiInput('Code', programCode)
149-
cy.enterMuiInput('Code', updatedProgramCode)
150-
cy.assertMuiInput('Code', updatedProgramCode)
66+
describe('Individual program', () => {
67+
const programCode = 'E2EICPU'
68+
const programName = 'E2E Individual Cash Program Updated'
69+
const maxBeneficiaries = "100"
70+
const programType = "INDIVIDUAL"
15171

152-
cy.enterMuiInput('Max Beneficiaries', updatedMaxBeneficiaries)
72+
before(() => {
73+
cy.login()
74+
cy.createProgram(programCode, programName, maxBeneficiaries, programType)
75+
})
15376

154-
cy.enterMuiInput('Institution', updatedInstitution)
77+
after(() => {
78+
cy.deleteProgram(programName)
79+
})
15580

156-
cy.enterMuiInput('Description', updatedDescription, 'textarea')
81+
it('Updates an individual program', function () {
82+
const updatedProgramCode = 'E2EICP42'
83+
const updatedMaxBeneficiaries = "111"
84+
const updatedInstitution = "Social Protection Agency"
85+
const updatedDescription = "Foo bar baz"
86+
87+
// Go back into the list page to find the program & edit
88+
cy.visit('/front/benefitPlans');
89+
cy.contains('tfoot', 'Rows Per Page')
90+
cy.contains('td', programName)
91+
.parent('tr').within(() => {
92+
// click on edit button
93+
cy.get('a.MuiIconButton-root').click()
94+
})
95+
96+
cy.assertMuiInput('Code', programCode)
97+
cy.enterMuiInput('Code', updatedProgramCode)
98+
cy.assertMuiInput('Code', updatedProgramCode)
99+
100+
cy.enterMuiInput('Max Beneficiaries', updatedMaxBeneficiaries)
101+
102+
cy.enterMuiInput('Institution', updatedInstitution)
103+
104+
cy.enterMuiInput('Description', updatedDescription, 'textarea')
105+
106+
cy.get('[title="Save changes"] button').click()
107+
108+
// Wait for update to complete
109+
cy.get('ul.MuiList-root li div[role="progressbar"]').should('exist')
110+
cy.get('ul.MuiList-root li div[role="progressbar"]').should('not.exist')
111+
112+
// Check last journal message
113+
cy.get('ul.MuiList-root li').first().click()
114+
cy.contains(`Update ${getProgramTerm()}`).should('exist')
115+
cy.contains('Failed to update').should('not.exist')
116+
117+
// Check program field values are persisted
118+
cy.reload()
119+
cy.checkProgramFieldValues(
120+
updatedProgramCode,
121+
programName,
122+
updatedMaxBeneficiaries,
123+
programType,
124+
updatedInstitution,
125+
updatedDescription,
126+
)
127+
})
128+
})
157129

158-
cy.get('[title="Save changes"] button').click()
130+
describe('Household program', () => {
131+
const programCode = 'E2EGCPU'
132+
const programName = 'E2E Household Cash Program Updated'
133+
const maxBeneficiaries = "200"
134+
const programType = "GROUP"
159135

160-
// Wait for update to complete
161-
cy.get('ul.MuiList-root li div[role="progressbar"]').should('exist')
162-
cy.get('ul.MuiList-root li div[role="progressbar"]').should('not.exist')
136+
before(() => {
137+
cy.login()
138+
cy.createProgram(programCode, programName, maxBeneficiaries, programType)
139+
})
163140

164-
// Check last journal message
165-
cy.get('ul.MuiList-root li').first().click()
166-
cy.contains(`Update ${getProgramTerm()}`).should('exist')
167-
cy.contains('Failed to update').should('not.exist')
141+
after(() => {
142+
cy.deleteProgram(programName)
143+
})
168144

169-
// Check program field values are persisted
170-
cy.reload()
171-
cy.checkProgramFieldValues(
172-
updatedProgramCode,
173-
programName,
174-
updatedMaxBeneficiaries,
175-
programType,
176-
updatedInstitution,
177-
updatedDescription,
178-
)
145+
it('Updates a household program', function () {
146+
const updatedProgramCode = 'E2EGCP42'
147+
const updatedMaxBeneficiaries = "222"
148+
const updatedInstitution = "Family Support Services"
149+
const updatedDescription = "A functional program"
150+
151+
// Go back into the list page to find the program & edit
152+
cy.visit('/front/benefitPlans');
153+
cy.contains('tfoot', 'Rows Per Page')
154+
cy.contains('td', programName)
155+
.parent('tr').within(() => {
156+
// click on edit button
157+
cy.get('a.MuiIconButton-root').click()
158+
})
159+
160+
cy.assertMuiInput('Code', programCode)
161+
cy.enterMuiInput('Code', updatedProgramCode)
162+
cy.assertMuiInput('Code', updatedProgramCode)
163+
164+
cy.enterMuiInput('Max Beneficiaries', updatedMaxBeneficiaries)
165+
166+
cy.enterMuiInput('Institution', updatedInstitution)
167+
168+
cy.enterMuiInput('Description', updatedDescription, 'textarea')
169+
170+
cy.get('[title="Save changes"] button').click()
171+
172+
// Wait for update to complete
173+
cy.get('ul.MuiList-root li div[role="progressbar"]').should('exist')
174+
cy.get('ul.MuiList-root li div[role="progressbar"]').should('not.exist')
175+
176+
// Check last journal message
177+
cy.get('ul.MuiList-root li').first().click()
178+
cy.contains(`Update ${getProgramTerm()}`).should('exist')
179+
cy.contains('Failed to update').should('not.exist')
180+
181+
// Check program field values are persisted
182+
cy.reload()
183+
cy.checkProgramFieldValues(
184+
updatedProgramCode,
185+
programName,
186+
updatedMaxBeneficiaries,
187+
programType,
188+
updatedInstitution,
189+
updatedDescription,
190+
)
191+
})
179192
})
193+
})
180194

181-
it('Imports individuals and groups', function () {
195+
describe('Individuals and groups/households', () => {
196+
before(() => {
197+
// Disable maker checker
182198
cy.loginAdminInterface()
183199
cy.setModuleConfig('individual', 'individual-config-minimal.json')
200+
cy.logoutAdminInterface()
201+
})
184202

203+
it('Imports individuals and groups', function () {
204+
cy.login()
185205
cy.visit('/front/groups')
186206
cy.getItemCount('Group').as('initialGroupCount');
187207

188208
cy.visit('/front/individuals')
189209
cy.getItemCount('Individual').as('initialIndividualCount');
190210

191-
cy.contains('li', 'UPLOAD').click()
192-
193-
cy.get('input[type="file"]').attachFile('individuals.csv');
194-
195-
cy.chooseMuiSelect('Workflow', 'Python Import Individuals')
196-
cy.contains('button', 'Upload Individuals').click();
197-
198-
cy.contains('button', 'Upload Individuals').should('not.exist')
211+
cy.uploadIndividualsCSV()
199212

200213
cy.visit('/front/individuals')
201214
cy.getItemCount("Individual").then(newCount => {

cypress/support/commands.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ Cypress.Commands.add('loginAdminInterface', () => {
2828
})
2929
})
3030

31+
Cypress.Commands.add('logoutAdminInterface', () => {
32+
cy.visit('/api/admin');
33+
cy.contains('button', 'Log out').click()
34+
})
35+
3136
Cypress.Commands.add('deleteModuleConfig', (moduleName) => {
3237
cy.visit('/api/admin/core/moduleconfiguration/');
3338

@@ -231,6 +236,17 @@ Cypress.Commands.add(
231236
})
232237
})
233238

239+
Cypress.Commands.add('uploadIndividualsCSV', () => {
240+
cy.contains('li', 'UPLOAD').click()
241+
242+
cy.get('input[type="file"]').attachFile('individuals.csv');
243+
244+
cy.chooseMuiSelect('Workflow', 'Python Import Individuals')
245+
cy.contains('button', 'Upload Individuals').click();
246+
247+
cy.contains('button', 'Upload Individuals').should('not.exist')
248+
})
249+
234250
Cypress.Commands.add('enterMuiInput', (label, value, inputTag='input') => {
235251
cy.contains('label', label)
236252
.siblings('.MuiInputBase-root')

0 commit comments

Comments
 (0)