Skip to content

Commit

Permalink
test(time-picker): add seconds segment test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
wattachai-lseg committed Nov 9, 2023
1 parent 6c834c1 commit e5a8313
Showing 1 changed file with 85 additions and 34 deletions.
119 changes: 85 additions & 34 deletions packages/elements/src/time-picker/__test__/time-picker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<ef-time-picker></ef-time-picker>');
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('<ef-time-picker></ef-time-picker>');
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('<ef-time-picker show-seconds></ef-time-picker>');
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);
});
});

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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('<ef-time-picker show-seconds></ef-time-picker>');
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);
});
});
});

0 comments on commit e5a8313

Please sign in to comment.