Skip to content

Commit

Permalink
Merge pull request DIGI-UW#1444 from vsvishalsharma/Update_NCE_E2E
Browse files Browse the repository at this point in the history
Updated selectors to use data test id in NonConformPage.js
  • Loading branch information
mozzy11 authored Jan 28, 2025
2 parents 562da1e + e177f35 commit 50a6522
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 55 deletions.
13 changes: 6 additions & 7 deletions frontend/cypress/e2e/nonConform.cy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import LoginPage from "../pages/LoginPage";
import HomePage from "../pages/HomePage";
import NonConform from "../pages/NonConformPage";


let homePage = null;
let loginPage = null;
Expand Down Expand Up @@ -65,7 +64,7 @@ describe("Report Non-Conforming Event", function () {
nonConform.enterSearchField(order.labNo);
nonConform.clickSearchButton();
nonConform.validateSearchResult(order.labNo);
nonConform.clickCheckbox();
nonConform.clickCheckbox({force: true});
nonConform.clickGoToNceFormButton();
});

Expand All @@ -80,7 +79,7 @@ describe("Report Non-Conforming Event", function () {
nonConform.enterDescription(nonConformData.description);
nonConform.enterSuspectedCause(nonConformData.suspectedCause);
nonConform.enterCorrectiveAction(nonConformData.proposedCorrectiveAction);
nonConform.submitFormNce();
nonConform.submitForm();
});
});
});
Expand All @@ -100,12 +99,12 @@ describe("View New Non-Conforming Event", function () {
.getViewNonConformTitle()
.should("contain.text", "View New Non Conform Event");
});

it("Should Search by Lab Number and Validate the results", function () {
cy.fixture("EnteredOrder").then((order) => {
nonConform.selectSearchType("Lab Number");
nonConform.enterSearchField(order.labNo);
nonConform.clickSearchButton();
//nonConform.clickRadioButtonNCE();
nonConform.validateLabNoSearchResult(order.labNo);
});
});
Expand Down Expand Up @@ -148,13 +147,13 @@ describe("Corrective Actions", function () {
.getViewNonConformTitle()
.should("contain.text", "Nonconforming Events Corrective Action");
});

it("Should Search by Lab Number and Validate the results", function () {
cy.fixture("EnteredOrder").then((order) => {
nonConform.selectSearchType("Lab Number");
nonConform.enterSearchField(order.labNo);
nonConform.clickSearchButton();
nonConform.validateLabNoSearchResultCorective(order.labNo);
//nonConform.clickRadioButtonNCE();
nonConform.validateLabNoSearchResult(order.labNo);
});
});

