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) }) })