-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigureFramework.test.tsx
More file actions
114 lines (101 loc) · 3.16 KB
/
configureFramework.test.tsx
File metadata and controls
114 lines (101 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import type { FC } from "react";
import { describe, it, expect, beforeEach, afterEach } from "vitest";
import { configureFramework, resolvePlugin } from "./configureFramework";
import { store } from "@/store";
import { registry } from "@/components/registry";
import type { HostStore } from "@/types/state/host";
import type { RegistrableComponent, Plugin } from "@/types/state/plugin";
function getComponents(): [string, RegistrableComponent][] {
interface DivProps {
text: string;
}
const Div: FC<DivProps> = ({ text }) => <div>{text}</div>;
return [
["A", Div],
["B", Div],
];
}
describe("configureFramework", () => {
it("should accept no arg", () => {
configureFramework();
expect(store.getState().configuration).toEqual({});
});
it("should accept empty arg", () => {
configureFramework({});
expect(store.getState().configuration).toEqual({});
});
it("should enable logging", () => {
configureFramework({
logging: {
enabled: true,
},
});
expect(store.getState().configuration).toEqual({
logging: { enabled: true },
});
});
it("should subscribe to host store", () => {
const listeners = [];
const hostStore: HostStore = {
get: (_key: string) => null,
subscribe: (l: () => void) => {
listeners.push(l);
},
};
configureFramework({
hostStore,
});
expect(listeners.length).toBe(1);
});
it("should install plugins", () => {
expect(registry.types.length).toBe(0);
configureFramework({
plugins: [{ components: getComponents() }],
});
expect(registry.types.length).toBe(2);
});
it("should allow adding plain components", () => {
expect(registry.types.length).toBe(0);
configureFramework({
plugins: [{ components: getComponents() }],
});
expect(registry.types.length).toBe(2);
});
});
describe("resolvePlugin", () => {
beforeEach(() => {
registry.clear();
});
afterEach(() => {
registry.clear();
});
it("should resolve a object", async () => {
const pluginObj: Plugin = { components: getComponents() };
expect(registry.types.length).toBe(0);
const result = await resolvePlugin(pluginObj);
expect(result).toBe(pluginObj);
expect(registry.types.length).toBe(2);
});
it("should resolve a function", async () => {
const pluginObj = { components: getComponents() };
const pluginFunction = () => pluginObj;
expect(registry.types.length).toBe(0);
const result = await resolvePlugin(pluginFunction);
expect(result).toBe(pluginObj);
expect(registry.types.length).toBe(2);
});
it("should resolve a promise", async () => {
const pluginObj = { components: getComponents() };
const pluginPromise = Promise.resolve(pluginObj);
expect(registry.types.length).toBe(0);
const result = await resolvePlugin(pluginPromise);
expect(result).toBe(pluginObj);
expect(registry.types.length).toBe(2);
});
it("should resolve undefined", async () => {
expect(registry.types.length).toBe(0);
const result = await resolvePlugin(undefined as unknown as Plugin);
expect(result).toBe(undefined);
expect(registry.types.length).toBe(0);
});
});