131 lines
4.5 KiB
JavaScript
131 lines
4.5 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import fs from 'node:fs';
|
|
import { compileFunction } from 'node:vm';
|
|
import { createRequire } from 'node:module';
|
|
import ts from 'typescript';
|
|
import React from 'react';
|
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
import * as navigation from '../../resources/js/lib/portal-navigation.ts';
|
|
|
|
const require = createRequire(import.meta.url);
|
|
function render(props, summaryAvailable = false) {
|
|
const module = { exports: {} };
|
|
const code = ts.transpileModule(
|
|
fs.readFileSync(
|
|
new URL(
|
|
'../../resources/js/components/dashboard-management.tsx',
|
|
import.meta.url,
|
|
),
|
|
'utf8',
|
|
),
|
|
{
|
|
compilerOptions: {
|
|
module: ts.ModuleKind.CommonJS,
|
|
jsx: ts.JsxEmit.ReactJSX,
|
|
},
|
|
},
|
|
).outputText;
|
|
compileFunction(code, ['require', 'module', 'exports'])(
|
|
(name) => {
|
|
if (name === '@/lib/portal-navigation') return navigation;
|
|
if (name === '@/components/profile-navigation')
|
|
return {
|
|
default: () =>
|
|
React.createElement(
|
|
'div',
|
|
{},
|
|
'Existing personal access',
|
|
),
|
|
};
|
|
if (name === '@inertiajs/react')
|
|
return {
|
|
usePage: () => ({ props }),
|
|
Head: () => null,
|
|
Link: ({ children, href, ...rest }) =>
|
|
React.createElement('a', { href, ...rest }, children),
|
|
};
|
|
return require(name);
|
|
},
|
|
module,
|
|
module.exports,
|
|
);
|
|
return renderToStaticMarkup(
|
|
React.createElement(module.exports.default, { summaryAvailable }),
|
|
);
|
|
}
|
|
|
|
void test('dashboard leads with the same authorised administration destinations as the portal menu', () => {
|
|
const html = render(
|
|
{
|
|
auth: {
|
|
user: { id: 'synthetic-manager' },
|
|
canManagePortal: true,
|
|
legacyManagementAccess: true,
|
|
},
|
|
administrationNavigation: [
|
|
{
|
|
label: 'Biblioteca e documentos',
|
|
href: '/gestao-conteudos/documentos',
|
|
},
|
|
],
|
|
contentManagementHref: '/gestao-conteudos',
|
|
dashboardNavigation: [{ label: 'Visão geral', href: '/dashboard' }],
|
|
scopedAdministration: [
|
|
{
|
|
label: 'Atribuições de interesses',
|
|
href: '/management/interests/atribuicoes',
|
|
},
|
|
],
|
|
profileAccess: {
|
|
administration: '/management/profiles',
|
|
request: '/profiles/request',
|
|
},
|
|
},
|
|
true,
|
|
);
|
|
assert.match(html, /Dashboard de gestão do portal/);
|
|
assert.match(html, /Conteúdos e oportunidades/);
|
|
assert.match(html, /Acessos e configuração/);
|
|
assert.match(html, /href="\/management\/profiles"/);
|
|
assert.match(html, /href="\/gestao-conteudos\/documentos"/);
|
|
assert.match(html, /Existing personal access/);
|
|
assert.equal(
|
|
(html.match(/href="\/management\/profiles"/g) ?? []).length,
|
|
1,
|
|
);
|
|
assert.doesNotMatch(html, /href="\/dashboard"/);
|
|
});
|
|
|
|
void test('scoped editor sees its granted destinations without inherited manager or access controls', () => {
|
|
const html = render({
|
|
auth: {
|
|
user: { id: 'synthetic-editor' },
|
|
canManagePortal: true,
|
|
legacyManagementAccess: false,
|
|
},
|
|
contentManagementHref: '/gestao-conteudos',
|
|
administrationNavigation: [
|
|
{ label: 'Documentos', href: '/gestao-conteudos/documentos' },
|
|
],
|
|
});
|
|
assert.match(html, /Dashboard de gestão do portal/);
|
|
assert.match(html, /href="\/gestao-conteudos\/documentos"/);
|
|
assert.doesNotMatch(
|
|
html,
|
|
/href="\/management\/profiles"|href="\/management\/interests"/,
|
|
);
|
|
});
|
|
|
|
void test('ordinary investor keeps personal workspace and never gains administrative cards', () => {
|
|
const html = render({
|
|
auth: { user: { id: 'synthetic-investor' }, canManagePortal: false },
|
|
});
|
|
assert.match(html, /A minha área de trabalho/);
|
|
assert.match(html, /Existing personal access/);
|
|
assert.doesNotMatch(
|
|
html,
|
|
/aria-label="Gestão do portal"|href="\/management\//,
|
|
);
|
|
});
|