|
| 1 | +import { describe, test, expect } from 'vitest' |
| 2 | +import { applyHiddenTabs, applyHistoricalModeFilter } from '../app/utils/tabUtils' |
| 3 | + |
| 4 | +describe('MainComponent hidden tabs filtering', () => { |
| 5 | + const ALL_BASE_TABS = ['languages', 'editors', 'copilot chat', 'agent activity', 'pull requests', 'github.com', 'seat analysis', 'user metrics', 'api response'] |
| 6 | + |
| 7 | + test('should keep all tabs when hiddenTabs is empty', () => { |
| 8 | + const tabs = ['organization', 'teams', ...ALL_BASE_TABS] |
| 9 | + const result = applyHiddenTabs(tabs, '') |
| 10 | + expect(result).toEqual(tabs) |
| 11 | + }) |
| 12 | + |
| 13 | + test('should hide a single tab when configured', () => { |
| 14 | + const tabs = ['organization', 'teams', ...ALL_BASE_TABS] |
| 15 | + const result = applyHiddenTabs(tabs, 'api response') |
| 16 | + expect(result).not.toContain('api response') |
| 17 | + expect(result).toContain('languages') |
| 18 | + expect(result).toContain('editors') |
| 19 | + expect(result).toContain('seat analysis') |
| 20 | + }) |
| 21 | + |
| 22 | + test('should hide multiple tabs when configured with comma-separated list', () => { |
| 23 | + const tabs = ['organization', 'teams', ...ALL_BASE_TABS] |
| 24 | + const result = applyHiddenTabs(tabs, 'api response, agent activity, pull requests') |
| 25 | + expect(result).not.toContain('api response') |
| 26 | + expect(result).not.toContain('agent activity') |
| 27 | + expect(result).not.toContain('pull requests') |
| 28 | + expect(result).toContain('languages') |
| 29 | + expect(result).toContain('copilot chat') |
| 30 | + expect(result).toContain('seat analysis') |
| 31 | + expect(result).toContain('user metrics') |
| 32 | + }) |
| 33 | + |
| 34 | + test('should be case-insensitive when matching tab names', () => { |
| 35 | + const tabs = ['organization', ...ALL_BASE_TABS] |
| 36 | + const result = applyHiddenTabs(tabs, 'API Response, Seat Analysis') |
| 37 | + expect(result).not.toContain('api response') |
| 38 | + expect(result).not.toContain('seat analysis') |
| 39 | + expect(result).toContain('languages') |
| 40 | + }) |
| 41 | + |
| 42 | + test('should not hide scope tabs (organization, enterprise, team)', () => { |
| 43 | + const tabs = ['organization', 'teams', ...ALL_BASE_TABS] |
| 44 | + // When hidden tabs config only targets content tabs, scope tabs remain |
| 45 | + const result = applyHiddenTabs(tabs, 'api response') |
| 46 | + expect(result).toContain('organization') |
| 47 | + expect(result).toContain('teams') |
| 48 | + }) |
| 49 | + |
| 50 | + test('should handle whitespace in the hidden tabs config', () => { |
| 51 | + const tabs = ['organization', ...ALL_BASE_TABS] |
| 52 | + const result = applyHiddenTabs(tabs, ' api response , agent activity ') |
| 53 | + expect(result).not.toContain('api response') |
| 54 | + expect(result).not.toContain('agent activity') |
| 55 | + expect(result).toContain('languages') |
| 56 | + }) |
| 57 | + |
| 58 | + test('should return empty array if all tabs are hidden', () => { |
| 59 | + const tabs = ['languages', 'editors'] |
| 60 | + const result = applyHiddenTabs(tabs, 'languages, editors') |
| 61 | + expect(result).toHaveLength(0) |
| 62 | + }) |
| 63 | + |
| 64 | + test('should ignore unknown tab names in hiddenTabs config', () => { |
| 65 | + const tabs = ['organization', ...ALL_BASE_TABS] |
| 66 | + const result = applyHiddenTabs(tabs, 'nonexistent-tab, api response') |
| 67 | + expect(result).not.toContain('api response') |
| 68 | + expect(result).toContain('languages') |
| 69 | + // Length should be original - 1 (only api response removed) |
| 70 | + expect(result).toHaveLength(tabs.length - 1) |
| 71 | + }) |
| 72 | + |
| 73 | + // Historical mode tests |
| 74 | + describe('auto-hide teams tab based on historical mode', () => { |
| 75 | + test('should hide teams tab when historical mode is false', () => { |
| 76 | + const tabs = ['organization', 'teams', ...ALL_BASE_TABS] |
| 77 | + const result = applyHistoricalModeFilter(tabs, false) |
| 78 | + expect(result).not.toContain('teams') |
| 79 | + expect(result).toContain('organization') |
| 80 | + expect(result).toContain('languages') |
| 81 | + }) |
| 82 | + |
| 83 | + test('should hide teams tab when historical mode is string "false"', () => { |
| 84 | + const tabs = ['organization', 'teams', ...ALL_BASE_TABS] |
| 85 | + const result = applyHistoricalModeFilter(tabs, 'false') |
| 86 | + expect(result).not.toContain('teams') |
| 87 | + }) |
| 88 | + |
| 89 | + test('should keep teams tab when historical mode is true', () => { |
| 90 | + const tabs = ['organization', 'teams', ...ALL_BASE_TABS] |
| 91 | + const result = applyHistoricalModeFilter(tabs, true) |
| 92 | + expect(result).toContain('teams') |
| 93 | + }) |
| 94 | + |
| 95 | + test('should keep teams tab when historical mode is string "true"', () => { |
| 96 | + const tabs = ['organization', 'teams', ...ALL_BASE_TABS] |
| 97 | + const result = applyHistoricalModeFilter(tabs, 'true') |
| 98 | + expect(result).toContain('teams') |
| 99 | + }) |
| 100 | + |
| 101 | + test('should not affect other tabs when hiding teams', () => { |
| 102 | + const tabs = ['organization', 'teams', ...ALL_BASE_TABS] |
| 103 | + const result = applyHistoricalModeFilter(tabs, false) |
| 104 | + expect(result).toHaveLength(tabs.length - 1) |
| 105 | + ALL_BASE_TABS.forEach(tab => expect(result).toContain(tab)) |
| 106 | + }) |
| 107 | + |
| 108 | + test('should not modify tabs when teams is not present', () => { |
| 109 | + const tabs = ['team', ...ALL_BASE_TABS] |
| 110 | + const result = applyHistoricalModeFilter(tabs, false) |
| 111 | + expect(result).toEqual(tabs) |
| 112 | + }) |
| 113 | + }) |
| 114 | +}) |
0 commit comments