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

fix(input-time-picker, time-picker): fixing direct value setting issue where the minutes and seconds weren't respected when a default value is supplied #4321

Merged
merged 3 commits into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
31 changes: 31 additions & 0 deletions src/components/input-time-picker/input-time-picker.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,37 @@ describe("calcite-input-time-picker", () => {
expect(inputTimePickerValue).toBe(expectedValue);
});

it("value displays correctly in the input when it is programmatically changed for a 12-hour language when a default value is present", async () => {
eriklharper marked this conversation as resolved.
Show resolved Hide resolved
const lang = "en";
const page = await newE2EPage({
html: `<calcite-input-time-picker step="1" value="11:00:00"></calcite-input-time-picker>`
});

const inputTimePicker = await page.find("calcite-input-time-picker");
const input = await page.find("calcite-input-time-picker >>> calcite-input");

expect(await input.getProperty("value")).toBe("11:00:00 AM");
expect(await inputTimePicker.getProperty("value")).toBe("11:00:00");

const date = new Date(0);
date.setHours(13);
date.setMinutes(59);
date.setSeconds(59);

const expectedValue = date.toISOString().substr(11, 8);
const expectedDisplayValue = localizeTimeString(expectedValue, lang);

inputTimePicker.setProperty("value", expectedValue);

await page.waitForChanges();

const inputValue = await input.getProperty("value");
const inputTimePickerValue = await inputTimePicker.getProperty("value");

expect(inputValue).toBe(expectedDisplayValue);
expect(inputTimePickerValue).toBe(expectedValue);
});

it("appropriately triggers calciteInputTimePickerChange event when the user types a value", async () => {
const page = await newE2EPage();
await page.setContent(`<calcite-input-time-picker step="1"></calcite-input-time-picker>`);
Expand Down
29 changes: 29 additions & 0 deletions src/components/time-picker/time-picker.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,35 @@ describe("calcite-time-picker", () => {
shadowFocusTargetSelector: `.${CSS.hour}`
}));

it("value displays correctly when value is programmatically changed", async () => {
const originalValue = "11:00:00";
const newValue = "14:30:40";
const page = await newE2EPage({
html: `<calcite-time-picker step="1" value="${originalValue}"></calcite-time-picker>`
});

const timePicker = await page.find("calcite-time-picker");
const hourEl = await page.find(`calcite-time-picker >>> .${CSS.hour}`);
const minuteEl = await page.find(`calcite-time-picker >>> .${CSS.minute}`);
const secondEl = await page.find(`calcite-time-picker >>> .${CSS.second}`);
const meridiemEl = await page.find(`calcite-time-picker >>> .${CSS.meridiem}`);

expect(await timePicker.getProperty("value")).toBe(originalValue);
expect(hourEl.textContent).toBe("11");
expect(minuteEl.textContent).toBe("00");
expect(secondEl.textContent).toBe("00");
expect(meridiemEl.textContent).toBe("AM");

timePicker.setProperty("value", newValue);
await page.waitForChanges();

expect(await timePicker.getProperty("value")).toBe(newValue);
expect(hourEl.textContent).toBe("02");
expect(minuteEl.textContent).toBe("30");
expect(secondEl.textContent).toBe("40");
expect(meridiemEl.textContent).toBe("PM");
});

describe("keyboard accessibility", () => {
it("tabbing focuses each input in the correct sequence", async () => {
const page = await newE2EPage({
Expand Down
7 changes: 0 additions & 7 deletions src/components/time-picker/time-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,6 @@ export class TimePicker {

@State() hour: string;

@Watch("hour")
hourChanged(newHour: string): void {
if (this.meridiem && isValidNumber(newHour)) {
this.setValuePart("meridiem", getMeridiem(newHour));
}
}

@State() hourCycle: HourCycle;

@State() localizedHour: string;
Expand Down