test(frontend): route specs through HttpClientTestingModule and lint-enforce it#5185
Merged
Yicong-Huang merged 2 commits intoMay 24, 2026
Merged
Conversation
`operator-reuse-cache-status.service.spec.ts`, `operator-menu.service.spec.ts`,
`execute-workflow.service.spec.ts`, and `user-computing-unit.component.spec.ts`
each wired the real Angular `HttpClient` rather than the testing variant —
either by importing `HttpClientModule`, providing `HttpClient` directly, or
hand-rolling a `StubHttpClient` that returns `of("a")` for every `post`. That
left the specs one missing mock away from a real network call in CI and drifted
from the convention in `frontend/TESTING.md`.
Swap each over to `HttpClientTestingModule`:
- The two `HttpClientModule` cases become a one-line import swap.
- `execute-workflow.service.spec.ts` drops the in-file `StubHttpClient`
entirely and the now-unused `Observable` import; the testing module supplies
`HttpClient` directly.
- `user-computing-unit.component.spec.ts` moves `HttpClient` out of `providers`
and pulls `HttpClientTestingModule` into `imports`.
All four specs (20 tests) continue to pass.
Closes apache#5182
Add an `*.spec.ts` override to `frontend/.eslintrc.json` so the anti-pattern that apache#5183 just swept the repo of can't grow back: - `no-restricted-imports` blocks `HttpClientModule` from `@angular/common/http` in specs. HttpClientTestingModule is the only legitimate way to wire HttpClient into a unit test. - `no-restricted-syntax` flags `HttpClient` listed as a bare provider inside a `providers: [...]` array. HttpClientTestingModule (in `imports`) already supplies HttpClient; layering the real one on top of that overrides the testing backend. The rule fires on five more specs that apache#5183 missed — each one had either redundant `HttpClientModule` imports or a stale `HttpClient` provider sitting next to a working `HttpClientTestingModule`. Clean those up so `yarn lint` stays green: - `user-avatar.component.spec.ts` — drop the redundant `HttpClientModule` from imports. - `user-workflow.component.spec.ts`, `coeditor-user-icon.component.spec.ts`, `coeditor-presence.service.spec.ts` — drop the bare `HttpClient` provider and the now-unused import. - `operator-metadata.service.spec.ts` — drop the bare `HttpClient` provider. The import stays because the spec injects HttpClient via `TestBed.inject(HttpClient)` to talk to HttpTestingController. All nine touched specs (37 tests) continue to pass. Closes apache#5184
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5185 +/- ##
=========================================
Coverage 43.71% 43.71%
Complexity 2218 2218
=========================================
Files 1049 1049
Lines 40578 40578
Branches 4327 4327
=========================================
Hits 17739 17739
Misses 21733 21733
Partials 1106 1106
*This pull request uses carry forward flags. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This was referenced May 24, 2026
aglinxinyuan
approved these changes
May 24, 2026
github-merge-queue Bot
pushed a commit
that referenced
this pull request
May 24, 2026
… specs (#5189) ### What changes were proposed in this PR? Three coordinated passes against the "specs that replace the parent template at test time" anti-pattern: 1. **`frontend/TESTING.md`**: anti-patterns 2 and 3 are rewritten to describe what actually goes wrong (the real `.component.html` never executes, so v8 coverage stays at 0%), and a new Recipe F + anti-pattern 8 cover the right way to handle a heavy child component when one truly cannot be instantiated — additive `overrideComponent({ remove, add })` with a minimal stub child. 2. **Spec cleanups**: every spec that carried `template: ""`, a stub-markup template substitute, `NO_ERRORS_SCHEMA`, or the broader `set: { imports: [], schemas: [...] }` override is migrated to render the real template. Two specs (Formly-driven and the full WorkspaceComponent) keep the old shape behind a scoped `eslint-disable` with a TODO; both need a more thorough redesign that isn't in scope here. 3. **ESLint guardrail**: an `*.spec.ts` override in `.eslintrc.json` blocks the patterns going forward — `NO_ERRORS_SCHEMA` imports from `@angular/core`, any `template` or `imports` key inside `overrideComponent({ set: ... })`. Each rule's message points at the right replacement. ### Any related issues, documentation, discussions? Closes #5188. Builds on the testing guide introduced in #5170 and the lint-guardrail pattern from #5185. ### How was this PR tested? `yarn ng test --watch=false --include=…` over the touched specs runs 13 files / 108 tests, all green. `yarn lint` and `yarn format:ci` both clean. The three template files that originally pinned at 0% — `preset-wrapper.component.html`, `operator-menu.component.html`, `menu.component.html` — now report 44 / 79 / 59% line coverage under the new shape. ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Claude Opus 4.7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this PR?
Two passes against the same anti-pattern — specs that wire the real Angular
HttpClientinstead of routing throughHttpClientTestingModule:HttpClientModule, listingHttpClientas a bare provider, or hand-rolling anHttpClientstub over toHttpClientTestingModule.*.spec.tsoverride tofrontend/.eslintrc.jsonso the pattern can't grow back.no-restricted-importsblocksHttpClientModule;no-restricted-syntaxflagsHttpClientas a bare provider entry. Type usage (let h: HttpClient) andTestBed.inject(HttpClient)remain allowed.The lint rule is what surfaced the last five offenders — the original grep audit missed them because they imported
HttpClientTestingModulealongside the offending provider or import.Any related issues, documentation, discussions?
Closes #5182, closes #5184.
How was this PR tested?
yarn lintexits 0;yarn format:ciclean.yarn ng test --watch=false --include=…on every touched spec passes locally.Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 4.7