Skip to content

Commit

Permalink
Add unit test for status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanjaye Narayan authored and Sanjaye Narayan committed Jan 30, 2025
1 parent 34f07b1 commit b902f40
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
39 changes: 39 additions & 0 deletions vscode/src/services/StatusBar.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { allValuesFrom } from '@sourcegraph/cody-shared'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { StatusBarAlignment, vsCodeMocks } from '../testutils/mocks'
import { CodyStatusBar } from './StatusBar'

vi.mock('vscode', () => ({
...vsCodeMocks,
StatusBarAlignment,
}))

describe('StatusBar loader debouncing', () => {
let statusBar: CodyStatusBar
let observedChanges: Promise<Set<any>[]>

beforeEach(() => {
vi.useFakeTimers()
statusBar = CodyStatusBar.init()
// Track all changes to the loaders collection
observedChanges = allValuesFrom(statusBar['loaders'].changes).then(changes =>

Check failure on line 19 in vscode/src/services/StatusBar.test.ts

View workflow job for this annotation

GitHub Actions / build

The computed expression can be simplified without the use of a string literal.

Check failure on line 19 in vscode/src/services/StatusBar.test.ts

View workflow job for this annotation

GitHub Actions / build

The computed expression can be simplified without the use of a string literal.
changes.map(set => new Set(set))
)
})

afterEach(() => {
statusBar?.dispose()
vi.useRealTimers()
})

it('tracks loader mutations', async () => {
statusBar.addLoader({ title: 'Test Loader' })
statusBar['loaders'].complete()

Check failure on line 31 in vscode/src/services/StatusBar.test.ts

View workflow job for this annotation

GitHub Actions / build

The computed expression can be simplified without the use of a string literal.

Check failure on line 31 in vscode/src/services/StatusBar.test.ts

View workflow job for this annotation

GitHub Actions / build

The computed expression can be simplified without the use of a string literal.

const states = await observedChanges
// Initial empty state
expect(states[0].size).toBe(0)
// After adding loader
expect(states[1].size).toBe(1)
})
})
2 changes: 1 addition & 1 deletion vscode/src/services/StatusBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const QUICK_PICK_ITEM_EMPTY_INDENT_PREFIX = '\u00A0\u00A0\u00A0\u00A0\u00A0 '

const ONE_HOUR = 60 * 60 * 1000

const DEBOUNCE_TIMEOUT_MS = 300
const DEBOUNCE_TIMEOUT_MS = 250

const STATUS_BAR_INTERACTION_COMMAND = 'cody.status-bar.interacted'

Expand Down
10 changes: 10 additions & 0 deletions vscode/src/testutils/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,16 @@ export const vsCodeMocks = {
key: 'foo',
dispose: () => {},
}),
createStatusBarItem: () => ({
dispose: () => {},
show: () => {},
hide: () => {},
text: '',
tooltip: '',
command: '',
backgroundColor: undefined,
color: undefined,
}),
withProgress: async (
options: vscode_types.ProgressOptions,
task: (
Expand Down

0 comments on commit b902f40

Please sign in to comment.