diff --git a/tests/helpers/load-plugin-modules.mjs b/tests/helpers/load-plugin-modules.mjs index cb3e5bf..58d9178 100644 --- a/tests/helpers/load-plugin-modules.mjs +++ b/tests/helpers/load-plugin-modules.mjs @@ -76,6 +76,7 @@ export async function bundleSource(entry, outputName, external = [], plugins = [ return outfile; } +let slideInsertionsModulePromise; let textUtilsModulePromise; let idleScheduleModulePromise; @@ -637,3 +638,11 @@ export function loadDocxEmbedLoaderModule() { }); return docxEmbedLoaderModulePromise; } + +export function loadSlideInsertionsModule() { + slideInsertionsModulePromise ??= bundleSource( + "src/SlideInsertions.ts", + "slide-insertions.cjs", + ).then((outfile) => require(outfile)); + return slideInsertionsModulePromise; +} diff --git a/tests/slide-insertions.test.mjs b/tests/slide-insertions.test.mjs new file mode 100644 index 0000000..feff5d1 --- /dev/null +++ b/tests/slide-insertions.test.mjs @@ -0,0 +1,67 @@ +import assert from "node:assert/strict"; +import { test } from "node:test"; +import { loadSlideInsertionsModule } from "./helpers/load-plugin-modules.mjs"; + +test("buildDuplicateSlideOrder builds correct order array", async () => { + const { buildDuplicateSlideOrder } = await loadSlideInsertionsModule(); + + // slideCount, sourceIndex, insertedIdx + // e.g., slides 0, 1, 2. We duplicate 1, inserting it at index 2. + // The slides were [0, 1, 2], so the new order should refer to old slides: [0, 1, 1, 2] -> 0 is old 0, 1 is old 1, 2 is old 1, 3 is old 2. + assert.deepEqual(buildDuplicateSlideOrder(4, 1, 2), [0, 1, 1, 2]); + + // Duplicating the first slide (index 0) and inserting at index 1 + assert.deepEqual(buildDuplicateSlideOrder(2, 0, 1), [0, 0]); + + // Duplicating the last slide in a 3-slide deck (source=2, inserted at 3), total count will be 4 + assert.deepEqual(buildDuplicateSlideOrder(4, 2, 3), [0, 1, 2, 2]); +}); + +test("countSlideTopLevelShapes returns correct number of top level shapes", async () => { + const { countSlideTopLevelShapes } = await loadSlideInsertionsModule(); + + const xml0 = ` + + + + + + + + + `; + assert.equal(countSlideTopLevelShapes(xml0, "ppt/slides/slide1.xml"), 0); + + const xml2 = ` + + + + + + + + + + + `; + assert.equal(countSlideTopLevelShapes(xml2, "ppt/slides/slide2.xml"), 2); + + const xmlWithGroups = ` + + + + + + + + + + + + + + + `; + // Expected to count , , and as top-level children of the spTree + assert.equal(countSlideTopLevelShapes(xmlWithGroups, "ppt/slides/slide3.xml"), 3); +});