|
| 1 | +import { |
| 2 | + comfyExpect as expect, |
| 3 | + comfyPageFixture as test |
| 4 | +} from '../../fixtures/ComfyPage' |
| 5 | +import { VueNodeFixture } from '../../fixtures/utils/vueNodeFixtures' |
| 6 | + |
| 7 | +test.describe('NodeHeader', () => { |
| 8 | + test.beforeEach(async ({ comfyPage }) => { |
| 9 | + await comfyPage.setSetting('Comfy.UseNewMenu', 'Enabled') |
| 10 | + await comfyPage.setSetting('Comfy.Graph.CanvasMenu', false) |
| 11 | + await comfyPage.setSetting('Comfy.EnableTooltips', true) |
| 12 | + await comfyPage.setup() |
| 13 | + // Load single SaveImage node workflow (positioned below menu bar) |
| 14 | + await comfyPage.loadWorkflow('single_save_image_node') |
| 15 | + }) |
| 16 | + |
| 17 | + test('displays node title', async ({ comfyPage }) => { |
| 18 | + // Get the single SaveImage node from the workflow |
| 19 | + const nodes = await comfyPage.getNodeRefsByType('SaveImage') |
| 20 | + expect(nodes.length).toBeGreaterThanOrEqual(1) |
| 21 | + |
| 22 | + const node = nodes[0] |
| 23 | + const vueNode = new VueNodeFixture(node, comfyPage.page) |
| 24 | + |
| 25 | + const title = await vueNode.getTitle() |
| 26 | + expect(title).toBe('Save Image') |
| 27 | + |
| 28 | + // Verify title is visible in the header |
| 29 | + const header = await vueNode.getHeader() |
| 30 | + await expect(header).toContainText('Save Image') |
| 31 | + }) |
| 32 | + |
| 33 | + test('allows title renaming', async ({ comfyPage }) => { |
| 34 | + // Get the single SaveImage node from the workflow |
| 35 | + const nodes = await comfyPage.getNodeRefsByType('SaveImage') |
| 36 | + const node = nodes[0] |
| 37 | + const vueNode = new VueNodeFixture(node, comfyPage.page) |
| 38 | + |
| 39 | + // Test renaming with Enter |
| 40 | + await vueNode.setTitle('My Custom Sampler') |
| 41 | + const newTitle = await vueNode.getTitle() |
| 42 | + expect(newTitle).toBe('My Custom Sampler') |
| 43 | + |
| 44 | + // Verify the title is displayed |
| 45 | + const header = await vueNode.getHeader() |
| 46 | + await expect(header).toContainText('My Custom Sampler') |
| 47 | + |
| 48 | + // Test cancel with Escape |
| 49 | + const titleElement = await vueNode.getTitleElement() |
| 50 | + await titleElement.dblclick() |
| 51 | + await comfyPage.nextFrame() |
| 52 | + |
| 53 | + // Type a different value but cancel |
| 54 | + const input = (await vueNode.getHeader()).locator( |
| 55 | + '[data-testid="node-title-input"]' |
| 56 | + ) |
| 57 | + await input.fill('This Should Be Cancelled') |
| 58 | + await input.press('Escape') |
| 59 | + await comfyPage.nextFrame() |
| 60 | + |
| 61 | + // Title should remain as the previously saved value |
| 62 | + const titleAfterCancel = await vueNode.getTitle() |
| 63 | + expect(titleAfterCancel).toBe('My Custom Sampler') |
| 64 | + }) |
| 65 | + |
| 66 | + test('handles node collapsing', async ({ comfyPage }) => { |
| 67 | + // Get the single SaveImage node from the workflow |
| 68 | + const nodes = await comfyPage.getNodeRefsByType('SaveImage') |
| 69 | + const node = nodes[0] |
| 70 | + const vueNode = new VueNodeFixture(node, comfyPage.page) |
| 71 | + |
| 72 | + // Initially should not be collapsed |
| 73 | + expect(await node.isCollapsed()).toBe(false) |
| 74 | + const body = await vueNode.getBody() |
| 75 | + await expect(body).toBeVisible() |
| 76 | + |
| 77 | + // Collapse the node |
| 78 | + await vueNode.toggleCollapse() |
| 79 | + expect(await node.isCollapsed()).toBe(true) |
| 80 | + |
| 81 | + // Verify node content is hidden |
| 82 | + const collapsedSize = await node.getSize() |
| 83 | + await expect(body).not.toBeVisible() |
| 84 | + |
| 85 | + // Expand again |
| 86 | + await vueNode.toggleCollapse() |
| 87 | + expect(await node.isCollapsed()).toBe(false) |
| 88 | + await expect(body).toBeVisible() |
| 89 | + |
| 90 | + // Size should be restored |
| 91 | + const expandedSize = await node.getSize() |
| 92 | + expect(expandedSize.height).toBeGreaterThanOrEqual(collapsedSize.height) |
| 93 | + }) |
| 94 | + |
| 95 | + test('shows collapse/expand icon state', async ({ comfyPage }) => { |
| 96 | + // Get the single SaveImage node from the workflow |
| 97 | + const nodes = await comfyPage.getNodeRefsByType('SaveImage') |
| 98 | + const node = nodes[0] |
| 99 | + const vueNode = new VueNodeFixture(node, comfyPage.page) |
| 100 | + |
| 101 | + // Check initial expanded state icon |
| 102 | + let iconClass = await vueNode.getCollapseIconClass() |
| 103 | + expect(iconClass).toContain('pi-chevron-down') |
| 104 | + |
| 105 | + // Collapse and check icon |
| 106 | + await vueNode.toggleCollapse() |
| 107 | + iconClass = await vueNode.getCollapseIconClass() |
| 108 | + expect(iconClass).toContain('pi-chevron-right') |
| 109 | + |
| 110 | + // Expand and check icon |
| 111 | + await vueNode.toggleCollapse() |
| 112 | + iconClass = await vueNode.getCollapseIconClass() |
| 113 | + expect(iconClass).toContain('pi-chevron-down') |
| 114 | + }) |
| 115 | + |
| 116 | + test('preserves title when collapsing/expanding', async ({ comfyPage }) => { |
| 117 | + // Get the single SaveImage node from the workflow |
| 118 | + const nodes = await comfyPage.getNodeRefsByType('SaveImage') |
| 119 | + const node = nodes[0] |
| 120 | + const vueNode = new VueNodeFixture(node, comfyPage.page) |
| 121 | + |
| 122 | + // Set custom title |
| 123 | + await vueNode.setTitle('Test Sampler') |
| 124 | + expect(await vueNode.getTitle()).toBe('Test Sampler') |
| 125 | + |
| 126 | + // Collapse |
| 127 | + await vueNode.toggleCollapse() |
| 128 | + expect(await vueNode.getTitle()).toBe('Test Sampler') |
| 129 | + |
| 130 | + // Expand |
| 131 | + await vueNode.toggleCollapse() |
| 132 | + expect(await vueNode.getTitle()).toBe('Test Sampler') |
| 133 | + |
| 134 | + // Verify title is still displayed |
| 135 | + const header = await vueNode.getHeader() |
| 136 | + await expect(header).toContainText('Test Sampler') |
| 137 | + }) |
| 138 | +}) |
0 commit comments