Skip to content

Commit 5b34f10

Browse files
Fix and append to frontend tests
1 parent 186583c commit 5b34f10

8 files changed

Lines changed: 78 additions & 33 deletions

File tree

frontend/src/app/annotate/annotation-input/annotation-input.component.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ describe("AnnotationInputComponent", () => {
5050
const mockProblem: Problem = {
5151
id: 123,
5252
base: null,
53+
hidden: false,
5354
premises: ["First premise", "Second premise"],
5455
hypothesis: "Test hypothesis",
5556
entailmentLabel: EntailmentLabel.ENTAILMENT,
@@ -121,6 +122,7 @@ describe("AnnotationInputComponent", () => {
121122
const mockProblem: Problem = {
122123
id: 123,
123124
base: null,
125+
hidden: false,
124126
premises: [],
125127
hypothesis: "Empty test hypothesis",
126128
entailmentLabel: EntailmentLabel.NEUTRAL,
@@ -143,6 +145,7 @@ describe("AnnotationInputComponent", () => {
143145
const mockProblem: Problem = {
144146
id: 1,
145147
base: null,
148+
hidden: false,
146149
premises: ["Test premise"],
147150
hypothesis: "Test hypothesis",
148151
entailmentLabel: EntailmentLabel.CONTRADICTION,
@@ -166,6 +169,7 @@ describe("AnnotationInputComponent", () => {
166169
const mockProblem: Problem = {
167170
id: 12,
168171
base: null,
172+
hidden: false,
169173
premises: [],
170174
hypothesis: "",
171175
entailmentLabel: EntailmentLabel.UNKNOWN,
@@ -187,6 +191,7 @@ describe("AnnotationInputComponent", () => {
187191
const mockProblem: Problem = {
188192
id: 17,
189193
base: null,
194+
hidden: false,
190195
premises: [],
191196
hypothesis: "",
192197
entailmentLabel: EntailmentLabel.UNKNOWN,

frontend/src/app/annotate/annotation-input/problem-details/problem-details.component.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const createMockProblem = (
1212
): Problem => ({
1313
id,
1414
base: null,
15+
hidden: false,
1516
dataset,
1617
entailmentLabel,
1718
premises: ["premise"],
Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,54 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
22

33
import { VisibilityToggleComponent } from './visibility-toggle.component';
4+
import { provideHttpClient } from '@angular/common/http';
5+
import { ProblemService } from '@/services/problem.service';
46

57
describe('VisibilityToggleComponent', () => {
68
let component: VisibilityToggleComponent;
79
let fixture: ComponentFixture<VisibilityToggleComponent>;
10+
let problemService: ProblemService;
811

912
beforeEach(async () => {
1013
await TestBed.configureTestingModule({
11-
imports: [VisibilityToggleComponent]
14+
imports: [VisibilityToggleComponent],
15+
providers: [provideHttpClient()],
1216
})
1317
.compileComponents();
1418

1519
fixture = TestBed.createComponent(VisibilityToggleComponent);
1620
component = fixture.componentInstance;
21+
problemService = TestBed.inject(ProblemService);
22+
const componentRef = fixture.componentRef;
23+
componentRef.setInput("problem", {
24+
id: 123,
25+
hidden: false
26+
});
1727
fixture.detectChanges();
1828
});
1929

2030
it('should create', () => {
2131
expect(component).toBeTruthy();
2232
});
33+
34+
it('should emit toggleVisibility$ with hidden=true when problem is visible', () => {
35+
const emitted: { id: number, hidden: boolean; }[] = [];
36+
problemService.toggleVisibility$.subscribe(v => emitted.push(v));
37+
38+
component.onToggleHidden();
39+
40+
expect(emitted).toEqual([{ id: 123, hidden: true }]);
41+
});
42+
43+
it('should show the alert banner only when the problem is hidden', () => {
44+
const getAlert = () =>
45+
fixture.nativeElement.querySelector('[role="alert"]');
46+
47+
expect(getAlert()).toBeNull();
48+
49+
fixture.componentRef.setInput('problem', { id: 123, hidden: true });
50+
fixture.detectChanges();
51+
52+
expect(getAlert()).not.toBeNull();
53+
});
2354
});
Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
1-
import { ComponentFixture, TestBed } from "@angular/core/testing";
2-
3-
import { SearchComponent } from "./search.component";
4-
import { ActivatedRoute } from "@angular/router";
5-
import { of } from "rxjs";
6-
7-
describe("SearchComponent", () => {
8-
let component: SearchComponent;
9-
let fixture: ComponentFixture<SearchComponent>;
10-
11-
beforeEach(async () => {
12-
await TestBed.configureTestingModule({
13-
imports: [SearchComponent],
14-
providers: [{
15-
provide: ActivatedRoute,
16-
useValue: {
17-
params: of({ problemId: "1" }),
18-
queryParamMap: of({ dataset: null, entailmentLabel: null, gold: null, text: "" }),
19-
}
20-
}]
21-
}).compileComponents();
22-
23-
fixture = TestBed.createComponent(SearchComponent);
24-
component = fixture.componentInstance;
25-
fixture.detectChanges();
26-
});
27-
28-
it("should create", () => {
29-
expect(component).toBeTruthy();
30-
});
31-
});
1+
import { ComponentFixture, TestBed } from "@angular/core/testing";
2+
3+
import { SearchComponent } from "./search.component";
4+
import { ActivatedRoute } from "@angular/router";
5+
import { of } from "rxjs";
6+
import { provideHttpClient, withInterceptorsFromDi } from "@angular/common/http";
7+
8+
describe("SearchComponent", () => {
9+
let component: SearchComponent;
10+
let fixture: ComponentFixture<SearchComponent>;
11+
12+
beforeEach(async () => {
13+
await TestBed.configureTestingModule({
14+
imports: [SearchComponent],
15+
providers: [
16+
provideHttpClient(withInterceptorsFromDi()),
17+
{
18+
provide: ActivatedRoute,
19+
useValue: {
20+
params: of({ problemId: "1" }),
21+
queryParamMap: of({ dataset: null, entailmentLabel: null, gold: null, text: "" }),
22+
}
23+
}]
24+
}).compileComponents();
25+
26+
fixture = TestBed.createComponent(SearchComponent);
27+
component = fixture.componentInstance;
28+
fixture.detectChanges();
29+
});
30+
31+
it("should create", () => {
32+
expect(component).toBeTruthy();
33+
});
34+
});

frontend/src/app/menu/user-menu/user-menu.component.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const fakeUserResponse: UserResponse = {
2626
canEditKb: false,
2727
canAddLabelAnnotations: false,
2828
canCopyProblem: false,
29+
canChangeProblemVisibility: false,
2930
};
3031

3132
const fakeAdminResponse: UserResponse = {
@@ -41,6 +42,7 @@ const fakeAdminResponse: UserResponse = {
4142
canEditKb: true,
4243
canAddLabelAnnotations: true,
4344
canCopyProblem: true,
45+
canChangeProblemVisibility: true,
4446
};
4547

4648
describe("UserMenuComponent", () => {

frontend/src/app/services/problem.service.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ describe("ProblemService", () => {
6060
},
6161
kbAnnotations: [],
6262
labelAnnotations: [],
63+
hidden: false,
6364
},
6465
index: 1,
6566
total: 1,
@@ -81,7 +82,7 @@ describe("ProblemService", () => {
8182
done();
8283
});
8384

84-
const req = httpMock.expectOne(`/api/problem/${mockProblemId}/?text=&dataset=&gold=&entailmentLabel=`);
85+
const req = httpMock.expectOne(`/api/problem/${mockProblemId}/?text=&dataset=&gold=&entailmentLabel=&hidden=`);
8586
expect(req.request.method).toBe("GET");
8687
req.flush(mockResponse);
8788
});

frontend/src/app/user/user-settings/user-settings.component.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const fakeUser: User = {
2929
canEditKb: false,
3030
canAddLabelAnnotations: false,
3131
canCopyProblem: false,
32+
canChangeProblemVisibility: false,
3233
};
3334

3435
@Injectable({ providedIn: "root" })

frontend/src/app/user/utils.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ describe("User utils", () => {
4545
canEditKb: false,
4646
canAddLabelAnnotations: false,
4747
canCopyProblem: false,
48+
canChangeProblemVisibility: false,
4849
};
4950
const user = parseUserData(result);
5051
expect(user).toBeInstanceOf(User);

0 commit comments

Comments
 (0)