Add invoice module E2E tests for payment management#95
Add invoice module E2E tests for payment management#95vaneck237 wants to merge 5 commits intoopenimis:developfrom
Conversation
Shahzaibahmad97
left a comment
There was a problem hiding this comment.
I have added my review, there are some code refactoring suggestions along with some standard following according to the already written e2e tests.
Major blocker in accepting this change is that this test assumes that an invoice is already available in the environment with the code IV-FCUL0001-171000001-2026-06 which will cause this test to always fail in the environment where this invoice doesn't exist. Approach in e2e tests should be to generated the related data for the test case before initiating the test rather than assuming it might already exist.
| cy.enterMuiInput('Fees', payment.fees); | ||
| cy.enterMuiInput('Amount Received', payment.amountReceived); | ||
| cy.chooseMuiDatePicker('Payment Date', payment.paymentDate); | ||
| cy.enterMuiInput('Payment Origin', payment.amountReceived); |
There was a problem hiding this comment.
The form fills amountReceived twice and never tests paymentOrigin. E2E tests should test all the updated fields in assert.
| //invoice actions | ||
| const Invoice = { | ||
|
|
||
| goToList: () => { |
There was a problem hiding this comment.
These actions (goToList, goToForm, fillForm, verifyExists) should be defined as commands in commands.js to align with the structure used throughout the e2e tests.
There was a problem hiding this comment.
I defined these actions in a specific file to the fe-invoice module (InvoicePage.js) because they are specific to the invoice module. For example, in the list view, there is no Add button since invoices are automatically generated by the system after a policy is assigned to a family.
There was a problem hiding this comment.
Since invoice generation is handled by the system, I only have the family's CHFID to retrieve the invoice, This is why I had to create an openRow specific to fe-invoice, which ensures that the generated invoice code contains the family's CHFID
| }) | ||
|
|
||
| // verify delete | ||
| Invoice.goToList(); |
There was a problem hiding this comment.
Navigation is duplicated across all 4 methods. goToList, goToForm, verifyExists, and delete all repeat the same "go to list → search by invoice code → open row" sequence.
This should be extracted as a command "goToInvoicePayments":
cy.commands('goToList');
cy.enterMuiInput('Code', data.invoice.code, 'input');
cy.contains('button', 'Search').click({ force: true });
cy.openRow(data.invoice.code);
cy.contains(data.invoice.code).should('be.visible');
cy.scrollTo('bottom');
cy.contains('Payments').click();
All methods then call this command.
| }); | ||
| cy.contains('button', 'Search').click(); | ||
| cy.get('table').should('be.visible'); | ||
| cy.contains('td', data.payment.code) |
There was a problem hiding this comment.
verifyExists is redundant with delete. delete calls verifyExists then repeats almost identical steps for the confirmation check. Can we extract the "navigate to payments and filter by code" part into a shared helper?
There was a problem hiding this comment.
adjusted in InvoicePage.js in support/pages repository
| let normalizedMonth = month; | ||
| let normalizedYear = year; | ||
|
|
||
| if (day && typeof day === 'object') { |
There was a problem hiding this comment.
After the previous if/else, day is always a primitive. The inner block is unreachable:
// This entire block is dead code — you can remove it if (day && typeof day === 'object') { ... }
There was a problem hiding this comment.
i've refactor the code in a new Datepicker command (chooseCraMuiDatePicker)
| cy.contains('button', 'Search').click(); | ||
| cy.get('table').should('be.visible'); | ||
| cy.contains('td', payment.code) | ||
| .should('be.visible') |
There was a problem hiding this comment.
After creating a payment, only payment.code is verified. A proper create test should assert that the saved record reflects the values that were submitted. Otherwise, the test cannot catch a form that submits but silently drops values.
There was a problem hiding this comment.
it's impossible to edit payment after creation
to ensure field was correctly saved i've implemented verifyRowValues method, to check fields values in row
| cy.contains('button', 'Search').click(); | ||
| cy.get('table').should('be.visible'); | ||
| cy.contains('td', data.payment.code) | ||
| .should('not.be.visible') |
There was a problem hiding this comment.
🟠 Wrong assertion for a deleted record — .should('not.be.visible') passes even if the element exists in the DOM but is hidden.
After deletion, the row should not exist at all.
Use: cy.contains('td', payment.code).should('not.exist');
There was a problem hiding this comment.
fixed in deletePayment method in InvoicePage.js
| paymentOrigin: "epargne" | ||
| }, | ||
| invoice: { | ||
| code: "IV-FCUL0001-171000001-2026-06" |
There was a problem hiding this comment.
🟡 Hardcoded invoice code will fail on any environment that doesn't have this exact record. This will fail in CI. Best approach is to ensure the data exists before testing. i.e. create this invoice in the test code and then use the code from the created invoice.
There was a problem hiding this comment.
i've add the family and policy attribution process to generate the invoice
| }, | ||
| "scripts": { | ||
| "cy:open": "cypress open" | ||
| "cy open": "cypress open", |
There was a problem hiding this comment.
🟡 Script names with spaces are not usable from the command line (npm run cy open will not work) and duplicate the colon-style scripts already present.
Remove the space-named entries. The correct scripts are already there:
"scripts": { "cy:open": "cypress open", "cy:run": "cypress run" }
| }); | ||
|
|
||
| it('Create a new payment for invoice', () => { | ||
| cy.login(); |
There was a problem hiding this comment.
🟡 Login belongs in beforeEach, not inside the test body.
This is the pattern used throughout the rest of the test suite. As more tests are added to this describe block, each one will need cy.login() manually. Move it up:
describe('Invoice payment workflow', () => { beforeEach(() => { cy.login(); }); // ... });
I made a lot of changes based on your feedbak, could you please double check? |
Description
This is an implementation of E2E test for add and delete invoice payment
The testing process is as follows:
Type of Change
Related Issue(s) / Task(s)
Demo
Screen.Recording.2026-04-21.at.2.06.01.PM.mov
Checklist