Skip to content

Conversation

@Acciolyy
Copy link

Summary

Add 6 unit tests that apply Modified Condition/Decision Coverage (MC/DC) to the function prepareElementsForExport (packages/excalidraw/data/index.ts).
The tests validate internal decisions (D1, D2a, D2b) and verify correct export behavior across main scenarios:
export all (fallback)
export selection with single frame
export selection with multiple elements
What changed

Added test file:
packages/excalidraw/tests/prepareElementsForExport.test.ts
No production code changes.
Tests use Vitest and vi.mock/vi.mocked to isolate dependencies (getSelectedElements, getElementsOverlappingFrame, isFrameLikeElement, cloneJSON, etc.).
Test cases implemented (mapping)

CT1 — A=V, B=V, multi-selection (D1 → D2b true)
CT2 — A=V, B=F (exportSelectionOnly true, but no valid selection)
CT3 — A=F, B=V (exportSelectionOnly false, selection exists — selection ignored)
CT4 — D2a single-frame (A=V, B=V, exportedElements.length === 1 && isFrameLike true)
CT5 — D2a single non-frame (A=V, B=F, exportedElements.length === 1 && isFrameLike false)
CT6 — fallback / export all (A=F, B=F)
MC/DC rationale (short)

Decisions covered:
D1: exportSelectionOnly && isSomeElementSelected(...)
D2a: exportedElements.length === 1 && isFrameLikeElement(...)
D2b: exportedElements.length > 1 (single-condition decision)
For D1 and D2a, MC/DC pairs were constructed so each atomic condition is shown to independently influence the decision outcome. D2b is covered with both true and false cases.
How to run locally

From repository root:
yarn test:app packages/excalidraw/tests/prepareElementsForExport.test.ts
or: npx vitest run packages/excalidraw/tests/prepareElementsForExport.test.ts --coverage
Expected: all tests pass (6 passed). Coverage HTML will be generated under coverage/lcov-report.
Notes about coverage & scope

Scope: tests focus exclusively on the method prepareElementsForExport. That method lives inside a larger module (packages/excalidraw/data/index.ts). As a result, the overall file coverage may remain low if other functions in the same file are not tested.
This is intentional: the assignment objective was to apply MC/DC to a chosen method. The coverage evidence included with this PR demonstrates the method’s lines are covered; the file-level percentage is shown for transparency.
If maintainers request higher file-level coverage, I can add follow-up tests to cover other functions in index.ts.
Files changed / where to review

packages/excalidraw/tests/prepareElementsForExport.test.ts
Comments inside the test file indicate: which condition(s) are exercised per test, the MC/DC pairs demonstrated, and main assertions.
Mocks: getSelectedElements, getElementsOverlappingFrame, isFrameLikeElement, cloneJSON.
Screenshots / artifacts (please attach to PR)

tests-result.png — terminal showing "6 passed"
coverage-after-function.png — HTML coverage view zoomed to prepareElementsForExport (lines showing green coverage)
coverage-after-index.png — file summary for packages/excalidraw/data/index.ts (transparency about file-level percent)
Suggested reviewer notes

Focus review on:
correctness of test scenarios vs decisions (D1, D2a, D2b)
appropriateness of mocks and assertions (exports & exportingFrame)
naming / readability of tests (I can rename IDs to match repo conventions if requested)
Checklist

Add 6 Vitest unit tests covering MC/DC for prepareElementsForExport
Use vi.mock/vi.mocked to isolate dependencies
Local coverage was generated and the method’s lines are covered (see attached HTML screenshot)
(Optional) Add broader tests to increase file-level coverage if requested

Thank you for reviewing — happy to iterate on test names, mocks, or assertions per maintainers’ feedback.

@vercel
Copy link

vercel bot commented Oct 31, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
excalidraw Ready Ready Preview Oct 31, 2025 6:08am

@vercel
Copy link

vercel bot commented Oct 31, 2025

@Acciolyy is attempting to deploy a commit to the Excalidraw Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant