Files
openchamber/packages/ui/src/components/chat/work-status/sections.test.ts
T
Bohdan Triapitsyn 9e2163d839 feat: enable turn stats by default and prepare release notes
Turn stats was hidden unless users opted in. Show it by default, migrate implicit hidden lists, and preserve explicit section choices through reloads and settings sync.

Prepare App and VS Code release notes with Turn stats as the headline and BTW composer changes under improvements.

Testing: 115 focused tests passed; UI type-check passed; UI lint has one existing warning. Changelog validation and diff checks passed. Oxlint findings are limited to existing code in sections.ts; interactive app validation was not run.
2026-09-08 01:38:28 +03:00

130 lines
5.0 KiB
TypeScript

import { describe, expect, test } from 'bun:test';
import {
WORK_STATUS_SECTION_IDS,
WORK_STATUS_SECTION_LABEL_KEYS,
areAllWorkStatusSectionsHidden,
getWorkStatusPanelPresentation,
isWorkStatusSectionVisible,
sanitizeWorkStatusHiddenSections,
} from './sections';
describe('section registry', () => {
test('every section has a label, and every label a section', () => {
// One list drives the panel and the dialog; a mismatch means a section the
// user cannot switch, or a switch for nothing.
expect(Object.keys(WORK_STATUS_SECTION_LABEL_KEYS).sort())
.toEqual([...WORK_STATUS_SECTION_IDS].sort());
});
});
describe('isWorkStatusSectionVisible', () => {
test('everything is visible by default', () => {
// Storing the hidden set means a section added later is on for everyone,
// rather than invisible to whoever had settings saved before it existed.
expect(isWorkStatusSectionVisible([], 'usage')).toBe(true);
expect(isWorkStatusSectionVisible(undefined, 'usage')).toBe(true);
expect(isWorkStatusSectionVisible(null, 'usage')).toBe(true);
});
test('hides exactly the listed section', () => {
expect(isWorkStatusSectionVisible(['usage'], 'usage')).toBe(false);
expect(isWorkStatusSectionVisible(['usage'], 'tasks')).toBe(true);
});
});
describe('areAllWorkStatusSectionsHidden', () => {
test('returns false when no sections are hidden', () => {
expect(areAllWorkStatusSectionsHidden([])).toBe(false);
});
test('returns false for null and undefined', () => {
expect(areAllWorkStatusSectionsHidden(null)).toBe(false);
expect(areAllWorkStatusSectionsHidden(undefined)).toBe(false);
});
test('returns false when only some sections are hidden', () => {
expect(areAllWorkStatusSectionsHidden(['usage', 'tasks'])).toBe(false);
});
test('returns true when every known section is hidden', () => {
expect(areAllWorkStatusSectionsHidden([...WORK_STATUS_SECTION_IDS])).toBe(true);
});
test('ignores stale ids that are no longer in the section list', () => {
// A future section-ID removal should not trick the length check into
// reporting all-hidden when real sections are still visible.
const withStale = [...WORK_STATUS_SECTION_IDS.slice(0, -1), 'removed_section'];
expect(areAllWorkStatusSectionsHidden(withStale)).toBe(false);
});
test('returns true even with extra stale ids alongside all real ones', () => {
const withExtra = [...WORK_STATUS_SECTION_IDS, 'removed_section'];
expect(areAllWorkStatusSectionsHidden(withExtra)).toBe(true);
});
});
describe('getWorkStatusPanelPresentation', () => {
test('keeps a visible all-hidden panel interactive and renders its recovery state', () => {
expect(getWorkStatusPanelPresentation({
visible: true,
contentMounted: true,
renderedSections: 0,
allSectionsHidden: true,
})).toEqual({ interactive: true, showEmptyState: true });
});
test('covers the optimistic fresh-mount count when all sections are hidden', () => {
expect(getWorkStatusPanelPresentation({
visible: true,
contentMounted: true,
renderedSections: 1,
allSectionsHidden: true,
})).toEqual({ interactive: true, showEmptyState: true });
});
test('preserves collapse when no section has data but sections remain enabled', () => {
expect(getWorkStatusPanelPresentation({
visible: true,
contentMounted: true,
renderedSections: 0,
allSectionsHidden: false,
})).toEqual({ interactive: false, showEmptyState: false });
});
test('does not expose controls or the empty state during a hidden collapse', () => {
expect(getWorkStatusPanelPresentation({
visible: false,
contentMounted: false,
renderedSections: 0,
allSectionsHidden: true,
})).toEqual({ interactive: false, showEmptyState: false });
});
});
describe('sanitizeWorkStatusHiddenSections', () => {
test('keeps known ids and drops everything else', () => {
expect(sanitizeWorkStatusHiddenSections(['usage', 'nope', 42, null, 'tasks']))
.toEqual(['usage', 'tasks']);
});
test('deduplicates', () => {
expect(sanitizeWorkStatusHiddenSections(['usage', 'usage'])).toEqual(['usage']);
});
test('treats a non-array payload as default hidden preference', () => {
expect(sanitizeWorkStatusHiddenSections(undefined)).toEqual([]);
expect(sanitizeWorkStatusHiddenSections('usage')).toEqual([]);
expect(sanitizeWorkStatusHiddenSections({ usage: true })).toEqual([]);
});
test('removes only the old implicit telemetry default', () => {
expect(sanitizeWorkStatusHiddenSections(['mcp', 'telemetry'], false)).toEqual(['mcp']);
expect(sanitizeWorkStatusHiddenSections([], false)).toEqual([]);
});
test('preserves explicit hiding, including hiding every section', () => {
expect(sanitizeWorkStatusHiddenSections(['mcp', 'telemetry'], true)).toEqual(['mcp', 'telemetry']);
expect(sanitizeWorkStatusHiddenSections([...WORK_STATUS_SECTION_IDS], true)).toEqual([...WORK_STATUS_SECTION_IDS]);
});
});