Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ node_modules/
cypress/screenshots/
cypress/downloads/
cypress/fixtures/tmp_individuals.csv
.DS_Store
./*.DS_Store
./.DS_Store
28 changes: 28 additions & 0 deletions cypress/e2e/claim.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ClaimPage } from "../support/pages/claimPage";

describe('Test for claim restoration', ()=>{
let data;
const claimPage = new ClaimPage();

before(() => {
cy.fixture('claim').then((fixture) => {
data = fixture;
});
});

beforeEach(() => {
cy.login();
});

it('Claim restoration workflow', ()=>{
claimPage.openFirstRejectedClaim();
claimPage.restoreClaim(data.restore.code);
claimPage.verifyClaim(data.restore.code);
});

it('Claim duplication workflow', ()=>{
claimPage.searchClaim(data.claim);
claimPage.duplicateClaim(data.duplicate);
claimPage.verifyClaim(data.duplicate.code);
})
})
18 changes: 18 additions & 0 deletions cypress/fixtures/claim.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"claim": {
"code": "CL006",
"chfId": "777746566",
"visitDateTo": {
"day": 30,
"month": 4,
"year": 2026
}
},
"restore": {
"code": "RES01"
},
"duplicate": {
"code": "DUP02",
"chfId": "104000001"
}
}
176 changes: 176 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ const getTodayFormatted = () => {
return `${day}-${month}-${year}`;
};

const SELECTORS = {
listbox: '[role="listbox"]',
option: '[role="option"]',
dialog: '[role="dialog"]',
addIcon: 'button.MuiFab-primary',
deleteBtn: 'button[title="Delete"]',
editBtn: '[aria-label="Edit"]',
saveButton: '[title="Save changes"] button',
restoreButton: '[title="Restore the claim"] button',
duplicateButton: '[title="Duplicate the claim"] button',
table: 'table',
deleteUserBtn: 'button[title="Delete user"]'
};

Cypress.Commands.add('login', () => {
cy.visit('/front');

Expand Down Expand Up @@ -1006,3 +1020,165 @@ Cypress.Commands.add('addGrievanceComment', (commentText, commentData = {}) => {
// cy.reload();
cy.contains(commentText).should('exist');
});

Cypress.Commands.add('waitForGraphQL', (alias = 'graphqlRequest') => {
cy.intercept('POST', '**/api/graphql').as(alias);
return cy.wait(`@${alias}`);
});

Cypress.Commands.add('save', () => {
cy.get(SELECTORS.saveButton).should('not.have.attr', 'disabled');
cy.get(SELECTORS.saveButton).click({ force: true });
cy.waitForGraphQL('save');
});

Cypress.Commands.add('goToList', (menuLabel, subMenuLabel, index = 0) => {
cy.contains(menuLabel).click();
cy.get('a').filter(`:contains("${subMenuLabel}")`).eq(index).click();
});

Cypress.Commands.add('selectDropdown', (identifier, value) => {
if (typeof identifier === 'number') {
cy.get('[aria-haspopup="listbox"]').eq(identifier).click({ force: true});
} else {
cy.contains('label', identifier)
.closest('.MuiFormControl-root')
.find('[aria-haspopup="listbox"]')
.click({ force: true });
}

if (value) {
cy.get(SELECTORS.option)
.filter((_, el) => el.innerText.trim() === value)
.first()
.click();
} else {
cy.get(SELECTORS.option).first().click();
}

cy.get(SELECTORS.listbox).should('not.exist');
});

Cypress.Commands.add('openFirstRow', (label) => {
cy.get('tbody tr')
.first()
.dblclick();
cy.contains('label', label)
.closest('.MuiFormControl-root')
.find('input')
.should('be.visible');
});

Cypress.Commands.add('restore', () => {
cy.get(SELECTORS.restoreButton).click({ force: true });
});

