Skip to content

Commit

Permalink
added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
odalys-dataport committed Nov 8, 2023
1 parent 52dee5f commit 073c363
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
20 changes: 18 additions & 2 deletions src/components/ui-date-time-picker/DatePicker.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ describe("DatePicker", () => {
expect(wrapper.emitted("update:date")).toHaveLength(1);
});

describe("when date is required", () => {
it("should not emit update:date event on empty input", async () => {
describe("when date is invalid", () => {
it("should emit error event", async () => {
setup({
date: new Date().toISOString(),
required: true,
Expand All @@ -76,6 +76,22 @@ describe("DatePicker", () => {
await wrapper.vm.$nextTick();

expect(wrapper.emitted("update:date")).toBeUndefined();
expect(wrapper.emitted("error")).toHaveLength(1);
});

it("should emit error event", async () => {
setup({
date: "55.55.5555",
});

const textField = wrapper.findComponent({ name: "v-text-field" });
const input = textField.find("input");

await input.setValue("");
await wrapper.vm.$nextTick();

expect(wrapper.emitted("update:date")).toBeUndefined();
expect(wrapper.emitted("error")).toHaveLength(1);
});
});
});
20 changes: 20 additions & 0 deletions src/components/ui-date-time-picker/DateTimePicker.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,24 @@ describe("DateTimePicker", () => {
expect(wrapper.emitted("input")).toBe(undefined);
});
});

describe("if date and time values are removed", () => {
it("should emit input event", async () => {
jest.useFakeTimers();
setup({ dateTime: new Date().toISOString() });

const datePicker = wrapper.findComponent({ name: "date-picker" });
datePicker.vm.$emit("update:date", "");
jest.advanceTimersByTime(1000);

expect(wrapper.emitted("input")).toBe(undefined);

const timePicker = wrapper.findComponent({ name: "time-picker" });
timePicker.vm.$emit("update:time", "");

jest.advanceTimersByTime(1000);

expect(wrapper.emitted("input")).toHaveLength(1);
});
});
});
12 changes: 6 additions & 6 deletions src/components/ui-date-time-picker/TimePicker.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe("TimePicker", () => {
});

describe("when time is required", () => {
it("should no emit update:time event on empty input", async () => {
it("should no emit update:time event but error event on empty input", async () => {
setup({
time: "12:30",
required: true,
Expand All @@ -109,23 +109,22 @@ describe("TimePicker", () => {
await wrapper.vm.$nextTick();

expect(wrapper.emitted("update:time")).toBeUndefined();
expect(wrapper.emitted("error")).toHaveLength(1);
});
});

describe("when time is not required and value is empty", () => {
it("should not emit update:time event", async () => {
it("should emit update:time event", async () => {
setup({ time: "12:30" });

const input = wrapper
.findComponent({ name: "v-text-field" })
.find("input");

await input.trigger("focus");
await input.setValue("");
await input.trigger("blur");
await wrapper.vm.$nextTick();
jest.advanceTimersByTime(1000);

expect(wrapper.emitted("update:time")).toBe(undefined);
expect(wrapper.emitted("update:time")).toHaveLength(1);
});
});

Expand All @@ -142,6 +141,7 @@ describe("TimePicker", () => {
await wrapper.vm.$nextTick();

expect(wrapper.emitted("update:time")).toBeUndefined();
expect(wrapper.emitted("error")).toHaveLength(1);
});
});
});
Expand Down

0 comments on commit 073c363

Please sign in to comment.