Files
pleno-vue/tests/unit/invoicing-period-view-totals.spec.js
T

84 lines
2.4 KiB
JavaScript

// @vitest-environment jsdom
import { afterEach, describe, expect, it, vi } from "vitest";
vi.mock(
"@/views/dashboards/superUserDashboard/InvoicingBillingPeriod/views/InvoicingBillingPeriodViewHome.vue",
() => ({ default: { template: "<div />" } })
);
vi.mock("@/views/dashboards/superUserDashboard/InvoicingBillingPeriod/views/InvoicingBillingPeriodViewAll.vue", () => ({
default: { template: "<div />" },
}));
vi.mock(
"@/views/dashboards/superUserDashboard/InvoicingBillingPeriod/views/InvoicingBillingPeriodViewSelfWash.vue",
() => ({ default: { template: "<div />" } })
);
import { view } from "@/views/dashboards/superUserDashboard/InvoicingBillingPeriod/imports/InvoicingBillingPeriodImportView.vue";
describe("Invoicing period view totals", () => {
afterEach(() => {
view.variables.currentView.value = "home";
view.variables.sharedVariables.value = null;
});
it("uses backend full-period type totals instead of the current page rows", () => {
view.variables.currentView.value = "all";
view.variables.sharedVariables.value = {
type_totals: {
all: {
total: 9000,
booked: 6000,
not_booked: 3000,
},
},
types: {
all: [
{
transactions: [
{
amount: 210,
booked: true,
excluded: false,
},
],
},
],
},
};
expect(view.computed.currentViewTotalNetAmount.value).toBe(9000);
expect(view.computed.currentViewTotalNetAmountBooked.value).toBe(6000);
expect(view.computed.currentViewTotalNetAmountNotBooked.value).toBe(3000);
});
it("falls back to row totals when full-period type totals are not present", () => {
view.variables.currentView.value = "all";
view.variables.sharedVariables.value = {
types: {
all: [
{
transactions: [
{
amount: 210,
booked: true,
excluded: false,
},
{
amount: 90,
booked: false,
excluded: false,
},
],
},
],
},
};
expect(view.computed.currentViewTotalNetAmount.value).toBe(300);
expect(view.computed.currentViewTotalNetAmountBooked.value).toBe(210);
expect(view.computed.currentViewTotalNetAmountNotBooked.value).toBe(90);
});
});