154 lines
5.0 KiB
JavaScript
154 lines
5.0 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import {
|
|
catalogueDetailHref,
|
|
catalogueReturnHref,
|
|
} from '../../resources/js/lib/catalogue-context.ts';
|
|
import {
|
|
portalNavigation,
|
|
legacyPortalNavigation,
|
|
currentNavigationGroup,
|
|
currentNavigationItem,
|
|
} from '../../resources/js/lib/portal-navigation.ts';
|
|
|
|
void test('public and authenticated navigation share groups without revealing management', () => {
|
|
const publicGroups = portalNavigation({
|
|
authenticated: false,
|
|
manager: false,
|
|
});
|
|
const investor = portalNavigation({ authenticated: true, manager: false });
|
|
assert.deepEqual(publicGroups.slice(0, 3), investor.slice(0, 3));
|
|
assert.deepEqual(
|
|
publicGroups.map((g) => g.id),
|
|
['discovery', 'realization', 'support', 'account'],
|
|
);
|
|
const hrefs = JSON.stringify(investor);
|
|
assert.equal(hrefs.includes('/management/'), false);
|
|
assert.equal(JSON.stringify(publicGroups).includes('/login'), true);
|
|
assert.equal(hrefs.includes('/investidor/profile'), true);
|
|
assert.equal(hrefs.includes('/balcao-virtual'), true);
|
|
});
|
|
|
|
void test('management and optional modules follow permissions and feature flags', () => {
|
|
const groups = portalNavigation({
|
|
authenticated: true,
|
|
manager: true,
|
|
businesses: true,
|
|
education: true,
|
|
ai: true,
|
|
});
|
|
assert.ok(groups.some((group) => group.id === 'management'));
|
|
assert.equal(JSON.stringify(groups).includes('/investidor/negocios'), true);
|
|
assert.equal(JSON.stringify(groups).includes('/management/ai'), true);
|
|
assert.equal(
|
|
JSON.stringify(
|
|
portalNavigation({
|
|
authenticated: false,
|
|
manager: false,
|
|
education: false,
|
|
}),
|
|
).includes('/educacao'),
|
|
false,
|
|
);
|
|
});
|
|
|
|
void test('detail URLs and filtered catalogue pages retain the current group', () => {
|
|
// Preserve the retained catalogue's detail/filter matching independently
|
|
// of the reconciled shell's new grouping names.
|
|
const groups = legacyPortalNavigation({
|
|
authenticated: true,
|
|
manager: true,
|
|
});
|
|
for (const url of [
|
|
'/carteira/project/fixture',
|
|
'/zonas?category=zee',
|
|
'/zonas/fixture',
|
|
'/oportunidades/fixture',
|
|
])
|
|
assert.equal(currentNavigationGroup(groups, url), 'explore');
|
|
assert.equal(
|
|
currentNavigationGroup(
|
|
groups,
|
|
'/balcao-virtual/dossiers/fixture?phase=market',
|
|
),
|
|
'support',
|
|
);
|
|
assert.equal(
|
|
currentNavigationGroup(groups, '/investidor/profile'),
|
|
'account',
|
|
);
|
|
assert.equal(
|
|
currentNavigationGroup(groups, '/management/crm/leads/fixture'),
|
|
'management',
|
|
);
|
|
assert.equal(currentNavigationGroup(groups, '/unknown'), null);
|
|
assert.equal(
|
|
currentNavigationItem(groups, '/carteira?q=QA&kind=project'),
|
|
'projects',
|
|
);
|
|
assert.equal(
|
|
currentNavigationItem(groups, '/zonas?category=zee&q=QA'),
|
|
'zee',
|
|
);
|
|
});
|
|
|
|
void test('reconciled navigation selects discovery, realization and private support correctly', () => {
|
|
const groups = portalNavigation({ authenticated: false, manager: false });
|
|
assert.equal(
|
|
currentNavigationGroup(groups, '/oportunidades/fixture'),
|
|
'discovery',
|
|
);
|
|
assert.equal(
|
|
currentNavigationGroup(groups, '/simulador-fiscal'),
|
|
'realization',
|
|
);
|
|
assert.equal(
|
|
currentNavigationGroup(groups, '/balcao-virtual/dossiers/fixture'),
|
|
'support',
|
|
);
|
|
assert.equal(currentNavigationGroup(groups, '/management/crm/leads'), null);
|
|
});
|
|
|
|
void test('discovery keeps four entry points and catalogue destinations without duplicates', () => {
|
|
const groups = portalNavigation({
|
|
authenticated: false,
|
|
manager: false,
|
|
businesses: true,
|
|
education: true,
|
|
});
|
|
const links = [];
|
|
const collect = (items) =>
|
|
items.forEach((item) => {
|
|
if (item.href) links.push(item.href);
|
|
if (item.children) collect(item.children);
|
|
});
|
|
collect(groups);
|
|
assert.equal(new Set(links).size, links.length);
|
|
for (const href of [
|
|
'/investimentos/iniciar',
|
|
'/oportunidades',
|
|
'/sectores',
|
|
'/oportunidades?view=map',
|
|
'/carteira',
|
|
'/zonas',
|
|
'/negocios',
|
|
'/educacao',
|
|
'/documentos',
|
|
'/legislacao',
|
|
])
|
|
assert.ok(links.includes(href), href);
|
|
});
|
|
|
|
void test('catalogue detail and return preserve the search inside the local catalogue', () => {
|
|
const query = 'q=turismo+em+Inhambane&kind=cluster&province_id=fixture';
|
|
const href = catalogueDetailHref('/carteira/fixture', query);
|
|
assert.equal(catalogueReturnHref('/carteira', href), '/carteira?' + query);
|
|
assert.equal(
|
|
catalogueReturnHref(
|
|
'/zonas',
|
|
'/zonas/fixture?catalogue_query=https%3A%2F%2Foutside.invalid',
|
|
),
|
|
'/zonas?https%3A%2F%2Foutside.invalid=',
|
|
);
|
|
});
|