Skip to content

Commit 103f226

Browse files
committed
(#455) Query tests
1 parent 4fbc167 commit 103f226

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed

lib/query.class.spec.ts

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import {
2+
isTextQuery,
3+
isWindowQuery,
4+
TextQuery,
5+
WindowQuery,
6+
} from "./query.class";
7+
import { Image, isImage } from "./image.class";
8+
9+
const dummyImage = new Image(0, 0, Buffer.of(0), 3, "foo", 0, 0);
10+
11+
describe("query types", () => {
12+
it.each<[TextQuery, boolean]>([
13+
[
14+
{
15+
id: "dummy",
16+
type: "text",
17+
by: {
18+
word: "dummy-query",
19+
},
20+
},
21+
true,
22+
],
23+
[
24+
{
25+
id: "dummy",
26+
type: "text",
27+
by: {
28+
line: "dummy-query",
29+
},
30+
},
31+
true,
32+
],
33+
[
34+
{
35+
id: "dummy",
36+
type: "foo",
37+
by: {
38+
line: "dummy-query",
39+
},
40+
} as unknown as TextQuery,
41+
false,
42+
],
43+
])(
44+
"should correctly identify text queries",
45+
(query: TextQuery, expected: boolean) => {
46+
// GIVEN
47+
48+
// WHEN
49+
const result = isTextQuery(query);
50+
51+
// THEN
52+
expect(result).toBe(expected);
53+
}
54+
);
55+
56+
it.each<[WindowQuery, boolean]>([
57+
[
58+
{
59+
id: "dummy",
60+
type: "window",
61+
by: {
62+
title: "dummy-query",
63+
},
64+
},
65+
true,
66+
],
67+
[
68+
{
69+
id: "dummy",
70+
type: "foo",
71+
by: {
72+
title: "dummy-query",
73+
},
74+
} as unknown as WindowQuery,
75+
false,
76+
],
77+
])(
78+
"should correctly identify window queries",
79+
(query: WindowQuery, expected: boolean) => {
80+
// GIVEN
81+
82+
// WHEN
83+
const result = isWindowQuery(query);
84+
85+
// THEN
86+
expect(result).toBe(expected);
87+
}
88+
);
89+
90+
it.each<[Image, boolean]>([
91+
[dummyImage, true],
92+
[
93+
{
94+
id: "dummy",
95+
type: "foo",
96+
by: {
97+
title: "dummy-query",
98+
},
99+
} as unknown as Image,
100+
false,
101+
],
102+
])(
103+
"should correctly identify image queries",
104+
(query: Image, expected: boolean) => {
105+
// GIVEN
106+
107+
// WHEN
108+
const result = isImage(query);
109+
110+
// THEN
111+
expect(result).toBe(expected);
112+
}
113+
);
114+
});

0 commit comments

Comments
 (0)