feat: lead dashboard with authorised portal management groups
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
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\//,
|
||||
);
|
||||
});
|
||||
@@ -11,7 +11,7 @@ new Function('require','module','exports',code)(name=>name==='@inertiajs/react'?
|
||||
test('each manager dashboard menu anchor resolves to a real section',()=>{
|
||||
const html=renderToStaticMarkup(React.createElement(module.exports.default,{summary:{requestsByStatus:{},publishedOpportunities:0,draftOpportunities:0,activeSectors:0,recentRequests:[]},workQueue:null}));
|
||||
for(const id of ['meu-trabalho','manifestacoes','indicadores-oportunidades','pedidos-recentes','accoes-rapidas'])assert.match(html,new RegExp('id="'+id+'"'));
|
||||
assert.match(html,/Painel do portal/);
|
||||
|
||||
});
|
||||
test('investor section remains distinct from administrative summary',()=>{
|
||||
const html=renderToStaticMarkup(React.createElement(module.exports.default,{summary:null,investorPath:{contexts:[],current:null}}));
|
||||
|
||||
@@ -42,6 +42,7 @@ const Dashboard = load('../../resources/js/pages/dashboard.tsx', {
|
||||
...mocks,
|
||||
'@/components/dashboard-work-queue': { default: Queue },
|
||||
'@/components/profile-navigation': { default: Empty },
|
||||
'@/components/dashboard-management': { default: Empty },
|
||||
'@/components/content-management-entry': { default: Empty },
|
||||
'@/routes': { dashboard: () => '/dashboard' },
|
||||
}).default;
|
||||
|
||||
Reference in New Issue
Block a user