import test from 'node:test'; import assert from 'node:assert/strict'; import { offerListHref } from '../../resources/js/lib/offer-navigation.ts'; import { portalNavigation, currentNavigationItem, currentNavigationGroup, } from '../../resources/js/lib/portal-navigation.ts'; await test('changing offer state preserves the operational and pending-report filters', () => { const filters = { operational: true, pending_reports: true, state: 'in_review', }; const selected = new URL(offerListHref(filters), 'https://qa.invalid'); assert.equal(selected.searchParams.get('operational'), '1'); assert.equal(selected.searchParams.get('pending_reports'), '1'); assert.equal(selected.searchParams.get('state'), 'in_review'); const allStates = new URL( offerListHref({ ...filters, state: '' }), selected.origin, ); assert.equal(allStates.searchParams.has('state'), false); assert.equal(allStates.searchParams.get('pending_reports'), '1'); assert.equal(offerListHref(), '/minhas-oportunidades/ofertas'); assert.equal( new URL( offerListHref({ ...filters, pending_reports: false }), selected.origin, ).searchParams.has('pending_reports'), false, ); }); await test('private offers use the existing work group and do not appear for an ungranted account', () => { const profile = { mine: '/minhas-oportunidades', create: '/minhas-oportunidades/criar', contexts: [], request: '/perfil/promotor', review: null, administration: null, }; const groups = portalNavigation({ authenticated: true, manager: false, profileAccess: profile, }); const work = groups.find((group) => group.id === 'work'); const offers = work.children.find((item) => item.id === 'private-offers'); assert.deepEqual( offers.children.map((item) => item.href), [ '/minhas-oportunidades/ofertas', '/minhas-oportunidades/ofertas/criar', ], ); assert.equal( currentNavigationItem(groups, '/minhas-oportunidades/ofertas'), 'my-private-offers', ); assert.equal( currentNavigationGroup(groups, '/minhas-oportunidades/ofertas/18'), 'work', ); const reader = portalNavigation({ authenticated: true, manager: false, profileAccess: { ...profile, create: null }, }); assert.ok(!JSON.stringify(reader).includes('new-private-offer')); for (const access of [ { authenticated: false, manager: false }, { authenticated: true, manager: false, profileAccess: { ...profile, mine: null, create: null }, }, ]) { assert.ok( !JSON.stringify(portalNavigation(access)).includes( '/minhas-oportunidades/ofertas', ), ); } assert.ok(!groups.some((group) => group.id === 'private-offers')); });