-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathui-service.test.ts
More file actions
83 lines (69 loc) · 2.77 KB
/
Copy pathui-service.test.ts
File metadata and controls
83 lines (69 loc) · 2.77 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
import { describe, it, expect } from 'vitest';
import type { IUIService } from './ui-service';
describe('UI Service Contract', () => {
it('should allow a minimal IUIService implementation with required methods', () => {
const service: IUIService = {
getView: (_name) => undefined,
listViews: (_object?) => [],
};
expect(typeof service.getView).toBe('function');
expect(typeof service.listViews).toBe('function');
});
it('should allow a full implementation with optional methods', () => {
const service: IUIService = {
getView: () => undefined,
listViews: () => [],
getDashboard: (_name) => undefined,
listDashboards: () => [],
registerView: (_name, _definition) => {},
registerDashboard: (_name, _definition) => {},
};
expect(service.getDashboard).toBeDefined();
expect(service.listDashboards).toBeDefined();
expect(service.registerView).toBeDefined();
expect(service.registerDashboard).toBeDefined();
});
it('should register and retrieve views', () => {
const views = new Map<string, unknown>();
const service: IUIService = {
getView: (name) => views.get(name),
listViews: (object?) => {
const all = Array.from(views.values());
if (object) return all.filter((v: any) => v.object === object);
return all;
},
registerView: (name, definition) => { views.set(name, definition); },
};
const viewDef = { name: 'account_list', object: 'account', type: 'grid', columns: ['name', 'email'] };
service.registerView!('account_list', viewDef);
expect(service.getView('account_list')).toEqual(viewDef);
expect(service.listViews()).toHaveLength(1);
expect(service.listViews('account')).toHaveLength(1);
expect(service.listViews('contact')).toHaveLength(0);
});
it('should manage dashboards', () => {
const dashboards = new Map<string, unknown>();
const service: IUIService = {
getView: () => undefined,
listViews: () => [],
getDashboard: (name) => dashboards.get(name),
listDashboards: () => Array.from(dashboards.values()),
registerDashboard: (name, definition) => { dashboards.set(name, definition); },
};
service.registerDashboard!('sales_overview', {
name: 'sales_overview',
label: 'Sales Overview',
widgets: [{ type: 'chart', title: 'Revenue' }],
});
expect(service.getDashboard!('sales_overview')).toBeDefined();
expect(service.listDashboards!()).toHaveLength(1);
expect(service.getDashboard!('missing')).toBeUndefined();
});
it('should return undefined for non-existent views', () => {
const service: IUIService = {
getView: () => undefined,
listViews: () => [],
};
expect(service.getView('nonexistent')).toBeUndefined();
});
});