Skip to content

Commit

Permalink
Merge pull request #1407 from Bahati308/E2E-fixes
Browse files Browse the repository at this point in the history
Added Lab Number Management E2E
  • Loading branch information
mozzy11 authored Jan 17, 2025
2 parents ae2166c + fd61f49 commit 1ca3111
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 0 deletions.
1 change: 1 addition & 0 deletions frontend/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = defineConfig({
"cypress/e2e/report.cy.js",
"cypress/e2e/batchOrderEntry.cy.js",
"cypress/e2e/dashboard.cy.js",
"cypress/e2e/labNumberManagement.cy.js",
];
return config;
},
Expand Down
44 changes: 44 additions & 0 deletions frontend/cypress/e2e/labNumberManagement.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import LoginPage from "../pages/LoginPage";

let loginPage = null;
let homePage = null;
let adminPage = null;
let labNumMgtPage = null;

before(() => {
// Initialize LoginPage object and navigate to Admin Page
loginPage = new LoginPage();
loginPage.visit();

homePage = loginPage.goToHomePage();
adminPage = homePage.goToAdminPage();
});

beforeEach(() => {
// Load fixture data for each test
cy.fixture("LabNumberManagement").as("labNMData");
});

describe("Lab Number Management", function () {
it("User navigates to the Lab Number Management page", function () {
labNumMgtPage = adminPage.goToLabNumberManagementPage();
});

it("User selects legacy lab number type and submits", function () {
cy.get("@labNMData").then((labNumberManagementData) => {
labNumMgtPage.selectLabNumber(
labNumberManagementData.legacyLabNumberType,
);
labNumMgtPage.clickSubmitButton();
});
});

it("User selects alpha numeric lab number type and submits", function () {
cy.get("@labNMData").then((labNumberManagementData) => {
labNumMgtPage.selectLabNumber(labNumberManagementData.alphaLabNumberType);
labNumMgtPage.checkPrefixCheckBox();
labNumMgtPage.typePrefix(labNumberManagementData.userPrefix);
labNumMgtPage.clickSubmitButton();
});
});
});
5 changes: 5 additions & 0 deletions frontend/cypress/fixtures/LabNumberManagement.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"alphaLabNumberType": "Alpha Numeric",
"legacyLabNumberType": "Legacy",
"userPrefix": "REG-"
}
33 changes: 33 additions & 0 deletions frontend/cypress/pages/AdminPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//This handles all pages of the admin
import LabNumberManagementPage from "./LabNumberManagementPage";

class AdminPage {
constructor() {}

visit() {
cy.visit("/administration"); //need to confirm this
}
//this page is also included in the homepage
goToAdminPage() {
this.openNavigationMenu();
cy.get("#menu_administration").click();
cy.get("#menu_administration_nav").click();
return new AdminPage();
}

//lab number management
goToLabNumberManagementPage() {
// Click on the element using the provided selector
cy.get("a.cds--side-nav__link[href='#labNumber']")
.should("be.visible") // Ensure the element is visible
.click(); // Click to navigate to the page

// Verify the URL or some unique identifier of the target page
cy.url().should("include", "#labNumber"); // Validate URL fragment
cy.contains("Lab Number Management").should("be.visible"); // Confirm presence of the page content

return new LabNumberManagementPage(); // Return the page object
}
}

export default AdminPage;
7 changes: 7 additions & 0 deletions frontend/cypress/pages/HomePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import RoutineReportPage from "./RoutineReportPage";
import StudyReportPage from "./StudyReportPage";

import DashBoardPage from "./DashBoard";
import AdminPage from "./AdminPage";

class HomePage {
constructor() {}
Expand Down Expand Up @@ -192,6 +193,12 @@ class HomePage {
cy.get("#menu_immunochemdashboard_nav").click();
return new DashBoardPage();
}

goToAdminPage() {
this.openNavigationMenu();
cy.get("#menu_administration").click();
return new AdminPage();
}
}

export default HomePage;
30 changes: 30 additions & 0 deletions frontend/cypress/pages/LabNumberManagementPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class LabNumberManagementPage {
constructor() {}

verifyPageLoaded() {
// Confirm the page is loaded by checking a unique element
cy.contains("Lab Number Management").should("be.visible");
}

selectLabNumber(labNumberType) {
// Ensure the dropdown is visible and interactable
cy.get("#lab_number_type").should("be.visible").select(labNumberType); // Select the lab number type passed as an argument
}

checkPrefixCheckBox() {
cy.get("#usePrefix").check({ force: true }); // Check the checkbox
}
typePrefix(prefix) {
this.checkPrefixCheckBox();

// Wait for the input to become enabled
cy.get("#alphanumPrefix").should("not.be.disabled").type(prefix);
}
clickSubmitButton() {
cy.get("button.cds--btn.cds--btn--primary[type='submit']")
.should("be.visible")
.click();
}
}

export default LabNumberManagementPage;

0 comments on commit 1ca3111

Please sign in to comment.