forked from Comfy-Org/ComfyUI_frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreditHelpers.spec.ts
More file actions
390 lines (342 loc) · 12.9 KB
/
Copy pathcreditHelpers.spec.ts
File metadata and controls
390 lines (342 loc) · 12.9 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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
import { expect } from '@playwright/test'
import { comfyPageFixture as test } from '@e2e/fixtures/ComfyPage'
import { LGraphEventMode } from '@/lib/litegraph/src/types/globalEnums'
import type { ComfyNodeDef } from '@/schemas/nodeDefSchema'
function buildMockApiNode(
name: string,
displayName: string,
expr: string
): ComfyNodeDef {
return {
name,
display_name: displayName,
description: 'Test API node for pricing badge checks',
category: 'testing',
input: { required: { image: ['IMAGE', {}] } },
output: ['IMAGE'],
output_is_list: [false],
output_name: ['IMAGE'],
output_node: false,
python_module: 'test_nodes',
deprecated: false,
experimental: false,
api_node: true,
price_badge: {
engine: 'jsonata',
expr,
depends_on: { widgets: [], inputs: [], input_groups: [] }
}
}
}
const MOCK_API_NODES: Record<string, ComfyNodeDef> = {
TestCreditApiNodeUsd: buildMockApiNode(
'TestCreditApiNodeUsd',
'Test Credit API Node USD',
'{"type":"usd","usd":0.05}'
),
TestCreditApiNodeRange: buildMockApiNode(
'TestCreditApiNodeRange',
'Test Credit API Node Range',
'{"type":"range_usd","min_usd":0.01,"max_usd":0.10}'
),
TestCreditApiNodeList: buildMockApiNode(
'TestCreditApiNodeList',
'Test Credit API Node List',
'{"type":"list_usd","usd":[0.02,0.05]}'
)
}
const testWithMockedObjectInfo = test.extend<{ mockApiNodes: void }>({
mockApiNodes: [
async ({ page }, use) => {
const pattern = '**/api/object_info'
await page.route(pattern, (route) =>
route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify(MOCK_API_NODES)
})
)
await use()
await page.unroute(pattern)
},
{ auto: true }
]
})
testWithMockedObjectInfo.describe(
'Credit helper pricing badges',
{ tag: '@node' },
() => {
testWithMockedObjectInfo.use({ locale: 'en-US' })
testWithMockedObjectInfo.beforeEach(async ({ comfyPage }) => {
await comfyPage.settings.setSetting('Comfy.UseNewMenu', 'Disabled')
await comfyPage.settings.setSetting('Comfy.NodeSearchBoxImpl', 'default')
await comfyPage.settings.setSetting(
'Comfy.LinkRelease.Action',
'search box'
)
await comfyPage.settings.setSetting(
'Comfy.LinkRelease.ActionShift',
'search box'
)
})
testWithMockedObjectInfo(
'shows API node indicator in node search results',
async ({ comfyPage }) => {
await comfyPage.canvasOps.doubleClick()
await expect(comfyPage.searchBoxV2.input).toBeVisible()
await comfyPage.searchBoxV2.input.fill('TestCreditApiNodeUsd')
const result = comfyPage.searchBoxV2.results
.filter({ hasText: 'Test Credit API Node USD' })
.first()
await expect(result).toBeVisible()
// In search results with showDescription=true, the component icon is shown
// (not the pricing badge). Verify the API node indicator is present.
const apiIndicator = result.locator('i[class*="lucide--component"]')
await expect(apiIndicator).toBeVisible()
}
)
testWithMockedObjectInfo(
'shows pricing badge in VueNodes node header',
async ({ comfyPage }) => {
await comfyPage.settings.setSetting('Comfy.VueNodes.Enabled', true)
await comfyPage.settings.setSetting(
'Comfy.NodeBadge.ShowApiPricing',
true
)
await comfyPage.nodeOps.clearGraph()
const nodeId = await comfyPage.page.evaluate(() => {
const node = window.LiteGraph!.createNode('TestCreditApiNodeUsd')
window.app!.graph.add(node!)
return node!.id
})
await comfyPage.vueNodes.waitForNodes(1)
const header = comfyPage.page.locator(
`[data-testid="node-header-${nodeId}"]`
)
await expect(header).toBeVisible()
// CreditBadge uses icon-[lucide--component] for the credits icon
const creditsBadge = header.locator('i[class*="lucide--component"]')
await expect(creditsBadge).toBeVisible()
// Verify the badge text contains expected credit amount (10.6 credits for $0.05)
const badgeContainer = header.locator(
'span:has(> i[class*="lucide--component"])'
)
await expect
.poll(async () => (await badgeContainer.textContent())?.trim() ?? '')
.toContain('10.6')
}
)
testWithMockedObjectInfo(
'shows range pricing in VueNodes node header',
async ({ comfyPage }) => {
await comfyPage.settings.setSetting('Comfy.VueNodes.Enabled', true)
await comfyPage.settings.setSetting(
'Comfy.NodeBadge.ShowApiPricing',
true
)
await comfyPage.nodeOps.clearGraph()
const nodeId = await comfyPage.page.evaluate(() => {
const node = window.LiteGraph!.createNode('TestCreditApiNodeRange')
window.app!.graph.add(node!)
return node!.id
})
await comfyPage.vueNodes.waitForNodes(1)
const header = comfyPage.page.locator(
`[data-testid="node-header-${nodeId}"]`
)
await expect(header).toBeVisible()
// Verify range format (2.1-21.1 credits for $0.01-$0.10)
const badgeContainer = header.locator(
'span:has(> i[class*="lucide--component"])'
)
await expect
.poll(async () => (await badgeContainer.textContent())?.trim() ?? '')
.toContain('2.1-21.1')
}
)
testWithMockedObjectInfo(
'shows list pricing in VueNodes node header',
async ({ comfyPage }) => {
await comfyPage.settings.setSetting('Comfy.VueNodes.Enabled', true)
await comfyPage.settings.setSetting(
'Comfy.NodeBadge.ShowApiPricing',
true
)
await comfyPage.nodeOps.clearGraph()
const nodeId = await comfyPage.page.evaluate(() => {
const node = window.LiteGraph!.createNode('TestCreditApiNodeList')
window.app!.graph.add(node!)
return node!.id
})
await comfyPage.vueNodes.waitForNodes(1)
const header = comfyPage.page.locator(
`[data-testid="node-header-${nodeId}"]`
)
await expect(header).toBeVisible()
// Verify list format (4.2/10.6 credits for [$0.02, $0.05])
const badgeContainer = header.locator(
'span:has(> i[class*="lucide--component"])'
)
await expect
.poll(async () => (await badgeContainer.textContent())?.trim() ?? '')
.toContain('4.2/10.6')
}
)
for (const { compact, hideStatus } of [
{ compact: false, hideStatus: false },
{ compact: false, hideStatus: true },
{ compact: true, hideStatus: false },
{ compact: true, hideStatus: true }
] as const) {
testWithMockedObjectInfo(
`keeps collapsed badges independent with compact=${compact} and hideStatus=${hideStatus}`,
async ({ comfyPage }) => {
await comfyPage.settings.setSetting('Comfy.VueNodes.Enabled', true)
await comfyPage.settings.setSetting(
'Comfy.NodeBadge.ShowApiPricing',
true
)
await comfyPage.settings.setSetting(
'Comfy.VueNodes.CompactCollapsedNodes',
compact
)
await comfyPage.settings.setSetting(
'Comfy.VueNodes.HideStatusBadges',
hideStatus
)
await comfyPage.nodeOps.clearGraph()
const nodeId = await comfyPage.page.evaluate((mode) => {
const node = window.LiteGraph!.createNode('TestCreditApiNodeUsd')!
node.mode = mode
node.title = 'API'
node.setPos(100, 100)
node.setSize([400, node.size[1]])
window.app!.graph.add(node)
return node.id
}, LGraphEventMode.BYPASS)
await comfyPage.vueNodes.waitForNodes(1)
const vueNode = comfyPage.vueNodes.getNodeLocator(String(nodeId))
const header = vueNode.locator(
`[data-testid="node-header-${nodeId}"]`
)
const collapseButton = vueNode.getByTestId('node-collapse-button')
const pricing = header.locator(
'span:has(> i[class*="lucide--component"])'
)
const status = header.getByText('Bypassed', { exact: true })
await expect(pricing).toContainText('10.6')
await expect(status).toHaveCount(hideStatus ? 0 : 1)
const expandedBox = await vueNode.boundingBox()
if (!expandedBox) throw new Error('Expanded node has no bounds')
await collapseButton.press('Enter')
await expect(vueNode).toHaveAttribute('data-collapsed', 'true')
await expect(pricing).toHaveCount(compact ? 0 : 1)
await expect(status).toHaveCount(compact || hideStatus ? 0 : 1)
if (compact) {
await expect
.poll(async () => (await vueNode.boundingBox())?.width)
.toBeLessThan(expandedBox.width)
} else {
await expect
.poll(() =>
vueNode.evaluate((element) =>
Number.parseFloat(getComputedStyle(element).width)
)
)
.toBeGreaterThanOrEqual(225)
}
await collapseButton.press('Enter')
await expect(pricing).toHaveCount(1)
await expect(status).toHaveCount(hideStatus ? 0 : 1)
await expect
.poll(async () => (await vueNode.boundingBox())?.width)
.toBeCloseTo(expandedBox.width, 0)
}
)
}
testWithMockedObjectInfo(
'updates compact and status settings while a node is mounted',
async ({ comfyPage }) => {
await comfyPage.settings.setSetting('Comfy.VueNodes.Enabled', true)
await comfyPage.settings.setSetting(
'Comfy.NodeBadge.ShowApiPricing',
true
)
await comfyPage.settings.setSetting(
'Comfy.VueNodes.CompactCollapsedNodes',
false
)
await comfyPage.settings.setSetting(
'Comfy.VueNodes.HideStatusBadges',
false
)
await comfyPage.nodeOps.clearGraph()
const nodeId = await comfyPage.page.evaluate((mode) => {
const node = window.LiteGraph!.createNode('TestCreditApiNodeUsd')!
node.mode = mode
node.title = 'API'
node.setPos(100, 100)
node.setSize([400, node.size[1]])
window.app!.graph.add(node)
return node.id
}, LGraphEventMode.NEVER)
await comfyPage.vueNodes.waitForNodes(1)
const nodeFixture = await comfyPage.vueNodes.getFixtureByTitle('API')
const vueNode = comfyPage.vueNodes.getNodeLocator(String(nodeId))
const header = vueNode.locator(`[data-testid="node-header-${nodeId}"]`)
const pricing = header.locator(
'span:has(> i[class*="lucide--component"])'
)
const status = header.getByText('Muted', { exact: true })
await expect(pricing).toContainText('10.6')
await nodeFixture.collapseButton.press('Enter')
await expect(pricing).toHaveCount(1)
await expect(status).toHaveCount(1)
const normalCollapsedBox = await vueNode.boundingBox()
if (!normalCollapsedBox) throw new Error('Collapsed node has no bounds')
await comfyPage.settings.setSetting(
'Comfy.VueNodes.CompactCollapsedNodes',
true
)
await expect(pricing).toHaveCount(0)
await expect(status).toHaveCount(0)
await expect
.poll(async () => (await vueNode.boundingBox())?.width)
.toBeLessThan(normalCollapsedBox.width)
await comfyPage.settings.setSetting(
'Comfy.VueNodes.CompactCollapsedNodes',
false
)
await expect(pricing).toHaveCount(1)
await expect(status).toHaveCount(1)
await comfyPage.settings.setSetting(
'Comfy.VueNodes.HideStatusBadges',
true
)
await expect(status).toHaveCount(0)
await expect(pricing).toHaveCount(1)
await nodeFixture.collapseButton.press('Enter')
await expect(status).toHaveCount(0)
await expect(pricing).toHaveCount(1)
await comfyPage.settings.setSetting(
'Comfy.VueNodes.HideStatusBadges',
false
)
await expect(status).toHaveCount(1)
await comfyPage.settings.setSetting(
'Comfy.VueNodes.CompactCollapsedNodes',
true
)
await nodeFixture.setTitle(
'A deliberately long API node title that must remain width capped'
)
const expandedBox = await vueNode.boundingBox()
if (!expandedBox) throw new Error('Expanded node has no bounds')
await nodeFixture.collapseButton.press('Enter')
await expect
.poll(async () => (await vueNode.boundingBox())?.width)
.toBeLessThanOrEqual(expandedBox.width)
}
)
}
)