test(frontend): add unit tests for WorkspaceComponent#4969
test(frontend): add unit tests for WorkspaceComponent#4969Yicong-Huang wants to merge 2 commits intoapache:mainfrom
Conversation
Closes apache#4967. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
aglinxinyuan
left a comment
There was a problem hiding this comment.
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 Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…cess, destroy paths in WorkspaceComponent Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
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
WorkspaceComponentbehaviors (ngOnInit,ngAfterViewInit,loadWorkflowWithId,triggerCenter,registerAutoPersistWorkflow,copilotEnabled) with service stubs and a minimal overridden template. - Updated frontend test configurations to stop excluding
workspace.component.spec.tsso it is compiled and executed as part ofng 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: [] }, |
There was a problem hiding this comment.
If we don't load children, the test cannot verify the side effects after loading them.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
We can fix it later. Let's note it somewhere.
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.jsonandangular.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:ciclean.Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 4.7 (1M context)