apache / apache/texera

Add unit tests for AppComponent

Open
#5,472 2 comments 0 reactions 1 assignee Claimed by @sshiv012 View on GitHub
Dominant language
Scala
Stars
314
Forks
187
Avg merge
1d 21h
Merged PRs (30d)
214

Description

### Task Summary

`AppComponent` (`frontend/src/app/app.component.ts`) has no `*.spec.ts` file. It is the root shell component with one piece of logic: in the constructor it sets `configLoaded = true` if reading `config.env` succeeds, or `false` if accessing it throws. It also has a `retry()` method that reloads the page. Both are quick to test by stubbing `GuiConfigService`.

### What to do (step by step)

1. Create `frontend/src/app/app.component.spec.ts` with the Apache license header.
2. Provide a stubbed `GuiConfigService` with an `env` getter you can make succeed or throw.
3. Assert `configLoaded` for both cases.
4. For `retry()`, spy on `window.location.reload` (in jsdom you may need to redefine it; see tip below) and assert it is called. If reload is awkward to spy on in the test environment, it is acceptable to skip that single assertion and note why in the PR.
5. Run `yarn test -- app.component`, then `yarn lint`.

### Cover

- `configLoaded === true` when `config.env` returns normally.
- `configLoaded === false` when accessing `config.env` throws.
- `retry()` triggers a page reload (best-effort).

### Suggested providers / mocks

```ts
import { GuiConfigService } from "src/app/common/service/gui-config.service";

// success case:
{ provide: GuiConfigService, useValue: { get env() { return {}; } } }
// failure case:
{ provide: GuiConfigService, useValue: { get env() { throw new Error("not loaded"); } } }
```

Tip for `retry()`: `const reload = vi.fn(); Object.defineProperty(window, "location", { value: { reload }, writable: true });` then assert `reload` was called.

### Task Type

- [ ] Refactor / Cleanup
- [ ] DevOps / Deployment / CI
- [x] Testing / QA
- [ ] Documentation
- [ ] Performance
- [ ] Other

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.