Skip to content

test(frontend): add unit tests for FileSaverService - #9045

Open
Ma77Ball wants to merge 11 commits into
apache:mainfrom
Ma77Ball:test/file-saver-service-spec
Open

Ma77Ball wants to merge 11 commits into
apache:mainfrom
Ma77Ball:test/file-saver-service-spec

Conversation

@Ma77Ball

@Ma77Ball Ma77Ball commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

  • Adds a Vitest spec for FileSaverService, the thin wrapper whose saveAs(data, filename?, options?) forwards straight to the file-saver library's saveAs.
  • Mocks the file-saver library so the suite can assert the call is forwarded unchanged: a Blob payload passes through with its filename and options, and a string payload (such as a URL) passes through.
  • Asserts that an omitted filename and options arrive as undefined, and that an error thrown by the underlying saveAs propagates to the caller instead of being swallowed.

Any related issues, documentation, discussions?

Closes: #6448
Supersedes #6460, which the stale bot auto-closed for inactivity. The branch is now merged up to current main.

How was this PR tested?

  • Run cd frontend && npx ng test --include="**/file-saver.service.spec.ts" --watch=false, expect the FileSaverService suite to pass.
  • Confirm the forwarding cases hold: a Blob and a string payload each reach the mocked saveAs unchanged, an omitted filename and options arrive as undefined, and a thrown error surfaces to the caller.

Was this PR authored or co-authored using generative AI tooling?

Co-authored with Claude Opus 4.8 in compliance with ASF

Ma77Ball and others added 9 commits July 16, 2026 03:24
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Xinyuan Lin <xinyual3@uci.edu>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Updates the branch to current main and carries its single net change, a Vitest spec for FileSaverService.

- FileSaverService is a thin wrapper whose saveAs(data, filename?, options?) forwards straight to the file-saver library's saveAs; the spec mocks that library and asserts the call is forwarded unchanged. It covers a Blob payload passed through with its filename and options, a string payload such as a URL passed through, omitted filename and options arriving as undefined, and an error thrown by saveAs propagating to the caller instead of being swallowed.
@github-actions github-actions Bot added the frontend Changes related to the frontend GUI label Oct 20, 2026
@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Automated Reviewer Suggestions

Based on the git blame history of the changed files, we recommend the following reviewers:

  • Contributors with relevant context: @aglinxinyuan
    You can notify them by mentioning @aglinxinyuan in a comment.

@codecov-commenter

codecov-commenter commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.93%. Comparing base (e1d676d) to head (f71c43c).
⚠️ Report is 52 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #9045      +/-   ##
============================================
+ Coverage     91.87%   91.93%   +0.06%     
+ Complexity     5048     5046       -2     
============================================
  Files          1265     1273       +8     
  Lines         54915    55266     +351     
  Branches       6940     6989      +49     
============================================
+ Hits          50452    50810     +358     
+ Misses         2769     2763       -6     
+ Partials       1694     1693       -1     
Flag Coverage Δ *Carryforward flag
access-control-service 77.38% <ø> (ø) Carriedforward from d1d2885
agent-service 99.16% <ø> (ø) Carriedforward from d1d2885
amber 86.14% <ø> (+0.08%) ⬆️ Carriedforward from d1d2885
computing-unit-managing-service 60.48% <ø> (ø) Carriedforward from d1d2885
config-service 87.37% <ø> (ø) Carriedforward from d1d2885
file-service 82.00% <ø> (ø) Carriedforward from d1d2885
frontend 96.47% <100.00%> (-0.03%) ⬇️
notebook-migration-service 83.73% <ø> (ø) Carriedforward from d1d2885
pyamber 98.57% <ø> (+0.03%) ⬆️ Carriedforward from d1d2885
workflow-compiling-service 72.43% <ø> (ø) Carriedforward from d1d2885

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aglinxinyuan

Copy link
Copy Markdown
Contributor

Please fix the ci.

… delegate

FileSaverService holds its reference to file-saver's `saveAs` in a
`protected saveAsFn` instance property that defaults to
`FileSaver.saveAs`, and its public `saveAs(data, filename?, options?)`
calls `this.saveAsFn(data, filename, options)`. Routing the one call-out
through an own property gives tests a boundary they can replace per
instance, without touching the file-saver module.

The spec injects FileSaverService via TestBed, assigns a fresh `vi.fn()`
to the instance's `saveAsFn` in `beforeEach`, and drives the public
`saveAs`: it checks the service is created, that a Blob payload is
forwarded with its filename and options, that a string payload passes
through unchanged, that an omitted filename and options arrive as
`undefined`, and that an error thrown by `saveAsFn` propagates out of
`saveAs` rather than being swallowed.

Replacing the instance property is independent of module resolution and
bundling, unlike the previous `vi.mock("file-saver")`, which did not
reach the copy the service imports once the runner bundled the CommonJS
module across the full suite.

This branch has not been deployed

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

Labels

frontend Changes related to the frontend GUI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add frontend unit tests for FileSaverService

3 participants