Skip to content

test(frontend): route four specs through HttpClientTestingModule#5183

Closed
Yicong-Huang wants to merge 2 commits into
apache:mainfrom
Yicong-Huang:test/use-http-client-testing-module
Closed

test(frontend): route four specs through HttpClientTestingModule#5183
Yicong-Huang wants to merge 2 commits into
apache:mainfrom
Yicong-Huang:test/use-http-client-testing-module

Conversation

@Yicong-Huang
Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

Four specs wired the real Angular HttpClient rather than the testing variant — either by importing HttpClientModule, providing HttpClient directly, or hand-rolling a StubHttpClient that returned 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.

Each spec is now routed through HttpClientTestingModule:

  • operator-reuse-cache-status.service.spec.ts / operator-menu.service.spec.ts — one-line import swap from @angular/common/http (HttpClientModule) to @angular/common/http/testing (HttpClientTestingModule).
  • execute-workflow.service.spec.ts — drops the in-file StubHttpClient and its Observable import; the testing module now supplies HttpClient.
  • user-computing-unit.component.spec.ts — moves HttpClient out of providers and pulls HttpClientTestingModule into imports.

Any related issues, documentation, discussions?

Closes #5182. The rule itself is documented in frontend/TESTING.md (introduced in #5170).

How was this PR tested?

yarn ng test --watch=false --include=… against the four affected specs locally: 4 files, 20 tests, all pass. yarn format:ci clean.

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

Generated-by: Claude Opus 4.7

`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
@github-actions github-actions Bot added the frontend Changes related to the frontend GUI label May 24, 2026
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 43.71%. Comparing base (b228d51) to head (68c9f2c).

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #5183   +/-   ##
=========================================
  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           
Flag Coverage Δ *Carryforward flag
access-control-service 39.53% <ø> (ø) Carriedforward from b228d51
agent-service 33.76% <ø> (ø) Carriedforward from b228d51
amber 44.17% <ø> (ø) Carriedforward from b228d51
computing-unit-managing-service 0.00% <ø> (ø) Carriedforward from b228d51
config-service 0.00% <ø> (ø) Carriedforward from b228d51
file-service 32.18% <ø> (ø) Carriedforward from b228d51
frontend 35.18% <ø> (ø)
python 90.50% <ø> (ø) Carriedforward from b228d51
workflow-compiling-service 56.81% <ø> (ø) Carriedforward from b228d51

*This pull request uses carry forward flags. 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.

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
@Yicong-Huang
Copy link
Copy Markdown
Contributor Author

Consolidated into #5185 — the lint guardrail and the extra spec cleanups it surfaced live in the same branch as this PR's data fix, so reviewing the whole anti-pattern (cleanup + prevention) in one place is simpler.

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.

Four frontend specs bypass HttpClientTestingModule

2 participants