document-unviewable.client.spec.ts 1.1 KB

12345678910111213141516171819202122232425
  1. // @vitest-environment jsdom
  2. import { describe, expect, it } from 'vitest'
  3. import { unviewableBinaryPath } from '../src/client/document/unviewable.ts'
  4. describe('unviewableBinaryPath', () => {
  5. it('matches one sample from every listed category', () => {
  6. for (const path of [
  7. 'clip.mp4', 'song.mp3', 'bundle.zip', 'report.docx', 'tool.exe',
  8. 'face.woff2', 'image.dmg', 'design.psd',
  9. ]) expect(unviewableBinaryPath(path), path).toBe(true)
  10. })
  11. it('matches regardless of case, directories, and path separators', () => {
  12. expect(unviewableBinaryPath('MOVIE.MP4')).toBe(true)
  13. expect(unviewableBinaryPath('work/deep/archive.tar.gz')).toBe(true)
  14. expect(unviewableBinaryPath('work\\deep\\notes.docx')).toBe(true)
  15. })
  16. it('leaves renderer-claimed, text, and unknown suffixes to their existing paths', () => {
  17. for (const path of [
  18. 'main.ts', 'README.md', 'photo.png', 'page.html', 'paper.pdf', 'logo.svg',
  19. 'server.log', 'config.env', 'notes.unknown', 'Makefile', 'mp4', 'private.key',
  20. ]) expect(unviewableBinaryPath(path), path).toBe(false)
  21. })
  22. })