diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..318978b Binary files /dev/null and b/.DS_Store differ diff --git a/cypress/e2e/contribution_plan.cy.js b/cypress/e2e/contribution_plan.cy.js new file mode 100644 index 0000000..b863ca4 --- /dev/null +++ b/cypress/e2e/contribution_plan.cy.js @@ -0,0 +1,121 @@ +const contributionPlan = { + code: "CP007", + name: "Plan familiale", + calculationRule: "CV: legacy", + product: "BCTA0001 Basic Cover Tahida", + periodicity: "4.00", + validFrom: "13" +} + +// contributions plans actions +const ContributionPlan = { + + goToList: () => { + cy.contains('Administration').click(); + cy.contains('a', 'Contribution Plans').click(); + }, + + goToForm: (data) => { + ContributionPlan.goToList(); + if (data?.code) { + cy.enterMuiInput('Code', data.code, "input"); + cy.contains('button', 'Search').click({ force: true }); + cy.openRow(data.code); + } else { + cy.get('.fab').click(); + } + }, + + fillForm: (data) => { + cy.enterMuiInput('Code', data.code); + cy.enterMuiInput('Name', data.name); + cy.chooseMuiSelect('Calculation Rule', data.calculationRule); + cy.chooseMuiSelect('Product', data.product); + cy.enterMuiInput('Periodicity (no of months)', data.periodicity); + cy.chooseMuiDatePicker('Valid from',data.validFrom); + //cy.assertMuiInput('Valid from', data.validFrom) + }, + + verifyExists: (data) => { + ContributionPlan.goToList(); + cy.enterMuiInput('Code', data.code, "input"); + cy.contains('button', 'Search').click({ force: true }); + cy.get('table').should('be.visible'); + //cy.scrollTo('right'); + }, + + open: (data) => { + ContributionPlan.verifyExists(data); + cy.contains(data.code); + cy.contains(data.name); + cy.contains('td', data.code) + .should('be.visible') + .dblclick() + }, + + delete: (data, options = {}) => { + const { failIfMissing = true } = options; + + ContributionPlan.verifyExists(data) + cy.contains(data.code); + cy.scrollTo('right'); + + cy.get('body').then(($body) => { + const hasContributionPlan = $body.find('tr').toArray().some((row) => row.innerText.includes(data.code)); + + if (!hasContributionPlan) { + if (!failIfMissing) { + cy.log(`Contribtion Plan ${data.code} not found, skipping deletion`); + return; + } + throw new Error(`Contribution Plan ${data.code} not found for deletion`); + } + + cy.contains('tr', data.code) + .within(() => { + cy.contains('button', 'Delete').click(); + }); + cy.contains('button', 'OK', { matchCase: false }).click(); + + // Vérifier la suppression + ContributionPlan.verifyExists(contributionPlan); + cy.contains('td', contributionPlan.code).should('not.exist'); + }); + }, +}; + +// Tests for contributions plans +describe('Contribution Plan Workflow', () => { + + afterEach(() => { + // delete + ContributionPlan.delete(contributionPlan, { failIfMissing: false }); + }); + + it('Create and update a new Contribution plan', () => { + + cy.login(); + // create + ContributionPlan.goToForm(null); + ContributionPlan.fillForm(contributionPlan); + cy.save(); + + // // Verification + ContributionPlan.verifyExists(contributionPlan); + cy.contains(contributionPlan.code).should('be.visible'); + cy.contains(contributionPlan.name).should('be.visible'); + + // Update Contribution Plan + const updatedName = 'Contribution 00033'; + ContributionPlan.open(contributionPlan); + cy.enterMuiInput('Name', updatedName); + cy.save(); + + // check + ContributionPlan.verifyExists({ + ...contributionPlan, + name: updatedName + }); + }); + +}); \ No newline at end of file diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 8d48d0d..810d751 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -6,7 +6,7 @@ const getTodayFormatted = () => { return `${day}-${month}-${year}`; }; -DEFAULT_LOGIN_FORM_TIMEOUT = 20000 +const DEFAULT_LOGIN_FORM_TIMEOUT = 200000; Cypress.Commands.add('login', () => { const loginFormTimeout = Number(Cypress.env('LOGIN_FORM_TIMEOUT')) || DEFAULT_LOGIN_FORM_TIMEOUT;