-
Notifications
You must be signed in to change notification settings - Fork 449
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,94 @@ | ||||||||||||||||||||
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(); | ||||||||||||||||||||
|
||||||||||||||||||||
const patientName = "Dummy Patient 16"; | ||||||||||||||||||||
const currentFacilityPerson = "new"; | ||||||||||||||||||||
const currentFacilityPhone = "9465666768"; | ||||||||||||||||||||
const shiftReasonInitial = "emmergency"; | ||||||||||||||||||||
const ambulanceDriverNameInitial = "Rahul"; | ||||||||||||||||||||
const ambulancePhoneInitial = "9865666768"; | ||||||||||||||||||||
const ambulanceNumberInitial = "1"; | ||||||||||||||||||||
const commentInitial = "Some comment"; | ||||||||||||||||||||
|
||||||||||||||||||||
const shiftReasonUpdated = "new reason"; | ||||||||||||||||||||
const ambulanceDriverNameUpdated = "Ramesh"; | ||||||||||||||||||||
const ambulancePhoneUpdated = "9755443232"; | ||||||||||||||||||||
const ambulanceNumberUpdated = "2"; | ||||||||||||||||||||
const commentUpdated = "New comment"; | ||||||||||||||||||||
|
||||||||||||||||||||
before(() => { | ||||||||||||||||||||
loginPage.loginAsDistrictAdmin(); | ||||||||||||||||||||
cy.saveLocalStorage(); | ||||||||||||||||||||
}); | ||||||||||||||||||||
|
||||||||||||||||||||
beforeEach(() => { | ||||||||||||||||||||
cy.restoreLocalStorage(); | ||||||||||||||||||||
}); | ||||||||||||||||||||
|
||||||||||||||||||||
it("Shift Request Creation and Update", () => { | ||||||||||||||||||||
cy.visit('/patients'); | ||||||||||||||||||||
patientPage.visitPatient(patientName); | ||||||||||||||||||||
patientConsultationPage.clickShiftPatientButton(); | ||||||||||||||||||||
|
||||||||||||||||||||
shiftCreation.typeCurrentFacilityPerson(currentFacilityPerson); | ||||||||||||||||||||
shiftCreation.typeCurrentFacilityPhone(currentFacilityPhone); | ||||||||||||||||||||
shiftCreation.typeShiftReason(shiftReasonInitial); | ||||||||||||||||||||
shiftCreation.typeAmbulanceDriverName(ambulanceDriverNameInitial); | ||||||||||||||||||||
shiftCreation.typeAmbulancePhone(ambulancePhoneInitial); | ||||||||||||||||||||
shiftCreation.typeAmbulanceNumber(ambulanceNumberInitial); | ||||||||||||||||||||
shiftCreation.typeComment(commentInitial); | ||||||||||||||||||||
shiftCreation.interceptShiftCreationRequest(); | ||||||||||||||||||||
shiftCreation.submitShiftForm(); | ||||||||||||||||||||
|
||||||||||||||||||||
cy.wait("@shiftRequest").its("response.statusCode").should("eq", 201); | ||||||||||||||||||||
Comment on lines
+54
to
+57
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 Move API intercept before form interactions. The intercept should be placed before any form interactions to ensure no requests are missed. + shiftCreation.interceptShiftCreationRequest();
shiftCreation.typeCurrentFacilityPerson(currentFacilityPerson);
shiftCreation.typeCurrentFacilityPhone(currentFacilityPhone);
// ... other form interactions ...
- shiftCreation.interceptShiftCreationRequest();
shiftCreation.submitShiftForm(); 📝 Committable suggestion
Suggested change
🧰 Tools🪛 eslint[error] 56-56: Delete (prettier/prettier) |
||||||||||||||||||||
|
||||||||||||||||||||
cy.visit("/shifting/board"); | ||||||||||||||||||||
cy.contains(patientName).should("exist"); | ||||||||||||||||||||
|
||||||||||||||||||||
Comment on lines
+59
to
+61
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 Verify initial data after creation. After creating the shift request, verify that all initial data is correctly reflected in the shift details page before proceeding with updates. cy.visit("/shifting/board");
cy.contains(patientName).should("exist");
// Verify initial data
shiftingBoard.openDetails(patientName);
cy.get('[data-testid="shift-details-name"]')
.should("be.visible")
.and("have.text", patientName);
// Add more verifications for other fields 🧰 Tools🪛 eslint[error] 61-61: Delete (prettier/prettier)
Comment on lines
+42
to
+61
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 Split creation and update into separate test cases. The current test combines creation and update flows. This makes the test harder to maintain and debug. Consider splitting into separate test cases:
🧰 Tools🪛 eslint[error] 43-43: Replace (prettier/prettier) [error] 46-46: Delete (prettier/prettier) [error] 56-56: Delete (prettier/prettier) [error] 61-61: Delete (prettier/prettier) |
||||||||||||||||||||
shiftingBoard.openDetails(patientName); | ||||||||||||||||||||
shiftDetails.clickUpdateStatusButton(); | ||||||||||||||||||||
|
||||||||||||||||||||
shiftUpdate.typeShiftReason(shiftReasonUpdated); | ||||||||||||||||||||
shiftUpdate.typeAmbulanceDriverName(ambulanceDriverNameUpdated); | ||||||||||||||||||||
shiftUpdate.typeAmbulancePhone(ambulancePhoneUpdated); | ||||||||||||||||||||
shiftUpdate.typeAmbulanceNumber(ambulanceNumberUpdated); | ||||||||||||||||||||
shiftUpdate.typeComment(commentUpdated); | ||||||||||||||||||||
shiftUpdate.interceptShiftUpdateRequest(); | ||||||||||||||||||||
shiftUpdate.submitShiftForm(); | ||||||||||||||||||||
|
||||||||||||||||||||
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. remove unwanted spaces |
||||||||||||||||||||
cy.wait('@shiftUpdateRequest').then((interception) => { | ||||||||||||||||||||
const responseData = interception.response.body; | ||||||||||||||||||||
expect(responseData.patient_object.name).to.eq(patientName); | ||||||||||||||||||||
expect(responseData.ambulance_phone_number).to.eq(`+91${ambulancePhoneUpdated}`); | ||||||||||||||||||||
expect(responseData.comments).to.eq(commentUpdated); | ||||||||||||||||||||
expect(responseData.reason).to.eq(shiftReasonUpdated); | ||||||||||||||||||||
expect(responseData.ambulance_driver_name).to.eq(ambulanceDriverNameUpdated); | ||||||||||||||||||||
expect(responseData.ambulance_number).to.eq(ambulanceNumberUpdated); | ||||||||||||||||||||
}); | ||||||||||||||||||||
|
||||||||||||||||||||
cy.get('#shift_details_name').should('be.visible').and('have.text', patientName); | ||||||||||||||||||||
cy.get('#shift_details_ambulance_phone_number').should('be.visible').and('have.text', `+91${ambulancePhoneUpdated}`); | ||||||||||||||||||||
cy.get('#shift_details_ambulance_number').should('be.visible').and('have.text', ambulanceNumberUpdated); | ||||||||||||||||||||
cy.get('#shift_details_comments').should('be.visible').and('have.text', commentUpdated); | ||||||||||||||||||||
cy.get('#shift_details_reason').should('be.visible').and('have.text', shiftReasonUpdated); | ||||||||||||||||||||
cy.get('#shift_details_ambulance_driver_name').should('be.visible').and('have.text', ambulanceDriverNameUpdated); | ||||||||||||||||||||
Comment on lines
+83
to
+88
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 instead of ID selectors. For better maintainability and resilience to UI changes, use data-testid attributes instead of ID selectors. - cy.get('#shift_details_name')
+ cy.get('[data-testid="shift-details-name"]')
.should('be.visible')
.and('have.text', patientName);
// Apply similar changes to other selectors
🧰 Tools🪛 eslint[error] 83-83: Replace (prettier/prettier) [error] 84-84: Replace (prettier/prettier) [error] 85-85: Replace (prettier/prettier) [error] 86-86: Replace (prettier/prettier) [error] 87-87: Replace (prettier/prettier) [error] 88-88: Replace (prettier/prettier) |
||||||||||||||||||||
|
||||||||||||||||||||
}); | ||||||||||||||||||||
Comment on lines
+42
to
+90
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 test cases for error scenarios. The test suite should include error scenarios such as:
Example test case: it("Should handle API errors when creating shift request", () => {
cy.intercept('POST', '**/api/v1/shift/**', {
statusCode: 500,
body: { error: 'Internal Server Error' }
}).as('failedShiftRequest');
// Perform creation steps
shiftCreation.submitShiftForm();
// Verify error handling
cy.get('[data-testid="error-message"]').should('be.visible');
}); 🧰 Tools🪛 eslint[error] 43-43: Replace (prettier/prettier) [error] 46-46: Delete (prettier/prettier) [error] 56-56: Delete (prettier/prettier) [error] 61-61: Delete (prettier/prettier) [error] 73-73: Replace (prettier/prettier) [error] 76-76: Replace (prettier/prettier) [error] 79-79: Replace (prettier/prettier) [error] 83-83: Replace (prettier/prettier) [error] 84-84: Replace (prettier/prettier) [error] 85-85: Replace (prettier/prettier) [error] 86-86: Replace (prettier/prettier) [error] 87-87: Replace (prettier/prettier) [error] 88-88: Replace (prettier/prettier) [error] 89-90: Delete (prettier/prettier) |
||||||||||||||||||||
afterEach(() => { | ||||||||||||||||||||
cy.saveLocalStorage(); | ||||||||||||||||||||
}); | ||||||||||||||||||||
}); |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -139,4 +139,14 @@ export class PatientConsultationPage { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cy.get("#consultation-buttons").contains("Claims").click(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cy.wait("@policyStatus").its("response.statusCode").should("eq", 200); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
clickShiftPatientButton() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cy.get("#consultation-buttons").scrollIntoView(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cy.get("button").contains("Manage Patient").click(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cy.verifyAndClickElement( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"#consultation-buttons", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"Shift Patient", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cy.wait(3000); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+143
to
+150
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 Inconsistent selector usage needs to be fixed Based on the evidence:
The implementation in 🔗 Analysis chainVerify and align selector usage across similar methods There's an inconsistency in how the "Manage Patient" button is accessed across different methods:
Please verify which selector should be used and align the implementation across all methods. Also applies to: 104-106 Let me gather more information about the Let me try a different approach to find the method implementation. 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Find all usages of these selectors to determine the correct one
echo "Searching for #show-more selector..."
rg --type ts "#show-more"
echo -e "\nSearching for #consultation-buttons selector..."
rg --type ts "#consultation-buttons"
Length of output: 2081 Script: #!/bin/bash
# Find the implementation of clickManagePatientButton
ast-grep --pattern 'clickManagePatientButton() {
$$$
}'
Length of output: 59 Script: #!/bin/bash
# Search for clickManagePatientButton in typescript files
rg --type ts "clickManagePatientButton" -A 5
Length of output: 1046 🧰 Tools🪛 Biome (1.9.4)[error] 142-142: Expected a semicolon or an implicit semicolon after a statement, but found none An explicit or implicit semicolon is expected here... ...Which is required to end this statement (parse) [error] 142-150: This block statement doesn't serve any purpose and can be safely removed. Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code. (lint/complexity/noUselessLoneBlockStatements) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+143
to
+151
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 Refactor to reduce code duplication and improve reliability The implementation duplicates logic from Here's a suggested refactor: + private clickManagePatientButton() {
+ cy.get("#consultation-buttons").scrollIntoView();
+ cy.get("button").contains("Manage Patient").click();
+ }
clickEditConsultationButton() {
- cy.get("#consultation-buttons").scrollIntoView();
- cy.get("button").contains("Manage Patient").click();
+ this.clickManagePatientButton();
cy.verifyAndClickElement(
"#consultation-buttons",
"Edit Consultation Details",
- );
- cy.wait(3000);
+ ).should('not.exist'); // Wait for menu to close
}
clickShiftPatientButton() {
- cy.get("#consultation-buttons").scrollIntoView();
- cy.get("button").contains("Manage Patient").click();
+ this.clickManagePatientButton();
cy.verifyAndClickElement(
"#consultation-buttons",
"Shift Patient",
- );
- cy.wait(3000);
+ ).should('not.exist'); // Wait for menu to close
} The changes:
📝 Committable suggestion
Suggested change
🧰 Tools🪛 eslint[error] 119-122: Replace (prettier/prettier) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,28 @@ export class ShiftCreation { | |
cy.get("#reason").click().type(reason); | ||
} | ||
|
||
typeAmbulanceDriverName(name: string) { | ||
cy.get("#ambulance_driver_name").click().type(name); | ||
} | ||
|
||
typeAmbulancePhone(number: string) { | ||
cy.get("#ambulance_phone_number").click().type(number); | ||
} | ||
|
||
typeAmbulanceNumber(number: string) { | ||
cy.get("#ambulance_number").click().type(number); | ||
} | ||
|
||
typeComment(comment:string) { | ||
cy.get("#comments").click().type(comment) | ||
} | ||
|
||
submitShiftForm() { | ||
cy.get("#submit").contains("Submit").click(); | ||
cy.submitButton("Submit"); | ||
} | ||
|
||
interceptShiftCreationRequest(){ | ||
cy.intercept("POST", "api/v1/shift").as("shiftRequest"); | ||
Comment on lines
+34
to
+35
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 API interception with response validation. While the interception is correctly set up, consider adding response validation for more robust testing: interceptShiftCreationRequest(){
- cy.intercept("POST", "api/v1/shift").as("shiftRequest");
+ cy.intercept("POST", "api/v1/shift", (req) => {
+ req.on('response', (res) => {
+ expect(res.statusCode).to.be.oneOf([201, 200]);
+ expect(res.body).to.have.property('id');
+ });
+ }).as("shiftRequest");
} Also consider adding a timeout configuration if the API response might be slow: cy.wait('@shiftRequest', { timeout: 10000 }); |
||
} | ||
} | ||
export default ShiftCreation; |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,5 @@ | ||||||||||||||||||||||||||||
export class ShiftDetails{ | ||||||||||||||||||||||||||||
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 interface and documentation for the ShiftDetails class. Following TypeScript best practices, let's add proper interface and documentation. +/**
+ * Interface defining the contract for shift details operations
+ */
+interface IShiftDetails {
+ clickUpdateStatusButton(): Cypress.Chainable<void>;
+}
+
+/**
+ * Page Object Model class for handling shift details operations in Cypress tests
+ * @implements {IShiftDetails}
+ */
-export class ShiftDetails{
+export class ShiftDetails implements IShiftDetails { 📝 Committable suggestion
Suggested change
🧰 Tools🪛 eslint[error] 1-1: Insert (prettier/prettier) |
||||||||||||||||||||||||||||
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
+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 Improve method implementation for better reliability and maintainability The current implementation has several areas for improvement:
Apply these improvements: - clickUpdateStatusButton(){
- cy.contains("Update Status/Details").click()
- }
+ /**
+ * Clicks the update status button in the shift details view
+ * @returns {Cypress.Chainable<void>} Cypress chainable
+ * @throws {Error} If the button is not found or not clickable
+ */
+ clickUpdateStatusButton(): Cypress.Chainable<void> {
+ return cy
+ .get('[data-testid="shift-update-status-button"]', { timeout: 10000 })
+ .should('be.visible')
+ .should('be.enabled')
+ .click();
+ } Additionally, ensure to add the corresponding <button data-testid="shift-update-status-button">Update Status/Details</button> 🧰 Tools🪛 eslint[error] 2-2: Replace (prettier/prettier) [error] 3-3: Replace (prettier/prettier) [error] 4-4: Delete (prettier/prettier) |
||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
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) { | ||
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.
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. But the shiftUpdate class will require the function to be slightly different than the shiftCreation one , as they will clear the previous value that was already present in the input box . That is why i created the fuctions seperately that might seem to be duplicate . If you want i can get rid of the functions but the clearing the original values wil have to be done in original functions , is that okay ? |
||
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); | ||
} | ||
Comment on lines
+2
to
+20
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 while maintaining clear() functionality. I understand the necessity of
Example implementation: interface FormSelectors {
readonly REASON: '#reason';
readonly DRIVER_NAME: '#ambulance_driver_name';
// ... other selectors
}
const SELECTORS: FormSelectors = {
REASON: '#reason',
DRIVER_NAME: '#ambulance_driver_name',
// ... other selectors
} as const;
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)
.should('have.value', reason);
} 🧰 Tools🪛 eslint[error] 5-5: Delete (prettier/prettier) [error] 9-9: Delete (prettier/prettier) [error] 13-13: Delete (prettier/prettier) [error] 17-17: Delete (prettier/prettier) |
||
|
||
submitShiftForm() { | ||
cy.submitButton("Submit"); | ||
} | ||
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 Enhance form submission with loading and success states. The submission method should handle loading states and verify successful submission. submitShiftForm(): void {
cy.submitButton('Submit')
.should('not.be.disabled');
// Wait for loading state
cy.get('[data-testid="loading"]')
.should('exist')
.should('not.exist');
// Verify successful submission
cy.get('[data-testid="success-message"]')
.should('be.visible')
.and('contain', 'Shift updated successfully');
} |
||
|
||
interceptShiftUpdateRequest(){ | ||
cy.intercept("PUT", "**/api/v1/shift/**").as("shiftUpdateRequest"); | ||
} | ||
} | ||
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("#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. Multiple improvements needed for robustness and type safety
Apply these improvements: - openDetails(patientName) {
+ openDetails(patientName: string): void {
cy.get('#patient_name').type(patientName);
- cy.intercept("GET", "**/api/v1/shift/**").as("getShiftingRequest");
+ cy.intercept("GET", "/api/v1/shift/").as("getShiftingRequest");
cy.wait("@getShiftingRequest").its("response.statusCode").should("eq", 200);
- cy.contains("#details").click();
+ cy.get("#details").click();
} Additionally, consider adding timeout and error handling: openDetails(patientName: string): void {
cy.get('#patient_name').type(patientName);
cy.intercept("GET", "/api/v1/shift/").as("getShiftingRequest");
cy.wait("@getShiftingRequest", { timeout: 10000 })
.then((interception) => {
if (interception.response?.statusCode !== 200) {
throw new Error(`Failed to load shifting request: ${interception.response?.statusCode}`);
}
});
cy.get("#details", { timeout: 5000 }).click();
} 🧰 Tools🪛 eslint[error] 2-2: Delete (prettier/prettier) [error] 3-3: Replace (prettier/prettier) [error] 4-4: Replace (prettier/prettier) [error] 5-5: Delete (prettier/prettier) [error] 6-6: Replace (prettier/prettier) [error] 7-7: Delete (prettier/prettier) |
||
} |
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
Move test data to a separate constants file and fix typo.
cypress/fixtures/shiftingRequest.json
) for better maintainability and reusability.emmergency
→emergency
Create a new file
cypress/fixtures/shiftingRequest.json
: