forked from deephaven/web-client-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginTypes.test.ts
More file actions
53 lines (48 loc) · 1.42 KB
/
PluginTypes.test.ts
File metadata and controls
53 lines (48 loc) · 1.42 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
import {
PluginType,
isAuthPlugin,
isDashboardPlugin,
isElementPlugin,
isMultiPlugin,
isTablePlugin,
isThemePlugin,
isWidgetPlugin,
type Plugin,
isPlugin,
} from './PluginTypes';
const pluginTypeToTypeGuardMap = [
[PluginType.AUTH_PLUGIN, isAuthPlugin],
[PluginType.DASHBOARD_PLUGIN, isDashboardPlugin],
[PluginType.ELEMENT_PLUGIN, isElementPlugin],
[PluginType.MULTI_PLUGIN, isMultiPlugin],
[PluginType.TABLE_PLUGIN, isTablePlugin],
[PluginType.THEME_PLUGIN, isThemePlugin],
[PluginType.WIDGET_PLUGIN, isWidgetPlugin],
] as const;
const pluginTypeToPluginMap: [type: string, moduleValue: Plugin][] =
Object.keys(PluginType).map(type => [
type,
{ name: `${type}`, type: PluginType[type] },
]);
describe.each(pluginTypeToTypeGuardMap)(
'plugin type guard: %s',
(expectedPluginType, typeGuard) => {
it.each(pluginTypeToTypeGuardMap)(
'should return true for expected plugin type: %s',
givenPluginType => {
expect(typeGuard({ name: 'test', type: givenPluginType })).toBe(
givenPluginType === expectedPluginType
);
}
);
}
);
describe('isPlugin', () => {
it.each(pluginTypeToPluginMap)('returns true for %s type', (type, plugin) => {
expect(isPlugin(plugin)).toBe(true);
});
it('returns false for non-plugin types', () => {
expect(isPlugin({ name: 'test', type: 'other' })).toBe(false);
expect(isPlugin({})).toBe(false);
});
});