Skip to content

test(frontend): add unit tests for storage util - #6620

Merged
aglinxinyuan merged 1 commit into
apache:mainfrom
Ma77Ball:test/storage-util-spec
Jul 20, 2026
Merged

test(frontend): add unit tests for storage util#6620
aglinxinyuan merged 1 commit into
apache:mainfrom
Ma77Ball:test/storage-util-spec

Conversation

@Ma77Ball

@Ma77Ball Ma77Ball commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

  • Add frontend/src/app/common/util/storage.spec.ts, a new Vitest spec for storage.ts, which previously had no dedicated unit tests.
  • Cover the localStorage helpers (localSetObject/localGetObject/localRemoveObject) and sessionStorage helpers (sessionSetObject/sessionGetObject/sessionRemoveObject) across set, get, and remove round-trips.
  • Cover the edge branches: absent key returns null, empty-string and other falsy values, and the invalid-JSON parse path that throws.
  • Cover jsonCast for well-formed and malformed input, using mocked storage globals so the tests are deterministic and isolated.

Any related issues, documentation, discussions?

Closes: #6619

How was this PR tested?

  • Run: cd frontend && node --max-old-space-size=8192 ./node_modules/nx/dist/bin/nx.js test gui --watch=false --include=src/app/common/util/storage.spec.ts, expect all 12 tests passing.
  • Test-only change; no production code is modified.

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

Co-authored with Claude Opus 4.8 in compliance with ASF

@github-actions github-actions Bot added the frontend Changes related to the frontend GUI label Jul 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.

@aglinxinyuan
aglinxinyuan requested a review from Copilot July 20, 2026 21:41

@aglinxinyuan aglinxinyuan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds Vitest unit-test coverage for the frontend browser storage utility helpers in storage.ts, addressing issue #6619 by validating expected behaviors for localStorage/sessionStorage wrappers and jsonCast.

Changes:

  • Add a new storage.spec.ts covering localSetObject/localGetObject/localRemoveObject and sessionSetObject/sessionGetObject/sessionRemoveObject.
  • Add tests for jsonCast success and invalid-JSON throw behavior.
  • Use deterministic mocked localStorage/sessionStorage via vi.stubGlobal to isolate tests from the runtime environment.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@aglinxinyuan
aglinxinyuan added this pull request to the merge queue Jul 20, 2026
Merged via the queue into apache:main with commit 3087334 Jul 20, 2026
29 checks passed
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 unit test coverage for storage util

3 participants