136 lines
6.4 KiB
JavaScript
136 lines
6.4 KiB
JavaScript
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
const root = process.cwd();
|
|
const paginationModelsRoot = join(root, "src/components/displays/pagination/models");
|
|
const paginationGeneralSearchSource = readFileSync(
|
|
join(root, "src/components/displays/pagination/PaginationDisplayGeneralSearchReload.vue"),
|
|
"utf8"
|
|
);
|
|
const mainSource = readFileSync(join(root, "src/main.js"), "utf8");
|
|
const userOrdersPaginationSource = readFileSync(
|
|
join(root, "src/components/displays/pagination/models/UserDashboard/OrdersPagination.vue"),
|
|
"utf8"
|
|
);
|
|
const customerComplaintsPaginationSource = readFileSync(
|
|
join(root, "src/components/displays/pagination/models/SuperUserDashboard/CustomerComplaintsPagination.vue"),
|
|
"utf8"
|
|
);
|
|
const customersPaginationSource = readFileSync(
|
|
join(root, "src/components/displays/pagination/models/SuperUserDashboard/CustomersPagination.vue"),
|
|
"utf8"
|
|
);
|
|
const customerComplaintsTableSource = readFileSync(
|
|
join(root, "src/components/displays/superuser/tables/customerComplaintsTable.vue"),
|
|
"utf8"
|
|
);
|
|
const customersTableSource = readFileSync(
|
|
join(root, "src/components/displays/superuser/tables/customersTable.vue"),
|
|
"utf8"
|
|
);
|
|
const departmentsPaginationSource = readFileSync(
|
|
join(root, "src/components/displays/pagination/models/SuperUserDashboard/DepartmentsPagination.vue"),
|
|
"utf8"
|
|
);
|
|
const departmentsTableSource = readFileSync(
|
|
join(root, "src/components/displays/superuser/tables/departmentsTable.vue"),
|
|
"utf8"
|
|
);
|
|
const usersPaginationSource = readFileSync(
|
|
join(root, "src/components/displays/pagination/models/SuperUserDashboard/UsersPagination.vue"),
|
|
"utf8"
|
|
);
|
|
const usersTableSource = readFileSync(join(root, "src/components/displays/superuser/tables/usersTable.vue"), "utf8");
|
|
|
|
const collectVueFiles = (dir) => {
|
|
const entries = readdirSync(dir);
|
|
return entries.flatMap((entry) => {
|
|
const fullPath = join(dir, entry);
|
|
const stats = statSync(fullPath);
|
|
if (stats.isDirectory()) {
|
|
return collectVueFiles(fullPath);
|
|
}
|
|
if (entry.endsWith(".vue")) {
|
|
return [fullPath];
|
|
}
|
|
return [];
|
|
});
|
|
};
|
|
|
|
describe("table standards contract", () => {
|
|
it("keeps pagination model templates free from legacy raw <table> markup", () => {
|
|
const vueFiles = collectVueFiles(paginationModelsRoot);
|
|
const filesWithRawTableMarkup = vueFiles.filter((filePath) => {
|
|
const source = readFileSync(filePath, "utf8");
|
|
return source.includes("<table");
|
|
});
|
|
|
|
expect(filesWithRawTableMarkup).toEqual([]);
|
|
});
|
|
|
|
it("exposes a shared excel export action in the opdater dropdown controls", () => {
|
|
expect(paginationGeneralSearchSource).toContain("pagination.download_excel");
|
|
expect(paginationGeneralSearchSource).toContain("handleExportExcel");
|
|
expect(paginationGeneralSearchSource).toContain("exportToExcel");
|
|
expect(paginationGeneralSearchSource).toContain("toggleActionDropdown");
|
|
expect(paginationGeneralSearchSource).toContain("action-dropdown-main");
|
|
expect(paginationGeneralSearchSource).toContain("action-dropdown-toggle");
|
|
});
|
|
|
|
it("initializes automatic visible-row export hooks for legacy non-paginated tables", () => {
|
|
expect(mainSource).toContain("initializeAutoTableExports");
|
|
expect(mainSource).toContain("initializeAutoTableExports()");
|
|
});
|
|
|
|
it("uses excel export for historical washes instead of legacy csv download", () => {
|
|
expect(userOrdersPaginationSource).toContain("setExportTransform");
|
|
expect(userOrdersPaginationSource).toContain("clearExportTransform");
|
|
expect(userOrdersPaginationSource).not.toContain("exportCsvFile");
|
|
expect(userOrdersPaginationSource).not.toContain("orders.csv");
|
|
expect(userOrdersPaginationSource).not.toContain('@click="downloadExcel"');
|
|
});
|
|
|
|
it("uses shared pagination and action wheel components for customer complaints", () => {
|
|
expect(customerComplaintsPaginationSource).toContain("TableLabeledPagination");
|
|
expect(customerComplaintsPaginationSource).not.toContain("LoadButtonWhileAwait");
|
|
expect(customerComplaintsPaginationSource).not.toContain('data-testid="superuser-complaints-search"');
|
|
expect(customerComplaintsTableSource).toContain("ActionSettingsWheelButton");
|
|
expect(customerComplaintsTableSource).toContain("ActionSettingsWheelItem");
|
|
expect(customerComplaintsTableSource).not.toContain('class="button is-small is-danger"');
|
|
});
|
|
|
|
it("uses shared pagination and action wheel components for customers", () => {
|
|
expect(customersPaginationSource).toContain("TableLabeledPagination");
|
|
expect(customersPaginationSource).not.toContain("LoadButtonWhileAwait");
|
|
expect(customersPaginationSource).not.toContain("<input");
|
|
expect(customersTableSource).toContain("ActionSettingsWheelButton");
|
|
expect(customersTableSource).toContain("ActionSettingsWheelItem");
|
|
expect(customersTableSource).toContain(':click-action="showCustomerBarred"');
|
|
expect(customersTableSource).toContain("Importer kunde fra E-conomic");
|
|
expect(customersTableSource).not.toContain("dropdown is-right is-hoverable");
|
|
expect(customersTableSource).not.toContain('class="button is-small is-danger"');
|
|
});
|
|
|
|
it("uses shared search, pagination, and action wheel components for departments", () => {
|
|
expect(departmentsPaginationSource).toContain("TableLabeledPagination");
|
|
expect(departmentsPaginationSource).not.toContain("PaginationDisplayGeneralSearchReload");
|
|
expect(departmentsPaginationSource).not.toContain("PaginationNavigation");
|
|
expect(departmentsTableSource).toContain("ActionSettingsWheelButton");
|
|
expect(departmentsTableSource).toContain("ActionSettingsWheelItem");
|
|
expect(departmentsTableSource).not.toContain('class="button is-small"');
|
|
expect(departmentsTableSource).not.toContain('class="button is-small is-dark"');
|
|
});
|
|
|
|
it("uses shared search, pagination, and action wheel components for employees", () => {
|
|
expect(usersPaginationSource).toContain("TableLabeledPagination");
|
|
expect(usersPaginationSource).toContain(":search-placeholder=\"t('global.search_user')\"");
|
|
expect(usersPaginationSource).not.toContain("LoadButtonWhileAwait");
|
|
expect(usersPaginationSource).not.toContain("<input");
|
|
expect(usersTableSource).toContain("ActionSettingsWheelButton");
|
|
expect(usersTableSource).toContain("ActionSettingsWheelItem");
|
|
expect(usersTableSource).toContain(':click-action="() => editUser(user)"');
|
|
expect(usersTableSource).not.toContain('@click="showEditUserForm');
|
|
});
|
|
});
|