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(datepicker): make date parsing work again #882

Merged
merged 4 commits into from
Apr 20, 2024
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
10 changes: 5 additions & 5 deletions packages/oruga/src/components/datepicker/Datepicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -854,11 +854,11 @@
const date = (props.dateParser as any)(value, defaultDateParser);
mlmoravek marked this conversation as resolved.
Show resolved Hide resolved

if (
date &&
Array.isArray(date) &&
date.length === 2 &&
!isNaN(date[0]) &&
!isNaN(date[1])
date instanceof Date ||
mlmoravek marked this conversation as resolved.
Show resolved Hide resolved
(Array.isArray(date) &&
date.length === 2 &&
date[0] instanceof Date &&
date[1] instanceof Date)

Check warning on line 861 in packages/oruga/src/components/datepicker/Datepicker.vue

View check run for this annotation

Codecov / codecov/patch

packages/oruga/src/components/datepicker/Datepicker.vue#L858-L861

Added lines #L858 - L861 were not covered by tests
) {
vmodel.value = date;
} else {
Expand Down
25 changes: 25 additions & 0 deletions packages/oruga/src/components/datepicker/tests/datepicker.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { afterEach, describe, expect, test } from "vitest";
import { mount, enableAutoUnmount } from "@vue/test-utils";

import ODatepicker from "@/components/datepicker/Datepicker.vue";

describe("ODatepicker", () => {
enableAutoUnmount(afterEach);

test("parses keyboard input", () => {
const wrapper = mount(ODatepicker, { props: { readonly: false } });

const target = wrapper.find("input");
expect(target.exists()).toBeTruthy();
target.setValue("2024-04-10");

const updates = wrapper.emitted("update:modelValue");
expect(updates).toHaveLength(1);
expect(updates[0]).toHaveLength(1);
const updateValue = updates[0][0];
expect(updateValue).toBeInstanceOf(Date);
expect((updateValue as Date).toISOString()).toBe(
"2024-04-10T00:00:00.000Z",
);
});
});