56 lines
1.4 KiB
JavaScript
56 lines
1.4 KiB
JavaScript
// @vitest-environment jsdom
|
|
import { enableAutoUnmount, mount } from "@vue/test-utils";
|
|
import { nextTick } from "vue";
|
|
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
import LocalDataResetDialog from "@/components/global/LocalDataResetDialog.vue";
|
|
|
|
enableAutoUnmount(afterEach);
|
|
|
|
const flush = async () => {
|
|
await Promise.resolve();
|
|
await nextTick();
|
|
};
|
|
|
|
const clickBodyButton = async (testId) => {
|
|
await flush();
|
|
document.body.querySelector(`[data-testid='${testId}']`).click();
|
|
await flush();
|
|
};
|
|
|
|
describe("LocalDataResetDialog", () => {
|
|
beforeEach(() => {
|
|
document.body.innerHTML = "";
|
|
});
|
|
|
|
afterEach(() => {
|
|
document.body.innerHTML = "";
|
|
});
|
|
|
|
it("emits dismiss and model update when Nej is pressed", async () => {
|
|
const wrapper = mount(LocalDataResetDialog, {
|
|
attachTo: document.body,
|
|
props: {
|
|
modelValue: true,
|
|
},
|
|
});
|
|
|
|
await clickBodyButton("local-data-reset-cancel");
|
|
|
|
expect(wrapper.emitted("dismiss")).toHaveLength(1);
|
|
expect(wrapper.emitted("update:modelValue")).toEqual([[false]]);
|
|
});
|
|
|
|
it("emits confirm when Ja, ryd alt is pressed", async () => {
|
|
const wrapper = mount(LocalDataResetDialog, {
|
|
attachTo: document.body,
|
|
props: {
|
|
modelValue: true,
|
|
},
|
|
});
|
|
|
|
await clickBodyButton("local-data-reset-confirm");
|
|
|
|
expect(wrapper.emitted("confirm")).toHaveLength(1);
|
|
});
|
|
});
|