feat: add support for unit testing using vitest in editor-ui (#4184)

* feat: add support for unit testing using vitest in editor-ui

* fix(editor): update tsconfig types and typeRoots

* chore(editor): update package-lock.json
This commit is contained in:
Alex Grozav
2022-09-28 11:26:20 +03:00
committed by GitHub
parent ed403972a9
commit bb66e60afc
9 changed files with 397 additions and 8404 deletions

View File

@@ -0,0 +1,47 @@
import { parsePermissionsTable } from '@/permissions';
import { IUser } from "@/Interface";
describe('parsePermissionsTable()', () => {
const user: IUser = {
id: "1",
firstName: "John",
lastName: "Doe",
isDefaultUser: false,
isOwner: true,
isPending: false,
isPendingUser: false,
};
it('should return permissions object using generic permissions table', () => {
const permissions = parsePermissionsTable(user, []);
expect(permissions.isInstanceOwner).toBe(true);
});
it('should set permission based on permissions table row test function', () => {
const permissions = parsePermissionsTable(user, [
{ name: 'canRead', test: () => true },
{ name: 'canUpdate', test: () => false },
]);
expect(permissions.canRead).toBe(true);
expect(permissions.canUpdate).toBe(false);
});
it('should set permission based on previously computed permission', () => {
const permissions = parsePermissionsTable(user, [
{ name: 'canRead', test: ['isInstanceOwner'] },
]);
expect(permissions.canRead).toBe(true);
});
it('should set permission based on multiple previously computed permissions', () => {
const permissions = parsePermissionsTable(user, [
{ name: 'isResourceOwner', test: ['isInstanceOwner'] },
{ name: 'canRead', test: ['isInstanceOwner', 'isResourceOwner'] },
]);
expect(permissions.canRead).toBe(true);
});
});