Cypress.Commands.add('chooseCraMuiDatePicker', (label, dateOrDay, month, year) => {
let day;
if (dateOrDay && typeof dateOrDay === 'object') {
if (dateOrDay instanceof Date) {
day = dateOrDay.getDate();
month = dateOrDay.getMonth() + 1;
year = dateOrDay.getFullYear();
} else {
({ day, month, year } = dateOrDay);
}
} else {
day = dateOrDay;
}

cy.contains('label', label)
.closest('.MuiFormControl-root')
.find('input')
.click({ force: true })

cy.get('.MuiPickersModal-dialogRoot').should('be.visible');

if (month || year) {
cy.get('.MuiPickersCalendarHeader-transitionContainer p').then(($header) => {
const headerText = $header.text();

const months = [
'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'
];

const currentMonth = months.findIndex((m) => headerText.includes(m)) + 1;
const currentYear = parseInt(headerText.match(/\d{4}/)?.[0]);

const targetMonth = month ?? currentMonth;
const targetYear = year ?? currentYear;

const diff =
(targetYear - currentYear) * 12 + (targetMonth - currentMonth);

const navSelector = diff > 0
? '.MuiPickersCalendarHeader-iconButton:last-child'
: '.MuiPickersCalendarHeader-iconButton:first-child';

Cypress._.times(Math.abs(diff), () => {
cy.get(navSelector).click();
cy.get('.MuiPickersCalendarHeader-transitionContainer').should('not.have.class', 'MuiPickersSlideTransition-slideEnter');
});
});
}

cy.get('.MuiPickersCalendar-transitionContainer')
.find('.MuiPickersDay-day:not(.MuiPickersDay-hidden)')
.each(($el) => {
if ($el.find('p').text().trim() === String(day)) {
cy.wrap($el).click();
return false; // stoppe le .each() dès le premier match
}
});

cy.get('.MuiPickersModal-withAdditionalAction')
.contains('button', 'OK')
.click();
});

Cypress.Commands.add('chooseServiceAutocomplete', (element, index) => {
if(element.name){
cy.get('input[placeholder="Search Service…"]').eq(index)
.clear().type(element.name);
} else {
cy.get('input[placeholder="Search Service…"]').eq(index)
.clear().type(" ");
}
cy.get('.MuiAutocomplete-popper').should('be.visible')
.find('li').first().click();

});

Cypress.Commands.add('searchInput', (label, value) => {
cy.enterMuiInput(label, value, 'input');
cy.contains('button', 'Search').click({ force: true });
cy.waitForGraphQL('search');
cy.get(SELECTORS.table).should('be.visible');
});

Cypress.Commands.add('goToClaimForm', ()=>{
cy.chooseMuiAutocomplete('Claim Administrator')
cy.get(SELECTORS.addIcon).click({ force: true });
});

Cypress.Commands.add('openRow', (label, value) => {
cy.contains('td', value)
.closest('tr')
.dblclick();
cy.contains('label', label)
.closest('.MuiFormControl-root')
.find('input')
.should('have.value', value);
});

Cypress.Commands.add('duplicate', () => {
cy.get(SELECTORS.duplicateButton).click({ force: true });
});

Cypress.Commands.add('filterInputValue', (identifier, value) => {
cy.contains('button', 'Reset filters').click({ force: true });
cy.enterMuiInput(identifier, value);
cy.contains('button', 'Search').click({ force: true });
cy.waitForGraphQL('search');
})
62 changes: 62 additions & 0 deletions cypress/support/pages/claimPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
export class ClaimPage {
openFirstRejectedClaim(){
cy.goToList('Claims', 'Health Facility Claims');
cy.selectDropdown('Claim Status', 'Rejected');
cy.contains('button', 'Search').click({ force: true });
cy.waitForGraphQL('search')
cy.openFirstRow('Claim No.');
}

restoreClaim(newCode){
cy.restore();
cy.enterMuiInput('Claim No.', newCode);
cy.contains(`Claim ${newCode}`).should('be.visible');
cy.save();
}

verifyClaim(code){
cy.goToList('Claims', 'Health Facility Claims');
cy.contains('button', 'Reset filters').click({ force: true });
cy.searchInput('Claim No.', code);
cy.contains('td', code).should('be.visible');
}

searchClaim(claim){
cy.goToList('Claims', 'Health Facility Claims');
cy.searchInput('Claim No.', claim.code);
cy.get('body').then(($body) => {
const exists = $body
.find('tr')
.toArray()
.some((row) => row.innerText.includes(claim.code));

if (!exists) {
this.createClaim(claim);
cy.goToList('Claims', 'Health Facility Claims');
cy.filterInputValue('Claim No.',claim.code);
}
cy.openRow('Claim No.', claim.code);
});
}

duplicateClaim(claim){
cy.duplicate();
cy.enterMuiInput('Insurance No.', claim.chfId);
cy.enterMuiInput('Claim No.', claim.code);
cy.save();
}

createClaim(claim){
cy.goToClaimForm();
this.fillClaim(claim);
cy.save();
}

fillClaim(claim) {
cy.enterMuiInput('Insurance No.', claim.chfId);
cy.chooseCraMuiDatePicker('Visit Date To', claim.visitDateTo);
cy.chooseMuiAutocomplete('Main Diagnosis');
cy.enterMuiInput('Claim No.', claim.code);
cy.chooseServiceAutocomplete("", 0);
}
}