Skip to content

Commit

Permalink
Fix node searchbox filter removal (#881)
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei authored Sep 19, 2024
1 parent 63302a6 commit 98de010
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 3 deletions.
48 changes: 48 additions & 0 deletions browser_tests/ComfyPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,37 @@ interface Size {
height: number
}

class ComfyNodeSearchFilterSelectionPanel {
constructor(public readonly page: Page) {}

async selectFilterType(filterType: string) {
await this.page
.locator(
`.filter-type-select .p-togglebutton-label:has-text("${filterType}")`
)
.click()
}

async selectFilterValue(filterValue: string) {
await this.page.locator('.filter-value-select .p-select-dropdown').click()
await this.page
.locator(
`.p-select-overlay .p-select-list .p-select-option-label:text-is("${filterValue}")`
)
.click()
}

async addFilter(filterValue: string, filterType: string) {
await this.selectFilterType(filterType)
await this.selectFilterValue(filterValue)
await this.page.locator('.p-button-label:has-text("Add")').click()
}
}

class ComfyNodeSearchBox {
public readonly input: Locator
public readonly dropdown: Locator
public readonly filterSelectionPanel: ComfyNodeSearchFilterSelectionPanel

constructor(public readonly page: Page) {
this.input = page.locator(
Expand All @@ -26,6 +54,11 @@ class ComfyNodeSearchBox {
this.dropdown = page.locator(
'.comfy-vue-node-search-container .p-autocomplete-list'
)
this.filterSelectionPanel = new ComfyNodeSearchFilterSelectionPanel(page)
}

get filterButton() {
return this.page.locator('.comfy-vue-node-search-container ._filter-button')
}

async fillAndSelectFirstNode(
Expand All @@ -43,6 +76,21 @@ class ComfyNodeSearchBox {
.nth(options?.suggestionIndex || 0)
.click()
}

async addFilter(filterValue: string, filterType: string) {
await this.filterButton.click()
await this.filterSelectionPanel.addFilter(filterValue, filterType)
}

get filterChips() {
return this.page.locator(
'.comfy-vue-node-search-container .p-autocomplete-chip-item'
)
}

async removeFilter(index: number) {
await this.filterChips.nth(index).locator('.p-chip-remove-icon').click()
}
}

class NodeLibrarySidebarTab {
Expand Down
24 changes: 24 additions & 0 deletions browser_tests/nodeSearchBox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,30 @@ test.describe('Node search box', () => {
await comfyPage.page.waitForTimeout(256)
await expect(comfyPage.searchBox.input).not.toHaveCount(0)
})

test.describe('Filtering', () => {
test.beforeEach(async ({ comfyPage }) => {
await comfyPage.doubleClickCanvas()
})

test('Can add filter', async ({ comfyPage }) => {
await comfyPage.searchBox.addFilter('MODEL', 'Input Type')
await expect(comfyPage.searchBox.filterChips).toHaveCount(1)
})

test('Can add multiple filters', async ({ comfyPage }) => {
await comfyPage.searchBox.addFilter('MODEL', 'Input Type')
await comfyPage.searchBox.addFilter('CLIP', 'Output Type')
await expect(comfyPage.searchBox.filterChips).toHaveCount(2)
})

test('Can remove filter', async ({ comfyPage }) => {
await comfyPage.searchBox.addFilter('MODEL', 'Input Type')
await comfyPage.searchBox.addFilter('CLIP', 'Output Type')
await comfyPage.searchBox.removeFilter(0)
await expect(comfyPage.searchBox.filterChips).toHaveCount(1)
})
})
})

test.describe('Release context menu', () => {
Expand Down
6 changes: 4 additions & 2 deletions src/components/searchbox/NodeSearchBoxPopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

<script setup lang="ts">
import { app } from '@/scripts/app'
import { computed, onMounted, onUnmounted, ref, watchEffect } from 'vue'
import { computed, onMounted, onUnmounted, ref, toRaw, watchEffect } from 'vue'
import NodeSearchBox from './NodeSearchBox.vue'
import Dialog from 'primevue/dialog'
import { ConnectingLink } from '@comfyorg/litegraph'
Expand Down Expand Up @@ -66,7 +66,9 @@ const addFilter = (filter: FilterAndValue) => {
nodeFilters.value.push(filter)
}
const removeFilter = (filter: FilterAndValue) => {
nodeFilters.value = nodeFilters.value.filter((f) => f !== filter)
nodeFilters.value = nodeFilters.value.filter(
(f) => toRaw(f) !== toRaw(filter)
)
}
const clearFilters = () => {
nodeFilters.value = []
Expand Down
8 changes: 7 additions & 1 deletion src/components/searchbox/NodeSearchFilter.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<template>
<div class="_content">
<SelectButton
class="filter-type-select"
v-model="selectedFilter"
:options="filters"
:allowEmpty="false"
optionLabel="name"
@change="updateSelectedFilterValue"
/>
<Select v-model="selectedFilterValue" :options="filterValues" filter />
<Select
class="filter-value-select"
v-model="selectedFilterValue"
:options="filterValues"
filter
/>
</div>
<div class="_footer">
<Button type="button" :label="$t('add')" @click="submit"></Button>
Expand Down

0 comments on commit 98de010

Please sign in to comment.