From 2d0a87495956163c7aa7cf38f5777875333ebe55 Mon Sep 17 00:00:00 2001 From: MarsLuay <70299537+MarsLuay@users.noreply.github.com> Date: Sun, 6 Sep 2026 04:35:25 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=A7=AA=20Create=20test=20file=20for?= =?UTF-8?q?=20src/SlideInsertions.ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addresses missing unit test coverage for utility functions in `src/SlideInsertions.ts`. Added test loader module hooks in `tests/helpers/load-plugin-modules.mjs` and wrote test cases in `tests/slide-insertions.test.mjs` covering `buildDuplicateSlideOrder` and `countSlideTopLevelShapes` to ensure logical robustness. --- tests/helpers/load-plugin-modules.mjs | 9 ++++ tests/slide-insertions.test.mjs | 67 +++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 tests/slide-insertions.test.mjs 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); +}); From e17accc76671c10b603130920dc771a2bc1db263 Mon Sep 17 00:00:00 2001 From: MarsLuay <70299537+MarsLuay@users.noreply.github.com> Date: Sun, 6 Sep 2026 05:49:38 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A7=AA=20Create=20test=20file=20for?= =?UTF-8?q?=20src/SlideInsertions.ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addresses missing unit test coverage for utility functions in `src/SlideInsertions.ts`. Added test loader module hooks in `tests/helpers/load-plugin-modules.mjs` and wrote test cases in `tests/slide-insertions.test.mjs` covering `buildDuplicateSlideOrder` and `countSlideTopLevelShapes` to ensure logical robustness.