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

[datetime2] fix(DateInput2): display updated timezone immediately #5718

Merged
merged 2 commits into from
Nov 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -608,6 +608,7 @@ export const DateInput2: React.FC<DateInput2Props> = React.memo(function _DateIn
isTimezoneSelectHidden,
placeholder,
shouldShowErrorStyling,
timezoneValue,
props.disabled,
props.inputProps,
props.rightElement,
Expand Down
23 changes: 18 additions & 5 deletions packages/datetime2/test/components/dateInput2Tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { mount, ReactWrapper } from "enzyme";
import * as React from "react";
import * as sinon from "sinon";

import { Classes as CoreClasses, InputGroup, Keys } from "@blueprintjs/core";
import { Classes as CoreClasses, InputGroup, Keys, Tag } from "@blueprintjs/core";
import { DatePicker, Classes as DatetimeClasses, Months, TimePrecision, TimeUnit } from "@blueprintjs/datetime";
import { Popover2, Classes as Popover2Classes } from "@blueprintjs/popover2";

Expand Down Expand Up @@ -479,7 +479,7 @@ describe("<DateInput2>", () => {
assert.doesNotThrow(() => mount(<DateInput2 {...DEFAULT_PROPS_CONTROLLED} value={null} />));
});

describe("when changing timezone", () => {
describe.only("when changing timezone", () => {
adidahiya marked this conversation as resolved.
Show resolved Hide resolved
it("calls onChange with the updated ISO string", () => {
const wrapper = mount(<DateInput2 {...DEFAULT_PROPS_CONTROLLED} />);
clickTimezoneItem(wrapper, "Paris");
Expand All @@ -495,6 +495,14 @@ describe("<DateInput2>", () => {
assert.isTrue(onChange.calledOnce);
assert.strictEqual(onChange.firstCall.args[0], "2021-11-29T10:30+01:00");
});

it("updates the displayed timezone", () => {
const wrapper = mount(<DateInput2 {...DEFAULT_PROPS_CONTROLLED} />);
clickTimezoneItem(wrapper, "New York");
const tzTag = wrapper.find(Tag);
// date-fns does not know about Daylight Saving Time in Node.js
assert.strictEqual(tzTag.text(), "EST");
});
});

it("changing the time calls onChange with the updated ISO string", () => {
Expand Down Expand Up @@ -725,13 +733,18 @@ describe("<DateInput2>", () => {

function clickTimezoneItem(wrapper: ReactWrapper<DateInput2Props>, searchQuery: string) {
wrapper.find(`.${Classes.TIMEZONE_SELECT}`).hostNodes().simulate("click");
wrapper
const tzItem = wrapper
.find(`.${Classes.TIMEZONE_SELECT_POPOVER}`)
.find(`.${CoreClasses.MENU_ITEM}`)
.hostNodes()
.findWhere(item => item.text().includes(searchQuery))
.first()
.simulate("click");
.first();

if (tzItem.exists()) {
tzItem.simulate("click");
} else {
assert.fail(`Could not find timezone option with query '${searchQuery}'`);
}
}

function clickCalendarDay(wrapper: ReactWrapper<DateInput2Props>, dayNumber: number) {
Expand Down