forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstickyNotesText.test.ts
More file actions
52 lines (44 loc) · 1.75 KB
/
Copy pathstickyNotesText.test.ts
File metadata and controls
52 lines (44 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { describe, it, expect } from 'vitest'
import { cleanNoteText, toStickyNotes } from './stickyNotesText'
describe('cleanNoteText', () => {
it('collapses whitespace and trims', () => {
expect(cleanNoteText(' hello world ')).toBe('hello world')
})
it('strips control characters but keeps newlines', () => {
expect(cleanNoteText('a b\nc')).toBe('a b\nc')
})
it('normalizes CRLF and collapses blank-line runs', () => {
expect(cleanNoteText('a\r\n\r\n\r\nb')).toBe('a\n\nb')
})
it('returns empty for whitespace-only input', () => {
expect(cleanNoteText(' \r\n ')).toBe('')
})
it('strips a leading Sticky Notes \\id=<guid> block anchor', () => {
expect(
cleanNoteText('\\id=fe2dab27-48db-4383-b2c1-e7dca0cd6f40 My favorite movie is the machinist')
).toBe('My favorite movie is the machinist')
})
it('separates and strips multiple block anchors', () => {
expect(
cleanNoteText(
'\\id=aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee First line\\id=11111111-2222-3333-4444-555555555555 Second line'
)
).toBe('First line\nSecond line')
})
})
describe('toStickyNotes', () => {
it('drops deleted and empty notes and sorts newest-first', () => {
const out = toStickyNotes([
{ id: '1', text: 'keep me', updatedAt: 100 },
{ id: '2', text: ' ', updatedAt: 200 }, // empty after clean
{ id: '3', text: 'deleted', updatedAt: 300, deleted: true },
{ id: '4', text: 'newer', updatedAt: 400 }
])
expect(out.map((n) => n.id)).toEqual(['4', '1'])
expect(out[0].text).toBe('newer')
})
it('handles a null/undefined text column gracefully', () => {
const out = toStickyNotes([{ id: '1', text: null as unknown as string, updatedAt: 1 }])
expect(out).toEqual([])
})
})