Automerge backed Markdown editor for the Atmosphere
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374// src/utils/__tests__/folder-path.test.tsimport { describe, it, expect } from 'vitest'import { normalizeFolderPath, validateFolderPath } from '../folder-path'
describe('normalizeFolderPath', () => { const cases: Array<[string, string]> = [ ['', ''], [' ', ''], ['/', ''], ['///', ''], ['notes', 'notes'], ['notes/', 'notes'], ['/notes', 'notes'], ['/notes/', 'notes'], [' notes ', 'notes'], ['notes/sub', 'notes/sub'], ['notes//sub', 'notes/sub'], ['notes///sub', 'notes/sub'], ['/notes/sub/', 'notes/sub'], ['a/b/c', 'a/b/c'], ] for (const [input, expected] of cases) { it(`normalizes ${JSON.stringify(input)} → ${JSON.stringify(expected)}`, () => { expect(normalizeFolderPath(input)).toBe(expected) }) }})
describe('validateFolderPath', () => { it('accepts empty / root-equivalent inputs as ok with normalized=""', () => { expect(validateFolderPath('')).toEqual({ ok: true, normalized: '' }) expect(validateFolderPath(' ')).toEqual({ ok: true, normalized: '' }) expect(validateFolderPath('/')).toEqual({ ok: true, normalized: '' }) expect(validateFolderPath('///')).toEqual({ ok: true, normalized: '' }) })
it('accepts simple and nested paths', () => { expect(validateFolderPath('notes')).toEqual({ ok: true, normalized: 'notes' }) expect(validateFolderPath('a/b')).toEqual({ ok: true, normalized: 'a/b' }) expect(validateFolderPath('/a/b/')).toEqual({ ok: true, normalized: 'a/b' }) })
it('rejects `.` and `..` segments', () => { const dotResult = validateFolderPath('a/./b') expect(dotResult.ok).toBe(false) if (!dotResult.ok) expect(dotResult.reason).toMatch(/'\.'/)
const dotdotResult = validateFolderPath('../foo') expect(dotdotResult.ok).toBe(false) if (!dotdotResult.ok) expect(dotdotResult.reason).toMatch(/'\.\.'/)
expect(validateFolderPath('a/../b').ok).toBe(false) expect(validateFolderPath('./x').ok).toBe(false) expect(validateFolderPath('..').ok).toBe(false) })
it('rejects segments with internal whitespace', () => { const r = validateFolderPath('a /b') expect(r.ok).toBe(false) if (!r.ok) expect(r.reason).toMatch(/whitespace/i)
expect(validateFolderPath('a/ b').ok).toBe(false) expect(validateFolderPath('a /').ok).toBe(false) })
it('collapses consecutive slashes before validation', () => { expect(validateFolderPath('a//b')).toEqual({ ok: true, normalized: 'a/b' }) })
it('outer slashes do not count as inner-whitespace failures', () => { expect(validateFolderPath(' /notes/ ').ok).toBe(true) })})