|
1 | 1 | import { existsSync, mkdtempSync, rmSync } from 'node:fs'; |
2 | 2 | import { tmpdir } from 'node:os'; |
3 | 3 | import { join } from 'node:path'; |
4 | | -import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'; |
| 4 | +import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; |
5 | 5 | import { exportPptx, extractSlides } from './pptx'; |
6 | 6 |
|
7 | 7 | const pngBytes = Buffer.from( |
@@ -30,6 +30,10 @@ let tempDir = ''; |
30 | 30 |
|
31 | 31 | beforeAll(() => { |
32 | 32 | tempDir = mkdtempSync(join(tmpdir(), 'codesign-pptx-test-')); |
| 33 | +}); |
| 34 | + |
| 35 | +beforeEach(() => { |
| 36 | + vi.clearAllMocks(); |
33 | 37 | launchMock.mockResolvedValue({ |
34 | 38 | newPage: newPageMock, |
35 | 39 | close: closeMock, |
@@ -131,6 +135,46 @@ describe('exportPptx', () => { |
131 | 135 | ); |
132 | 136 | }); |
133 | 137 |
|
| 138 | + it('uses slide-like containers when section elements are absent', async () => { |
| 139 | + querySectionsMock.mockImplementation(async (selector: string) => |
| 140 | + selector === 'section' ? [] : [{ boundingBox: sectionBoundingBoxMock }], |
| 141 | + ); |
| 142 | + const dest = join(tempDir, 'slide-class-visual.pptx'); |
| 143 | + |
| 144 | + await exportPptx('<div class="slide"><h1>Visual</h1></div>', dest); |
| 145 | + |
| 146 | + expect(querySectionsMock).toHaveBeenNthCalledWith(1, 'section'); |
| 147 | + expect(querySectionsMock).toHaveBeenNthCalledWith(2, '[data-slide], [data-pptx-slide], .slide'); |
| 148 | + expect(screenshotMock).toHaveBeenCalledWith( |
| 149 | + expect.objectContaining({ type: 'png', clip: expect.any(Object) }), |
| 150 | + ); |
| 151 | + }); |
| 152 | + |
| 153 | + it('paginates sectionless documents into viewport-sized screenshots', async () => { |
| 154 | + querySectionsMock.mockResolvedValue([]); |
| 155 | + evaluateMock.mockImplementation(async (source: unknown) => |
| 156 | + typeof source === 'function' ? { pageCount: 3 } : undefined, |
| 157 | + ); |
| 158 | + const dest = join(tempDir, 'sectionless-visual.pptx'); |
| 159 | + |
| 160 | + await exportPptx('<main><h1>Long artifact</h1></main>', dest); |
| 161 | + |
| 162 | + expect(screenshotMock).toHaveBeenCalledTimes(3); |
| 163 | + expect(screenshotMock).toHaveBeenNthCalledWith(1, { |
| 164 | + type: 'png', |
| 165 | + clip: { x: 0, y: 0, width: 1280, height: 720 }, |
| 166 | + }); |
| 167 | + expect(screenshotMock).toHaveBeenNthCalledWith(2, { |
| 168 | + type: 'png', |
| 169 | + clip: { x: 0, y: 720, width: 1280, height: 720 }, |
| 170 | + }); |
| 171 | + expect(screenshotMock).toHaveBeenNthCalledWith(3, { |
| 172 | + type: 'png', |
| 173 | + clip: { x: 0, y: 1440, width: 1280, height: 720 }, |
| 174 | + }); |
| 175 | + expect(screenshotMock).not.toHaveBeenCalledWith(expect.objectContaining({ fullPage: true })); |
| 176 | + }); |
| 177 | + |
134 | 178 | it('wraps JSX source before screenshotting PPTX slides', async () => { |
135 | 179 | setContentMock.mockClear(); |
136 | 180 | const dest = join(tempDir, 'jsx-visual.pptx'); |
|
0 commit comments