Skip to content

Commit

Permalink
Refactor test so it wont fail when the UTC day changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanpro committed Mar 28, 2024
1 parent 05765c5 commit c14f724
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"run-cypress": "TZ=UTC nyc cypress run",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build",
"test-storybook": "test-storybook"
"test-storybook": "test-storybook",
"serve": "npm run dev"
},
"main": "./dist/vue-form-builder.umd.js",
"module": "./dist/vue-form-builder.es.js",
Expand Down
25 changes: 11 additions & 14 deletions tests/e2e/specs/DatePickerTimezone.spec.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/* eslint-disable no-param-reassign */
import moment from "moment-timezone";

const timezoneTest = "America/Los_Angeles";
moment.tz.setDefault(timezoneTest);

describe("Date Picker", () => {
beforeEach(() => {
// Set date to midnight January 1, 2024.
// The timezone is UTC. We set it to UTC in package.json `TZ=UTC`
cy.clock(new Date(2024, 0, 0, 0, 0, 0), ['Date']);
cy.visit("/");
cy.openAcordeon("collapse-1");

// Set the User's timezone to Los Angeles. This is what DatePicker will use
cy.window().then((win) => {
win.ProcessMaker.user.timezone = timezoneTest;
win.ProcessMaker.user.timezone = "America/Los_Angeles";
});
});

Expand All @@ -24,9 +25,11 @@ describe("Date Picker", () => {
cy.get(
"[data-cy=preview-content] [data-cy='screen-field-form_date_picker_1'] input"
).click();
// Choose today. In Los Angeles, that would be December 31, 2023
cy.get(
"[data-cy=preview-content] [data-cy='screen-field-form_date_picker_1'] .selectable.today"
).click();
// Set time to 8:15 PM Los Angeles time
cy.get(
"[data-cy=preview-content] [data-cy='screen-field-form_date_picker_1'] .vdpHoursInput"
).type("8");
Expand All @@ -36,21 +39,15 @@ describe("Date Picker", () => {
cy.get(
"[data-cy=preview-content] [data-cy='screen-field-form_date_picker_1'] .vdp12HourToggleBtn"
).then((toggle) => {
// Change to AM/PM - Time is now 8:15 PM, Los Angeles time
if (toggle.is(".vdp12HourToggleBtn")) {
cy.get(toggle).click();
}
});

cy.wait(500);
const todaysDate = moment();
const todayDateChanged = `${moment
.tz(todaysDate, "America/Los_Angeles")
.format("YYYY-MM-DD")}T20:15:00`;
const today = moment(todayDateChanged).utc();
cy.log("today", today.toISOString());

cy.assertPreviewData({
form_date_picker_1: moment(today).toISOString()
// 8:15 PM on December 31, 2023 in Los Angeles is 04:15 (4:15am) the next day (January 1, 2024) in UTC
form_date_picker_1: "2024-01-01T04:15:00.000Z"
});
});
});

0 comments on commit c14f724

Please sign in to comment.