commit SGF2311

This commit is contained in:
2026-11-23 11:48:07 +02:00
parent cd9897df05
commit 82e447a6ab
18 changed files with 1952 additions and 338 deletions
+27 -14
View File
@@ -2,12 +2,11 @@
import assert from 'node:assert/strict';
import React from 'react';
import {renderToStaticMarkup} from 'react-dom/server';
import {createServer} from 'vite';
const server=await createServer({server:{middlewareMode:true},appType:'custom'});
try {
const {navigationGroups,navigationTopics,default:Navigation}=await server.ssrLoadModule('/resources/js/WorkspaceNavigation.jsx');
const {default:Home}=await server.ssrLoadModule('/resources/js/WorkspaceHome.jsx');
const {default:PurchasingHome}=await server.ssrLoadModule('/resources/js/PurchasingHome.jsx');
import {renderCheckModule} from './render-check-module.mjs';
{
const {navigationGroups,navigationTopics,default:Navigation}=await renderCheckModule('resources/js/WorkspaceNavigation.jsx');
const {default:Home}=await renderCheckModule('resources/js/WorkspaceHome.jsx');
const {default:PurchasingHome}=await renderCheckModule('resources/js/PurchasingHome.jsx');
const context={company:{name:'Empresa sintética'},unit:{id:7,name:'Unidade sintética'}};
const check=(grants)=>{
const can=(permission,unit=null)=>grants.some(g=>g[0]===permission&&g[1]===unit);
@@ -15,10 +14,13 @@ try {
return {groups,html:renderToStaticMarkup(React.createElement(Home,{context,can,groups,navigate:()=>{}}))};
};
const preparer=check([['company.view',null],['industrial_budgets.view',7],['industrial_budgets.prepare',7]]);
assert(preparer.html.includes('<h1>Início</h1>'));
assert(preparer.html.includes('<h1>Início do SGF</h1>'));
assert(preparer.html.includes('Funções disponíveis para o seu trabalho'));
assert(preparer.html.includes('Orçamentos e comparação'));
assert(!preparer.groups.some(g=>g.id==='billing'));assert(!preparer.groups.flatMap(g=>g.items).some(i=>i.id==='access'));
const reviewer=check([['company.view',null],['industrial_budgets.view',7],['industrial_budgets.validate',7]]);
assert(!reviewer.html.includes('<button'));
assert(reviewer.html.includes('Orçamentos e comparação'));
assert(!reviewer.html.includes('Informação existente neste módulo'));
const otherUnit=check([['company.view',null],['industrial_budgets.view',99],['industrial_budgets.prepare',99]]);
assert(!otherUnit.groups.some(g=>g.id==='costs'));
const noAccess=check([]);assert.deepEqual(noAccess.groups.map(g=>g.id),['start']);
@@ -26,12 +28,12 @@ try {
assert(!reader.html.includes('<h2>A validar</h2>'));assert(!reader.html.includes('<h2>A preparar e acompanhar</h2>'));
assert(!reader.html.includes('home-context'));
const allGroups=navigationGroups(()=>true,7),topics=navigationTopics(allGroups);
assert.deepEqual(topics.map(t=>t.label),['Início','Comercial','Compras','Stock','Oficinas','Financeiro','Contabilidade','Configuração']);
assert.deepEqual(topics.map(t=>t.label),['Início','Comercial','Compras','Stock','Oficinas','Financeiro','Contabilidade','Configuração','Fornecedores']);
// Independent inventory: comparing the generated menu with itself cannot detect a removed module.
assert.deepEqual(allGroups.map(g=>g.id).sort(),['start','purchasing','stock','services','billing','billing_support','receivables','workshop','costs','accounting','admin'].sort());
assert.deepEqual(allGroups.map(g=>g.id).sort(),['start','purchasing','stock','services','billing','billing_support','treasury','receivables','workshop','costs','accounting','admin'].sort());
const accountingTopic=topics.find(t=>t.id==='accounting');
assert.deepEqual(accountingTopic.sections.map(g=>g.id),['accounting']);
assert.deepEqual(accountingTopic.sections[0].items.map(i=>i.id),['accounting_panel','accounting_daily','accounting_review','accounting_analysis','accounting_closing','accounting_configuration','catalogue_accounting','service_fiscal']);
assert.deepEqual(accountingTopic.sections[0].items.map(i=>i.id),['accounting_panel','accounting_daily','accounting_review','accounting_analysis','accounting_closing','accounting_configuration','catalogue_accounting','service_fiscal','fiscal_iva','fiscal_rules']);
for(const grants of [[['company.view',null]],[['catalogue_accounting.view',null]],[['service_fiscal.view',null]]]) {
const authorised=navigationTopics(check(grants).groups);
assert(authorised.some(t=>t.id==='accounting'&&t.label==='Contabilidade'));
@@ -40,8 +42,19 @@ try {
const before=allGroups.flatMap(g=>g.items.map(i=>i.id)).sort(),after=topics.flatMap(t=>t.sections.flatMap(g=>g.items.map(i=>i.id))).sort();
assert.deepEqual(after,before);assert.equal(new Set(after).size,after.length);
const groupedHome=renderToStaticMarkup(React.createElement(Home,{context,can:()=>true,groups:allGroups,topics,navigate:()=>{}}));
assert(groupedHome.includes('<h1>Início</h1>'));
for(const marker of ['<button','<details','<summary','class="panel','Consultas e atalhos permitidos','A preparar e acompanhar','A validar','Contexto actual'])assert(!groupedHome.includes(marker));
assert(groupedHome.includes('<h1>Início do SGF</h1>'));
assert(groupedHome.includes('Funções disponíveis para o seu trabalho'));
assert(groupedHome.includes('Continuidade entre módulos'));
for(const marker of ['<details','<summary','Consultas e atalhos permitidos','A preparar e acompanhar','A validar','Contexto actual'])assert(!groupedHome.includes(marker));
// Module guidance and sources follow the active context and existing permissions.
const moduleHome=(can)=>renderToStaticMarkup(React.createElement(Home,{context:{...context,module_id:'commercial',service_documents_enabled:true},can,groups:[]}));
const commercialHome=moduleHome(()=>true);
assert(commercialHome.includes('<h1>Comercial</h1>'));
assert(commercialHome.includes('Do primeiro registo à evidência final'));
assert(commercialHome.includes('Informação existente neste módulo'));
assert(commercialHome.includes('Documentos comerciais'));
assert(!moduleHome(()=>false).includes('Informação existente neste módulo'));
assert(!noAccess.html.includes('Funções disponíveis para o seu trabalho'));
for(const id of ['accounting_panel','purchasing_home'])assert(allGroups.flatMap(g=>g.items).some(i=>i.id===id));
const navHtml=renderToStaticMarkup(React.createElement(Navigation,{groups:allGroups,page:'billing_drafts',navigate:()=>{},user:{name:'Avaliador sintético',email:'consulta@example.test'},busy:false,logout:()=>{}}));
assert(navHtml.includes('workspace-topbar'));assert(!navHtml.includes('grouped-sidebar'));assert(!navHtml.includes('navigation-drawer'));
@@ -60,4 +73,4 @@ try {
assert(budgetOnly.groups.find(g=>g.id==='purchasing').items.some(i=>i.id==='purchasing_budget'));
assert(!budgetOnly.groups.find(g=>g.id==='purchasing').items.some(i=>i.id==='supplier_payables'));
console.log('Home/navigation render checks passed: preparer, reviewer, reader, other unit and absent permissions. No database or browser used.');
} finally {await server.close();}
}