|
| 1 | +import type { DevframeDockEntry } from '@devframes/hub' |
| 2 | +import type { DocksContext } from '@devframes/hub/client' |
| 3 | +import { describe, expect, it } from 'vitest' |
| 4 | +import { getCurrentDockId, holdsCurrentDock } from './docks' |
| 5 | + |
| 6 | +const group = { type: 'group', id: 'tools', title: 'Tools', icon: 'i' } as DevframeDockEntry |
| 7 | +const member = { type: 'iframe', id: 'logs', title: 'Logs', icon: 'i', url: '/', groupId: 'tools' } as DevframeDockEntry |
| 8 | +const action = { type: 'action', id: 'reload', title: 'Reload', icon: 'i' } as DevframeDockEntry |
| 9 | + |
| 10 | +function contextWith(selected: DevframeDockEntry | null, options: { clientType?: 'embedded' | 'standalone', open?: boolean, recent?: string[], topLevel?: DevframeDockEntry[] } = {}): DocksContext { |
| 11 | + // eslint-disable-next-line slop/no-chained-type-assertions -- this fixture supplies only the context fields the dock helpers read. |
| 12 | + return { |
| 13 | + clientType: options.clientType ?? 'standalone', |
| 14 | + panel: { session: { open: options.open ?? true, recentDockIds: options.recent } }, |
| 15 | + docks: { selected, entries: [group, member, action], groupedEntries: [['default', options.topLevel ?? [group, action]]] }, |
| 16 | + } as unknown as DocksContext |
| 17 | +} |
| 18 | + |
| 19 | +describe('getCurrentDockId', () => { |
| 20 | + it('is the selected view, never an action, and none while an embedded panel is closed', () => { |
| 21 | + expect(getCurrentDockId(contextWith(member))).toBe('logs') |
| 22 | + expect(getCurrentDockId(contextWith(action))).toBeUndefined() |
| 23 | + expect(getCurrentDockId(contextWith(null))).toBeUndefined() |
| 24 | + expect(getCurrentDockId(contextWith(member, { clientType: 'embedded', open: false }))).toBeUndefined() |
| 25 | + expect(getCurrentDockId(contextWith(member, { clientType: 'embedded', open: true }))).toBe('logs') |
| 26 | + }) |
| 27 | +}) |
| 28 | + |
| 29 | +describe('holdsCurrentDock', () => { |
| 30 | + it('holds the current dock itself and the group of a current member', () => { |
| 31 | + const context = contextWith(member) |
| 32 | + expect(holdsCurrentDock(context, member, 'logs')).toBe(true) |
| 33 | + expect(holdsCurrentDock(context, group, 'logs')).toBe(true) |
| 34 | + expect(holdsCurrentDock(context, action, 'logs')).toBe(false) |
| 35 | + expect(holdsCurrentDock(context, group, undefined)).toBe(false) |
| 36 | + }) |
| 37 | + |
| 38 | + it('leaves the group out when the member has its own button on the bar', () => { |
| 39 | + expect(holdsCurrentDock(contextWith(member, { recent: ['logs'] }), group, 'logs')).toBe(false) |
| 40 | + expect(holdsCurrentDock(contextWith(member, { topLevel: [group, member] }), group, 'logs')).toBe(false) |
| 41 | + }) |
| 42 | +}) |
0 commit comments