-
Notifications
You must be signed in to change notification settings - Fork 429
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
added cypress tests for shifting request #9035
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import LoginPage from "pageobject/Login/LoginPage" | ||
import { PatientConsultationPage } from "pageobject/Patient/PatientConsultation"; | ||
import { PatientPage } from "pageobject/Patient/PatientCreation"; | ||
import ShiftCreation from "pageobject/Shift/ShiftCreation"; | ||
import { ShiftDetails } from "pageobject/Shift/ShiftDetails"; | ||
import { ShiftingBoard } from "pageobject/Shift/ShiftingBoard"; | ||
import ShiftUpdate from "pageobject/Shift/ShiftUpdate"; | ||
|
||
describe("New shifting request",() =>{ | ||
const loginPage = new LoginPage(); | ||
const shiftCreation = new ShiftCreation() | ||
const shiftingBoard = new ShiftingBoard() | ||
const shiftDetails = new ShiftDetails() | ||
const shiftUpdate = new ShiftUpdate() | ||
const patientPage = new PatientPage() | ||
const patientConsultationPage = new PatientConsultationPage() | ||
|
||
before(() => { | ||
loginPage.loginAsDisctrictAdmin(); | ||
cy.saveLocalStorage(); | ||
}); | ||
|
||
beforeEach(() => { | ||
cy.restoreLocalStorage(); | ||
}); | ||
|
||
it("Creating and verifying new shifting request", () => { | ||
cy.intercept("POST", "api/v1/shift").as("shiftRequest"); | ||
|
||
cy.visit('/patients') | ||
patientPage.visitPatient("Dummy Patient 16") | ||
patientConsultationPage.clickShiftPatientButton() | ||
|
||
shiftCreation.typeCurrentFacilityPerson("new"); | ||
shiftCreation.typeCurrentFacilityPhone("9465666768"); | ||
shiftCreation.typeShiftReason("emmergency"); | ||
shiftCreation.typeAmbulanceDriverName("Rahul"); | ||
shiftCreation.typeAmbulancePhone("9865666768") | ||
shiftCreation.typeAmbulanceNumber("1") | ||
shiftCreation.typeComment("Some comment") | ||
shiftCreation.submitShiftForm(); | ||
|
||
cy.wait("@shiftRequest").its("response.statusCode").should("eq", 201); | ||
|
||
cy.visit("/shifting/board"); | ||
cy.contains("Dummy Patient 16").should("exist"); | ||
}); | ||
|
||
it("Editing and verifying refelctions in existing request", () => { | ||
cy.intercept("PUT", "**/api/v1/shift/**").as("shiftUpdateRequest"); | ||
cy.visit("/shifting/board"); | ||
cy.contains("Dummy Patient 16").should("exist"); | ||
|
||
shiftingBoard.openDetails("Dummy Patient 16") | ||
shiftDetails.clickUpdateStatusButton() | ||
|
||
shiftUpdate.typeShiftReason("new reason"); | ||
shiftUpdate.typeAmbulanceDriverName("Ramesh"); | ||
shiftUpdate.typeAmbulancePhone("9755443232") | ||
shiftUpdate.typeAmbulanceNumber("2") | ||
shiftUpdate.typeComment("New comment") | ||
shiftUpdate.submitShiftForm(); | ||
|
||
cy.wait('@shiftUpdateRequest').then((interception) => { | ||
const responseData = interception.response.body; | ||
|
||
expect(responseData.patient_object.name).to.eq("Dummy Patient 16"); | ||
expect(responseData.ambulance_phone_number).to.eq("+919755443232"); | ||
expect(responseData.comments).to.eq("New comment"); | ||
expect(responseData.reason).to.eq("new reason"); | ||
expect(responseData.ambulance_driver_name).to.eq("Ramesh"); | ||
expect(responseData.ambulance_number).to.eq("2"); | ||
}); | ||
|
||
}); | ||
|
||
afterEach(() => { | ||
cy.saveLocalStorage(); | ||
}); | ||
}) |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,6 @@ | ||||||||||||||||||||||||||||||||||||||
export class ShiftDetails{ | ||||||||||||||||||||||||||||||||||||||
clickUpdateStatusButton(){ | ||||||||||||||||||||||||||||||||||||||
cy.contains("Update Status/Details").click() | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Use data-testid for more robust element selection Using text content for element selection is fragile and can break if the text changes or with i18n. Use data-testid attributes instead. - cy.contains("Update Status/Details").click()
+ cy.get('[data-testid="shift-update-status-button"]').click()
|
||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
Comment on lines
+1
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add TypeScript types and documentation The class should follow TypeScript best practices with proper type annotations and documentation. +/**
+ * Page Object Model class for handling shift details operations
+ */
export class ShiftDetails{
- clickUpdateStatusButton(){
+ /**
+ * Clicks the update status button in the shift details view
+ * @returns {Cypress.Chainable<void>} Cypress chain
+ */
+ clickUpdateStatusButton(): Cypress.Chainable<void> {
cy.contains("Update Status/Details").click()
}
} 📝 Committable suggestion
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export class ShiftUpdate { | ||
typeShiftReason(reason: string) { | ||
cy.get("#reason").click().clear().type(reason); | ||
} | ||
Comment on lines
+2
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Enhance form interaction methods with better practices. The input methods could be improved with:
Here's a suggested implementation pattern: /** Constants file */
export const SELECTORS = {
REASON: '#reason',
DRIVER_NAME: '#ambulance_driver_name',
// ... other selectors
} as const;
/** Example improved method */
/**
* Types the shift reason into the reason field
* @param reason - The reason for the shift
* @throws {Error} If the reason field is not found
*/
typeShiftReason(reason: string): void {
if (!reason?.trim()) {
throw new Error('Shift reason cannot be empty');
}
cy.get(SELECTORS.REASON)
.should('be.visible')
.click()
.clear()
.type(reason, { delay: 50 })
.should('have.value', reason);
} Also applies to: 6-8, 10-12, 14-16, 18-20 |
||
|
||
typeAmbulanceDriverName(name: string) { | ||
cy.get("#ambulance_driver_name").click().clear().type(name); | ||
} | ||
|
||
typeAmbulancePhone(number: string) { | ||
cy.get("#ambulance_phone_number").click().clear().type(number); | ||
} | ||
|
||
typeAmbulanceNumber(number: string) { | ||
cy.get("#ambulance_number").click().clear().type(number); | ||
} | ||
|
||
typeComment(comment: string) { | ||
cy.get('#comments').click().clear().type(comment); | ||
} | ||
|
||
submitShiftForm() { | ||
cy.get("#submit").contains("Submit").click(); | ||
} | ||
Comment on lines
+22
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve form submission handling. The submit method should be more robust by:
/**
* Submits the shift form and verifies successful submission
* @throws {Error} If submission fails or times out
*/
submitShiftForm(): void {
cy.get('#submit')
.should('be.visible')
.and('not.be.disabled')
.click();
// Wait for loading state
cy.get('.loading-indicator').should('exist');
// Verify successful submission
cy.get('.success-message')
.should('be.visible')
.and('contain', 'Shift updated successfully');
} |
||
} | ||
export default ShiftUpdate; | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,8 @@ | ||||||||||||||||||||||||||||||||||||
export class ShiftingBoard { | ||||||||||||||||||||||||||||||||||||
openDetails(patientName) { | ||||||||||||||||||||||||||||||||||||
cy.get('#patient_name').type(patientName); | ||||||||||||||||||||||||||||||||||||
cy.intercept("GET", "**/api/v1/shift/**").as("getShiftingRequest"); | ||||||||||||||||||||||||||||||||||||
cy.wait("@getShiftingRequest").its("response.statusCode").should("eq", 200); | ||||||||||||||||||||||||||||||||||||
Comment on lines
+4
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Make the API intercept pattern more specific to match the actual endpoint Based on the search results, the broad pattern
Since this intercept is used in the cy.intercept("GET", "/api/v1/shift/").as("getShiftingRequest"); 🔗 Analysis chainVerify API endpoint pattern and response handling. The API interception pattern Let's verify the API endpoint pattern: 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Search for shift-related API endpoints to ensure we're using the correct pattern
rg -g '*.{ts,js,tsx,jsx}' --no-heading "api/v1/shift" -A 2 -B 2
Length of output: 3699 |
||||||||||||||||||||||||||||||||||||
cy.contains("All Details").click(); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
Comment on lines
+2
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add TypeScript type safety and improve error handling. The method implementation could be more robust with the following improvements:
Consider applying these improvements: - openDetails(patientName) {
+ openDetails(patientName: string) {
cy.get('#patient_name').type(patientName);
cy.intercept("GET", "**/api/v1/shift/**").as("getShiftingRequest");
- cy.wait("@getShiftingRequest").its("response.statusCode").should("eq", 200);
+ cy.wait("@getShiftingRequest", { timeout: 10000 })
+ .then((interception) => {
+ if (interception.response?.statusCode !== 200) {
+ throw new Error(`API request failed with status ${interception.response?.statusCode}`);
+ }
+ });
- cy.contains("All Details").click();
+ cy.contains("All Details", { timeout: 5000 }).click();
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Fix typo and enhance error handling scenarios.
Add error scenarios: