Skip to content

test(frontend): add unit tests for WorkspaceComponent#4969

Open
Yicong-Huang wants to merge 2 commits intoapache:mainfrom
Yicong-Huang:test/workspace-component-spec
Open

test(frontend): add unit tests for WorkspaceComponent#4969
Yicong-Huang wants to merge 2 commits intoapache:mainfrom
Yicong-Huang:test/workspace-component-spec

Conversation

@Yicong-Huang
Copy link
Copy Markdown
Contributor

@Yicong-Huang Yicong-Huang commented May 6, 2026

What changes were proposed in this PR?

Replace the license-only placeholder spec with 19 unit tests covering WorkspaceComponent's public surface — pid parsing, cold/warm start, workflow loading (success / 403 / broken / URL fragment), view-count wiring, write-access from metadata, auto-persist idempotency, destroy-time persist + cleanup, and the copilot getter.

The fixture overrides the template to <div #codeEditor> so the heavyweight children don't compile in the test build, and stubs all 14 injected services.

Drop the spec from the exclude lists in tsconfig.spec.json and angular.json.

Any related issues, documentation, discussions?

Closes #4967.

How was this PR tested?

yarn ng test --watch=false: 267 pass, 8 skip, 2 todo. yarn format:ci clean.

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

Generated-by: Claude Opus 4.7 (1M context)

Closes apache#4967.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the frontend Changes related to the frontend GUI label May 6, 2026
Copy link
Copy Markdown
Contributor

@aglinxinyuan aglinxinyuan left a comment

Choose a reason for hiding this comment

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

The fixture overrides the component's template to a minimal <div #codeEditor>

Do we have to overrides the component's template to a minimal <div #codeEditor>? If we don't load children, the test cannot verify the side effects after loading them.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 41.17%. Comparing base (8b5dbf8) to head (234573e).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4969      +/-   ##
============================================
- Coverage     42.49%   41.17%   -1.33%     
  Complexity     2180     2180              
============================================
  Files          1005     1045      +40     
  Lines         37429    39853    +2424     
  Branches       3914     4201     +287     
============================================
+ Hits          15907    16409     +502     
- Misses        20558    22422    +1864     
- Partials        964     1022      +58     
Flag Coverage Δ
frontend 30.52% <ø> (-1.75%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aglinxinyuan aglinxinyuan requested a review from Copilot May 6, 2026 07:04
…cess, destroy paths in WorkspaceComponent

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 replaces the placeholder WorkspaceComponent spec with a real Vitest-based unit test suite and re-enables that spec in the frontend test build configuration, improving confidence in the workspace route’s initialization and workflow-loading behaviors.

Changes:

  • Implemented unit tests covering key WorkspaceComponent behaviors (ngOnInit, ngAfterViewInit, loadWorkflowWithId, triggerCenter, registerAutoPersistWorkflow, copilotEnabled) with service stubs and a minimal overridden template.
  • Updated frontend test configurations to stop excluding workspace.component.spec.ts so it is compiled and executed as part of ng test.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
frontend/src/app/workspace/component/workspace.component.spec.ts Adds a real unit test suite for WorkspaceComponent with mocked dependencies and a minimal template override.
frontend/src/tsconfig.spec.json Removes the workspace spec from the TypeScript spec exclude list so it compiles in test builds.
frontend/angular.json Removes the workspace spec from the Angular test exclude list so it runs under the unit-test builder.

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

locationMock = { go: vi.fn() };

TestBed.overrideComponent(WorkspaceComponent, {
set: { template: '<div #codeEditor class="stub-host"></div>', imports: [], providers: [] },
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.

If we don't load children, the test cannot verify the side effects after loading them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

code editor has other issue on tests. do you think we can enable it later? or maybe we can fix code editor's test first. WDYT?

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.

We can fix it later. Let's note it somewhere.

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 tests for WorkspaceComponent

4 participants