mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-30 11:11:53 +00:00
Removed Css states from bypassbutton and updates tests
This commit is contained in:
@@ -3,19 +3,23 @@ import PrimeVue from 'primevue/config'
|
|||||||
import Tooltip from 'primevue/tooltip'
|
import Tooltip from 'primevue/tooltip'
|
||||||
import { beforeEach, describe, expect, test, vi } from 'vitest'
|
import { beforeEach, describe, expect, test, vi } from 'vitest'
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
|
import { computed } from 'vue'
|
||||||
import { createI18n } from 'vue-i18n'
|
import { createI18n } from 'vue-i18n'
|
||||||
|
|
||||||
import BypassButton from '@/components/graph/selectionToolbox/BypassButton.vue'
|
import BypassButton from '@/components/graph/selectionToolbox/BypassButton.vue'
|
||||||
import { useSelectionState } from '@/composables/graph/useSelectionState'
|
|
||||||
import { useCommandStore } from '@/stores/commandStore'
|
|
||||||
|
|
||||||
// Mock all dependencies
|
const commandStore = {
|
||||||
|
execute: vi.fn()
|
||||||
|
}
|
||||||
|
const selectionState = {
|
||||||
|
hasAnySelection: ref(true)
|
||||||
|
}
|
||||||
vi.mock('@/stores/commandStore', () => ({
|
vi.mock('@/stores/commandStore', () => ({
|
||||||
useCommandStore: vi.fn()
|
useCommandStore: vi.fn(() => commandStore)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
vi.mock('@/composables/graph/useSelectionState', () => ({
|
vi.mock('@/composables/graph/useSelectionState', () => ({
|
||||||
useSelectionState: vi.fn()
|
useSelectionState: vi.fn(() => selectionState)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
describe('BypassButton', () => {
|
describe('BypassButton', () => {
|
||||||
@@ -26,46 +30,17 @@ describe('BypassButton', () => {
|
|||||||
en: {
|
en: {
|
||||||
selectionToolbox: {
|
selectionToolbox: {
|
||||||
bypassButton: {
|
bypassButton: {
|
||||||
tooltip: 'Bypass/Unbypass Selected Nodes'
|
tooltip: 'Fake Bypass text'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'commands.Comfy_Canvas_ToggleSelectedNodes_Bypass.label':
|
'commands.Comfy_Canvas_ToggleSelectedNodes_Bypass.label':
|
||||||
'Toggle Bypass Selected Nodes'
|
'Fake Toggle Bypass'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Mock interfaces
|
|
||||||
interface MockCommandStore {
|
|
||||||
execute: ReturnType<typeof vi.fn>
|
|
||||||
}
|
|
||||||
|
|
||||||
interface MockSelectionState {
|
|
||||||
hasAnySelection: { value: boolean }
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mock instances
|
|
||||||
let mockCommandStore: MockCommandStore
|
|
||||||
let mockSelectionState: MockSelectionState
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks()
|
vi.resetAllMocks()
|
||||||
|
|
||||||
// Setup mock command store
|
|
||||||
mockCommandStore = {
|
|
||||||
execute: vi.fn().mockResolvedValue(undefined)
|
|
||||||
}
|
|
||||||
vi.mocked(useCommandStore).mockReturnValue(
|
|
||||||
mockCommandStore as unknown as ReturnType<typeof useCommandStore>
|
|
||||||
)
|
|
||||||
|
|
||||||
// Setup mock selection state
|
|
||||||
mockSelectionState = {
|
|
||||||
hasAnySelection: ref(true)
|
|
||||||
}
|
|
||||||
vi.mocked(useSelectionState).mockReturnValue(
|
|
||||||
mockSelectionState as unknown as ReturnType<typeof useSelectionState>
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const mountComponent = () => {
|
const mountComponent = () => {
|
||||||
@@ -95,8 +70,7 @@ describe('BypassButton', () => {
|
|||||||
test('should execute bypass command when clicked', async () => {
|
test('should execute bypass command when clicked', async () => {
|
||||||
const wrapper = mountComponent()
|
const wrapper = mountComponent()
|
||||||
await wrapper.find('button').trigger('click')
|
await wrapper.find('button').trigger('click')
|
||||||
|
expect(commandStore.execute).toHaveBeenCalledWith(
|
||||||
expect(mockCommandStore.execute).toHaveBeenCalledWith(
|
|
||||||
'Comfy.Canvas.ToggleSelectedNodes.Bypass'
|
'Comfy.Canvas.ToggleSelectedNodes.Bypass'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -104,11 +78,14 @@ describe('BypassButton', () => {
|
|||||||
test('should show button when hasAnySelection is true', () => {
|
test('should show button when hasAnySelection is true', () => {
|
||||||
const wrapper = mountComponent()
|
const wrapper = mountComponent()
|
||||||
const button = wrapper.find('button')
|
const button = wrapper.find('button')
|
||||||
expect(button.isVisible()).toBe(true)
|
expect(button.element.style.display).toBe('')
|
||||||
})
|
})
|
||||||
|
|
||||||
test('should call useSelectionState composable', () => {
|
test('Button should not show when hasAnySelection is false', async () => {
|
||||||
mountComponent()
|
selectionState.hasAnySelection = computed(() => false)
|
||||||
expect(useSelectionState).toHaveBeenCalled()
|
const wrapper = mountComponent()
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
const button = wrapper.find('button')
|
||||||
|
expect(button.element.style.display).toBe('none')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -8,11 +8,7 @@
|
|||||||
severity="secondary"
|
severity="secondary"
|
||||||
text
|
text
|
||||||
data-testid="bypass-button"
|
data-testid="bypass-button"
|
||||||
:class="{
|
class="hover:dark-theme:bg-[#262729] hover:bg-[#E7E6E6]"
|
||||||
'hover:dark-theme:!bg-[#262729] hover:!bg-[#E7E6E6]': true,
|
|
||||||
'dark-theme:[&:not(:active)]:!bg-[#262729] [&:not(:active)]:!bg-[#E7E6E6]':
|
|
||||||
isBypassed
|
|
||||||
}"
|
|
||||||
@click="toggleBypass"
|
@click="toggleBypass"
|
||||||
>
|
>
|
||||||
<template #icon>
|
<template #icon>
|
||||||
@@ -23,7 +19,6 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import Button from 'primevue/button'
|
import Button from 'primevue/button'
|
||||||
import { ref } from 'vue'
|
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
|
|
||||||
import { useSelectionState } from '@/composables/graph/useSelectionState'
|
import { useSelectionState } from '@/composables/graph/useSelectionState'
|
||||||
@@ -32,7 +27,7 @@ import { useCommandStore } from '@/stores/commandStore'
|
|||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const commandStore = useCommandStore()
|
const commandStore = useCommandStore()
|
||||||
const { hasAnySelection } = useSelectionState()
|
const { hasAnySelection } = useSelectionState()
|
||||||
const isBypassed = ref(false)
|
console.log('hasAnySelection', hasAnySelection)
|
||||||
|
|
||||||
const toggleBypass = async () => {
|
const toggleBypass = async () => {
|
||||||
await commandStore.execute('Comfy.Canvas.ToggleSelectedNodes.Bypass')
|
await commandStore.execute('Comfy.Canvas.ToggleSelectedNodes.Bypass')
|
||||||
|
|||||||
Reference in New Issue
Block a user