commit SGF2311
This commit is contained in:
@@ -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();}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import React from 'react';
|
||||
import {renderToStaticMarkup} from 'react-dom/server';
|
||||
import {createServer} from 'vite';
|
||||
import {renderCheckModule} from './render-check-module.mjs';
|
||||
import {ContextTransition} from '../resources/js/context-transition.js';
|
||||
|
||||
const server=await createServer({server:{middlewareMode:true},appType:'custom'});
|
||||
try {
|
||||
const {default:Navigation,moduleGroups}=await server.ssrLoadModule('/resources/js/ModuleNavigation.jsx');
|
||||
const {navigationGroups}=await server.ssrLoadModule('/resources/js/WorkspaceNavigation.jsx');
|
||||
{
|
||||
const {default:Navigation,moduleGroups}=await renderCheckModule('resources/js/ModuleNavigation.jsx');
|
||||
const {navigationGroups}=await renderCheckModule('resources/js/WorkspaceNavigation.jsx');
|
||||
const groups=navigationGroups(()=>true,7);
|
||||
assert.deepEqual(moduleGroups(groups,'purchasing').map(g=>g.id),['purchasing','shared_records']);
|
||||
assert.deepEqual(moduleGroups(groups,'commercial').map(g=>g.id),['services','billing','billing_support']);
|
||||
assert.equal(moduleGroups(groups,'invalid').length,0);
|
||||
const html=renderToStaticMarkup(React.createElement(Navigation,{groups,context:{module_id:'workshop',modules:[{id:'workshop',label:'Oficinas'}]},page:'workshop',user:{name:'Synthetic'},navigate(){},changeModule(){},logout(){}}));
|
||||
assert(html.includes('Módulo activo'));assert(html.includes('Navegação de Oficinas'));assert(html.includes('Opções gerais'));
|
||||
assert(html.includes('class="active-module"'));
|
||||
assert(html.includes('<summary aria-current="true">Oficinas'));
|
||||
assert(html.includes('aria-label="Funções de Oficinas"'));assert(html.includes('Opções gerais'));
|
||||
assert(!html.includes('Todos os documentos'));assert(!html.includes('Obrigações a fornecedores'));
|
||||
assert(html.includes('aria-current="page"'));assert(!html.includes('consulta@example'));
|
||||
const t=new ContextTransition();
|
||||
@@ -29,4 +30,4 @@ try {
|
||||
let finish;const concurrent={...form,requestSubmit:()=>{void t.command(()=>new Promise(resolve=>{finish=resolve;}));}};
|
||||
t.changed(concurrent);const saving=t.save();t.changed(concurrent);finish(true);await assert.rejects(()=>saving,/posteriores/);assert(t.dirty.has(concurrent));
|
||||
console.log('Module navigation and transitions passed: module separation, active context, save, failed save, invalid form, discard, unsupported editor and edits during save. No browser or database.');
|
||||
} finally {await server.close();}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import {build} from 'vite';
|
||||
|
||||
// Compile in memory: render checks do not need the dev server or its SSR transport.
|
||||
// Resolve external packages to file URLs so native imports share React with the test.
|
||||
export async function renderCheckModule(entry) {
|
||||
const result=await build({
|
||||
configFile:false,
|
||||
logLevel:'error',
|
||||
build:{
|
||||
ssr:entry,
|
||||
write:false,
|
||||
minify:false,
|
||||
rolldownOptions:{output:{paths:id=>import.meta.resolve(id)}},
|
||||
},
|
||||
});
|
||||
const chunks=result.output.filter(item=>item.type==='chunk');
|
||||
if(chunks.length!==1)throw new Error('Render check requires a single SSR chunk.');
|
||||
return import('data:text/javascript;base64,'+Buffer.from(chunks[0].code).toString('base64'));
|
||||
}
|
||||
Reference in New Issue
Block a user