|
| 1 | +import assert from 'node:assert/strict' |
| 2 | +import { test } from 'node:test' |
| 3 | +import { loadMobileModule } from '../../tooling/load-mobile-module.ts' |
| 4 | + |
| 5 | +Object.defineProperty(globalThis, 'localStorage', { configurable: true, value: { getItem: () => null, setItem: () => {}, removeItem: () => {} } }) |
| 6 | +const { MobileVault } = await loadMobileModule(['./src/bridge/vault-fs']) |
| 7 | + |
| 8 | +// A folder opened before its notes arrived (#1023): this app makes `inbox/` on |
| 9 | +// first open, and nothing may keep the notes that land beside it out of view. |
| 10 | +function fixture(files: string[], dirs: string[] = []) { |
| 11 | + const vault = new MobileVault('Fixture') |
| 12 | + const children = (dir: string) => { |
| 13 | + const prefix = dir ? `${dir}/` : '' |
| 14 | + const names = new Map<string, 'file' | 'directory'>() |
| 15 | + for (const file of files) { |
| 16 | + if (!file.startsWith(prefix)) continue |
| 17 | + const [head, ...rest] = file.slice(prefix.length).split('/') |
| 18 | + names.set(head!, rest.length ? 'directory' : 'file') |
| 19 | + } |
| 20 | + for (const entry of dirs) { |
| 21 | + if (!entry.startsWith(prefix)) continue |
| 22 | + const [head, ...rest] = entry.slice(prefix.length).split('/') |
| 23 | + if (head && !rest.length) names.set(head, 'directory') |
| 24 | + } |
| 25 | + return [...names].map(([name, type]) => ({ name, type })) |
| 26 | + } |
| 27 | + Object.assign(vault, { |
| 28 | + fs: { readdir: async (dir: string) => children(dir), readTextOrNull: async () => null, rootPath: '/fixture' } |
| 29 | + }) |
| 30 | + return vault |
| 31 | +} |
| 32 | +const layout = async (vault: InstanceType<typeof MobileVault>) => (await vault.getVaultSettings()).primaryNotesLocation |
| 33 | + |
| 34 | +test('an empty inbox does not hold back folders that arrived beside it', async () => { |
| 35 | + assert.equal(await layout(fixture(['Trips/Rome.md', 'Work/Plan.md'], ['inbox', 'quick', 'archive', 'trash'])), 'root') |
| 36 | +}) |
| 37 | + |
| 38 | +test('an empty inbox does not hold back a loose note at the root', async () => { |
| 39 | + assert.equal(await layout(fixture(['Loose.md'], ['inbox'])), 'root') |
| 40 | +}) |
| 41 | + |
| 42 | +test('dotfiles inside the inbox are not notes', async () => { |
| 43 | + assert.equal(await layout(fixture(['inbox/.DS_Store', 'Trips/Rome.md'], ['inbox'])), 'root') |
| 44 | +}) |
| 45 | + |
| 46 | +test('an inbox with anything in it stays inbox mode, loose folders or not', async () => { |
| 47 | + assert.equal(await layout(fixture(['inbox/Welcome.md', 'Daily/2026-11-04.md'])), 'inbox') |
| 48 | +}) |
| 49 | + |
| 50 | +test('an empty vault and a media-only vault stay inbox mode', async () => { |
| 51 | + assert.equal(await layout(fixture([], ['inbox'])), 'inbox') |
| 52 | + assert.equal(await layout(fixture(['VID_1.mp4'], ['inbox'])), 'inbox') |
| 53 | +}) |
| 54 | + |
| 55 | +test('the banner sees notes an inbox-mode vault.json hides when the inbox is empty', async () => { |
| 56 | + const vault = fixture(['Trips/Rome.md'], ['inbox']) |
| 57 | + Object.assign(vault, { settingsCache: { ...(await vault.getVaultSettings()), primaryNotesLocation: 'inbox' } }) |
| 58 | + assert.equal(await vault.rootContentHiddenByInboxMode(), true) |
| 59 | +}) |
| 60 | + |
| 61 | +test('the banner speaks up when an inbox with a note hides folders beside it', async () => { |
| 62 | + const vault = fixture(['inbox/First.md', 'Trips/Rome.md']) |
| 63 | + assert.equal(await layout(vault), 'inbox') |
| 64 | + assert.equal(await vault.rootContentHiddenByInboxMode(), true) |
| 65 | +}) |
| 66 | + |
| 67 | +test('the banner stays quiet with nothing loose at the root', async () => { |
| 68 | + const vault = fixture(['inbox/First.md', 'VID_1.mp4'], ['quick', 'archive', 'trash']) |
| 69 | + assert.equal(await vault.rootContentHiddenByInboxMode(), false) |
| 70 | +}) |
| 71 | + |
| 72 | +test('a resume that settles the layout re-reads it', async () => { |
| 73 | + const files: string[] = [] |
| 74 | + const vault = fixture(files, ['inbox']) |
| 75 | + assert.equal(await layout(vault), 'inbox') |
| 76 | + files.push('Trips/Rome.md') |
| 77 | + Object.assign(vault, { listNotes: async () => [] }) |
| 78 | + await vault.rescan() |
| 79 | + assert.equal(await layout(vault), 'root') |
| 80 | +}) |
0 commit comments