mirror of
https://git.shipoclu.com/moon/plspace.git
synced 2026-08-13 02:42:30 +00:00
47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { account, status } from '$test/fixtures'
|
|
import type { Notification } from './api/types'
|
|
import { NotificationTracker, presentNotification } from './notifications'
|
|
|
|
function notification(overrides: Partial<Notification> = {}): Notification {
|
|
return {
|
|
id: 'notification-1',
|
|
type: 'mention',
|
|
created_at: '2026-01-01T00:00:00.000Z',
|
|
account: account({ display_name: 'Bob', acct: 'bob' }),
|
|
status: status({ id: 'mentioned-entry', content: '<p>Hello there</p>' }),
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
describe('NotificationTracker', () => {
|
|
it('uses the first page as a quiet baseline and emits only unseen items later', () => {
|
|
const tracker = new NotificationTracker()
|
|
const baseline = notification({ id: 'old' })
|
|
const fresh = notification({ id: 'new' })
|
|
|
|
expect(tracker.ingest([baseline])).toEqual([])
|
|
expect(tracker.cursor).toBe('old')
|
|
expect(tracker.ingest([fresh, baseline])).toEqual([fresh])
|
|
expect(tracker.cursor).toBe('new')
|
|
expect(tracker.ingest([fresh, baseline])).toEqual([])
|
|
})
|
|
})
|
|
|
|
describe('presentNotification', () => {
|
|
it('links status notifications to the relevant entry', () => {
|
|
expect(presentNotification(notification())).toEqual({
|
|
actor: 'Bob',
|
|
message: 'mentioned you in an entry',
|
|
excerpt: 'Hello there',
|
|
href: '#/blog/mentioned-entry',
|
|
})
|
|
})
|
|
|
|
it('links friend requests to their manager', () => {
|
|
expect(
|
|
presentNotification(notification({ type: 'follow_request', status: null })).href,
|
|
).toBe('#/mail/requests')
|
|
})
|
|
})
|