- Introduced `.prettierrc.json` to enforce consistent code formatting across the project. - Updated unit and e2e test files to address formatting issues, improve readability, and ensure alignment with the new Prettier configuration.
230 lines
6.9 KiB
JavaScript
230 lines
6.9 KiB
JavaScript
// @vitest-environment jsdom
|
|
import { computed, nextTick } from "vue";
|
|
import { mount } from "@vue/test-utils";
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const { sharedVariablesRef, currentViewRef, startDateRef, endDateRef, queueRef, inProgressRef } = vi.hoisted(() => {
|
|
const { ref } = require("vue");
|
|
|
|
return {
|
|
sharedVariablesRef: ref({ types: { all: [] } }),
|
|
currentViewRef: ref("all"),
|
|
startDateRef: ref(new Date("2026-04-01T00:00:00.000Z")),
|
|
endDateRef: ref(new Date("2026-04-30T23:59:59.000Z")),
|
|
queueRef: ref([]),
|
|
inProgressRef: ref([]),
|
|
};
|
|
});
|
|
|
|
vi.mock("@/services/economicTransferQueue.js", () => ({
|
|
ECONOMIC_QUEUE_STATUS: {
|
|
QUEUED: "QUEUED",
|
|
PROCESSING: "PROCESSING",
|
|
COMPLETED: "COMPLETED",
|
|
FAILED: "FAILED",
|
|
},
|
|
}));
|
|
|
|
vi.mock("@/components/session/token/SessionUser.vue", () => ({
|
|
SessionUser: {
|
|
objects: {
|
|
global: {
|
|
language: {
|
|
processing: "Processing",
|
|
queued: "Queued",
|
|
all_booked: "All booked",
|
|
none: "None",
|
|
invoice_now: "Invoice now",
|
|
},
|
|
},
|
|
orders: {
|
|
meta: {
|
|
labels: {
|
|
single: "order",
|
|
multiple: "orders",
|
|
},
|
|
},
|
|
get: {
|
|
multiple: vi.fn().mockResolvedValue([]),
|
|
},
|
|
},
|
|
collectedOrderInvoices: {
|
|
functions: {
|
|
createVehicleSubscriptionInvoice: vi.fn(),
|
|
add_fixed_pricing: vi.fn(),
|
|
add_vehicle_subscriptions: vi.fn(),
|
|
},
|
|
},
|
|
vehicles: {
|
|
columns: {
|
|
wash_subscription: {
|
|
label: "Subscription",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
functions: {
|
|
currency: {
|
|
toLocal: (value) => String(value),
|
|
},
|
|
},
|
|
},
|
|
}));
|
|
|
|
vi.mock(
|
|
"@/views/dashboards/superUserDashboard/InvoicingBillingPeriod/imports/InvoicingBillingPeriodImportView.vue",
|
|
() => ({
|
|
view: {
|
|
variables: {
|
|
currentView: currentViewRef,
|
|
sharedVariables: sharedVariablesRef,
|
|
},
|
|
computed: {
|
|
componentName: computed(() => currentViewRef.value),
|
|
},
|
|
functions: {
|
|
filterExcluded: (transactions = []) => transactions.filter((transaction) => !transaction?.excluded),
|
|
getCustomerViewTotalNetAmount: (customer) => {
|
|
const transactions = Array.isArray(customer?.transactions) ? customer.transactions : [];
|
|
return transactions.reduce((sum, transaction) => sum + Number(transaction?.amount ?? 0), 0);
|
|
},
|
|
},
|
|
},
|
|
})
|
|
);
|
|
|
|
vi.mock(
|
|
"@/views/dashboards/superUserDashboard/InvoicingBillingPeriod/imports/InvoicingBillingPeriodImportDates.vue",
|
|
() => ({
|
|
dates: {
|
|
variables: {
|
|
start: startDateRef,
|
|
end: endDateRef,
|
|
},
|
|
},
|
|
})
|
|
);
|
|
|
|
vi.mock(
|
|
"@/views/dashboards/superUserDashboard/InvoicingBillingPeriod/imports/InvoicingBillingPeriodImportInvoiceQueue.vue",
|
|
() => ({
|
|
invoiceQueue: {
|
|
addInvoiceCollectionsToQueue: vi.fn(),
|
|
processInvoiceCollectionQueue: vi.fn(),
|
|
invoiceCollectionQueue: queueRef,
|
|
invoiceCollectionQueueInProgress: inProgressRef,
|
|
invoiceCollectionQueueFailed: require("vue").ref([]),
|
|
invoiceCollectionQueueSuccess: require("vue").ref([]),
|
|
},
|
|
})
|
|
);
|
|
|
|
import InvoicingBillingPeriodViewAll from "@/views/dashboards/superUserDashboard/InvoicingBillingPeriod/views/InvoicingBillingPeriodViewAll.vue";
|
|
|
|
const mountView = () =>
|
|
mount(InvoicingBillingPeriodViewAll, {
|
|
global: {
|
|
stubs: {
|
|
InvoicingBillingPeriodStatistics: { template: "<div />" },
|
|
InvoicingBillingPeriodFilters: { template: "<div />" },
|
|
WhiteBox: { template: "<div><slot /></div>" },
|
|
ColorIndicator: { template: "<div><slot /></div>" },
|
|
ActionSettingsWheelButton: { template: "<div><slot name='actions' /></div>" },
|
|
InvoiceOrdersPagination: { template: "<div />" },
|
|
SmallCustomerActivityChart: { template: "<div />" },
|
|
InvoicingBillingPeriodCustomerAttributes: { template: "<div />" },
|
|
InvoicingBillingPeriodInvoiceProgressBar: { template: "<div />" },
|
|
},
|
|
},
|
|
});
|
|
|
|
describe("Invoicing period queue state", () => {
|
|
beforeEach(() => {
|
|
currentViewRef.value = "all";
|
|
queueRef.value = [];
|
|
inProgressRef.value = [];
|
|
sharedVariablesRef.value = {
|
|
types: {
|
|
all: [
|
|
{
|
|
id: 1,
|
|
customer_number: 1001,
|
|
customer_name: "Queued Customer",
|
|
requires_action: false,
|
|
queue: {
|
|
has_active_job: true,
|
|
statuses: ["QUEUED"],
|
|
invoice_collection_ids: [14578],
|
|
is_action_blocked: true,
|
|
},
|
|
transactions: [
|
|
{
|
|
id: 5001,
|
|
amount: 100,
|
|
booked: false,
|
|
excluded: false,
|
|
queue_status: "QUEUED",
|
|
queue_job_id: 9,
|
|
invoice_collection_id: 14578,
|
|
date: "2026-04-10T10:00:00.000Z",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
id: 2,
|
|
customer_number: 1002,
|
|
customer_name: "Mixed Customer",
|
|
requires_action: true,
|
|
queue: {
|
|
has_active_job: true,
|
|
statuses: ["PROCESSING"],
|
|
invoice_collection_ids: [2001],
|
|
is_action_blocked: false,
|
|
},
|
|
transactions: [
|
|
{
|
|
id: 5002,
|
|
amount: 120,
|
|
booked: false,
|
|
excluded: false,
|
|
queue_status: "PROCESSING",
|
|
queue_job_id: 10,
|
|
invoice_collection_id: 2001,
|
|
date: "2026-04-11T10:00:00.000Z",
|
|
},
|
|
{
|
|
id: 5003,
|
|
amount: 80,
|
|
booked: false,
|
|
excluded: false,
|
|
queue_status: null,
|
|
queue_job_id: null,
|
|
invoice_collection_id: null,
|
|
date: "2026-04-12T10:00:00.000Z",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
};
|
|
});
|
|
|
|
it("renders a disabled queued CTA when the backend marks the customer as action-blocked", async () => {
|
|
const wrapper = mountView();
|
|
await nextTick();
|
|
|
|
const queuedButton = wrapper.get("[data-testid='invoicing-period-customer-queue-1001']");
|
|
expect(queuedButton.text()).toContain("Queued");
|
|
expect(queuedButton.attributes("disabled")).toBeDefined();
|
|
expect(wrapper.find("[data-testid='invoicing-period-customer-invoice-1001']").exists()).toBe(false);
|
|
});
|
|
|
|
it("keeps the invoice action visible for mixed queued and still-unqueued customers", async () => {
|
|
const wrapper = mountView();
|
|
await nextTick();
|
|
|
|
expect(wrapper.find("[data-testid='invoicing-period-customer-queue-1002']").exists()).toBe(false);
|
|
expect(wrapper.get("[data-testid='invoicing-period-customer-invoice-1002']").text()).toContain("Invoice now");
|
|
});
|
|
});
|