Files
tolaria/src/utils/windowMode.test.ts
Test 7c16ebd065 feat: open note in new window (Cmd+Shift+Click / Cmd+Shift+O)
Add multi-window support: notes can be opened in dedicated secondary
Tauri windows with editor-only layout (no sidebar, no note list).

Triggers: Cmd+Shift+Click on notes, Cmd+K → "Open in New Window",
Cmd+Shift+O shortcut, Note → "Open in New Window" menu bar item.

Secondary windows have their own auto-save, theme, and wikilink
navigation. Closing a secondary window does not affect the main window.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 08:47:25 +01:00

74 lines
2.0 KiB
TypeScript

import { describe, it, expect, beforeEach, afterEach } from 'vitest'
import { isNoteWindow, getNoteWindowParams } from './windowMode'
describe('windowMode', () => {
let originalSearch: string
beforeEach(() => {
originalSearch = window.location.search
})
afterEach(() => {
Object.defineProperty(window, 'location', {
writable: true,
value: { ...window.location, search: originalSearch },
})
})
function setSearch(search: string) {
Object.defineProperty(window, 'location', {
writable: true,
value: { ...window.location, search },
})
}
describe('isNoteWindow', () => {
it('returns false when no query params', () => {
setSearch('')
expect(isNoteWindow()).toBe(false)
})
it('returns true when window=note', () => {
setSearch('?window=note&path=/test.md&vault=/vault')
expect(isNoteWindow()).toBe(true)
})
it('returns false for other window values', () => {
setSearch('?window=main')
expect(isNoteWindow()).toBe(false)
})
})
describe('getNoteWindowParams', () => {
it('returns null when not a note window', () => {
setSearch('')
expect(getNoteWindowParams()).toBeNull()
})
it('returns null when path is missing', () => {
setSearch('?window=note&vault=/vault')
expect(getNoteWindowParams()).toBeNull()
})
it('returns null when vault is missing', () => {
setSearch('?window=note&path=/test.md')
expect(getNoteWindowParams()).toBeNull()
})
it('returns params when all are present', () => {
setSearch('?window=note&path=%2Fvault%2Ftest.md&vault=%2Fvault&title=My%20Note')
expect(getNoteWindowParams()).toEqual({
notePath: '/vault/test.md',
vaultPath: '/vault',
noteTitle: 'My Note',
})
})
it('defaults title to Untitled', () => {
setSearch('?window=note&path=/test.md&vault=/vault')
const params = getNoteWindowParams()
expect(params?.noteTitle).toBe('Untitled')
})
})
})