Add comprehensive unit and e2e tests for invoice collection, queue logic, and modal interactions:
- Introduced e2e test for "Change Invoice Collection" in `change-invoice-collection.spec.ts`. - Added unit tests for `CollectedOrderInvoiceOverview.vue` including edit flow for `closed_at`. - Implemented tests for queue reliability, state handling, and customer actions: - `CollectedOrderInvoicesQueueHistory.vue`: polling, error handling, richer diagnostics, and retry logic. - `InvoicingBillingPeriod` views: refresh and queue state handling. - Enhanced test coverage for Stripe queue functionality and related actions.
This commit is contained in:
@@ -3,6 +3,7 @@ import { mount } from "@vue/test-utils";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createI18n } from "vue-i18n";
|
||||
import ActionSettingsWheelButton from "@/components/displays/buttons/ActionSettingsWheelButton.vue";
|
||||
import { SessionUser } from "@/components/session/token/SessionUser.vue";
|
||||
|
||||
const getUserIdMock = vi.hoisted(() =>
|
||||
vi.fn(() => Promise.resolve({ data: { data: { user_id: 777 } } }))
|
||||
@@ -128,6 +129,7 @@ const flushMicrotasks = async () => {
|
||||
describe("ActionSettingsWheelButton", () => {
|
||||
beforeEach(() => {
|
||||
getUserIdMock.mockClear();
|
||||
SessionUser.objects.orders.functions.showChangeInvoiceCollectionForm.mockClear();
|
||||
});
|
||||
|
||||
it("resolves customer user id once on mount and not on unrelated rerenders", async () => {
|
||||
@@ -181,4 +183,80 @@ describe("ActionSettingsWheelButton", () => {
|
||||
await flushMicrotasks();
|
||||
expect(getUserIdMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("routes 'change invoice collection' action without opening a new tab", async () => {
|
||||
const windowOpenSpy = vi.spyOn(window, "open").mockImplementation(() => null);
|
||||
|
||||
const wrapper = mount(ActionSettingsWheelButton, {
|
||||
props: {
|
||||
order_id: 42,
|
||||
invoice_collection_id: 991,
|
||||
},
|
||||
slots: {
|
||||
actions: "",
|
||||
},
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
stubs: {
|
||||
CustomerModal: { template: "<div />" },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await flushMicrotasks();
|
||||
await wrapper.find(".dropdown-trigger button").trigger("click");
|
||||
|
||||
const buttons = wrapper.findAll("button.dropdown-item-action");
|
||||
const changeInvoiceCollectionButton = buttons.find((buttonWrapper) =>
|
||||
buttonWrapper.text().includes("admin.pos.settings_wheel.change_invoice_collection")
|
||||
);
|
||||
|
||||
expect(changeInvoiceCollectionButton).toBeTruthy();
|
||||
await changeInvoiceCollectionButton.trigger("click");
|
||||
await flushMicrotasks();
|
||||
|
||||
expect(SessionUser.objects.orders.functions.showChangeInvoiceCollectionForm).toHaveBeenCalledTimes(1);
|
||||
expect(SessionUser.objects.orders.functions.showChangeInvoiceCollectionForm).toHaveBeenCalledWith(42, expect.any(Function));
|
||||
expect(windowOpenSpy).not.toHaveBeenCalled();
|
||||
|
||||
windowOpenSpy.mockRestore();
|
||||
});
|
||||
|
||||
it("routes 'view invoice collection in new tab' action to window.open only", async () => {
|
||||
const windowOpenSpy = vi.spyOn(window, "open").mockImplementation(() => null);
|
||||
|
||||
const wrapper = mount(ActionSettingsWheelButton, {
|
||||
props: {
|
||||
order_id: 42,
|
||||
invoice_collection_id: 777,
|
||||
},
|
||||
slots: {
|
||||
actions: "",
|
||||
},
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
stubs: {
|
||||
CustomerModal: { template: "<div />" },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await flushMicrotasks();
|
||||
SessionUser.objects.orders.functions.showChangeInvoiceCollectionForm.mockClear();
|
||||
await wrapper.find(".dropdown-trigger button").trigger("click");
|
||||
|
||||
const buttons = wrapper.findAll("button.dropdown-item-action");
|
||||
const viewInvoiceCollectionButton = buttons.find((buttonWrapper) =>
|
||||
buttonWrapper.text().includes("admin.pos.settings_wheel.view_invoice_collection_new_tab")
|
||||
);
|
||||
|
||||
expect(viewInvoiceCollectionButton).toBeTruthy();
|
||||
await viewInvoiceCollectionButton.trigger("click");
|
||||
await flushMicrotasks();
|
||||
|
||||
expect(windowOpenSpy).toHaveBeenCalledWith("/superuser/invoices/777", "_blank");
|
||||
expect(SessionUser.objects.orders.functions.showChangeInvoiceCollectionForm).not.toHaveBeenCalled();
|
||||
|
||||
windowOpenSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user