apache / apache/texera

Add unit tests for RegistrationRequestModalComponent

Open
#5,467 3 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

`RegistrationRequestModalComponent` (`frontend/src/app/common/service/user/registration-request-modal/registration-request-modal.component.ts`) has no `*.spec.ts` file. It is a small form modal with no service dependencies. It seeds `name` and `email` from the injected `NZ_MODAL_DATA`, and `getValues()` returns the trimmed `affiliation` and `reason`. Both are easy to test directly.

### What to do (step by step)

1. Create the spec file next to the component, with the Apache license header.
2. Provide `NZ_MODAL_DATA` with `{ uid, email, name }`.
3. Assert constructor seeding and `getValues()` trimming behavior.
4. Run `yarn test -- registration-request-modal`, then `yarn lint`.

### Cover

- `should create`.
- Constructor copies `data.name` into `name` and `data.email` into `email`.
- Constructor handles a null/empty `data` gracefully (`name`/`email` become `""`). (You can test this by providing `NZ_MODAL_DATA` as `null`.)
- `getValues()` trims whitespace: set `component.affiliation = " UCI "` and `component.reason = " hi "`, expect `{ affiliation: "UCI", reason: "hi" }`.

### Starter skeleton

```ts
//
import { TestBed } from "@angular/core/testing";
import { NZ_MODAL_DATA } from "ng-zorro-antd/modal";
import { RegistrationRequestModalComponent } from "./registration-request-modal.component";

function setup(data: any) {
TestBed.configureTestingModule({
imports: [RegistrationRequestModalComponent],
providers: [{ provide: NZ_MODAL_DATA, useValue: data }],
});
const fixture = TestBed.createComponent(RegistrationRequestModalComponent);
return fixture.componentInstance;
}

describe("RegistrationRequestModalComponent", () => {
it("seeds name and email from modal data", () => {
const c = setup({ uid: 1, email: "a@b.c", name: "Ada" });
expect(c.name).toBe("Ada");
expect(c.email).toBe("a@b.c");
});

it("trims affiliation and reason in getValues()", () => {
const c = setup({ uid: 1, email: "", name: "" });
c.affiliation = " UCI ";
c.reason = " hi ";
expect(c.getValues()).toEqual({ affiliation: "UCI", reason: "hi" });
});
});
```

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