|
| 1 | +/** |
| 2 | + * @vitest-environment jsdom |
| 3 | + */ |
| 4 | +import { describe, expect, it } from 'vitest' |
| 5 | +import { buildPresentation } from '@/lib/pptx-renderer/model/presentation' |
| 6 | +import type { PptxFiles } from '@/lib/pptx-renderer/parser/zip-parser' |
| 7 | + |
| 8 | +function createFiles(presentation: string): PptxFiles { |
| 9 | + return { |
| 10 | + contentTypes: '<Types />', |
| 11 | + presentation, |
| 12 | + presentationRels: `<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"> |
| 13 | + <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide" Target="slides/slide1.xml" /> |
| 14 | + <Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide" Target="slides/slide2.xml" /> |
| 15 | + </Relationships>`, |
| 16 | + slides: new Map([ |
| 17 | + ['ppt/slides/slide1.xml', createSlideXml()], |
| 18 | + ['ppt/slides/slide2.xml', createSlideXml()], |
| 19 | + ]), |
| 20 | + slideRels: new Map([ |
| 21 | + ['ppt/slides/_rels/slide1.xml.rels', '<Relationships />'], |
| 22 | + ['ppt/slides/_rels/slide2.xml.rels', '<Relationships />'], |
| 23 | + ]), |
| 24 | + slideLayouts: new Map(), |
| 25 | + slideLayoutRels: new Map(), |
| 26 | + slideMasters: new Map(), |
| 27 | + slideMasterRels: new Map(), |
| 28 | + themes: new Map(), |
| 29 | + media: new Map(), |
| 30 | + charts: new Map(), |
| 31 | + chartStyles: new Map(), |
| 32 | + chartColors: new Map(), |
| 33 | + diagramDrawings: new Map(), |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +function createPresentationXml(markers = ''): string { |
| 38 | + return `<p:presentation xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" ${markers}> |
| 39 | + <p:sldSz cx="9144000" cy="5143500" /> |
| 40 | + <p:sldIdLst> |
| 41 | + <p:sldId id="256" r:id="rId2" /> |
| 42 | + <p:sldId id="257" r:id="rId1" /> |
| 43 | + </p:sldIdLst> |
| 44 | + </p:presentation>` |
| 45 | +} |
| 46 | + |
| 47 | +function createSlideXml(): string { |
| 48 | + return `<p:sld xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main"> |
| 49 | + <p:cSld> |
| 50 | + <p:spTree> |
| 51 | + <p:nvGrpSpPr><p:cNvPr id="1" name="" /><p:cNvGrpSpPr /><p:nvPr /></p:nvGrpSpPr> |
| 52 | + <p:grpSpPr /> |
| 53 | + </p:spTree> |
| 54 | + </p:cSld> |
| 55 | + </p:sld>` |
| 56 | +} |
| 57 | + |
| 58 | +describe('buildPresentation', () => { |
| 59 | + it('does not treat the standard wps namespace prefix as WPS Office', () => { |
| 60 | + const presentation = buildPresentation( |
| 61 | + createFiles( |
| 62 | + createPresentationXml( |
| 63 | + 'xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape"' |
| 64 | + ) |
| 65 | + ) |
| 66 | + ) |
| 67 | + |
| 68 | + expect(presentation.isWps).toBe(false) |
| 69 | + }) |
| 70 | + |
| 71 | + it('orders slides by relationship id instead of numeric slide id', () => { |
| 72 | + const presentation = buildPresentation(createFiles(createPresentationXml())) |
| 73 | + |
| 74 | + expect(presentation.slides.map((slide) => slide.slidePath)).toEqual([ |
| 75 | + 'ppt/slides/slide2.xml', |
| 76 | + 'ppt/slides/slide1.xml', |
| 77 | + ]) |
| 78 | + }) |
| 79 | +}) |
0 commit comments