-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathwidget-types.test.js
More file actions
263 lines (227 loc) · 6.92 KB
/
widget-types.test.js
File metadata and controls
263 lines (227 loc) · 6.92 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
import { describe, it, expect } from 'vitest';
import {
WIDGET_TYPES,
WIDGET_TYPE_KEYS,
BRAND_DEFAULTS,
defaultConfig,
validateConfig,
isReady,
resolveChainId,
chainLabel,
CHAIN_SLUGS,
} from '../../src/widget-types.js';
describe('WIDGET_TYPES', () => {
it('exposes the known widget types', () => {
expect(WIDGET_TYPE_KEYS.sort()).toEqual(
[
'turntable',
'animation-gallery',
'talking-agent',
'passport',
'hotspot-tour',
'pumpfun-feed',
'kol-trades',
'live-trades-canvas',
].sort(),
);
});
it('every entry has label, desc, status, icon', () => {
for (const key of WIDGET_TYPE_KEYS) {
const entry = WIDGET_TYPES[key];
expect(typeof entry.label).toBe('string');
expect(typeof entry.desc).toBe('string');
expect(['ready', 'pending']).toContain(entry.status);
expect(typeof entry.icon).toBe('string');
}
});
it('BRAND_DEFAULTS is frozen', () => {
expect(Object.isFrozen(BRAND_DEFAULTS)).toBe(true);
});
});
describe('isReady', () => {
it('returns true for ready widgets', () => {
expect(isReady('turntable')).toBe(true);
expect(isReady('animation-gallery')).toBe(true);
expect(isReady('talking-agent')).toBe(true);
expect(isReady('passport')).toBe(true);
expect(isReady('hotspot-tour')).toBe(true);
});
it('returns false for unknown types', () => {
expect(isReady('bogus')).toBe(false);
});
});
describe('defaultConfig', () => {
it('merges BRAND_DEFAULTS with type defaults', () => {
const cfg = defaultConfig('turntable');
expect(cfg.background).toBe(BRAND_DEFAULTS.background);
expect(cfg.rotationSpeed).toBe(0.5);
});
it('returns hotspot-tour defaults with empty array', () => {
const cfg = defaultConfig('hotspot-tour');
expect(cfg.hotspots).toEqual([]);
});
it('throws on unknown type', () => {
expect(() => defaultConfig('unknown')).toThrow(/unknown widget type/);
});
});
describe('validateConfig — turntable', () => {
it('accepts default config', () => {
expect(() => validateConfig('turntable', defaultConfig('turntable'))).not.toThrow();
});
it('rejects rotationSpeed above 10', () => {
expect(() =>
validateConfig('turntable', { ...defaultConfig('turntable'), rotationSpeed: 11 }),
).toThrow(/rotationSpeed/);
});
it('rejects negative rotationSpeed', () => {
expect(() =>
validateConfig('turntable', { ...defaultConfig('turntable'), rotationSpeed: -1 }),
).toThrow(/rotationSpeed/);
});
it('rejects bad hex color', () => {
expect(() =>
validateConfig('turntable', { ...defaultConfig('turntable'), background: 'red' }),
).toThrow();
});
});
describe('validateConfig — talking-agent', () => {
it('accepts default config', () => {
expect(() => validateConfig('talking-agent', defaultConfig('talking-agent'))).not.toThrow();
});
it('requires proxyURL when brainProvider is custom', () => {
expect(() =>
validateConfig('talking-agent', {
...defaultConfig('talking-agent'),
brainProvider: 'custom',
proxyURL: '',
}),
).toThrow(/proxyURL/);
});
it('accepts custom brainProvider with https proxyURL', () => {
const cfg = validateConfig('talking-agent', {
...defaultConfig('talking-agent'),
brainProvider: 'custom',
proxyURL: 'https://my-proxy.example/chat',
});
expect(cfg.proxyURL).toBe('https://my-proxy.example/chat');
});
it('rejects http (non-https) proxyURL', () => {
expect(() =>
validateConfig('talking-agent', {
...defaultConfig('talking-agent'),
proxyURL: 'http://insecure.example',
}),
).toThrow();
});
it('rejects temperature above 1', () => {
expect(() =>
validateConfig('talking-agent', {
...defaultConfig('talking-agent'),
temperature: 1.5,
}),
).toThrow();
});
});
describe('validateConfig — passport', () => {
it('accepts default config', () => {
expect(() => validateConfig('passport', defaultConfig('passport'))).not.toThrow();
});
it('rejects non-numeric agentId', () => {
expect(() =>
validateConfig('passport', { ...defaultConfig('passport'), agentId: 'abc' }),
).toThrow(/agentId/);
});
it('rejects malformed wallet address', () => {
expect(() =>
validateConfig('passport', { ...defaultConfig('passport'), wallet: '0xnothex' }),
).toThrow(/wallet/);
});
it('accepts valid uint256 agentId', () => {
const cfg = validateConfig('passport', {
...defaultConfig('passport'),
agentId: '12345',
});
expect(cfg.agentId).toBe('12345');
});
it('rejects refreshIntervalSec above 3600', () => {
expect(() =>
validateConfig('passport', { ...defaultConfig('passport'), refreshIntervalSec: 5000 }),
).toThrow();
});
});
describe('validateConfig — hotspot-tour', () => {
it('accepts empty hotspots array', () => {
expect(() => validateConfig('hotspot-tour', defaultConfig('hotspot-tour'))).not.toThrow();
});
it('rejects hotspot with missing position', () => {
expect(() =>
validateConfig('hotspot-tour', {
...defaultConfig('hotspot-tour'),
hotspots: [{ id: 'a', label: 'Foo' }],
}),
).toThrow();
});
it('accepts well-formed hotspot', () => {
const cfg = validateConfig('hotspot-tour', {
...defaultConfig('hotspot-tour'),
hotspots: [{ id: 'a', label: 'Foo', position: [0, 1, 2] }],
});
expect(cfg.hotspots).toHaveLength(1);
});
it('rejects more than 40 hotspots', () => {
const many = Array.from({ length: 41 }, (_, i) => ({
id: `h${i}`,
label: `Hotspot ${i}`,
position: [0, 0, 0],
}));
expect(() =>
validateConfig('hotspot-tour', { ...defaultConfig('hotspot-tour'), hotspots: many }),
).toThrow();
});
});
describe('validateConfig — errors', () => {
it('throws on unknown type', () => {
expect(() => validateConfig('unknown', {})).toThrow(/unknown widget type/);
});
it('validation errors have code "validation_error"', () => {
try {
validateConfig('turntable', { rotationSpeed: 999 });
} catch (err) {
expect(err.code).toBe('validation_error');
}
});
});
describe('resolveChainId', () => {
it('returns chainId for known slugs', () => {
expect(resolveChainId('base')).toBe(8453);
expect(resolveChainId('base-sepolia')).toBe(84532);
expect(resolveChainId('ethereum')).toBe(1);
});
it('returns numeric ref as-is', () => {
expect(resolveChainId(1)).toBe(1);
expect(resolveChainId(8453)).toBe(8453);
});
it('parses numeric string', () => {
expect(resolveChainId('137')).toBe(137);
});
it('returns null for unknown slug', () => {
expect(resolveChainId('bogus-chain')).toBe(null);
});
it('returns null for non-string, non-number input', () => {
expect(resolveChainId(null)).toBe(null);
expect(resolveChainId(undefined)).toBe(null);
expect(resolveChainId({})).toBe(null);
});
it('is case-insensitive for slugs', () => {
expect(resolveChainId('BASE')).toBe(CHAIN_SLUGS.base);
});
});
describe('chainLabel', () => {
it('returns slug for known chainId', () => {
expect(chainLabel(8453)).toBe('base');
expect(chainLabel(1)).toBe('ethereum');
});
it('returns fallback for unknown chainId', () => {
expect(chainLabel(999999)).toBe('chain-999999');
});
});