171 lines
4.8 KiB
JavaScript
171 lines
4.8 KiB
JavaScript
// @vitest-environment jsdom
|
|
import { flushPromises, mount } from "@vue/test-utils";
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
vi.mock("vue-i18n", async (importOriginal) => {
|
|
const actual = await importOriginal();
|
|
return {
|
|
...actual,
|
|
useI18n: () => ({
|
|
t: (key) => key,
|
|
}),
|
|
};
|
|
});
|
|
|
|
vi.mock("sweetalert2", () => ({
|
|
default: {
|
|
fire: vi.fn(),
|
|
},
|
|
}));
|
|
|
|
vi.mock("@/components/session/token/SessionUser.vue", () => ({
|
|
SessionUser: {
|
|
objects: {
|
|
global: {
|
|
language: {
|
|
hide_content: "Hide",
|
|
show_content: "Show",
|
|
status: "Status",
|
|
completed: "Completed",
|
|
not_completed: "Not completed",
|
|
},
|
|
},
|
|
orders: {
|
|
columns: {
|
|
id: { label: "ID", visible: true },
|
|
created_at: { label: "Created", visible: true },
|
|
},
|
|
},
|
|
collectedOrderInvoices: {
|
|
functions: {
|
|
split_by_month: vi.fn(),
|
|
economic: {
|
|
invoice: vi.fn(),
|
|
},
|
|
},
|
|
},
|
|
vehicles: {
|
|
columns: {
|
|
wash_subscription: {
|
|
label: "Subscription",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
functions: {
|
|
currency: {
|
|
toLocal: (value) => String(value),
|
|
},
|
|
parseErrorMessage: (error) => error?.message ?? String(error),
|
|
},
|
|
},
|
|
}));
|
|
|
|
vi.mock("@/views/dashboards/superUserDashboard/user/displays/other/UserOtherSpecialArrangement.vue", () => ({
|
|
default: { template: "<div />" },
|
|
}));
|
|
|
|
vi.mock("@/views/dashboards/superUserDashboard/user/displays/other/UserOtherVaskeabonnement.vue", () => ({
|
|
default: { template: "<div />" },
|
|
}));
|
|
|
|
vi.mock("@/components/displays/department/pos/order/orderItemsTable.vue", () => ({
|
|
default: { template: "<div />" },
|
|
}));
|
|
|
|
vi.mock("@/components/displays/superuser/tables/OrderContentTable.vue", () => ({
|
|
default: { template: "<div />" },
|
|
}));
|
|
|
|
import Swal from "sweetalert2";
|
|
import InvoiceOrderTable from "@/components/displays/superuser/tables/InvoiceOrderTable.vue";
|
|
import { SessionUser } from "@/components/session/token/SessionUser.vue";
|
|
|
|
const mountTable = (orders) =>
|
|
mount(InvoiceOrderTable, {
|
|
props: {
|
|
orders,
|
|
options: {},
|
|
columns: {},
|
|
user_id: 42,
|
|
},
|
|
global: {
|
|
mocks: {
|
|
$t: (key) =>
|
|
({
|
|
"global.invoice_now": "Invoice now",
|
|
"global.unselect": "Unselect",
|
|
"common.all": "All",
|
|
"common.select": "Select",
|
|
}[key] ?? key),
|
|
},
|
|
},
|
|
});
|
|
|
|
describe("InvoiceOrderTable multi-month warning", () => {
|
|
beforeEach(() => {
|
|
Swal.fire.mockReset();
|
|
SessionUser.objects.collectedOrderInvoices.functions.split_by_month.mockReset();
|
|
SessionUser.objects.collectedOrderInvoices.functions.economic.invoice.mockReset();
|
|
SessionUser.objects.collectedOrderInvoices.functions.economic.invoice.mockResolvedValue({});
|
|
});
|
|
|
|
it("warns for selected invoice collections containing orders from multiple months before invoicing together", async () => {
|
|
Swal.fire.mockResolvedValueOnce({ isDenied: true }).mockReturnValueOnce(new Promise(() => {}));
|
|
const wrapper = mountTable([
|
|
{
|
|
id: 1,
|
|
invoice_collection_id: 9001,
|
|
created_at: "2026-03-15 10:00:00",
|
|
},
|
|
{
|
|
id: 2,
|
|
invoice_collection_id: 9001,
|
|
created_at: "2026-04-02 10:00:00",
|
|
},
|
|
]);
|
|
|
|
await wrapper.find("tbody input[type='checkbox']").trigger("click");
|
|
await wrapper.get("[data-testid='invoice-order-table-invoice-button']").trigger("click");
|
|
await flushPromises();
|
|
|
|
expect(Swal.fire).toHaveBeenNthCalledWith(
|
|
1,
|
|
expect.objectContaining({
|
|
icon: "warning",
|
|
showDenyButton: true,
|
|
})
|
|
);
|
|
expect(SessionUser.objects.collectedOrderInvoices.functions.split_by_month).not.toHaveBeenCalled();
|
|
expect(SessionUser.objects.collectedOrderInvoices.functions.economic.invoice).toHaveBeenCalledWith(9001, 42);
|
|
});
|
|
|
|
it("does not warn for selected invoice collections containing only one month", async () => {
|
|
Swal.fire.mockReturnValueOnce(new Promise(() => {}));
|
|
const wrapper = mountTable([
|
|
{
|
|
id: 1,
|
|
invoice_collection_id: 9002,
|
|
created_at: "2026-04-01 10:00:00",
|
|
},
|
|
{
|
|
id: 2,
|
|
invoice_collection_id: 9002,
|
|
created_at: "2026-04-02 10:00:00",
|
|
},
|
|
]);
|
|
|
|
await wrapper.find("tbody input[type='checkbox']").trigger("click");
|
|
await wrapper.get("[data-testid='invoice-order-table-invoice-button']").trigger("click");
|
|
await flushPromises();
|
|
|
|
expect(Swal.fire).toHaveBeenCalledTimes(1);
|
|
expect(Swal.fire).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
title: "Fakturaer oprettet",
|
|
})
|
|
);
|
|
expect(SessionUser.objects.collectedOrderInvoices.functions.economic.invoice).toHaveBeenCalledWith(9002, 42);
|
|
});
|
|
});
|