Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jscheiny committed Dec 11, 2024
1 parent 4ff1c48 commit 48136fb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/datetime2/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ module.exports = async function (config) {
},
}),
);
process.env.TZ = 'Etc/UTC';
};
23 changes: 23 additions & 0 deletions packages/datetime2/test/components/datePicker3Tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,16 @@ describe("<DatePicker3>", () => {
});

describe("clearing a selection", () => {
const MOCK_TODAY = new Date(2024, 11, 24, 16, 30);
let clock: sinon.SinonFakeTimers;
beforeEach(() => {
clock = sinon.useFakeTimers(MOCK_TODAY);
});

afterEach(() => {
clock.restore();
});

it("onChange correctly passes a Date and never null when canClearSelection is false", () => {
const onChange = sinon.spy();
const { getDay } = wrap(<DatePicker3 {...LOCALE_LOADER} canClearSelection={false} onChange={onChange} />);
Expand Down Expand Up @@ -845,6 +855,19 @@ describe("<DatePicker3>", () => {
assert.equal(value!.getFullYear(), today.getFullYear());
});

it("selects the current day in the given timezone when Today is clicked", () => {
const { root } = wrap(<DatePicker3 {...LOCALE_LOADER} showActionsBar={true} timezone="Asia/Tokyo" />);
root.find({ className: Classes.DATEPICKER_FOOTER }).find(Button).first().simulate("click");

const value = root.state("value")!;
assert.isNotNull(value);
assert.equal(value.getDate(), MOCK_TODAY.getDate() + 1);
assert.equal(value.getMonth(), MOCK_TODAY.getMonth());
assert.equal(value.getFullYear(), MOCK_TODAY.getFullYear());
assert.equal(value.getHours(), 1);
assert.equal(value.getMinutes(), 30);
});

it("clears the value when Clear is clicked", () => {
const { getDay, root } = wrap(<DatePicker3 {...LOCALE_LOADER} showActionsBar={true} />);
getDay().simulate("click");
Expand Down

0 comments on commit 48136fb

Please sign in to comment.