Expand Down
57 changes: 33 additions & 24 deletions frontend/cypress/pages/NonConformPage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class NonConform {
// Title validation (kept as-is per request)
getReportNonConformTitle() {
return cy.get("h2");
}
Expand All @@ -7,6 +8,7 @@ class NonConform {
return cy.get("h2");
}

// Form interactions
selectSearchType(type) {
cy.get("#type").select(type);
}
Expand All @@ -16,41 +18,40 @@ class NonConform {
}

clickSearchButton() {
cy.get(":nth-child(4) > .cds--btn").click();
cy.get("[data-testid='nce-search-button']").click();
}

// Search results validation
validateSearchResult(expectedValue) {
cy.get("tbody > tr > :nth-child(2)")
cy.get("[data-testid='nce-search-result']")
.first()
.invoke("text")
.should("eq", expectedValue);
}

validateLabNoSearchResult(labNo) {
cy.get(".orderLegendBody > :nth-child(2) > :nth-child(7) > :nth-child(2)")
cy.get("[data-testid='nce-search-result']")
.invoke("text")
.should("eq", labNo);
}


validateNCESearchResult(NCENo) {
cy.get('[style="margin-bottom: 10px; color: rgb(85, 85, 85);"]')
cy.get("[data-testid='nce-number-result']")
.invoke("text")
.should("eq", NCENo);
}

validateLabNoSearchResultCorective(labNo) {
cy.get(".cds--subgrid > :nth-child(7) > :nth-child(2)")
.invoke("text")
.should("eq", labNo);
}

// Checkbox and navigation
clickCheckbox() {
cy.get(".cds--checkbox-label").click();
cy.get("[data-testid='nce-sample-checkbox']").first().click({force:true});
}

clickGoToNceFormButton() {
cy.get(":nth-child(2) > :nth-child(2) > .cds--btn").click();
cy.get("[data-testid='nce-goto-form-button']").click();
}

// Form fields (preserve original IDs)
enterStartDate(date) {
cy.get(".cds--date-picker-input__wrapper > #startDate").type(date);
}
Expand All @@ -71,6 +72,7 @@ class NonConform {
cy.get("#text-area-3").type(correctiveaction);
}

// Dropdowns
enterNceCategory(nceCategory) {
cy.get("#nceCategory").select(nceCategory);
}
Expand All @@ -91,50 +93,57 @@ class NonConform {
cy.get("#labComponent").select(labComponent);
}

// Text areas
enterDescriptionAndComments(testText) {
cy.get("#text-area-10").type(testText);
cy.get("#text-area-3").type(testText);
cy.get("#text-area-2").type(testText);
}

// Submission
submitForm() {
cy.get(":nth-child(28) > .cds--btn").click();
}

submitFormNce() {
cy.get(":nth-child(14) > .cds--btn").click();
cy.get("[data-testid='nce-submit-button']").click();
}

// Corrective actions
enterDiscussionDate(date) {
cy.get(".cds--date-picker-input__wrapper > #tdiscussionDate").type(date);
cy.get("#tdiscussionDate").type(date);
}

enterProposedCorrectiveAction(action) {
cy.get("#text-area-corrective").type(action, { force: true });
}

enterDateCompleted(date) {
cy.get(".cds--date-picker-input__wrapper > #dateCompleted").type(date);
cy.get("#dateCompleted").type(date);
}

selectActionType() {
cy.get(":nth-child(1) > .cds--checkbox-label").click();
cy.get("[data-testid='nce-action-checkbox']").click({force:true});
}

selectResolution() {
cy.get(":nth-child(1) > .cds--radio-button__label").click();
}

clickRadioButtonNCE() {
cy.get("[data-testid='Radio-button']")
.eq(0) // 0 for first, 1 for second, 2 for third, etc.
.should('be.visible')
.click();
}
enterDateCompleted0(date) {
cy.get(".cds--date-picker-input__wrapper > #dateCompleted-0").type(date);
}

clickSubmitButton() {
cy.get(":nth-child(38) > .cds--btn").click();
cy.get("[data-testid='nce-submit-button']")
.should('not.be.disabled')
.click();
}

// Data management
getAndSaveNceNumber() {
cy.get(".orderLegendBody > :nth-child(2) > :nth-child(3) > :nth-child(2)")
cy.get("[data-testid='nce-number-result']")
.invoke("text")
.then((text) => {
cy.readFile("cypress/fixtures/NonConform.json").then((existingData) => {
Expand All @@ -148,4 +157,4 @@ class NonConform {
}
}

export default NonConform;
export default NonConform;
24 changes: 15 additions & 9 deletions frontend/src/components/nonconform/common/NCECorrectiveAction.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export const NCECorrectiveAction = () => {
<br />
</Column>
<Column lg={16}>
<Button type="button" onClick={handleSubmit}>
<Button type="button" data-testid='nce-search-button' onClick={handleSubmit}>
<FormattedMessage id="label.button.search" />
</Button>
</Column>
Expand Down Expand Up @@ -320,20 +320,20 @@ export const NCECorrectiveAction = () => {
</TableRow>
</TableHead>
<TableBody>
{tData.nceEventsSearchResults.map((row) => (
{tData.nceEventsSearchResults.map((row) => (
<TableRow key={row.nceNumber}>
<TableCell key={`${row}-checkbox`}>
<TableCell key={`${row}-checkbox`} data-testid='Radio-button'>
<RadioButton
name="radio-group"
onClick={() => setSelected(row.nceNumber)}
labelText=""
id={row.id}
/>
</TableCell>
<TableCell key={row.key + "date"}>
<TableCell key={row.key + "date"}>
{new Date(row.reportDate).toDateString()}
</TableCell>
<TableCell key={row.key + "1"}>
<TableCell key={row.key + "1"}>
{row.nceNumber}
</TableCell>
<TableCell key={row.key + "2"}>
Expand All @@ -357,13 +357,13 @@ export const NCECorrectiveAction = () => {
<Grid fullWidth={true}>
<Column lg={3}>
<div style={{ marginBottom: "10px" }}>
<span style={{ color: "#3366B3", fontWeight: "bold" }}>
<span style={{ color: "#3366B3", fontWeight: "bold" }} >
<b>
<FormattedMessage id="nonconform.nce.number" />
</b>
</span>
</div>
<div style={{ marginBottom: "10px", color: "#555" }}>
<div style={{ marginBottom: "10px", color: "#555" }} data-testid='nce-number-result'>
{data.nceNumber}
</div>
</Column>
Expand Down Expand Up @@ -422,7 +422,7 @@ export const NCECorrectiveAction = () => {
<FormattedMessage id="sample.label.labnumber" />
</span>
</div>
<div style={{ marginBottom: "10px" }}>
<div style={{ marginBottom: "10px" }} data-testid='nce-search-result'>
{data.labOrderNumber}
</div>
</Column>
Expand Down Expand Up @@ -575,6 +575,7 @@ export const NCECorrectiveAction = () => {
<CustomDatePicker
key="tdiscussionDate"
id={"tdiscussionDate"}
data-testid="start-date"
labelText={
<FormattedMessage id="nonconform.date.discussion.nce" />
}
Expand Down Expand Up @@ -676,6 +677,7 @@ export const NCECorrectiveAction = () => {
}
onClick={() => handleActionTypeChange("1")}
id="correctiveAction"
data-testid="nce-action-checkbox"
/>

<Checkbox
Expand Down Expand Up @@ -759,6 +761,7 @@ export const NCECorrectiveAction = () => {
}
disabled
id="correctiveAction"

/>

<Checkbox
Expand Down Expand Up @@ -810,12 +813,14 @@ export const NCECorrectiveAction = () => {
alignItems: "flex-start",
marginTop: "10px",
}}
data-testid="nce-resolution-radio"
>
<RadioButton
checked={submit === true}
labelText={<FormattedMessage id="yes.option" />}
id={`yes.option`}
onChange={() => setSubmit(true)}

></RadioButton>
<RadioButton
labelText={<FormattedMessage id="no.option" />}
Expand All @@ -829,7 +834,7 @@ export const NCECorrectiveAction = () => {
<Column lg={8}>
<CustomDatePicker
key="dateCompleted-0"
id={"dateCompleted-0"}
id="dateCompleted-0"
labelText={
<FormattedMessage id="nonconform.date.completed" />
}
Expand Down Expand Up @@ -860,6 +865,7 @@ export const NCECorrectiveAction = () => {
type="button"
disabled={!submit}
onClick={handleNCEFormSubmit}
data-testid="nce-submit-button"
>
<FormattedMessage id="label.button.submit" />
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ export const ReportNonConformingEvent = () => {
<br></br>
</Column>
<Column lg={16} md={8} sm={4}>
<Button type="button" onClick={handleSubmit}>
<Button type="button" data-testid='nce-search-button'
onClick={handleSubmit}>
<FormattedMessage id="label.button.search" />
</Button>
</Column>
Expand Down Expand Up @@ -351,12 +352,13 @@ export const ReportNonConformingEvent = () => {
<TableRow key={row.id}>
<TableCell key={`${row.id}-checkbox`}></TableCell>
{headers.map((header) => (
<TableCell key={header.key}>
<TableCell key={header.key} data-testid='nce-search-result' >
<UnorderedList>
{header.key === "type"
? row.sampleItems.map((item) => (
<Checkbox
id={row.labOrderNumber + "-" + item.number}
data-testid="nce-sample-checkbox"
key={item.id}
labelText={
item.type +
Expand Down Expand Up @@ -423,6 +425,7 @@ export const ReportNonConformingEvent = () => {
});
}
}}
data-testid="nce-goto-form-button"
>
<FormattedMessage id="nonconform.goToNceForm" />
</Button>
Expand Down Expand Up @@ -457,7 +460,7 @@ export const ReportNonConformingEvent = () => {
<FormattedMessage id="nonconform.nce.number" />
</span>
</div>
<div style={{ marginBottom: "10px" }}>{nceForm.data.nceNumber}</div>
<div style={{ marginBottom: "10px" }} data-testid='nce-number-result'>{nceForm.data.nceNumber}</div>
</Column>

<Column lg={3} md={3} sm={3} style={{ marginBottom: "20px" }}>
Expand Down Expand Up @@ -645,7 +648,7 @@ export const ReportNonConformingEvent = () => {
{!!nceForm.error && (
<div style={{ color: "#c62828", margin: 4 }}>{nceForm.error}</div>
)}
<Button type="button" onClick={() => handleNCEFormSubmit()}>
<Button type="button" data-testid="nce-submit-button" onClick={() => handleNCEFormSubmit()}>
<FormattedMessage id="label.button.submit" />
</Button>
</Column>
Expand Down
Loading

0 comments on commit 50a6522

Please sign in to comment.