r-util-js/packages/uview-plus/test/datetime-picker.test.ts

74 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, test, expect } from "vitest";
import { effectScope } from "vue";
import { useDateTimePicker } from "../src/datetime-picker";
describe("useDateTimePicker", () => {
test("默认值", () => {
const scope = effectScope();
scope.run(() => {
const { value, show, text } = useDateTimePicker({});
expect(value.value).toBeNull();
expect(show.value).toBe(false);
expect(text.value).toBe("请选择");
});
scope.stop();
});
test("自定义 placeholder", () => {
const scope = effectScope();
scope.run(() => {
const { text } = useDateTimePicker({ placeholder: "选择时间" });
expect(text.value).toBe("选择时间");
});
scope.stop();
});
test("有 value 时 text 显示 value", () => {
const scope = effectScope();
scope.run(() => {
const { value, text } = useDateTimePicker({ value: "2024-01-15 10:00" });
expect(text.value).toBe("2024-01-15 10:00");
value.value = "2024-06-01 08:30";
expect(text.value).toBe("2024-06-01 08:30");
});
scope.stop();
});
test("showPicker / hidePicker", () => {
const scope = effectScope();
scope.run(() => {
const { show, showPicker, hidePicker } = useDateTimePicker({});
expect(show.value).toBe(false);
showPicker();
expect(show.value).toBe(true);
hidePicker();
expect(show.value).toBe(false);
});
scope.stop();
});
test("handleConfirm 关闭弹窗(不更新 value", () => {
const scope = effectScope();
scope.run(() => {
const { value, show, handleConfirm } = useDateTimePicker({ value: "2024-01-01" });
show.value = true;
const event = { indexs: [], value: [], values: [] } as any;
handleConfirm(event);
expect(show.value).toBe(false);
expect(value.value).toBe("2024-01-01");
});
scope.stop();
});
test("handleCancel 关闭弹窗", () => {
const scope = effectScope();
scope.run(() => {
const { show, handleCancel } = useDateTimePicker({});
show.value = true;
handleCancel();
expect(show.value).toBe(false);
});
scope.stop();
});
});