2026-08-04 20:39:45 +03:00
|
|
|
import { describe, expect, test } from 'bun:test';
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
CONTEXT_SURFACES,
|
|
|
|
|
getVisibleContextRailSurfaces,
|
|
|
|
|
WALKTHROUGH_MIN_WIDTH,
|
|
|
|
|
} from './registry';
|
|
|
|
|
|
|
|
|
|
const baseOptions = {
|
|
|
|
|
railOrder: [],
|
|
|
|
|
planModeEnabled: true,
|
|
|
|
|
isVSCode: false,
|
|
|
|
|
screenWidth: 1200,
|
|
|
|
|
tabs: [],
|
|
|
|
|
} as const;
|
|
|
|
|
|
|
|
|
|
describe('getVisibleContextRailSurfaces', () => {
|
|
|
|
|
test('hides the plan surface while plan mode is disabled', () => {
|
|
|
|
|
const surfaces = getVisibleContextRailSurfaces({ ...baseOptions, planModeEnabled: false });
|
|
|
|
|
expect(surfaces.some((surface) => surface.id === 'plan')).toBe(false);
|
|
|
|
|
expect(surfaces.some((surface) => surface.id === 'context')).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('shows the plan surface while plan mode is enabled', () => {
|
|
|
|
|
const surfaces = getVisibleContextRailSurfaces({ ...baseOptions, planModeEnabled: true });
|
|
|
|
|
expect(surfaces.some((surface) => surface.id === 'plan')).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('hides the walkthrough on VS Code and below the min width', () => {
|
|
|
|
|
expect(getVisibleContextRailSurfaces({ ...baseOptions, isVSCode: true }).some((s) => s.id === 'walkthrough')).toBe(false);
|
|
|
|
|
expect(
|
|
|
|
|
getVisibleContextRailSurfaces({ ...baseOptions, screenWidth: WALKTHROUGH_MIN_WIDTH - 1 }).some((s) => s.id === 'walkthrough'),
|
|
|
|
|
).toBe(false);
|
|
|
|
|
expect(
|
|
|
|
|
getVisibleContextRailSurfaces({ ...baseOptions, screenWidth: WALKTHROUGH_MIN_WIDTH }).some((s) => s.id === 'walkthrough'),
|
|
|
|
|
).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
2026-08-13 22:44:13 +03:00
|
|
|
test('offers no browser surface inside VS Code', () => {
|
|
|
|
|
expect(getVisibleContextRailSurfaces(baseOptions).some((s) => s.id === 'browser')).toBe(true);
|
|
|
|
|
// Nothing that makes the panel worth having works there, so offering it
|
|
|
|
|
// would promise the panel people see on the desktop.
|
|
|
|
|
expect(getVisibleContextRailSurfaces({ ...baseOptions, isVSCode: true }).some((s) => s.id === 'browser')).toBe(false);
|
|
|
|
|
});
|
|
|
|
|
|
2026-08-04 20:39:45 +03:00
|
|
|
test('hides content-driven surfaces until a matching tab exists', () => {
|
2026-08-13 22:44:13 +03:00
|
|
|
const chat = CONTEXT_SURFACES.find((surface) => surface.id === 'chat');
|
|
|
|
|
if (!chat) {
|
|
|
|
|
throw new Error('chat surface missing from registry');
|
2026-08-04 20:39:45 +03:00
|
|
|
}
|
2026-08-13 22:44:13 +03:00
|
|
|
expect(chat.availability).toBe('has-content');
|
|
|
|
|
expect(getVisibleContextRailSurfaces(baseOptions).some((s) => s.id === 'chat')).toBe(false);
|
|
|
|
|
expect(getVisibleContextRailSurfaces({ ...baseOptions, tabs: [{ mode: chat.mode }] }).some((s) => s.id === 'chat')).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('the browser surface can be opened from the rail with no tab yet', () => {
|
|
|
|
|
const browser = CONTEXT_SURFACES.find((surface) => surface.id === 'browser');
|
|
|
|
|
expect(browser?.availability).toBe('always');
|
|
|
|
|
expect(getVisibleContextRailSurfaces(baseOptions).some((s) => s.id === 'browser')).toBe(true);
|
2026-08-04 20:39:45 +03:00
|
|
|
});
|
|
|
|
|
|
2026-08-14 03:16:04 +00:00
|
|
|
test('hides the pr surface for other git providers but keeps it for github/gitlab/gitea', () => {
|
2026-08-13 19:37:02 +00:00
|
|
|
expect(getVisibleContextRailSurfaces({ ...baseOptions, gitProvider: 'other' }).some((s) => s.id === 'pr')).toBe(false);
|
|
|
|
|
expect(getVisibleContextRailSurfaces({ ...baseOptions, gitProvider: 'gitlab' }).some((s) => s.id === 'pr')).toBe(true);
|
|
|
|
|
expect(getVisibleContextRailSurfaces({ ...baseOptions, gitProvider: 'github' }).some((s) => s.id === 'pr')).toBe(true);
|
2026-08-14 03:16:04 +00:00
|
|
|
expect(getVisibleContextRailSurfaces({ ...baseOptions, gitProvider: 'gitea' }).some((s) => s.id === 'pr')).toBe(true);
|
2026-08-13 19:37:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('keeps the pr surface while the git provider is unknown', () => {
|
|
|
|
|
expect(getVisibleContextRailSurfaces({ ...baseOptions, gitProvider: null }).some((s) => s.id === 'pr')).toBe(true);
|
|
|
|
|
expect(getVisibleContextRailSurfaces(baseOptions).some((s) => s.id === 'pr')).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
2026-08-04 20:39:45 +03:00
|
|
|
test('respects the persisted user rail order', () => {
|
|
|
|
|
const surfaces = getVisibleContextRailSurfaces({ ...baseOptions, railOrder: ['git', 'context'] });
|
|
|
|
|
expect(surfaces.slice(0, 2).map((surface) => surface.id)).toEqual(['git', 'context']);
|
|
|
|
|
});
|
|
|
|
|
});
|