Skip to content

Commit 7c120e8

Browse files
committed
(#455) Tests for DefaultProviderRegistry
1 parent 103f226 commit 7c120e8

File tree

2 files changed

+262
-52
lines changed

2 files changed

+262
-52
lines changed

Diff for: lib/provider/provider-registry.class.spec.ts

+207
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
import providerRegistry from "./provider-registry.class";
2+
import { MouseProviderInterface } from "./mouse-provider.interface";
3+
import { ImageProcessor } from "./image-processor.interface";
4+
import { ImageWriter } from "./image-writer.type";
5+
import { ImageReader } from "./image-reader.type";
6+
import { ClipboardProviderInterface } from "./clipboard-provider.interface";
7+
import { KeyboardProviderInterface } from "./keyboard-provider.interface";
8+
import { ScreenProviderInterface } from "./screen-provider.interface";
9+
import { WindowProviderInterface } from "./window-provider.interface";
10+
11+
describe("DefaultProviderRegistry", () => {
12+
describe("non-defaults", () => {
13+
it("should not have a default ImageFinder registered", () => {
14+
// GIVEN
15+
16+
// WHEN
17+
18+
// THEN
19+
expect(providerRegistry.getImageFinder).toThrowError(
20+
/.*Error: No ImageFinder registered/
21+
);
22+
});
23+
24+
it("should not have a default TextFinder registered", () => {
25+
// GIVEN
26+
27+
// WHEN
28+
29+
// THEN
30+
expect(providerRegistry.getTextFinder).toThrowError(
31+
/.*Error: No TextFinder registered/
32+
);
33+
});
34+
35+
it("should not have a default WindowFinder registered", () => {
36+
// GIVEN
37+
38+
// WHEN
39+
40+
// THEN
41+
expect(providerRegistry.getWindowFinder).toThrowError(
42+
/.*Error: No WindowFinder registered/
43+
);
44+
});
45+
});
46+
47+
describe("defaults", () => {
48+
it("should have a default ImageProcessor registered", () => {
49+
// GIVEN
50+
51+
// WHEN
52+
53+
// THEN
54+
expect(providerRegistry.getImageProcessor).not.toThrowError();
55+
});
56+
it("should have a default ImageWriter registered", () => {
57+
// GIVEN
58+
59+
// WHEN
60+
61+
// THEN
62+
expect(providerRegistry.getImageWriter).not.toThrowError();
63+
});
64+
it("should have a default ImageReader registered", () => {
65+
// GIVEN
66+
67+
// WHEN
68+
69+
// THEN
70+
expect(providerRegistry.getImageReader).not.toThrowError();
71+
});
72+
it("should have a default Clipboard registered", () => {
73+
// GIVEN
74+
75+
// WHEN
76+
77+
// THEN
78+
expect(providerRegistry.getClipboard).not.toThrowError();
79+
});
80+
it("should have a default Keyboard registered", () => {
81+
// GIVEN
82+
83+
// WHEN
84+
85+
// THEN
86+
expect(providerRegistry.getKeyboard).not.toThrowError();
87+
});
88+
it("should have a default Mouse registered", () => {
89+
// GIVEN
90+
91+
// WHEN
92+
93+
// THEN
94+
expect(providerRegistry.getMouse).not.toThrowError();
95+
});
96+
it("should have a default Screen registered", () => {
97+
// GIVEN
98+
99+
// WHEN
100+
101+
// THEN
102+
expect(providerRegistry.getScreen).not.toThrowError();
103+
});
104+
it("should have a default WindowProvider registered", () => {
105+
// GIVEN
106+
107+
// WHEN
108+
109+
// THEN
110+
expect(providerRegistry.getWindow).not.toThrowError();
111+
});
112+
it("should have a default LogProvider registered", () => {
113+
// GIVEN
114+
115+
// WHEN
116+
117+
// THEN
118+
expect(providerRegistry.getLogProvider).not.toThrowError();
119+
});
120+
});
121+
describe("resets", () => {
122+
it("should throw on missing ImageProcessor", () => {
123+
// GIVEN
124+
125+
// WHEN
126+
providerRegistry.registerImageProcessor(
127+
undefined as unknown as ImageProcessor
128+
);
129+
130+
// THEN
131+
expect(providerRegistry.getImageProcessor).toThrowError();
132+
});
133+
it("should throw on missing ImageWriter", () => {
134+
// GIVEN
135+
136+
// WHEN
137+
providerRegistry.registerImageWriter(undefined as unknown as ImageWriter);
138+
139+
// THEN
140+
expect(providerRegistry.getImageWriter).toThrowError();
141+
});
142+
it("should throw on missing ImageReader", () => {
143+
// GIVEN
144+
145+
// WHEN
146+
providerRegistry.registerImageReader(undefined as unknown as ImageReader);
147+
148+
// THEN
149+
expect(providerRegistry.getImageReader).toThrowError();
150+
});
151+
it("should throw on missing Clipboard", () => {
152+
// GIVEN
153+
154+
// WHEN
155+
providerRegistry.registerClipboardProvider(
156+
undefined as unknown as ClipboardProviderInterface
157+
);
158+
159+
// THEN
160+
expect(providerRegistry.getClipboard).toThrowError();
161+
});
162+
it("should throw on missing Keyboard", () => {
163+
// GIVEN
164+
165+
// WHEN
166+
providerRegistry.registerKeyboardProvider(
167+
undefined as unknown as KeyboardProviderInterface
168+
);
169+
170+
// THEN
171+
expect(providerRegistry.getKeyboard).toThrowError();
172+
});
173+
it("should throw on missing Mouse", () => {
174+
// GIVEN
175+
176+
// WHEN
177+
providerRegistry.registerMouseProvider(
178+
undefined as unknown as MouseProviderInterface
179+
);
180+
181+
// THEN
182+
expect(providerRegistry.getMouse).toThrowError();
183+
});
184+
it("should throw on missing Screen", () => {
185+
// GIVEN
186+
187+
// WHEN
188+
providerRegistry.registerScreenProvider(
189+
undefined as unknown as ScreenProviderInterface
190+
);
191+
192+
// THEN
193+
expect(providerRegistry.getScreen).toThrowError();
194+
});
195+
it("should throw on missing Window", () => {
196+
// GIVEN
197+
198+
// WHEN
199+
providerRegistry.registerWindowProvider(
200+
undefined as unknown as WindowProviderInterface
201+
);
202+
203+
// THEN
204+
expect(providerRegistry.getWindow).toThrowError();
205+
});
206+
});
207+
});

0 commit comments

Comments
 (0)