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

test: fix datepicker tests #37042

Open
wants to merge 3 commits into
base: release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe(

// ADS changes to date input property causes this test to fail
// skipping it temporarily.
it.skip("DatePicker-Date Name validation", function () {
it("DatePicker-Date Name validation", function () {
// changing the date to today
cy.get(formWidgetsPage.defaultDate).click();
cy.SetDateToToday();
Expand All @@ -36,10 +36,8 @@ describe(

/**
* setDate--> is a Command to select the date in the date picker
* @param1 --> its takes currentday+ <future day> eg: 1
* @param2 --> user date formate
*/
cy.setDate(1, "ddd MMM DD YYYY");
cy.setDate(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Update required: setDate command usage is inconsistent with implementation

The current implementation of setDate only accepts a single parameter for days offset, but there are multiple occurrences in the codebase where it's called with two parameters. This needs to be fixed:

  • DatePicker_With_Switch_spec.js: Uses setDate(1, "ddd MMM DD YYYY")
  • DatePicker_Text_spec.js: Two instances using setDate(1, "ddd MMM DD YYYY")

These calls need to be updated to match the current implementation which only accepts the days offset parameter.

🔗 Analysis chain

Verify the impact of simplified setDate command.

The setDate command has been simplified to use a single parameter. Ensure this change is consistent with the command implementation.


Let me check the implementation of the setDate command to verify if the simplified usage is correct.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all usages of setDate command to verify consistency
rg "cy\.setDate\(" --type js

Length of output: 889


Script:

#!/bin/bash
# Search for the implementation of setDate command
rg -A 10 "Cypress\.Commands\.add\(['\"]setDate" --type js

Length of output: 941

const nextDay = dayjs().add(1, "days").format("DD/MM/YYYY");
cy.log(nextDay);
cy.get(formWidgetsPage.datepickerWidget + " .bp3-input").should(
Expand Down
4 changes: 3 additions & 1 deletion app/client/cypress/limited-tests.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# To run only limited tests - give the spec names in below format:
cypress/e2e/Regression/ClientSide/Templates/Fork_Template_spec.js
cypress/e2e/Regression/ClientSide/Widgets/Datepicker/DatePicker2_spec.js
cypress/e2e/Regression/ClientSide/Binding/DatePicker_Text_spec.js
cypress/e2e/Regression/ClientSide/Widgets/Datepicker/DatePicker_With_Switch_spec.js

# For running all specs - uncomment below:
#cypress/e2e/**/**/*
Expand Down
7 changes: 3 additions & 4 deletions app/client/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,10 +524,9 @@ Cypress.Commands.add("getDate", (date, dateFormate) => {
return eDate;
});

Cypress.Commands.add("setDate", (date, dateFormate) => {
const expDate = dayjs().add(date, "days").format(dateFormate);
const sel = `.DayPicker-Day[aria-label=\"${expDate}\"]`;
cy.get(sel).click();
Cypress.Commands.add("setDate", (date) => {
const expDate = dayjs().add(date, "days").format("dddd, MMMM DD");
cy.get(`.react-datepicker__day[aria-label^="Choose ${expDate}"]`).click();
Comment on lines +527 to +529
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

Consider making the date format configurable.

The hardcoded date format "dddd, MMMM DD" reduces flexibility. Consider keeping the format parameter to support different date formats across tests.

-Cypress.Commands.add("setDate", (date) => {
+Cypress.Commands.add("setDate", (date, dateFormat = "dddd, MMMM DD") => {
   const expDate = dayjs()
     .add(date, "days")
-    .format("dddd, MMMM DD");
+    .format(dateFormat);
   cy.get(`.react-datepicker__day[aria-label^="Choose ${expDate}"]`).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
Cypress.Commands.add("setDate", (date) => {
const expDate = dayjs().add(date, "days").format("dddd, MMMM DD");
cy.get(`.react-datepicker__day[aria-label^="Choose ${expDate}"]`).click();
Cypress.Commands.add("setDate", (date, dateFormat = "dddd, MMMM DD") => {
const expDate = dayjs().add(date, "days").format(dateFormat);
cy.get(`.react-datepicker__day[aria-label^="Choose ${expDate}"]`).click();

});

Cypress.Commands.add("validateDisableWidget", (widgetCss, disableCss) => {
Expand Down
Loading