Files
Momento/memento-note/tests/unit/note-visible-in-view.test.ts
Antigravity 96e7902f01
Some checks failed
CI / Lint, Unit Tests & Build (push) Failing after 1m22s
CI / Deploy production (on server) (push) Has been skipped
feat: publication IA (magazine/brief/essay) + fixes critique
Publication IA:
- 4 templates (magazine, brief, essay, simple) avec CSS riche
- Rewrite IA (article/exercises/tutorial/reference/mixed)
- Modération avec timeout 12s + fallback safe
- Quotas publish_enhance par tier (basic=2, pro=15, business=100)
- Détection contenu stale (hash)
- Migration DB publishedContent/publishedTemplate/publishedSourceHash

Fixes:
- cheerio v1.2: Element -> AnyNode (domhandler), decodeEntities cast
- _isShared ajouté au type Note (champ virtuel serveur)
- callout colors PDF export: extraction fonction pure testable
- admin/published: guard note.userId null
- Cmd+S fonctionne en mode dialog (pas seulement fullPage)

i18n:
- 23 clés publish* traduites dans les 15 locales
- Extension Web Clipper: 13 locales mise à jour

Tests:
- callout-colors.test.ts (6 tests)
- note-visible-in-view.test.ts (5 tests)
- entitlements.test.ts + byok-entitlements.test.ts: mock usageLog + unstubAllEnvs
- 199/199 tests passent

Tracker: user-stories.md sync avec sprint-status.yaml
2026-06-28 07:32:57 +00:00

54 lines
2.4 KiB
TypeScript

import { describe, test, expect } from 'vitest'
interface ViewFilterInput {
notebookId?: string | null
_isShared?: boolean
}
type FilterParams = {
notebook: string | null
sharedOnly: boolean
}
export function noteVisibleInCurrentView(note: ViewFilterInput, params: FilterParams): boolean {
if (params.sharedOnly) return !!note._isShared
if (params.notebook) return note.notebookId === params.notebook && !note._isShared
return !note.notebookId && !note._isShared
}
describe('noteVisibleInCurrentView', () => {
const ownNote = { notebookId: 'nb1', _isShared: false }
const sharedNote = { notebookId: null, _isShared: true }
const orphanNote = { notebookId: null, _isShared: false }
test('sharedOnly=true shows only shared notes', () => {
expect(noteVisibleInCurrentView(sharedNote, { notebook: null, sharedOnly: true })).toBe(true)
expect(noteVisibleInCurrentView(ownNote, { notebook: null, sharedOnly: true })).toBe(false)
expect(noteVisibleInCurrentView(orphanNote, { notebook: null, sharedOnly: true })).toBe(false)
})
test('notebook filter shows only own notes in that notebook', () => {
expect(noteVisibleInCurrentView(ownNote, { notebook: 'nb1', sharedOnly: false })).toBe(true)
expect(noteVisibleInCurrentView(ownNote, { notebook: 'nb2', sharedOnly: false })).toBe(false)
expect(noteVisibleInCurrentView(sharedNote, { notebook: 'nb1', sharedOnly: false })).toBe(false)
})
test('no filter shows only orphan notes (no notebook, not shared)', () => {
expect(noteVisibleInCurrentView(orphanNote, { notebook: null, sharedOnly: false })).toBe(true)
expect(noteVisibleInCurrentView(ownNote, { notebook: null, sharedOnly: false })).toBe(false)
expect(noteVisibleInCurrentView(sharedNote, { notebook: null, sharedOnly: false })).toBe(false)
})
test('_isShared undefined is treated as false', () => {
const noSharedField = { notebookId: null }
expect(noteVisibleInCurrentView(noSharedField, { notebook: null, sharedOnly: false })).toBe(true)
expect(noteVisibleInCurrentView(noSharedField, { notebook: null, sharedOnly: true })).toBe(false)
})
test('moving a note to null notebook keeps it visible in default view', () => {
const moved = { ...ownNote, notebookId: null }
expect(noteVisibleInCurrentView(moved, { notebook: null, sharedOnly: false })).toBe(true)
expect(noteVisibleInCurrentView(moved, { notebook: 'nb1', sharedOnly: false })).toBe(false)
})
})