Skip to content

Commit 39e5983

Browse files
committed
test(desktop): read the blockers the OS holds instead of asserting the mock was called
1 parent 72806fc commit 39e5983

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

‎apps/desktop/src/main/desktop-executor/sleep-blocker.test.ts‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
import { describe, expect, it, vi } from 'vitest'
1+
import { describe, expect, it } from 'vitest'
22
import { createSleepBlocker } from '@/main/desktop-executor/sleep-blocker'
33

44
function harness(enabled = true) {
55
let nextId = 1
6-
const active = new Set<number>()
6+
/** The blockers the OS holds now, by id, with the kind each one prevents. */
7+
const active = new Map<number, string>()
78
const powerSaveBlocker = {
8-
start: vi.fn(() => {
9+
start: (type: 'prevent-app-suspension') => {
910
const id = nextId++
10-
active.add(id)
11+
active.set(id, type)
1112
return id
12-
}),
13-
stop: vi.fn((id: number) => {
13+
},
14+
stop: (id: number) => {
1415
active.delete(id)
15-
}),
16+
},
1617
isStarted: (id: number) => active.has(id),
1718
}
1819
let preference = enabled
1920
const blocker = createSleepBlocker({ enabled: () => preference, powerSaveBlocker })
2021
return {
2122
blocker,
22-
powerSaveBlocker,
2323
active,
2424
setPreference: (value: boolean) => {
2525
preference = value
@@ -30,12 +30,11 @@ function harness(enabled = true) {
3030

3131
describe('keeping the machine awake for background work', () => {
3232
it('holds one blocker only while a chat has work running', () => {
33-
const { blocker, powerSaveBlocker, active } = harness()
33+
const { blocker, active } = harness()
3434

3535
blocker.setBusy(true)
3636
blocker.setBusy(true)
37-
expect(active.size).toBe(1)
38-
expect(powerSaveBlocker.start).toHaveBeenCalledWith('prevent-app-suspension')
37+
expect([...active.values()]).toEqual(['prevent-app-suspension'])
3938

4039
blocker.setBusy(false)
4140
expect(active.size).toBe(0)

0 commit comments

Comments
 (0)