Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Facility Export & Add New Sidebar collapse & expand Test #9066

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
19 changes: 17 additions & 2 deletions cypress/e2e/facility_spec/FacilityHomepage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe("Facility Homepage Function", () => {
const facilitiesAlias = "downloadFacilitiesCSV";
const doctorsAlias = "downloadDoctorsCSV";
const triagesAlias = "downloadTriagesCSV";
const capacitiesAlias = "downloadCapacitiesCSV";
const facilityName = "Dummy Facility 40";
const facilityLocaion = "Dummy Location";
const stateName = "Kerala";
Expand Down Expand Up @@ -108,11 +109,12 @@ describe("Facility Homepage Function", () => {
facilityHome.clickExportButton();
facilityHome.clickMenuItem("Triages");
facilityHome.verifyDownload(triagesAlias);
});

it("Verify Capacity Export Functionality", () => {
// Verify Capacity Export
facilityHome.csvDownloadIntercept(capacitiesAlias, "&capacity");
facilityHome.clickExportButton();
facilityHome.clickMenuItem("Capacities");
facilityHome.verifyDownload(capacitiesAlias);
});

it("Verify Facility Detail page redirection to CNS and Live Minitoring ", () => {
Expand All @@ -136,6 +138,19 @@ describe("Facility Homepage Function", () => {
facilityHome.verifyLiveMonitorUrl();
});

it("Verify sidebar collapse and expand functionality", () => {
facilityHome.toggleSidebar();
facilityHome.verifyIconsAndTextVisible();

// Click toggle button to collapse sidebar, verify icons visible and text hidden
facilityHome.toggleSidebar();
facilityHome.verifyIconsVisibleAndTextHidden();

// Click toggle button again to expand sidebar, verify icons and text are visible again
facilityHome.toggleSidebar();
facilityHome.verifyIconsAndTextVisible();
});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • once the test is complete, the brackets are missing, syntax error

it("Verify Notice Board Functionality", () => {
// search facility and verify it's loaded or not
manageUserPage.interceptFacilitySearchReq();
Expand Down
23 changes: 23 additions & 0 deletions cypress/pageobject/Facility/FacilityHome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ class FacilityHome {
searchButton = "#search";
menuItem = "[role='menuitem']";

sidebarToggle = () => cy.get('[data-testid="sidebar-toggle"]');
sidebarItems = () => cy.get('[data-testid="sidebar-item"]');

// Operations
clickExportButton() {
cy.get(this.exportButton).scrollIntoView();
Expand Down Expand Up @@ -104,6 +107,26 @@ class FacilityHome {
const encodedText = encodeURIComponent(searchText).replace(/%20/g, "+");
this.getURL().should("include", `search=${encodedText}`);
}

toggleSidebar() {
this.sidebarToggle().click();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add visibility check before clicking

To prevent flaky tests, consider adding a visibility check before clicking:

  toggleSidebar() {
-    this.sidebarToggle().click();
+    this.sidebarToggle().should('be.visible').click();
  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
toggleSidebar() {
this.sidebarToggle().click();
}
toggleSidebar() {
this.sidebarToggle().should('be.visible').click();
}


verifyIconsAndTextVisible() {
this.sidebarItems().each(($item) => {
cy.wrap($item).find('[data-testid="sidebar-icon"]').should("be.visible");
cy.wrap($item).find('[data-testid="sidebar-text"]').should("be.visible");
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance verification methods reliability and reduce duplication

Consider these improvements:

  1. Add timeout and empty check
  2. Extract common verification logic
+ private verifySidebarElements(textVisibility: 'be.visible' | 'not.be.visible') {
+   this.sidebarItems().should('have.length.at.least', 1)
+     .each(($item) => {
+       cy.wrap($item, { timeout: 10000 })
+         .find('[data-testid="sidebar-icon"]')
+         .should('be.visible');
+       cy.wrap($item, { timeout: 10000 })
+         .find('[data-testid="sidebar-text"]')
+         .should(textVisibility);
+     });
+ }

  verifyIconsAndTextVisible() {
-   this.sidebarItems().each(($item) => {
-     cy.wrap($item).find('[data-testid="sidebar-icon"]').should("be.visible");
-     cy.wrap($item).find('[data-testid="sidebar-text"]').should("be.visible");
-   });
+   this.verifySidebarElements('be.visible');
  }

  verifyIconsVisibleAndTextHidden() {
-   this.sidebarItems().each(($item) => {
-     cy.wrap($item).find('[data-testid="sidebar-icon"]').should("be.visible");
-     cy.wrap($item)
-       .find('[data-testid="sidebar-text"]')
-       .should("not.be.visible");
-   });
+   this.verifySidebarElements('not.be.visible');
  }

Also applies to: 122-129


verifyIconsVisibleAndTextHidden() {
this.sidebarItems().each(($item) => {
cy.wrap($item).find('[data-testid="sidebar-icon"]').should("be.visible");
cy.wrap($item)
.find('[data-testid="sidebar-text"]')
.should("not.be.visible");
});
}
}

export default FacilityHome;
1 change: 1 addition & 0 deletions src/components/Common/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ const ToggleShrink = ({ shrinked, toggle }: ToggleShrinkProps) => {
<Tooltip>
<TooltipTrigger asChild>
<button
data-testid="sidebar-toggle"
className={`flex h-6 w-6 cursor-pointer items-center justify-center rounded focus:outline-none focus:ring-2 focus:ring-indigo-500 ${shrinked ? "bg-gray-200" : "bg-gray-100"} text-gray-600 hover:bg-primary-200 hover:text-primary-800 ${
shrinked ? "mx-auto" : "mr-4"
} transition-all ease-in-out`}
Expand Down
6 changes: 5 additions & 1 deletion src/components/Common/Sidebar/SidebarItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const SidebarItemBase = forwardRef<HTMLAnchorElement, SidebarItemBaseProps>(
<Link
ref={ref}
id={props?.id}
data-testid="sidebar-item"
className={`tooltip relative ml-1 mr-2 h-12 flex-1 cursor-pointer rounded-md py-1 font-medium text-gray-600 transition md:flex-none ${
props.selected
? "bg-white text-green-800 shadow"
Expand Down Expand Up @@ -62,8 +63,11 @@ const SidebarItemBase = forwardRef<HTMLAnchorElement, SidebarItemBaseProps>(
shrinked ? "justify-center" : "justify-start pl-5 pr-4"
} transition-all duration-200 ease-in-out`}
>
<div className="flex-none text-lg">{props.icon}</div>
<div data-testid="sidebar-icon" className="flex-none text-lg">
{props.icon}
</div>
<span
data-testid="sidebar-text"
className={`${
shrinked ? "hidden" : "grow"
} flex w-full items-center text-nowrap pl-4 text-sm tracking-wide`}
Expand Down