Skip to content

Commit 8a95114

Browse files
refactor(e2e): reuse autocomplete helper and remove redundant picker command
1 parent f6fd7be commit 8a95114

3 files changed

Lines changed: 62 additions & 91 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
This repository provides configuration files for deploying openIMIS via Docker. This is intended to help you setup all components to quickly setup, test and evaluate the solution.
88

99
Detailed instructions are in our Wiki: [Installation Guide](https://openimis.atlassian.net/wiki/spaces/OP/pages/963182705/MO1.1+Install+the+modular+openIMIS+using+Docker)
10+

cypress/e2e/grievance.cy.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ describe('Grievance module workflows', () => {
296296
});
297297

298298
it('Filters grievances by category', function () {
299-
cy.selectDropdownByLabel('Category', 'Category A');
299+
cy.chooseMuiAutocomplete('Category', 'Category A');
300300
cy.wait(900); // wait for 800ms filter debounce before triggering search
301301
cy.contains('button', 'Search').click();
302302
cy.contains('tfoot', 'Rows Per Page').should('be.visible');
@@ -309,7 +309,7 @@ describe('Grievance module workflows', () => {
309309
});
310310

311311
it('Filters grievances by priority', function () {
312-
cy.selectDropdownByLabel('Priority', 'Critical');
312+
cy.chooseMuiSelect('Priority', 'Critical');
313313
cy.wait(900); // wait for 800ms filter debounce before triggering search
314314
cy.contains('button', 'Search').click();
315315
cy.contains('tfoot', 'Rows Per Page').should('be.visible');
@@ -348,8 +348,8 @@ describe('Grievance module workflows', () => {
348348

349349
it('Clears all filters when Clear button is clicked', function () {
350350
cy.enterMuiInput('Title', 'Test Filter');
351-
cy.selectDropdownByLabel('Priority', 'Critical');
352-
cy.selectDropdownByLabel('Category', 'Category A');
351+
cy.chooseMuiSelect('Priority', 'Critical');
352+
cy.chooseMuiAutocomplete('Category', 'Category A');
353353

354354
cy.contains('button', 'Reset filters').click();
355355

@@ -366,20 +366,19 @@ describe('Grievance module workflows', () => {
366366

367367
describe('Grievance update workflow', () => {
368368
const timestamp = getTimestamp();
369+
const grievanceData = {
370+
title: `E2E Update Test Grievance ${timestamp}`,
371+
category: 'Category A',
372+
flag: 'Flag A',
373+
channel: 'Channel A',
374+
priority: 'Normal',
375+
details: 'Initial grievance details for update testing.',
376+
reporterType: 'Attending Staff',
377+
};
369378
let grievanceCode;
370379

371380
before(function () {
372381
cy.login();
373-
const grievanceData = {
374-
title: `E2E Update Test Grievance ${timestamp}`,
375-
category: 'Category A',
376-
flag: 'Flag A',
377-
channel: 'Channel A',
378-
priority: 'Normal',
379-
details: 'Initial grievance details for update testing.',
380-
reporterType: 'None',
381-
};
382-
383382
cy.createGrievance(grievanceData);
384383
cy.getGrievanceCodeFromList(grievanceData.title).then(code => {
385384
grievanceCode = code;
@@ -393,7 +392,9 @@ describe('Grievance module workflows', () => {
393392
category: 'Category B',
394393
};
395394

396-
cy.updateGrievance(grievanceCode, updateData);
395+
cy.updateGrievance(grievanceCode, updateData, {
396+
reporterFieldLabel: 'User',
397+
});
397398

398399
cy.visit('/front/ticket/tickets');
399400
cy.checkGrievanceFieldValuesInListView(updateData.title, updateData.category);
@@ -405,7 +406,9 @@ describe('Grievance module workflows', () => {
405406
details: 'Updated grievance details with critical priority.',
406407
};
407408

408-
cy.updateGrievance(grievanceCode, updateData);
409+
cy.updateGrievance(grievanceCode, updateData, {
410+
reporterFieldLabel: 'User',
411+
});
409412
});
410413
});
411414

cypress/support/commands.js

Lines changed: 42 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -633,21 +633,6 @@ Cypress.Commands.add('chooseMuiSelect', (label, value) => {
633633
cy.get('@option').click()
634634
})
635635

636-
Cypress.Commands.add('selectDropdownByLabel', (label, value = null) => {
637-
cy.contains('label', label)
638-
.parent()
639-
.click()
640-
641-
if (value) {
642-
cy.contains('li[role="option"]', value)
643-
.click()
644-
} else {
645-
cy.get('li[role="option"]')
646-
.first()
647-
.click()
648-
}
649-
})
650-
651636
Cypress.Commands.add('assertMuiInput', (label, value, inputTag='input') => {
652637
cy.contains('label', label)
653638
.siblings('.MuiInputBase-root')
@@ -673,13 +658,23 @@ Cypress.Commands.add('assertMuiSelectValue', (label, value) => {
673658
.contains(value)
674659
})
675660

676-
Cypress.Commands.add('chooseMuiAutocomplete', (label, value) => {
661+
Cypress.Commands.add('chooseMuiAutocomplete', (label, value = null) => {
677662
cy.contains('label', label)
678663
.siblings('.MuiInputBase-root')
679664
.find('input')
680665
.click()
681666

682-
cy.contains('[role="menu"] li, [role="presentation"] li', value).click();
667+
const optionSelector = '[role="menu"] li, [role="presentation"] li, [role="listbox"] li, li[role="option"]'
668+
669+
if (value) {
670+
cy.contains(optionSelector, value).click();
671+
return
672+
}
673+
674+
cy.get(optionSelector)
675+
.should('have.length.at.least', 1)
676+
.first()
677+
.click()
683678
})
684679

685680
Cypress.Commands.add('setModuleConfig', (moduleName, configFixtureFile) => {
@@ -731,13 +726,13 @@ Cypress.Commands.add('createGrievance', (grievanceData) => {
731726

732727
// Required fields
733728
cy.enterMuiInput('Grievance Title', grievanceData.title);
734-
cy.selectDropdownByLabel('Category', grievanceData.category);
735-
cy.selectDropdownByLabel('Flag', grievanceData.flag);
736-
cy.selectDropdownByLabel('Channel', grievanceData.channel);
729+
cy.chooseMuiAutocomplete('Category', grievanceData.category);
730+
cy.chooseMuiAutocomplete('Flag', grievanceData.flag);
731+
cy.chooseMuiAutocomplete('Channel', grievanceData.channel);
737732

738733
// Optional fields
739734
if (grievanceData.priority) {
740-
cy.selectDropdownByLabel('Priority', grievanceData.priority);
735+
cy.chooseMuiSelect('Priority', grievanceData.priority);
741736
}
742737

743738
if (grievanceData.dateOfIncident) {
@@ -757,7 +752,7 @@ Cypress.Commands.add('createGrievance', (grievanceData) => {
757752

758753
// Reporter type handling
759754
if (grievanceData.reporterType) {
760-
cy.selectDropdownByLabel('Reporter Type', grievanceData.reporterType);
755+
cy.chooseMuiSelect('Reporter Type', grievanceData.reporterType);
761756

762757
if (grievanceData.reporterType === 'Individual') {
763758
if (grievanceData.benefitPlan) {
@@ -766,12 +761,7 @@ Cypress.Commands.add('createGrievance', (grievanceData) => {
766761
if (grievanceData.individual) {
767762
cy.chooseMuiAutocomplete('Individual', grievanceData.individual);
768763
} else {
769-
// Select first available individual
770-
cy.contains('label', 'Individual')
771-
.siblings('.MuiInputBase-root')
772-
.find('input')
773-
.click();
774-
cy.get('[role="menu"] li, [role="presentation"] li').first().click();
764+
cy.chooseMuiAutocomplete('Individual');
775765
}
776766
} else if (grievanceData.reporterType === 'Beneficiary') {
777767
if (grievanceData.benefitPlan) {
@@ -780,26 +770,13 @@ Cypress.Commands.add('createGrievance', (grievanceData) => {
780770
if (grievanceData.beneficiary) {
781771
cy.chooseMuiAutocomplete('BeneficiaryPicker', grievanceData.beneficiary);
782772
} else {
783-
// Select first available beneficiary
784-
cy.contains('label', 'BeneficiaryPicker')
785-
.siblings('.MuiInputBase-root')
786-
.find('input')
787-
.click();
788-
cy.get('[role="menu"] li, [role="presentation"] li')
789-
.should('have.length.at.least', 1)
790-
.first()
791-
.click();
773+
cy.chooseMuiAutocomplete('BeneficiaryPicker');
792774
}
793775
} else if (grievanceData.reporterType === 'Attending Staff') {
794776
if (grievanceData.attendingStaff) {
795777
cy.chooseMuiAutocomplete('Complainant', grievanceData.attendingStaff);
796778
} else {
797-
// Select first available staff
798-
cy.contains('label', 'Complainant')
799-
.siblings('.MuiInputBase-root')
800-
.find('input')
801-
.click();
802-
cy.get('[role="menu"] li, [role="presentation"] li').first().click();
779+
cy.chooseMuiAutocomplete('Complainant');
803780
}
804781
}
805782
}
@@ -817,7 +794,7 @@ Cypress.Commands.add('createGrievance', (grievanceData) => {
817794
cy.contains('Failed to create').should('not.exist');
818795
});
819796

820-
Cypress.Commands.add('updateGrievance', (grievanceCode, updateData) => {
797+
Cypress.Commands.add('updateGrievance', (grievanceCode, updateData, immutableFields = {}) => {
821798
cy.visit('/front/ticket/tickets');
822799
cy.contains('tfoot', 'Rows Per Page').should('be.visible');
823800

@@ -833,25 +810,36 @@ Cypress.Commands.add('updateGrievance', (grievanceCode, updateData) => {
833810
cy.get('button[title="Edit"]').click();
834811
});
835812

813+
if (immutableFields.reporterType) {
814+
cy.assertMuiInputDisabled('Reporter Type', immutableFields.reporterType);
815+
}
816+
817+
if (immutableFields.reporterFieldLabel) {
818+
cy.assertMuiInputDisabled(
819+
immutableFields.reporterFieldLabel,
820+
immutableFields.reporterFieldValue ?? null
821+
);
822+
}
823+
836824
// Update fields (excluding reporter type and reporter info)
837825
if (updateData.title) {
838826
cy.enterMuiInput('Title', updateData.title);
839827
}
840828

841829
if (updateData.category) {
842-
cy.selectDropdownByLabel('Category', updateData.category);
830+
cy.chooseMuiAutocomplete('Category', updateData.category);
843831
}
844832

845833
if (updateData.flag) {
846-
cy.selectDropdownByLabel('Flag', updateData.flag);
834+
cy.chooseMuiAutocomplete('Flag', updateData.flag);
847835
}
848836

849837
if (updateData.channel) {
850-
cy.selectDropdownByLabel('Channel', updateData.channel);
838+
cy.chooseMuiAutocomplete('Channel', updateData.channel);
851839
}
852840

853841
if (updateData.priority) {
854-
cy.selectDropdownByLabel('Priority', updateData.priority);
842+
cy.chooseMuiSelect('Priority', updateData.priority);
855843
}
856844

857845
if (updateData.details) {
@@ -901,17 +889,11 @@ Cypress.Commands.add('unlockGrievance', (grievanceCode) => {
901889
cy.contains('Failed').should('not.exist');
902890
});
903891

904-
Cypress.Commands.add('checkGrievanceFieldValues', (title, _category, flag, channel, priority = null, details = null) => {
892+
Cypress.Commands.add('checkGrievanceFieldValues', (title, category, flag, channel, priority = null, details = null) => {
905893
cy.assertMuiInput('Grievance Title', title);
906-
// Category uses DropDownCategoryPicker (Autocomplete with object options).
907-
// The API returns category as a plain string, so the Autocomplete cannot match it
908-
// to an option object and shows an empty input — skip this assertion.
909-
// Flag uses FlagsPicker (Autocomplete with string options → input is visible and has the value).
894+
cy.assertMuiInput('Category', category);
910895
cy.assertMuiInput('Flag', flag);
911-
// Channel uses ChannelPicker (Autocomplete with string options → same as Flag).
912896
cy.assertMuiInput('Channel', channel);
913-
// Priority uses TicketPriorityPicker (ConstantBasedPicker / MUI Select).
914-
// The selected text is rendered as DOM text content, so use assertMuiSelectValue.
915897
if (priority) {
916898
cy.assertMuiSelectValue('Priority', priority);
917899
}
@@ -986,7 +968,7 @@ Cypress.Commands.add('addGrievanceComment', (commentText, commentData = {}) => {
986968
});
987969

988970
if (commentData.reporterType) {
989-
cy.selectDropdownByLabel('Reporter Type', commentData.reporterType);
971+
cy.chooseMuiSelect('Reporter Type', commentData.reporterType);
990972

991973
if (commentData.reporterType === 'Individual') {
992974
if (commentData.benefitPlan) {
@@ -995,11 +977,7 @@ Cypress.Commands.add('addGrievanceComment', (commentText, commentData = {}) => {
995977
if (commentData.individual) {
996978
cy.chooseMuiAutocomplete('Individual', commentData.individual);
997979
} else {
998-
cy.contains('label', 'Individual')
999-
.siblings('.MuiInputBase-root')
1000-
.find('input')
1001-
.click();
1002-
cy.get('[role="menu"] li, [role="presentation"] li').first().click();
980+
cy.chooseMuiAutocomplete('Individual');
1003981
}
1004982
} else if (commentData.reporterType === 'Beneficiary') {
1005983
if (commentData.benefitPlan) {
@@ -1008,24 +986,13 @@ Cypress.Commands.add('addGrievanceComment', (commentText, commentData = {}) => {
1008986
if (commentData.beneficiary) {
1009987
cy.chooseMuiAutocomplete('Beneficiary', commentData.beneficiary);
1010988
} else {
1011-
cy.contains('label', 'Beneficiary')
1012-
.siblings('.MuiInputBase-root')
1013-
.find('input')
1014-
.click();
1015-
cy.get('[role="menu"] li, [role="presentation"] li')
1016-
.should('have.length.at.least', 1)
1017-
.first()
1018-
.click();
989+
cy.chooseMuiAutocomplete('Beneficiary');
1019990
}
1020991
} else if (commentData.reporterType === 'Attending Staff') {
1021992
if (commentData.attendingStaff) {
1022993
cy.chooseMuiAutocomplete('Commenter', commentData.attendingStaff);
1023994
} else {
1024-
cy.contains('label', 'Commenter')
1025-
.siblings('.MuiInputBase-root')
1026-
.find('input')
1027-
.click();
1028-
cy.get('[role="menu"] li, [role="presentation"] li').first().click();
995+
cy.chooseMuiAutocomplete('Commenter');
1029996
}
1030997
}
1031998
}

0 commit comments

Comments
 (0)