Skip to content

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

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

Ma77Ball wants to merge 10 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

Copy link
Copy Markdown
Contributor

Automated Reviewer Suggestions

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

  • No candidates found from git blame history.

@codecov-commenter

codecov-commenter commented Oct 20, 2026 •

Copy link
Copy Markdown

❌ 5 Tests Failed:

Tests completed Failed Passed Skipped
6832 5 6827 1
View the top 3 failed test(s) by shortest run time
src/app/dashboard/service/user/file/file-saver.service.spec.ts > FileSaverService > passes undefined through when filename and options are omitted
Stack Traces | 0.00296s run time
AssertionError: expected "vi.fn()" to be called with arguments: [ Blob{ …(1) }, undefined, undefined ]

Number of calls: 0

 ❯ .../user/file/file-saver.service.spec.ts:71:20
 ❯ src/test-zone-setup.ts:90:33
 ❯ _ZoneDelegate.invoke node_modules/zone.js/fesm2015/zone.js:398:28
 ❯ ProxyZoneSpec.onInvoke node_modules/zone.js/fesm2015/zone-testing.js:2132:39
 ❯ _ZoneDelegate.invoke node_modules/zone.js/fesm2015/zone.js:397:34
 ❯ ZoneImpl.run node_modules/zone.js/fesm2015/zone.js:113:43
 ❯ src/test-zone-setup.ts:88:16
src/app/dashboard/service/user/file/file-saver.service.spec.ts > FileSaverService > propagates errors thrown by saveAs
Stack Traces | 0.00304s run time
AssertionError: expected function to throw an error, but it didn't
 ❯ .../user/file/file-saver.service.spec.ts:63:57
 ❯ src/test-zone-setup.ts:90:33
 ❯ _ZoneDelegate.invoke node_modules/zone.js/fesm2015/zone.js:398:28
 ❯ ProxyZoneSpec.onInvoke node_modules/zone.js/fesm2015/zone-testing.js:2132:39
 ❯ _ZoneDelegate.invoke node_modules/zone.js/fesm2015/zone.js:397:34
 ❯ ZoneImpl.run node_modules/zone.js/fesm2015/zone.js:113:43
 ❯ src/test-zone-setup.ts:88:16
 ❯ new ZoneAwarePromise node_modules/zone.js/fesm2015/zone.js:2701:25
 ❯ wrapper src/test-zone-setup.ts:86:16
 ❯ src/test-zone-setup.ts:90:33
src/app/dashboard/service/user/file/file-saver.service.spec.ts > FileSaverService > propagates errors thrown by saveAs instead of swallowing them
Stack Traces | 0.0036s run time
AssertionError: expected function to throw an error, but it didn't
 ❯ .../user/file/file-saver.service.spec.ts:80:66
 ❯ src/test-zone-setup.ts:90:33
 ❯ _ZoneDelegate.invoke node_modules/zone.js/fesm2015/zone.js:398:28
 ❯ ProxyZoneSpec.onInvoke node_modules/zone.js/fesm2015/zone-testing.js:2132:39
 ❯ _ZoneDelegate.invoke node_modules/zone.js/fesm2015/zone.js:397:34
 ❯ ZoneImpl.run node_modules/zone.js/fesm2015/zone.js:113:43
 ❯ src/test-zone-setup.ts:88:16
 ❯ new ZoneAwarePromise node_modules/zone.js/fesm2015/zone.js:2701:25
 ❯ wrapper src/test-zone-setup.ts:86:16
 ❯ src/test-zone-setup.ts:90:33
src/app/dashboard/service/user/file/file-saver.service.spec.ts > FileSaverService > forwards a string payload (e.g. a URL) unchanged
Stack Traces | 0.00433s run time
AssertionError: expected "vi.fn()" to be called with arguments: [ Array(3) ]

Number of calls: 0

 ❯ .../user/file/file-saver.service.spec.ts:54:20
 ❯ src/test-zone-setup.ts:90:33
 ❯ _ZoneDelegate.invoke node_modules/zone.js/fesm2015/zone.js:398:28
 ❯ ProxyZoneSpec.onInvoke node_modules/zone.js/fesm2015/zone-testing.js:2132:39
 ❯ _ZoneDelegate.invoke node_modules/zone.js/fesm2015/zone.js:397:34
 ❯ ZoneImpl.run node_modules/zone.js/fesm2015/zone.js:113:43
 ❯ src/test-zone-setup.ts:88:16
src/app/dashboard/service/user/file/file-saver.service.spec.ts > FileSaverService > delegates a Blob payload to saveAs with filename and options
Stack Traces | 0.00484s run time
AssertionError: expected "vi.fn()" to be called 1 times, but got 0 times
 ❯ .../user/file/file-saver.service.spec.ts:47:20
 ❯ src/test-zone-setup.ts:90:33
 ❯ _ZoneDelegate.invoke node_modules/zone.js/fesm2015/zone.js:398:28
 ❯ ProxyZoneSpec.onInvoke node_modules/zone.js/fesm2015/zone-testing.js:2132:39
 ❯ _ZoneDelegate.invoke node_modules/zone.js/fesm2015/zone.js:397:34
 ❯ ZoneImpl.run node_modules/zone.js/fesm2015/zone.js:113:43
 ❯ src/test-zone-setup.ts:88:16
 ❯ new ZoneAwarePromise node_modules/zone.js/fesm2015/zone.js:2701:25
 ❯ wrapper src/test-zone-setup.ts:86:16
 ❯ src/test-zone-setup.ts:90:33

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@aglinxinyuan

Copy link
Copy Markdown
Contributor

Please fix the ci.

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