Add test for selecting nodes on mac (#1055)

* Add test for selecting nodes on mac

* Deselect nodes in teardown

* Fix unstable test. Remove test on unimplemented feature
This commit is contained in:
bymyself
2024-10-02 07:42:57 -07:00
committed by GitHub
parent 3f10fd53bd
commit 31b1aeeb69
2 changed files with 54 additions and 13 deletions

View File

@@ -413,6 +413,16 @@ export class ComfyPage {
}) })
} }
async getSelectedGraphNodesCount(): Promise<number> {
return await this.page.evaluate(() => {
return (
window['app']?.graph?.nodes?.filter(
(node: any) => node.is_selected === true
).length || 0
)
})
}
async setupWorkflowsDirectory(structure: FolderStructure) { async setupWorkflowsDirectory(structure: FolderStructure) {
const resp = await this.request.post( const resp = await this.request.post(
`${this.url}/api/devtools/setup_folder_structure`, `${this.url}/api/devtools/setup_folder_structure`,
@@ -914,13 +924,15 @@ export class ComfyPage {
return new NodeReference(id, this) return new NodeReference(id, this)
} }
async getNodeRefsByType(type: string): Promise<NodeReference[]> { async getNodeRefsByType(type: string): Promise<NodeReference[]> {
return ( return Promise.all(
await this.page.evaluate((type) => { (
return window['app'].graph.nodes await this.page.evaluate((type) => {
.filter((n) => n.type === type) return window['app'].graph.nodes
.map((n) => n.id) .filter((n) => n.type === type)
}, type) .map((n) => n.id)
).map((id: NodeId) => this.getNodeRefById(id)) }, type)
).map((id: NodeId) => this.getNodeRefById(id))
)
} }
async getFirstNodeRef(): Promise<NodeReference | null> { async getFirstNodeRef(): Promise<NodeReference | null> {
const id = await this.page.evaluate(() => { const id = await this.page.evaluate(() => {

View File

@@ -11,12 +11,41 @@ test.describe('Node Interaction', () => {
await expect(textBox).toHaveValue('Hello World 2') await expect(textBox).toHaveValue('Hello World 2')
}) })
test('Can highlight selected', async ({ comfyPage }) => { test.describe('Node Selection', () => {
await expect(comfyPage.canvas).toHaveScreenshot('default.png') test.afterEach(async ({ comfyPage }) => {
await comfyPage.clickTextEncodeNode1() // Deselect all nodes
await expect(comfyPage.canvas).toHaveScreenshot('selected-node1.png') await comfyPage.clickEmptySpace()
await comfyPage.clickTextEncodeNode2() })
await expect(comfyPage.canvas).toHaveScreenshot('selected-node2.png')
test('Can highlight selected', async ({ comfyPage }) => {
await expect(comfyPage.canvas).toHaveScreenshot('default.png')
await comfyPage.clickTextEncodeNode1()
await expect(comfyPage.canvas).toHaveScreenshot('selected-node1.png')
await comfyPage.clickTextEncodeNode2()
await expect(comfyPage.canvas).toHaveScreenshot('selected-node2.png')
})
test('Can drag-select nodes with Meta (mac)', async ({ comfyPage }) => {
const clipNodes = await comfyPage.getNodeRefsByType('CLIPTextEncode')
const clipNode1Pos = await clipNodes[0].getPosition()
const clipNode2Pos = await clipNodes[1].getPosition()
const offset = 64
await comfyPage.page.keyboard.down('Meta')
await comfyPage.dragAndDrop(
{
x: Math.min(clipNode1Pos.x, clipNode2Pos.x) - offset,
y: Math.min(clipNode1Pos.y, clipNode2Pos.y) - offset
},
{
x: Math.max(clipNode1Pos.x, clipNode2Pos.x) + offset,
y: Math.max(clipNode1Pos.y, clipNode2Pos.y) + offset
}
)
await comfyPage.page.keyboard.up('Meta')
expect(await comfyPage.getSelectedGraphNodesCount()).toBe(
clipNodes.length
)
})
}) })
test('Can drag node', async ({ comfyPage }) => { test('Can drag node', async ({ comfyPage }) => {