27 lines
1.6 KiB
TypeScript
27 lines
1.6 KiB
TypeScript
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { summarizeFolders, sumMailboxStatistics } from '../src/main/services/mailbox-statistics.ts'
|
|
import type { SpecialFolderRole } from '../src/shared/types/folder.ts'
|
|
import type { Folder } from '../src/shared/types/folder.ts'
|
|
|
|
test('считает входящие, отправленные и вложенные папки независимо от их названий', (): void => {
|
|
const folders: Folder[] = [
|
|
{ id: 'inbox', name: 'Входящие', role: 'inbox' as SpecialFolderRole, parentId: null, unreadCount: 3, totalCount: 10, children: [
|
|
{ id: 'work', name: 'Работа', role: 'none' as SpecialFolderRole, parentId: 'inbox', unreadCount: 2, totalCount: 5, children: [] }
|
|
] },
|
|
{ id: 'sent', name: 'Sent items', role: 'sent' as SpecialFolderRole, parentId: null, unreadCount: 0, totalCount: 7, children: [] }
|
|
]
|
|
assert.deepEqual(summarizeFolders(folders), { incoming: 10, sent: 7, unread: 5, total: 22, folders: 3 })
|
|
assert.equal(folders[0].totalCount, 10)
|
|
})
|
|
|
|
test('для пустого ящика возвращает нулевую статистику', (): void => {
|
|
assert.deepEqual(summarizeFolders([]), { incoming: 0, sent: 0, unread: 0, total: 0, folders: 0 })
|
|
})
|
|
|
|
test('суммирует показатели нескольких аккаунтов', (): void => {
|
|
assert.deepEqual(sumMailboxStatistics([
|
|
{ incoming: 10, sent: 7, unread: 5, total: 22, folders: 3 },
|
|
{ incoming: 4, sent: 1, unread: 1, total: 5, folders: 2 }
|
|
]), { incoming: 14, sent: 8, unread: 6, total: 27, folders: 5 })
|
|
})
|