Group dashboard activities under primary administration and tidy editorial overview
tests / ci (push) Waiting to run

This commit is contained in:
2026-11-14 11:43:56 +02:00
parent ce8b744d1f
commit 73e1d7b964
12 changed files with 314 additions and 102 deletions
@@ -0,0 +1,23 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import {createRequire} from 'node:module';
import React from 'react';
import {renderToStaticMarkup} from 'react-dom/server';
import ts from 'typescript';
const require=createRequire(import.meta.url), module={exports:{}};
const code=ts.transpileModule(fs.readFileSync(new URL('../../resources/js/pages/management/editorial-workflow.tsx',import.meta.url),'utf8'),{compilerOptions:{module:ts.ModuleKind.CommonJS,jsx:ts.JsxEmit.ReactJSX}}).outputText;
new Function('require','module','exports',code)(name=>name==='@inertiajs/react'?{Link:({href,children,...props})=>React.createElement('a',{href,...props},children),router:{}}:name==='./shared'?{Management:({title,children})=>React.createElement('main',null,React.createElement('h1',null,title),children),Field:({label,children})=>React.createElement('label',null,label,children),button:'',control:''}:require(name),module,module.exports);
const base={items:{data:[],current_page:1,last_page:1},notices:[],resourceAccess:true,opportunitiesUrl:'/opportunities-qa',opportunityPending:2,clustersUrl:'/clusters-qa',nativePending:{clusters:3,territories:0,zones:0},subjectsUrl:'/subjects-qa',territorialUrl:'/territories-qa',demographyUrl:'/demography-qa'};
test('dashboard groups authorised activities once with contextual counts and an empty notification state',()=>{
const html=renderToStaticMarkup(React.createElement(module.exports.default,base));
for(const title of ['Conteúdos e oportunidades','Investimentos e competitividade','Território e dados'])assert.match(html,new RegExp(title));
assert.equal((html.match(/href="\/opportunities-qa"/g)??[]).length,1);
assert.match(html,/2 pendentes/);assert.match(html,/3 pendentes/);
assert.match(html,/Não há notificações neste âmbito/);
assert.match(html,/md:grid-cols-2 xl:grid-cols-3/);
});
test('restricted dashboard omits unavailable groups, private content controls and counters',()=>{
const html=renderToStaticMarkup(React.createElement(module.exports.default,{items:base.items,notices:[],resourceAccess:false,opportunitiesUrl:null,opportunityPending:0}));
assert.doesNotMatch(html,/Fila de conteúdos|kind=legislation|Biblioteca e editores|Investimentos e competitividade|Território e dados/);
});
+16 -2
View File
@@ -238,7 +238,7 @@ void test('work area exposes existing content capability even when the old dashb
);
assert.ok(work.children.some((i) => i.href === '/gestao-conteudos'));
assert.ok(
work.children.some((i) => i.href === '/management/opportunities'),
destinations(groups.find(g => g.id === 'administration').children).includes('/management/opportunities'),
);
});
void test('every previously authorised management/profile destination survives the regrouping exactly once', () => {
@@ -276,7 +276,7 @@ void test('every previously authorised management/profile destination survives t
assert.equal(after.filter((x) => x === href).length, 1, href);
assert.equal(after.length, new Set(after).size);
assert.ok(
destinations(groups.find((g) => g.id === 'work').children).includes(
destinations(groups.find((g) => g.id === 'administration').children).includes(
'/management/economic-references/lot-01',
),
);
@@ -448,3 +448,17 @@ void test('installed concours has its own primary group and preserves public and
);
}
});
void test('administration owns dashboard activities once and remains hidden without authorised destinations', () => {
const dashboardNavigation = [{label: 'Visão geral', href: '/management/editorial'}, {label: 'Legislação', href: '/management/editorial?kind=legislation'}, {label: 'Competitividade', href: '/management/clusters'}];
const groups = portalNavigation({authenticated: true, manager: true, dashboardNavigation});
const admin = groups.find(g => g.id === 'administration');
const dashboard = admin.children.find(g => g.id === 'collaborative-dashboard');
assert.equal(dashboard.label, 'Dashboard');
assert.deepEqual(destinations(dashboard.children), dashboardNavigation.map(i => i.href));
assert.equal(currentNavigationGroup(groups, '/management/editorial?kind=legislation'), 'administration');
assert.equal(currentNavigationGroup(groups, '/management/clusters/synthetic/edit'), 'administration');
assert.equal(destinations(groups).filter(h => h === '/management/clusters').length, 1);
assert.equal(portalNavigation({authenticated: false, manager: false, dashboardNavigation}).some(g => g.id === 'administration'), false);
assert.equal(portalNavigation({authenticated: true, manager: false}).some(g => g.id === 'administration'), false);
});
@@ -192,3 +192,17 @@ test('actual header has exactly the requested six primary entries on desktop and
),
);
});
test('authorised administration is primary and dashboard is a nested expandable group on desktop and mobile', () => {
for (mobile of [false, true]) {
state = {url: '/management/editorial', props: {auth: {user: {name: 'QA'}, canManagePortal: false}, dashboardNavigation: [{label: 'Visão geral', href: '/management/editorial'}, {label: 'Legislação', href: '/management/editorial?kind=legislation'}]}};
const html = renderToStaticMarkup(React.createElement(module.exports.PortalGroupedMenu));
const nav = html.match(/<nav[^>]*aria-label="Áreas do portal"[\s\S]*?<\/nav>/)?.[0];
assert.ok(nav);
const labels = [...nav.matchAll(/<(?:a|button)[^>]*class="tempo-nav-trigger"[^>]*>([\s\S]*?)<\/(?:a|button)>/g)].map(m => m[1].replace(/<[^>]*>/g, '').replace('Grupo actual', '').trim());
assert.deepEqual(labels, ['Início', 'Descoberta', 'Realização', 'Suporte', 'Administração', 'Sobre nós', 'Mais']);
assert.equal((nav.match(/href="\/management\/editorial"/g) ?? []).length, 1);
assert.match(nav, /Dashboard/);
if (mobile) assert.match(nav, /<summary[^>]*>Dashboard<\/summary>/);
}
});