@nahisaho/yata-ui 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/yata-ui.js +42 -0
- package/dist/index.d.ts +203 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +548 -0
- package/dist/index.js.map +1 -0
- package/package.json +46 -0
- package/src/index.test.ts +160 -0
- package/src/index.ts +685 -0
- package/tsconfig.json +11 -0
- package/vitest.config.ts +14 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for YataUIServer
|
|
3
|
+
*
|
|
4
|
+
* @see REQ-YI-WEB-001 - Web-based Visualization
|
|
5
|
+
* @see REQ-YI-WEB-002 - Interactive Graph Editing
|
|
6
|
+
* @see REQ-YI-WEB-003 - Real-time Updates
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
10
|
+
import {
|
|
11
|
+
YataUIServer,
|
|
12
|
+
createYataUIServer,
|
|
13
|
+
DEFAULT_UI_CONFIG,
|
|
14
|
+
} from './index.js';
|
|
15
|
+
import type { GraphData, UIServerConfig } from './index.js';
|
|
16
|
+
|
|
17
|
+
describe('YataUIServer', () => {
|
|
18
|
+
let server: YataUIServer;
|
|
19
|
+
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
server = new YataUIServer({
|
|
22
|
+
port: 0, // Use random available port
|
|
23
|
+
enableRealtime: true,
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
afterEach(async () => {
|
|
28
|
+
if (server.isRunning()) {
|
|
29
|
+
await server.stop();
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// ============================================================
|
|
34
|
+
// Factory Function
|
|
35
|
+
// ============================================================
|
|
36
|
+
|
|
37
|
+
describe('createYataUIServer', () => {
|
|
38
|
+
it('should create server instance', () => {
|
|
39
|
+
const s = createYataUIServer({ port: 0 });
|
|
40
|
+
expect(s).toBeInstanceOf(YataUIServer);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// ============================================================
|
|
45
|
+
// Default Config
|
|
46
|
+
// ============================================================
|
|
47
|
+
|
|
48
|
+
describe('DEFAULT_UI_CONFIG', () => {
|
|
49
|
+
it('should have sensible defaults', () => {
|
|
50
|
+
expect(DEFAULT_UI_CONFIG.port).toBe(3000);
|
|
51
|
+
expect(DEFAULT_UI_CONFIG.host).toBe('localhost');
|
|
52
|
+
expect(DEFAULT_UI_CONFIG.cors).toBe(true);
|
|
53
|
+
expect(DEFAULT_UI_CONFIG.enableRealtime).toBe(true);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// ============================================================
|
|
58
|
+
// Server Lifecycle
|
|
59
|
+
// ============================================================
|
|
60
|
+
|
|
61
|
+
describe('server lifecycle', () => {
|
|
62
|
+
it('should start and stop', async () => {
|
|
63
|
+
expect(server.isRunning()).toBe(false);
|
|
64
|
+
|
|
65
|
+
await server.start();
|
|
66
|
+
expect(server.isRunning()).toBe(true);
|
|
67
|
+
|
|
68
|
+
await server.stop();
|
|
69
|
+
expect(server.isRunning()).toBe(false);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('should return URL', async () => {
|
|
73
|
+
const url = server.getUrl();
|
|
74
|
+
expect(url).toMatch(/^http:\/\/localhost:\d+$/);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// ============================================================
|
|
79
|
+
// Data Provider
|
|
80
|
+
// ============================================================
|
|
81
|
+
|
|
82
|
+
describe('data provider', () => {
|
|
83
|
+
it('should accept data provider function', () => {
|
|
84
|
+
const mockProvider = async (): Promise<GraphData> => ({
|
|
85
|
+
nodes: [{ id: '1', label: 'Test', type: 'entity' }],
|
|
86
|
+
edges: [],
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// Should not throw
|
|
90
|
+
server.setDataProvider(mockProvider);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// ============================================================
|
|
95
|
+
// Broadcast (REQ-YI-WEB-003)
|
|
96
|
+
// ============================================================
|
|
97
|
+
|
|
98
|
+
describe('broadcastUpdate', () => {
|
|
99
|
+
it('should not throw when no clients connected', () => {
|
|
100
|
+
// Should not throw
|
|
101
|
+
expect(() => {
|
|
102
|
+
server.broadcastUpdate('test', { foo: 'bar' });
|
|
103
|
+
}).not.toThrow();
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// ============================================================
|
|
108
|
+
// Express App
|
|
109
|
+
// ============================================================
|
|
110
|
+
|
|
111
|
+
describe('getApp', () => {
|
|
112
|
+
it('should return Express app instance', () => {
|
|
113
|
+
const app = server.getApp();
|
|
114
|
+
expect(app).toBeDefined();
|
|
115
|
+
expect(typeof app.listen).toBe('function');
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// ============================================================
|
|
121
|
+
// API Integration Tests (with supertest-like approach)
|
|
122
|
+
// ============================================================
|
|
123
|
+
|
|
124
|
+
describe('YataUIServer API', () => {
|
|
125
|
+
let server: YataUIServer;
|
|
126
|
+
let baseUrl: string;
|
|
127
|
+
|
|
128
|
+
beforeEach(async () => {
|
|
129
|
+
server = new YataUIServer({
|
|
130
|
+
port: 0,
|
|
131
|
+
enableRealtime: true,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
server.setDataProvider(async () => ({
|
|
135
|
+
nodes: [
|
|
136
|
+
{ id: 'node-1', label: 'Node 1', type: 'entity', namespace: 'test' },
|
|
137
|
+
{ id: 'node-2', label: 'Node 2', type: 'class' },
|
|
138
|
+
],
|
|
139
|
+
edges: [
|
|
140
|
+
{ id: 'edge-1', source: 'node-1', target: 'node-2', type: 'uses', label: 'uses' },
|
|
141
|
+
],
|
|
142
|
+
}));
|
|
143
|
+
|
|
144
|
+
// We can't easily get the actual port without starting
|
|
145
|
+
// For real integration tests, we'd use supertest
|
|
146
|
+
// Here we just test the app configuration
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
afterEach(async () => {
|
|
150
|
+
if (server.isRunning()) {
|
|
151
|
+
await server.stop();
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('should configure health endpoint', () => {
|
|
156
|
+
const app = server.getApp();
|
|
157
|
+
// Check that routes are registered
|
|
158
|
+
expect(app).toBeDefined();
|
|
159
|
+
});
|
|
160
|
+
});
|