Skip to content

Commit

Permalink
65012 custom date advanced search (#33734)
Browse files Browse the repository at this point in the history
* create spec file

* add tests

* parametrize methods

* add error validation and clear filter tests

* update constants

* add search results test

* add more error tests

* update advanced-filter tests

* add custom date range filter tests for other folders

* add axeCheck
  • Loading branch information
fazilqa authored Dec 23, 2024
1 parent c4b572f commit dd4e28f
Show file tree
Hide file tree
Showing 12 changed files with 737 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,113 @@ class PatientSearchPage {
const extractedDate = dateString.split(' at ')[0]; // "November 29, 2024"
const parsedDate = new Date(extractedDate);

// calculate three months back from the current date
const threeMonthsBack = new Date();
threeMonthsBack.setMonth(threeMonthsBack.getMonth() - numberOfMonth);
// calculate a few months back from the current date
const backDate = new Date();
backDate.setMonth(backDate.getMonth() - numberOfMonth);

// assert the date is within the last 3 months
expect(parsedDate).to.be.gte(threeMonthsBack);
expect(parsedDate).to.be.gte(backDate);
});
});
};

verifyStartDateFormElements = () => {
cy.get(Locators.BLOCKS.FILTER_START_DATE, { includeShadowDom: true })
.find(`.required`)
.should(`be.visible`)
.and(`have.text`, `(*Required)`);

cy.get(Locators.BLOCKS.FILTER_START_DATE)
.shadow()
.find(`.select-month`)
.should(`be.visible`);
cy.get(Locators.BLOCKS.FILTER_START_DATE)
.shadow()
.find(`.select-day`)
.should(`be.visible`);
cy.get(Locators.BLOCKS.FILTER_START_DATE)
.shadow()
.find(`.input-year`)
.should(`be.visible`);
};

verifyEndDateFormElements = () => {
cy.get(Locators.BLOCKS.FILTER_END_DATE, { includeShadowDom: true })
.find(`.required`)
.should(`be.visible`)
.and(`have.text`, `(*Required)`);

cy.get(Locators.BLOCKS.FILTER_END_DATE)
.shadow()
.find(`.select-month`)
.should(`be.visible`);
cy.get(Locators.BLOCKS.FILTER_END_DATE)
.shadow()
.find(`.select-day`)
.should(`be.visible`);
cy.get(Locators.BLOCKS.FILTER_END_DATE)
.shadow()
.find(`.input-year`)
.should(`be.visible`);
};

verifyMonthFilterRange = number => {
cy.get(Locators.BLOCKS.FILTER_START_DATE)
.find(`[name="discharge-dateMonth"]`)
.find(`option`)
.should(`have.length`, number);
};

verifyDayFilterRange = number => {
cy.get(Locators.BLOCKS.FILTER_START_DATE)
.find(`[name="discharge-dateDay"]`)
.find(`option`)
.should(`have.length`, number);
};

selectStartMonth = month => {
cy.get(Locators.BLOCKS.FILTER_START_DATE)
.find(`[name="discharge-dateMonth"]`)
.select(month);
};

selectEndMonth = month => {
cy.get(Locators.BLOCKS.FILTER_END_DATE)
.find(`[name="discharge-dateMonth"]`)
.select(month);
};

selectStartDay = day => {
cy.get(Locators.BLOCKS.FILTER_START_DATE)
.find(`[name="discharge-dateDay"]`)
.select(day);
};

selectEndDay = day => {
cy.get(Locators.BLOCKS.FILTER_END_DATE)
.find(`[name="discharge-dateDay"]`)
.select(day);
};

getStartYear = year => {
cy.get(Locators.BLOCKS.FILTER_START_DATE)
.find(`[name="discharge-dateYear"]`)
.type(year);
};

getEndYear = year => {
cy.get(Locators.BLOCKS.FILTER_END_DATE)
.find(`[name="discharge-dateYear"]`)
.type(year);
};

getRequiredFieldError = selector => {
return cy
.get(selector)
.find(`#error-message`)
.should(`be.visible`);
};

// retrieveMessages = function (folderID) {
// folderInfo.data.attributes.folderId = folderID;
// cy.intercept(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { format, subMonths } from 'date-fns';
import SecureMessagingSite from '../sm_site/SecureMessagingSite';
import PatientInboxPage from '../pages/PatientInboxPage';
import { AXE_CONTEXT, Locators, Alerts } from '../utils/constants';
import PatientSearchPage from '../pages/PatientSearchPage';
import FolderLoadPage from '../pages/FolderLoadPage';
import PatientMessageCustomFolderPage from '../pages/PatientMessageCustomFolderPage';

