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

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
33 changes: 25 additions & 8 deletions cypress/e2e/facility_spec/FacilityHomepage.cy.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// FacilityCreation

import LoginPage from "../../pageobject/Login/LoginPage";
import { AssetPagination } from "../../pageobject/Asset/AssetPagination";
import FacilityPage from "../../pageobject/Facility/FacilityCreation";
import FacilityHome from "../../pageobject/Facility/FacilityHome";
import LoginPage from "../../pageobject/Login/LoginPage";
import ManageUserPage from "../../pageobject/Users/ManageUserPage";
import FacilityPage from "../../pageobject/Facility/FacilityCreation";
import { UserPage } from "../../pageobject/Users/UserSearch";
import { AssetPagination } from "../../pageobject/Asset/AssetPagination";

describe("Facility Homepage Function", () => {
const loginPage = new LoginPage();
Expand All @@ -17,6 +16,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 @@ -107,11 +107,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 @@ -135,7 +136,23 @@ describe("Facility Homepage Function", () => {
facilityHome.verifyLiveMonitorUrl();
});

afterEach(() => {
cy.saveLocalStorage();
it("Verify sidebar collapse and expand functionality", () => {
facilityHome.toggleSidebar();
facilityHome.verifyIconsVisible();
facilityHome.verifyTextVisible();
Copy link
Member

Choose a reason for hiding this comment

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

  • it does not verify that each icon has a respective text next to it.

Copy link
Author

Choose a reason for hiding this comment

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

@nihal467 sir I have made changes for this & sorry for those syntax & duplicate errors I tried to fix merge conflicts directly & made those mistakes


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

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

afterEach(() => {
Copy link
Member

Choose a reason for hiding this comment

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

  • delete the duplicate aftereach function

cy.saveLocalStorage();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove duplicate afterEach hook.

There's a duplicate afterEach hook outside the describe block. This is redundant as the same hook already exists within the describe block and could lead to unexpected behavior.

Remove the duplicate hook:

-afterEach(() => {
-  cy.saveLocalStorage();
-});
📝 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
afterEach(() => {
cy.saveLocalStorage();
});
🧰 Tools
🪛 Biome

[error] 209-209: expected } but instead the file ends

the file ends here

(parse)


[error] 206-209: Disallow duplicate setup and teardown hooks.

Disallow afterEach duplicacy inside the describe function.

(lint/suspicious/noDuplicateTestHooks)

24 changes: 24 additions & 0 deletions cypress/pageobject/Facility/FacilityHome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ class FacilityHome {
searchButton = "#search";
menuItem = "[role='menuitem']";

sidebarToggle = () => cy.get('[data-testid="sidebar-toggle"]');
sidebarIcon = () => cy.get('[data-testid="sidebar-icon"]');
sidebarText = () => cy.get('[data-testid="sidebar-text"]');

// Operations
clickExportButton() {
cy.get(this.exportButton).scrollIntoView();
Expand Down Expand Up @@ -103,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();
}


verifyIconsVisible() {
this.sidebarIcon().each(($el) => {
cy.wrap($el).should("be.visible");
});
}

verifyTextVisible() {
this.sidebarText().each(($el) => {
cy.wrap($el).should("be.visible");
});
}

verifyTextHidden() {
this.sidebarText().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
5 changes: 4 additions & 1 deletion src/components/Common/Sidebar/SidebarItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,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
Loading