macos-web/tests/cases/07-notify.test.ts
2026-07-20 14:30:44 +08:00

53 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 07-notify: 通知系统(不触发 Sys/Dock
*/
import { describe, it, expect, beforeEach, beforeAll } from 'vitest'
import { Notify, setSysForNotify } from '../../src/composables/useNotify'
// Mock minimal Sys
const mockSys = {
settings: {
notificationsEnabled: true,
notifAllow: {} as Record<string, boolean>,
focus: false,
}
}
setSysForNotify(mockSys)
describe('07-notify — 通知系统', () => {
beforeAll(() => {
// 渲染通知中心 DOM
document.body.innerHTML = '<div id="notification-center" class="hidden"></div><div id="banner-container"></div><nav id="dock"></nav>'
})
beforeEach(() => { Notify.list = [] })
it('初始列表为空', () => { expect(Notify.list.length).toBe(0) })
it('send 添加通知', () => {
const n = Notify.send({ appId: 'finder', title: 'T', body: 'B', silent: true })
expect(n).not.toBeNull()
expect(Notify.list.length).toBe(1)
})
it('总开关关闭返回 null', () => {
mockSys.settings.notificationsEnabled = false
expect(Notify.send({ appId: 'f', title: 'T', body: 'B', silent: true })).toBeNull()
mockSys.settings.notificationsEnabled = true
})
it('per-app 关闭返回 null', () => {
mockSys.settings.notifAllow['finder'] = false
expect(Notify.send({ appId: 'finder', title: 'T', body: 'B', silent: true })).toBeNull()
mockSys.settings.notifAllow['finder'] = true
})
it('markRead 标记已读', () => {
const n = Notify.send({ appId: 'f', title: 'T', body: 'B', silent: true })
expect(n!.read).toBe(false)
Notify.markRead(n!.id)
expect(n!.read).toBe(true)
})
it('clearAll 清空', () => {
Notify.send({ appId: 'f', title: 'T', body: 'B', silent: true })
Notify.clearAll()
expect(Notify.list.length).toBe(0)
})
})