fix(navigation): expose work area and preserve authorised menu destinations in QA
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import fs from 'node:fs';
|
||||
import {createRequire} from 'node:module';
|
||||
import React from 'react';
|
||||
import {renderToStaticMarkup} from 'react-dom/server';
|
||||
import ts from 'typescript';
|
||||
import {portalNavigation,currentNavigationItem} from '../../resources/js/lib/portal-navigation.ts';
|
||||
import {searchTerritoryHref} from '../../resources/js/lib/search-territory.ts';
|
||||
|
||||
// Shallow SSR of the actual navigation component. Inertia and visual primitives
|
||||
// are replaced by semantic wrappers; this is not a browser/viewport proof.
|
||||
const require=createRequire(import.meta.url);
|
||||
const source=fs.readFileSync(new URL('../../resources/js/components/portal-sidebar-navigation.tsx',import.meta.url),'utf8');
|
||||
const output=ts.transpileModule(source,{compilerOptions:{module:ts.ModuleKind.CommonJS,target:ts.ScriptTarget.ES2022,jsx:ts.JsxEmit.ReactJSX}}).outputText;
|
||||
const primitive=(tag)=>({children,asChild,...props})=>asChild?React.cloneElement(children,{}):React.createElement(tag,props,children);
|
||||
const module={exports:{}};
|
||||
new Function('require','module','exports',output)((name)=>{
|
||||
if(name==='@inertiajs/react')return {Link:({href,children,...props})=>React.createElement('a',{href,...props},children)};
|
||||
if(name==='@/lib/portal-navigation')return {currentNavigationItem};
|
||||
if(name==='@/lib/search-territory')return {searchTerritoryHref};
|
||||
if(name==='lucide-react')return {LayoutGrid:()=>null};
|
||||
if(name==='@/components/ui/sidebar')return {SidebarGroup:primitive('section'),SidebarGroupLabel:primitive('h2'),SidebarMenu:primitive('ul'),SidebarMenuButton:primitive('div'),SidebarMenuItem:primitive('li')};
|
||||
return require(name);
|
||||
},module,module.exports);
|
||||
const Component=module.exports.PortalSidebarNavigation;
|
||||
const flatten=(rows)=>rows.flatMap(r=>[...(r.href?[r.href]:[]),...flatten(r.children??[])]);
|
||||
const render=(access,url='/')=>{const groups=portalNavigation(access);return {groups,html:renderToStaticMarkup(React.createElement(Component,{groups,url}))};};
|
||||
void test('sidebar renders every nested authorised destination instead of a first-child shortcut',()=>{
|
||||
const {groups,html}=render({authenticated:true,manager:true,businesses:true,education:true,ai:true,contentManagementHref:'/gestao-conteudos',contentManagementAccess:{opportunities:{index:'/management/opportunities',create:'/management/opportunities/create'}},scopedAdministration:[{label:'Referências económicas',href:'/management/economic-references/lot-01'}]});
|
||||
const hrefs=[...html.matchAll(/<a\b[^>]*href="([^"]+)"/g)].map(m=>m[1].replaceAll('&','&'));
|
||||
assert.deepEqual([...hrefs].sort(),flatten(groups).sort());
|
||||
assert.equal(hrefs[0],'/gestao-conteudos');
|
||||
for(const href of ['/carteira','/zonas','/documentos','/legislacao','/management/opportunities','/management/economic-references/lot-01'])assert.ok(hrefs.includes(href),href);
|
||||
assert.match(html,/Área de trabalho/);
|
||||
});
|
||||
void test('nested current destination is selected without changing its URL or replacing it with a group root',()=>{
|
||||
const {html}=render({authenticated:true,manager:false},'/zonas?category=zee');
|
||||
const current=[...html.matchAll(/<a\b([^>]*aria-current="page"[^>]*)>/g)];
|
||||
assert.equal(current.length,1);
|
||||
assert.match(current[0][1],/href="\/zonas"/);
|
||||
});
|
||||
void test('rendered visitor sidebar explains access without private operation links',()=>{
|
||||
const {html}=render({authenticated:false,manager:false});
|
||||
assert.match(html,/href="\/acesso-gestao"/);
|
||||
assert.doesNotMatch(html,/href="\/management\//);
|
||||
assert.doesNotMatch(html,/analysis=proactive/);
|
||||
});
|
||||
void test('sidebar carries the existing search territory when moving between catalogues',()=>{
|
||||
const {html}=render({authenticated:false,manager:false},'/oportunidades?province_id=QA-province&district_id=QA-district');
|
||||
assert.match(html,/href="\/carteira\?province_id=QA-province&district_id=QA-district"/);
|
||||
assert.match(html,/href="\/zonas\?province_id=QA-province&district_id=QA-district"/);
|
||||
assert.match(html,/href="\/acesso-gestao"/);
|
||||
});
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
legacyPortalNavigation,
|
||||
currentNavigationGroup,
|
||||
currentNavigationItem,
|
||||
canShowLegacyManagement,
|
||||
} from '../../resources/js/lib/portal-navigation.ts';
|
||||
|
||||
void test('public and authenticated navigation share groups without revealing management', () => {
|
||||
@@ -20,7 +21,7 @@ void test('public and authenticated navigation share groups without revealing ma
|
||||
assert.deepEqual(publicGroups.slice(0, 3), investor.slice(0, 3));
|
||||
assert.deepEqual(
|
||||
publicGroups.map((g) => g.id),
|
||||
['discovery', 'realization', 'support', 'account'],
|
||||
['discovery', 'realization', 'support', 'work', 'account'],
|
||||
);
|
||||
const hrefs = JSON.stringify(investor);
|
||||
assert.equal(hrefs.includes('/management/'), false);
|
||||
@@ -37,7 +38,7 @@ void test('management and optional modules follow permissions and feature flags'
|
||||
education: true,
|
||||
ai: true,
|
||||
});
|
||||
assert.ok(groups.some((group) => group.id === 'management'));
|
||||
assert.ok(groups.some((group) => group.id === 'work'));
|
||||
assert.equal(JSON.stringify(groups).includes('/investidor/negocios'), true);
|
||||
assert.equal(JSON.stringify(groups).includes('/management/ai'), true);
|
||||
assert.equal(
|
||||
@@ -151,3 +152,47 @@ void test('catalogue detail and return preserve the search inside the local cata
|
||||
'/zonas?https%3A%2F%2Foutside.invalid=',
|
||||
);
|
||||
});
|
||||
|
||||
const destinations=(items)=>items.flatMap(item=>[...(item.href?[item.href]:[]),...destinations(item.children??[])]);
|
||||
void test('both menu consumers respect the existing scoped server decision rather than generic manager status',()=>{
|
||||
assert.equal(canShowLegacyManagement({user:{id:1},canManagePortal:true,legacyManagementAccess:false}),false);
|
||||
assert.equal(canShowLegacyManagement({user:{id:1},canManagePortal:true,legacyManagementAccess:true}),true);
|
||||
assert.equal(canShowLegacyManagement({user:null,canManagePortal:true,legacyManagementAccess:true}),false);
|
||||
assert.equal(canShowLegacyManagement({user:{id:1},canManagePortal:true}),true);
|
||||
});
|
||||
void test('work entry is discoverable without exposing private capabilities to an anonymous visitor',()=>{
|
||||
const groups=portalNavigation({authenticated:false,manager:true,contentManagementHref:'/gestao-conteudos',contentManagementAccess:{opportunities:{index:'/management/opportunities',create:'/management/opportunities/create'}},scopedAdministration:[{label:'Private QA administration',href:'/management/secret'}]});
|
||||
assert.deepEqual(destinations(groups.find(g=>g.id==='work').children),['/acesso-gestao']);
|
||||
assert.equal(JSON.stringify(groups).includes('/management/'),false);
|
||||
assert.equal(JSON.stringify(groups).includes('/gestao-conteudos'),false);
|
||||
});
|
||||
void test('work area exposes existing content capability even when the old dashboard flag has no menu object',()=>{
|
||||
const groups=portalNavigation({authenticated:true,manager:true,opportunityManagement:null,contentManagementHref:'/gestao-conteudos',contentManagementAccess:{opportunities:{index:'/management/opportunities',create:'/management/opportunities/create'}}});
|
||||
const work=groups.find(g=>g.id==='work');
|
||||
assert.equal(work.label,'Área de trabalho');
|
||||
assert.ok(work.children.some(i=>i.label==='Preparar análise e ideia'&&i.href==='/management/opportunities/create?analysis=proactive'));
|
||||
assert.ok(work.children.some(i=>i.href==='/gestao-conteudos'));
|
||||
assert.ok(work.children.some(i=>i.href==='/management/opportunities'));
|
||||
});
|
||||
void test('every previously authorised management/profile destination survives the regrouping exactly once',()=>{
|
||||
const access={authenticated:true,manager:true,businesses:true,education:true,ai:true,contentManagementHref:'/gestao-conteudos',profileAccess:{contexts:[],mine:'/minhas-oportunidades',create:'/minhas-oportunidades/create',request:'/perfil/promotor',review:null,audit:'/perfis/auditoria',administration:'/perfis/gestao'},scopedAdministration:[{label:'Referências económicas',href:'/management/economic-references/lot-01'}]};
|
||||
const old=destinations(legacyPortalNavigation(access).filter(g=>['management','profile-opportunities'].includes(g.id)));
|
||||
const groups=portalNavigation(access);const after=destinations(groups);
|
||||
for(const href of old)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('/management/economic-references/lot-01'));
|
||||
assert.equal(after.filter(href=>href==='/management/profile-install').length,1,'profile installation already present in the old authorised sidebar must survive');
|
||||
});
|
||||
void test('ordinary authenticated account has an explanation entry and does not acquire creation or management links',()=>{
|
||||
const groups=portalNavigation({authenticated:true,manager:false});
|
||||
assert.deepEqual(destinations(groups.find(g=>g.id==='work').children),['/acesso-gestao']);
|
||||
assert.equal(JSON.stringify(groups).includes('analysis=proactive'),false);
|
||||
assert.equal(JSON.stringify(groups).includes('/management/'),false);
|
||||
});
|
||||
void test('direct analysis and ordinary creation preserve distinct selection state in the same work group',()=>{
|
||||
const access={authenticated:true,manager:false,profileAccess:{contexts:[],mine:'/minhas-oportunidades',create:'/minhas-oportunidades/create',request:'/perfil/promotor',review:null,administration:null}};
|
||||
const groups=portalNavigation(access);
|
||||
assert.equal(currentNavigationGroup(groups,'/minhas-oportunidades/create?analysis=proactive'),'work');
|
||||
assert.equal(currentNavigationItem(groups,'/minhas-oportunidades/create?analysis=proactive'),'prepare-analysis');
|
||||
assert.equal(currentNavigationItem(groups,'/minhas-oportunidades/create'),'new-my-opportunity');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user