返回 oh-my-ppt
slide-pack-archive.test.ts
根目录 / tests / unit / session-import / slide-pack-archive.test.ts
1 import { strToU8, unzipSync, zipSync } from 'fflate'
2 import { describe, expect, it } from 'vitest'
3 import { findSlidePackResourceZipInsideZip } from '../../../src/main/session-import/slide-pack-archive'
4
5 const createDeckZip = (): Uint8Array =>
6 zipSync({
7 'index.html': strToU8('<html><head><title>Deck</title></head><body></body></html>'),
8 'page-1.html': strToU8('<html><body>Page 1</body></html>')
9 })
10
11 describe('slide-pack app archive detection', () => {
12 it('finds slides.zip inside a macOS app slide-pack package', () => {
13 const appZip = zipSync({
14 'Deck-macos-arm64.app/Contents/Info.plist': strToU8('<plist></plist>'),
15 'Deck-macos-arm64.app/Contents/MacOS/Deck-macos-arm64': strToU8('viewer'),
16 'Deck-macos-arm64.app/Contents/Resources/slides.zip': createDeckZip()
17 })
18
19 const deckZip = findSlidePackResourceZipInsideZip(appZip)
20
21 expect(deckZip).not.toBeNull()
22 expect(Object.keys(unzipSync(deckZip as Uint8Array)).sort()).toEqual([
23 'index.html',
24 'page-1.html'
25 ])
26 })
27
28 it('ignores app resource zips that are not importable slide decks', () => {
29 const appZip = zipSync({
30 'Deck-macos-arm64.app/Contents/Resources/slides.zip': zipSync({
31 'nested/index.html': strToU8('<html></html>')
32 })
33 })
34
35 expect(findSlidePackResourceZipInsideZip(appZip)).toBeNull()
36 })
37 })
38
38 lines TYPESCRIPT