|
| 1 | +import type { Locator } from '@playwright/test' |
| 2 | + |
| 3 | +import { comfyExpect as expect } from '@e2e/fixtures/ComfyPage' |
| 4 | +import type { ComfyPage } from '@e2e/fixtures/ComfyPage' |
| 5 | +import { TestIds } from '@e2e/fixtures/selectors' |
| 6 | +import { dragByIndex } from '@e2e/fixtures/utils/dragAndDrop' |
| 7 | +import { VueNodeFixture } from '@e2e/fixtures/utils/vueNodeFixtures' |
| 8 | + |
| 9 | +export class SubgraphEditor { |
| 10 | + public readonly root: Locator |
| 11 | + public readonly promotionItems: Locator |
| 12 | + |
| 13 | + constructor(protected readonly comfyPage: ComfyPage) { |
| 14 | + this.root = this.comfyPage.menu.propertiesPanel.root |
| 15 | + this.promotionItems = this.root.getByTestId( |
| 16 | + TestIds.subgraphEditor.widgetItem |
| 17 | + ) |
| 18 | + } |
| 19 | + |
| 20 | + async open(subgraphNode: Locator) { |
| 21 | + await new VueNodeFixture(subgraphNode).select() |
| 22 | + const menu = await this.comfyPage.contextMenu.openFor(subgraphNode) |
| 23 | + await menu.clickMenuItemExact('Edit Subgraph Widgets') |
| 24 | + await expect(this.root, 'Open Properties Panel').toBeVisible() |
| 25 | + } |
| 26 | + |
| 27 | + resolveItem(options: { |
| 28 | + nodeName?: string |
| 29 | + nodeId?: string |
| 30 | + widgetName: string |
| 31 | + }): Locator { |
| 32 | + const nodeItems = |
| 33 | + options.nodeId !== undefined |
| 34 | + ? this.comfyPage.page.locator(`[data-nodeid="${options.nodeId}"]`) |
| 35 | + : options.nodeName !== undefined |
| 36 | + ? this.promotionItems.filter({ |
| 37 | + has: this.comfyPage.page |
| 38 | + .getByTestId(TestIds.subgraphEditor.nodeName) |
| 39 | + .filter({ hasText: options.nodeName }) |
| 40 | + }) |
| 41 | + : this.promotionItems |
| 42 | + |
| 43 | + return nodeItems.filter({ |
| 44 | + has: this.comfyPage.page |
| 45 | + .getByTestId(TestIds.subgraphEditor.widgetLabel) |
| 46 | + .filter({ hasText: options.widgetName }) |
| 47 | + }) |
| 48 | + } |
| 49 | + |
| 50 | + getToggleButton(item: Locator) { |
| 51 | + return item.getByTestId(TestIds.subgraphEditor.widgetToggle) |
| 52 | + } |
| 53 | + |
| 54 | + async togglePromotionOnItem(item: Locator, toState?: boolean) { |
| 55 | + const toggleIcon = item.getByTestId(TestIds.subgraphEditor.iconEye) |
| 56 | + if (toState !== undefined) { |
| 57 | + const expectedIcon = `icon-[lucide--eye${toState ? '-off' : ''}]` |
| 58 | + await expect(toggleIcon).toContainClass(expectedIcon) |
| 59 | + } |
| 60 | + await toggleIcon.click() |
| 61 | + } |
| 62 | + |
| 63 | + async togglePromotion( |
| 64 | + subgraphNode: Locator, |
| 65 | + options: { |
| 66 | + nodeName?: string |
| 67 | + nodeId?: string |
| 68 | + widgetName: string |
| 69 | + toState?: boolean |
| 70 | + } |
| 71 | + ) { |
| 72 | + await this.open(subgraphNode) |
| 73 | + |
| 74 | + const item = this.resolveItem(options) |
| 75 | + await this.togglePromotionOnItem(item, options.toState) |
| 76 | + } |
| 77 | + async dragItem(fromIndex: number, toIndex: number) { |
| 78 | + await dragByIndex(this.promotionItems, fromIndex, toIndex) |
| 79 | + await this.comfyPage.nextFrame() |
| 80 | + } |
| 81 | +} |
0 commit comments