From 48136fb4881393465b11e9bb7521712311beeefa Mon Sep 17 00:00:00 2001 From: Jonah Scheinerman Date: Wed, 11 Dec 2024 12:31:35 -0500 Subject: [PATCH] Tests --- packages/datetime2/karma.conf.js | 1 + .../test/components/datePicker3Tests.tsx | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/packages/datetime2/karma.conf.js b/packages/datetime2/karma.conf.js index cd949b02cd..46e1233087 100644 --- a/packages/datetime2/karma.conf.js +++ b/packages/datetime2/karma.conf.js @@ -33,4 +33,5 @@ module.exports = async function (config) { }, }), ); + process.env.TZ = 'Etc/UTC'; }; diff --git a/packages/datetime2/test/components/datePicker3Tests.tsx b/packages/datetime2/test/components/datePicker3Tests.tsx index 4e060ac28c..29874abcb3 100644 --- a/packages/datetime2/test/components/datePicker3Tests.tsx +++ b/packages/datetime2/test/components/datePicker3Tests.tsx @@ -801,6 +801,16 @@ describe("", () => { }); 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(); @@ -845,6 +855,19 @@ describe("", () => { assert.equal(value!.getFullYear(), today.getFullYear()); }); + it("selects the current day in the given timezone when Today is clicked", () => { + const { root } = wrap(); + 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(); getDay().simulate("click");