updates on the admin and zone things and minor changes
This commit is contained in:
51
tests/lib/consoleNav.test.js
Normal file
51
tests/lib/consoleNav.test.js
Normal file
@@ -0,0 +1,51 @@
|
||||
import { CLIENT_FLEET_OPS_PATHS, CLIENT_ONBOARDING_PATH, navGroupsFor } from '@/lib/consoleNav';
|
||||
import { canOnboardClients } from '@/lib/clientOnboarding';
|
||||
|
||||
const GROUPS = [
|
||||
{
|
||||
label: 'Fleet Ops',
|
||||
items: [
|
||||
{ label: 'Hubs', path: '/doormile/hubs' },
|
||||
{ label: 'Vehicles', path: '/doormile/vehicles' },
|
||||
{ label: 'Tripsheets', path: '/doormile/tripsheets' },
|
||||
{ label: 'Exceptions', path: '/doormile/exceptions' },
|
||||
{ label: 'Returns', path: '/doormile/returns' },
|
||||
{ label: 'Competitive Intel', path: '/doormile/competitive-intel' },
|
||||
{ label: 'App Users', path: '/doormile/app-users' },
|
||||
{ label: 'Agents', path: '/doormile/agents' },
|
||||
],
|
||||
},
|
||||
{ label: 'Reports', items: [{ label: 'Orders Summary', path: '/doormile/reports/orderssummary' }] },
|
||||
];
|
||||
const ONBOARD = { label: 'Client Onboarding', path: CLIENT_ONBOARDING_PATH };
|
||||
|
||||
const labelsOf = (groups, name) => groups.find((g) => g.label === name).items.map((i) => i.label);
|
||||
|
||||
describe('header menu per login', () => {
|
||||
test('a client sees Fleet Ops with only Hubs, Exceptions and Returns', () => {
|
||||
const groups = navGroupsFor(GROUPS, { isClient: true, canOnboard: false, onboardingItem: ONBOARD });
|
||||
expect(labelsOf(groups, 'Fleet Ops')).toEqual(['Hubs', 'Exceptions', 'Returns']);
|
||||
expect(labelsOf(groups, 'Reports')).toEqual(['Orders Summary']);
|
||||
});
|
||||
|
||||
test('a client never sees Agents or Client Onboarding, even if asked to', () => {
|
||||
const groups = navGroupsFor(GROUPS, { isClient: true, canOnboard: true, onboardingItem: ONBOARD });
|
||||
const all = groups.flatMap((g) => g.items.map((i) => i.path));
|
||||
expect(all).not.toContain('/doormile/agents');
|
||||
expect(all).not.toContain(CLIENT_ONBOARDING_PATH);
|
||||
expect(all.filter((p) => p.startsWith('/doormile/') && !p.includes('/reports/'))).toEqual(CLIENT_FLEET_OPS_PATHS);
|
||||
});
|
||||
|
||||
test('the onboarding owner sees the full Fleet Ops menu plus Client Onboarding', () => {
|
||||
const owner = { email: 'admin@doormile.com', role: 'admin' };
|
||||
const groups = navGroupsFor(GROUPS, { isClient: false, canOnboard: canOnboardClients(owner, false), onboardingItem: ONBOARD });
|
||||
expect(labelsOf(groups, 'Fleet Ops')).toEqual([...GROUPS[0].items.map((i) => i.label), 'Client Onboarding']);
|
||||
});
|
||||
|
||||
test('other Doormile staff see Fleet Ops and Agents but not Client Onboarding', () => {
|
||||
const staff = { email: 'ops@doormile.com', role: 'admin' };
|
||||
const groups = navGroupsFor(GROUPS, { isClient: false, canOnboard: canOnboardClients(staff, false), onboardingItem: ONBOARD });
|
||||
expect(labelsOf(groups, 'Fleet Ops')).toContain('Agents');
|
||||
expect(labelsOf(groups, 'Fleet Ops')).not.toContain('Client Onboarding');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user