apache / apache/texera

Add unit tests for FlarumComponent

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

Description

### Task Summary

`FlarumComponent` (`frontend/src/app/dashboard/component/user/flarum/flarum.component.ts`) has no `*.spec.ts` file. It is a 27-line component that builds a single `SafeResourceUrl` (`flarumUrl`) by passing `"forum"` through Angular's `DomSanitizer`. A short spec confirming the component is created and that the sanitizer is used is enough.

### What to do (step by step)

1. Create the spec next to the component, with the Apache license header.
2. Provide a mock `DomSanitizer` whose `bypassSecurityTrustResourceUrl` is a `vi.fn()` returning a sentinel value (e.g. `"SAFE_URL"`).
3. Assert the component is created, `bypassSecurityTrustResourceUrl` was called with `"forum"`, and `flarumUrl` is the sentinel value.
4. Run `yarn test -- flarum`, then `yarn lint`.

### Cover

- `should create`.
- `bypassSecurityTrustResourceUrl` is called with `"forum"`.
- `flarumUrl` equals the value returned by the sanitizer.

### Starter skeleton

```ts
//
import { ComponentFixture, TestBed } from "@angular/core/testing";
import { DomSanitizer } from "@angular/platform-browser";
import { FlarumComponent } from "./flarum.component";

describe("FlarumComponent", () => {
const sanitizerSpy = { bypassSecurityTrustResourceUrl: vi.fn().mockReturnValue("SAFE_URL") };
let component: FlarumComponent;
let fixture: ComponentFixture;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [FlarumComponent],
providers: [{ provide: DomSanitizer, useValue: sanitizerSpy }],
}).compileComponents();
fixture = TestBed.createComponent(FlarumComponent);
component = fixture.componentInstance;
});

it("builds a trusted forum url", () => {
expect(component).toBeTruthy();
expect(sanitizerSpy.bypassSecurityTrustResourceUrl).toHaveBeenCalledWith("forum");
expect(component.flarumUrl).toBe("SAFE_URL");
});
});
```

### 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.