Files
pleno-vue/tests/unit/subuser-grant-permission-nodes.spec.js
T
Jeppe Bundgaard c14f0cc1c4 Add utilities and tests for mobile order management and Subuser navigation:
- Introduced `mobileOrderCompletion.js` for mobile order metadata handling with safety seal syncing, metadata persistence, and booking linking utilities.
- Added tests for Subuser navigation menu (`navigation-menu-items-user-subusers.spec.js`) to validate links and permission gating.
- Created unit and end-to-end tests for Subuser grant permissions and management, including permission nodes and invites (`subuser-grant-permission-nodes.spec.js`, `subuser-management.spec.ts`).
- Implemented `SubuserCompleteRegistrationPage.vue` with validation, token handling, and registration flow for Subuser setup.
- Enhanced Playwright e2e tests for Subuser features (`subuserCompleteRegistration.spec.ts`).
2026-04-14 10:09:10 +02:00

72 lines
1.8 KiB
JavaScript

// @vitest-environment jsdom
import { mount } from "@vue/test-utils";
import { describe, expect, it, vi } from "vitest";
import SubuserGrantPermissionNodes from "@/components/displays/selectors/SubuserGrantPermissionNodes.vue";
const getPermissionNodesMock = vi.hoisted(() =>
vi.fn(async () => [
{
group: "Bookings",
description: "Booking permissions",
nodes: [
{
key: "BOOKINGS_LIST",
name: "List bookings",
description: "Can view bookings",
type: "LIST",
default: false,
},
],
},
])
);
const savePermissionsMock = vi.hoisted(() => vi.fn());
vi.mock("@/components/session/token/SessionUser.vue", () => ({
SessionUser: {
objects: {
subuser_grants: {
functions: {
getPermissionNodes: getPermissionNodesMock,
},
set: {
permissions: savePermissionsMock,
},
},
},
},
}));
const flushMicrotasks = async () => {
await Promise.resolve();
await Promise.resolve();
};
describe("SubuserGrantPermissionNodes", () => {
it("keeps permission changes local and emits the draft instead of auto-saving", async () => {
const wrapper = mount(SubuserGrantPermissionNodes, {
props: {
grant: {
id: 91,
name: "Demo driver",
permissions: ["BOOKINGS_LIST"],
},
permissions: ["BOOKINGS_LIST"],
},
});
await flushMicrotasks();
expect(getPermissionNodesMock).toHaveBeenCalledTimes(1);
const checkbox = wrapper.get('input[type="checkbox"]');
await checkbox.setValue(false);
await flushMicrotasks();
const emitted = wrapper.emitted("update:permissions") || [];
expect(emitted.at(-1)?.[0]).toEqual([]);
expect(savePermissionsMock).not.toHaveBeenCalled();
});
});