describe('SM INBOX ADVANCED CUSTOM DATE RANGE SEARCH', () => {
beforeEach(() => {
SecureMessagingSite.login();
PatientInboxPage.loadInboxMessages();
FolderLoadPage.loadFolders();
PatientMessageCustomFolderPage.loadMessages();
PatientInboxPage.openAdvancedSearch();
PatientInboxPage.selectDateRange('Custom');
});

it('verify advanced filter form elements', () => {
PatientSearchPage.verifyStartDateFormElements();
PatientSearchPage.verifyEndDateFormElements();

cy.injectAxe();
cy.axeCheck(AXE_CONTEXT);
});

it('verify month and day range', () => {
PatientSearchPage.verifyMonthFilterRange(14);
PatientSearchPage.verifyDayFilterRange(2);

PatientSearchPage.selectStartMonth(`February`);
PatientSearchPage.verifyDayFilterRange(31);

PatientSearchPage.selectStartMonth(`June`);
PatientSearchPage.verifyDayFilterRange(32);

PatientSearchPage.selectStartMonth(`October`);
PatientSearchPage.verifyDayFilterRange(33);

cy.injectAxe();
cy.axeCheck(AXE_CONTEXT);
});

it(`verify errors`, () => {
cy.get(Locators.BUTTONS.FILTER).click();

PatientSearchPage.getRequiredFieldError(
Locators.BLOCKS.FILTER_START_DATE,
).should(`have.text`, Alerts.DATE_FILTER.EMPTY_START_DATE);

PatientSearchPage.getRequiredFieldError(
Locators.BLOCKS.FILTER_END_DATE,
).should(`have.text`, Alerts.DATE_FILTER.EMPTY_END_DATE);

PatientSearchPage.selectStartMonth('April');
PatientSearchPage.selectEndMonth('February');
cy.get(Locators.BUTTONS.FILTER).click();

PatientSearchPage.getRequiredFieldError(
Locators.BLOCKS.FILTER_START_DATE,
).should(`include.text`, Alerts.DATE_FILTER.INVALID_START_DATE);

PatientSearchPage.getRequiredFieldError(
Locators.BLOCKS.FILTER_END_DATE,
).should(`include.text`, Alerts.DATE_FILTER.INVALID_END_DATE);

cy.injectAxe();
cy.axeCheck(AXE_CONTEXT);
});

it('verify clear filters button', () => {
PatientSearchPage.selectStartMonth(`February`);
PatientSearchPage.selectStartDay(`2`);
PatientSearchPage.selectEndMonth('April');
PatientSearchPage.selectEndDay(`11`);
cy.get(Locators.CLEAR_FILTERS).click();
cy.get(Locators.FIELDS.DATE_RANGE_OPTION).should(
`have.attr`,
`value`,
`any`,
);
cy.get(Locators.BLOCKS.FILTER_START_DATE).should(`not.exist`);
cy.get(Locators.BLOCKS.FILTER_END_DATE).should(`not.exist`);

cy.injectAxe();
cy.axeCheck(AXE_CONTEXT);
});

it('verify search results', () => {
const searchResultResponse = PatientSearchPage.createDateSearchMockResponse(
2,
1,
);
const currentYear = format(new Date(), 'yyyy');
const startMonth = format(subMonths(new Date(), 2), 'MMMM');
const endMonth = format(new Date(), 'MMMM');

PatientSearchPage.selectStartMonth(startMonth);
PatientSearchPage.selectStartDay(`1`);
PatientSearchPage.getStartYear(currentYear);
PatientSearchPage.selectEndMonth(endMonth);
PatientSearchPage.selectEndDay(`11`);
PatientSearchPage.getEndYear(currentYear);

PatientInboxPage.clickFilterMessagesButton(searchResultResponse);

PatientSearchPage.verifySearchResponseLength(searchResultResponse);
PatientSearchPage.verifyMessageDate(2);
PatientSearchPage.verifySearchMessageLabel(
searchResultResponse,
`${startMonth} 1st ${currentYear} to ${endMonth} 11th ${currentYear}`,
);

cy.injectAxe();
cy.axeCheck(AXE_CONTEXT);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import { format, subMonths } from 'date-fns';
import SecureMessagingSite from '../sm_site/SecureMessagingSite';
import PatientInboxPage from '../pages/PatientInboxPage';
import { AXE_CONTEXT, Locators, Alerts } from '../utils/constants';
import PatientSearchPage from '../pages/PatientSearchPage';
import FolderLoadPage from '../pages/FolderLoadPage';

describe('SM DRAFTS ADVANCED CUSTOM DATE RANGE SEARCH', () => {
beforeEach(() => {
SecureMessagingSite.login();
PatientInboxPage.loadInboxMessages();
FolderLoadPage.loadFolders();
FolderLoadPage.loadDraftMessages();
PatientInboxPage.openAdvancedSearch();
PatientInboxPage.selectDateRange('Custom');
});

it('verify advanced filter form elements', () => {
PatientSearchPage.verifyStartDateFormElements();
PatientSearchPage.verifyEndDateFormElements();

cy.injectAxe();
cy.axeCheck(AXE_CONTEXT);
});

it('verify month and day range', () => {
PatientSearchPage.verifyMonthFilterRange(14);
PatientSearchPage.verifyDayFilterRange(2);

PatientSearchPage.selectStartMonth(`February`);
PatientSearchPage.verifyDayFilterRange(31);

PatientSearchPage.selectStartMonth(`June`);
PatientSearchPage.verifyDayFilterRange(32);

PatientSearchPage.selectStartMonth(`October`);
PatientSearchPage.verifyDayFilterRange(33);

cy.injectAxe();
cy.axeCheck(AXE_CONTEXT);
});

it(`verify errors`, () => {
cy.get(Locators.BUTTONS.FILTER).click();

PatientSearchPage.getRequiredFieldError(
Locators.BLOCKS.FILTER_START_DATE,
).should(`have.text`, Alerts.DATE_FILTER.EMPTY_START_DATE);

PatientSearchPage.getRequiredFieldError(
Locators.BLOCKS.FILTER_END_DATE,
).should(`have.text`, Alerts.DATE_FILTER.EMPTY_END_DATE);

PatientSearchPage.selectStartMonth('April');
PatientSearchPage.selectEndMonth('February');
cy.get(Locators.BUTTONS.FILTER).click();

PatientSearchPage.getRequiredFieldError(
Locators.BLOCKS.FILTER_START_DATE,
).should(`include.text`, Alerts.DATE_FILTER.INVALID_START_DATE);

PatientSearchPage.getRequiredFieldError(
Locators.BLOCKS.FILTER_END_DATE,
).should(`include.text`, Alerts.DATE_FILTER.INVALID_END_DATE);

cy.injectAxe();
cy.axeCheck(AXE_CONTEXT);
});

it('verify clear filters button', () => {
PatientSearchPage.selectStartMonth(`February`);
PatientSearchPage.selectStartDay(`2`);
PatientSearchPage.selectEndMonth('April');
PatientSearchPage.selectEndDay(`11`);
cy.get(Locators.CLEAR_FILTERS).click();
cy.get(Locators.FIELDS.DATE_RANGE_OPTION).should(
`have.attr`,
`value`,
`any`,
);
cy.get(Locators.BLOCKS.FILTER_START_DATE).should(`not.exist`);
cy.get(Locators.BLOCKS.FILTER_END_DATE).should(`not.exist`);

cy.injectAxe();
cy.axeCheck(AXE_CONTEXT);
});

it('verify search results', () => {
const searchResultResponse = PatientSearchPage.createDateSearchMockResponse(
2,
1,
);
const currentYear = format(new Date(), 'yyyy');
const startMonth = format(subMonths(new Date(), 2), 'MMMM');
const endMonth = format(new Date(), 'MMMM');

PatientSearchPage.selectStartMonth(startMonth);
PatientSearchPage.selectStartDay(`1`);
PatientSearchPage.getStartYear(currentYear);
PatientSearchPage.selectEndMonth(endMonth);
PatientSearchPage.selectEndDay(`11`);
PatientSearchPage.getEndYear(currentYear);

PatientInboxPage.clickFilterMessagesButton(searchResultResponse);

PatientSearchPage.verifySearchResponseLength(searchResultResponse);
PatientSearchPage.verifyMessageDate(2);
PatientSearchPage.verifySearchMessageLabel(
searchResultResponse,
`${startMonth} 1st ${currentYear} to ${endMonth} 11th ${currentYear}`,
);

cy.injectAxe();
cy.axeCheck(AXE_CONTEXT);
});
});
Loading

0 comments on commit dd4e28f

Please sign in to comment.