From e5a831332b57ff4b9c73a698817725790b7c67e7 Mon Sep 17 00:00:00 2001
From: Wattachai Kanawitoon <117723407+wattachai-lseg@users.noreply.github.com>
Date: Thu, 9 Nov 2023 14:36:32 +0700
Subject: [PATCH] test(time-picker): add seconds segment test cases
---
.../time-picker/__test__/time-picker.test.js | 119 +++++++++++++-----
1 file changed, 85 insertions(+), 34 deletions(-)
diff --git a/packages/elements/src/time-picker/__test__/time-picker.test.js b/packages/elements/src/time-picker/__test__/time-picker.test.js
index cfad505ed8..8115cb1ac8 100644
--- a/packages/elements/src/time-picker/__test__/time-picker.test.js
+++ b/packages/elements/src/time-picker/__test__/time-picker.test.js
@@ -175,16 +175,43 @@ describe('time-picker/TimePicker', function () {
expect(el).shadowDom.to.equalSnapshot();
});
- it('should not pre-populate minutes value when hours value change', async function () {
+ it('should not pre-populate other segments value when hours value changes', async function () {
const el = await fixture('');
- const hoursPart = el.renderRoot.querySelector('#hours');
- hoursPart.value = '12';
- hoursPart.dispatchEvent(
+ const hoursInput = el.hoursInput;
+ hoursInput.value = '12';
+ hoursInput.dispatchEvent(
new CustomEvent('focused-changed', { bubbles: true, detail: { value: false } })
);
await elementUpdated(el);
expect(el.hours).to.equal(12);
expect(el.minutes).to.equal(null);
+ expect(el.seconds).to.equal(null);
+ });
+
+ it('should not pre-populate other segments value when minutes value change', async function () {
+ const el = await fixture('');
+ const minutesInput = el.minutesInput;
+ minutesInput.value = '30';
+ minutesInput.dispatchEvent(
+ new CustomEvent('focused-changed', { bubbles: true, detail: { value: false } })
+ );
+ await elementUpdated(el);
+ expect(el.hours).to.equal(null);
+ expect(el.minutes).to.equal(30);
+ expect(el.seconds).to.equal(null);
+ });
+
+ it('should not pre-populate other segments value when seconds value change', async function () {
+ const el = await fixture('');
+ const secondsInput = el.secondsInput;
+ secondsInput.value = '45';
+ secondsInput.dispatchEvent(
+ new CustomEvent('focused-changed', { bubbles: true, detail: { value: false } })
+ );
+ await elementUpdated(el);
+ expect(el.hours).to.equal(null);
+ expect(el.minutes).to.equal(null);
+ expect(el.seconds).to.equal(45);
});
});
@@ -588,36 +615,6 @@ describe('time-picker/TimePicker', function () {
}
});
- it('Cycling through minutes should not pre-populate hours value', async function () {
- el = await fixture(timePickerDefaults);
- expect(el.minutes).to.equal(null);
- expect(el.hours).to.equal(null);
- createKeyboardEvent(el.minutesInput, InputKey.arrowDown);
- await elementUpdated(el);
- expect(el.minutes).to.equal(0);
- expect(el.hours).to.equal(null);
-
- createKeyboardEvent(el.minutesInput, InputKey.arrowDown);
- await elementUpdated(el);
- expect(el.minutes).to.equal(59);
- expect(el.hours).to.equal(null);
- });
-
- it('Cycling through hours should not pre-populate minutes value', async function () {
- el = await fixture(timePickerDefaults);
- expect(el.minutes).to.equal(null);
- expect(el.hours).to.equal(null);
- createKeyboardEvent(el.hoursInput, InputKey.arrowDown);
- await elementUpdated(el);
- expect(el.minutes).to.equal(null);
- expect(el.hours).to.equal(0);
-
- createKeyboardEvent(el.hoursInput, InputKey.arrowDown);
- await elementUpdated(el);
- expect(el.minutes).to.equal(null);
- expect(el.hours).to.equal(23);
- });
-
it('Cycling through minutes/seconds should affect their parents values', async function () {
expect(secondsPart).to.exist;
expect(el.seconds).to.equal(0);
@@ -655,5 +652,59 @@ describe('time-picker/TimePicker', function () {
expect(el.minutes).to.equal(0);
expect(el.hours).to.equal(0);
});
+
+ it('Cycling through seconds should not pre-populate other segments value', async function () {
+ el = await fixture('');
+ expect(el.hours).to.equal(null);
+ expect(el.minutes).to.equal(null);
+ expect(el.seconds).to.equal(null);
+ createKeyboardEvent(el.secondsInput, InputKey.arrowDown);
+ await elementUpdated(el);
+ expect(el.hours).to.equal(null);
+ expect(el.minutes).to.equal(null);
+ expect(el.seconds).to.equal(0);
+
+ createKeyboardEvent(el.secondsInput, InputKey.arrowDown);
+ await elementUpdated(el);
+ expect(el.hours).to.equal(null);
+ expect(el.minutes).to.equal(null);
+ expect(el.seconds).to.equal(59);
+ });
+
+ it('Cycling through minutes should not pre-populate other segments value', async function () {
+ el = await fixture(timePickerDefaults);
+ expect(el.hours).to.equal(null);
+ expect(el.minutes).to.equal(null);
+ expect(el.seconds).to.equal(null);
+ createKeyboardEvent(el.minutesInput, InputKey.arrowDown);
+ await elementUpdated(el);
+ expect(el.hours).to.equal(null);
+ expect(el.minutes).to.equal(0);
+ expect(el.seconds).to.equal(null);
+
+ createKeyboardEvent(el.minutesInput, InputKey.arrowDown);
+ await elementUpdated(el);
+ expect(el.hours).to.equal(null);
+ expect(el.minutes).to.equal(59);
+ expect(el.seconds).to.equal(null);
+ });
+
+ it('Cycling through hours should not pre-populate other segments value', async function () {
+ el = await fixture(timePickerDefaults);
+ expect(el.hours).to.equal(null);
+ expect(el.minutes).to.equal(null);
+ expect(el.seconds).to.equal(null);
+ createKeyboardEvent(el.hoursInput, InputKey.arrowDown);
+ await elementUpdated(el);
+ expect(el.hours).to.equal(0);
+ expect(el.minutes).to.equal(null);
+ expect(el.seconds).to.equal(null);
+
+ createKeyboardEvent(el.hoursInput, InputKey.arrowDown);
+ await elementUpdated(el);
+ expect(el.hours).to.equal(23);
+ expect(el.minutes).to.equal(null);
+ expect(el.seconds).to.equal(null);
+ });
});
});