Cross-platform packages / Validate source (push) Has been cancelled
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (arm64, linux, ubuntu-24.04-arm) (push) Has been cancelled
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (arm64, macos, macos-15) (push) Has been cancelled
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (arm64, windows, windows-2025) (push) Has been cancelled
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (x64, linux, ubuntu-24.04) (push) Has been cancelled
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (x64, macos, macos-15-intel) (push) Has been cancelled
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (x64, windows, windows-2025) (push) Has been cancelled
Cross-platform packages / Publish GitHub Release (push) Has been cancelled
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { showDesktopNotificationWhenUnfocused } from './desktop-notification'
|
|
|
|
const notificationMocks = vi.hoisted(() => ({
|
|
isSupported: vi.fn(() => true),
|
|
show: vi.fn()
|
|
}))
|
|
|
|
vi.mock('electron', () => ({
|
|
Notification: class {
|
|
static isSupported = notificationMocks.isSupported
|
|
|
|
show = notificationMocks.show
|
|
}
|
|
}))
|
|
|
|
describe('showDesktopNotificationWhenUnfocused', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
notificationMocks.isSupported.mockReturnValue(true)
|
|
})
|
|
|
|
it('suppresses desktop notifications while GoodBuddy is focused', () => {
|
|
const shown = showDesktopNotificationWhenUnfocused(
|
|
{
|
|
isDestroyed: vi.fn(() => false),
|
|
isFocused: vi.fn(() => true)
|
|
} as never,
|
|
{ title: '任务已完成' }
|
|
)
|
|
|
|
expect(shown).toBe(false)
|
|
expect(notificationMocks.show).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('shows desktop notifications while GoodBuddy is unfocused', () => {
|
|
const shown = showDesktopNotificationWhenUnfocused(
|
|
{
|
|
isDestroyed: vi.fn(() => false),
|
|
isFocused: vi.fn(() => false)
|
|
} as never,
|
|
{ title: '任务已完成' }
|
|
)
|
|
|
|
expect(shown).toBe(true)
|
|
expect(notificationMocks.show).toHaveBeenCalledOnce()
|
|
})
|
|
})
|