Skip to content

Commit 1788516

Browse files
Fix frontend tests
1 parent 2bf0631 commit 1788516

1 file changed

Lines changed: 30 additions & 36 deletions

File tree

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

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { TestBed } from "@angular/core/testing";
22
import { of } from "rxjs";
33

44
import { ProblemService } from "@/services/problem.service";
5-
import { Dataset, EntailmentLabel, KnowledgeBaseRelationship } from "@/types";
6-
import { AnnotationCommentsComponent, AnnotationEvent } from "./annotation-comments.component";
5+
import { Dataset, EntailmentLabel, KnowledgeBaseAnnotation, KnowledgeBaseRelationship, LabelAnnotation, Problem } from "@/types";
6+
import { AnnotationCommentsComponent } from "./annotation-comments.component";
77

88
const baseAnnotationFields = {
99
id: 1,
@@ -14,8 +14,8 @@ const baseAnnotationFields = {
1414
removedBy: null,
1515
};
1616

17-
function setupComponent(kbAnnotations: unknown[] = [], labelAnnotations: unknown[] = []) {
18-
const mockProblem = {
17+
function setupComponent(kbAnnotations: KnowledgeBaseAnnotation[] = [], labelAnnotations: LabelAnnotation[] = []) {
18+
const mockProblem: Problem = {
1919
id: 1,
2020
base: null,
2121
premises: [],
@@ -45,7 +45,7 @@ describe("AnnotationCommentsComponent", () => {
4545
expect(component).toBeTruthy();
4646
});
4747

48-
it("emits an 'added' event for each annotation", (done) => {
48+
it("emits an 'added' event for each annotation", () => {
4949
const component = setupComponent(
5050
[],
5151
[
@@ -59,21 +59,19 @@ describe("AnnotationCommentsComponent", () => {
5959
]
6060
);
6161

62-
component.events$.subscribe((events: AnnotationEvent[]) => {
63-
expect(events.length).toBe(1);
64-
expect(events[0]).toEqual(
65-
jasmine.objectContaining({
66-
kind: "added",
67-
annotationKind: "label",
68-
actor: "Alice",
69-
description: "negation",
70-
})
71-
);
72-
done();
73-
});
62+
const events = component.filteredEvents()!;
63+
expect(events.length).toBe(1);
64+
expect(events[0]).toEqual(
65+
jasmine.objectContaining({
66+
kind: "added",
67+
annotationKind: "label",
68+
actor: "Alice",
69+
description: "negation",
70+
})
71+
);
7472
});
7573

76-
it("emits a 'removed' event when removedAt is set", (done) => {
74+
it("emits a 'removed' event when removedAt is set", () => {
7775
const component = setupComponent(
7876
[
7977
{
@@ -90,21 +88,19 @@ describe("AnnotationCommentsComponent", () => {
9088
[]
9189
);
9290

93-
component.events$.subscribe((events: AnnotationEvent[]) => {
94-
expect(events.length).toBe(2);
95-
const removed = events.find((e) => e.kind === "removed");
96-
expect(removed).toEqual(
97-
jasmine.objectContaining({
98-
kind: "removed",
99-
annotationKind: "knowledgeBase",
100-
description: "cat = feline",
101-
})
102-
);
103-
done();
104-
});
91+
const events = component.filteredEvents()!;
92+
expect(events.length).toBe(2);
93+
const removed = events.find((e) => e.kind === "removed");
94+
expect(removed).toEqual(
95+
jasmine.objectContaining({
96+
kind: "removed",
97+
annotationKind: "knowledgeBase",
98+
description: "cat = feline",
99+
})
100+
);
105101
});
106102

107-
it("sorts events by timestamp descending", (done) => {
103+
it("sorts events by timestamp descending", () => {
108104
const component = setupComponent(
109105
[],
110106
[
@@ -127,10 +123,8 @@ describe("AnnotationCommentsComponent", () => {
127123
]
128124
);
129125

130-
component.events$.subscribe((events: AnnotationEvent[]) => {
131-
expect(events[0].description).toBe("latest");
132-
expect(events[1].description).toBe("first");
133-
done();
134-
});
126+
const events = component.filteredEvents()!;
127+
expect(events[0].description).toBe("latest");
128+
expect(events[1].description).toBe("first");
135129
});
136130
});

0 commit comments

Comments
 (0)