Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions browser_tests/assets/inputs/boolean_input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"last_node_id": 1,
"last_link_id": 0,
"nodes": [
{
"id": 1,
"type": "PrimitiveBoolean",
"pos": [300, 200],
"size": [350, 240],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "BOOLEAN",
"type": "BOOLEAN",
"links": []
}
],
"properties": {
"Node name for S&R": "PrimitiveBoolean"
},
"widgets_values": [true],
"title": "Boolean"
}
],
"links": [],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 0.8,
"offset": [0, 0]
}
},
"version": 0.4
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import type { Locator } from '@playwright/test'

import {
comfyExpect as expect,
comfyPageFixture as test
} from '@e2e/fixtures/ComfyPage'
import { WidgetSelectDropdownFixture } from '@e2e/fixtures/components/WidgetSelectDropdown'
import { createMockJob } from '@e2e/fixtures/helpers/AssetsHelper'
import { TestIds } from '@e2e/fixtures/selectors'
import type { DraftPayloadV2 } from '@/platform/workflow/persistence/base/draftTypes'
import type { ComfyWorkflowJSON } from '@/platform/workflow/validation/schemas/workflowSchema'
import { assetPath } from '@e2e/fixtures/utils/paths'
import { mockViewFiles } from '@e2e/fixtures/utils/viewFileMocks'

Expand All @@ -16,6 +20,54 @@ test.describe(
await comfyPage.workflow.setupWorkflowsDirectory({})
})

test.describe('Boolean drafts', () => {
test.use({ initialSettings: { 'Comfy.Workflow.Persist': true } })

for (const { action, toggleValue } of [
{ action: 'click', toggleValue: (toggle: Locator) => toggle.click() },
{
action: 'Enter',
toggleValue: (toggle: Locator) => toggle.press('Enter')
}
]) {
test(`keeps a toggle-only ${action} edit after reload`, async ({
comfyPage
}) => {
await comfyPage.workflow.loadWorkflow('inputs/boolean_input')
await comfyPage.workflow.waitForDraftPersisted()
await comfyPage.workflow.reloadAndWaitForApp()
const toggle = comfyPage.vueNodes
.getNodeByTitle('Boolean')
.getByRole('switch')
await expect(toggle).toBeChecked()

await toggleValue(toggle)
await expect(toggle).not.toBeChecked()

await expect
.poll(() =>
comfyPage.page.evaluate(() => {
return Object.keys(localStorage).some((key) => {
if (!key.startsWith('Comfy.Workflow.Draft.v2:')) return false
const payload: DraftPayloadV2 = JSON.parse(
localStorage.getItem(key)!
)
const workflow: ComfyWorkflowJSON = JSON.parse(payload.data)
return workflow.nodes.some(
(node) =>
node.type === 'PrimitiveBoolean' &&
Object.values(node.widgets_values ?? {})[0] === false
)
})
})
)
.toBe(true)
await comfyPage.workflow.reloadAndWaitForApp()
await expect(toggle).not.toBeChecked()
})
}
})

test('an emptied text widget remains empty after save and reopen', async ({
comfyPage
}) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { render, screen } from '@testing-library/vue'
import userEvent from '@testing-library/user-event'
import { fromPartial } from '@total-typescript/shoehorn'
import { defineComponent, ref } from 'vue'
import { createI18n } from 'vue-i18n'
import { describe, expect, it, vi } from 'vitest'

import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group'
import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore'
import type { IWidgetOptions } from '@/lib/litegraph/src/types/widgets'
import type { SimplifiedWidget } from '@/types/simplifiedWidget'

Expand Down Expand Up @@ -86,6 +88,39 @@ describe('WidgetToggleSwitch Value Binding', () => {
expect(onModelUpdate).toHaveBeenCalledWith(true)
})

it.for([
{ name: 'switch', options: {}, role: 'switch', label: 'test_toggle' },
{
name: 'labelled toggle',
options: { on: 'enabled', off: 'disabled' },
role: 'button',
label: 'disabled'
}
])(
'records the updated value after clicking a $name',
async ({ options, role, label }) => {
let currentValue = true
const recordedValues: boolean[] = []
useWorkflowStore().activeWorkflow = fromPartial({
changeTracker: {
captureCanvasState: () => recordedValues.push(currentValue)
}
})
const { user } = mountComponent(
createToggleWidget(true, options),
true,
(value) => {
currentValue = value ?? currentValue
}
)

await user.click(screen.getByRole(role, { name: label }))

expect(currentValue).toBe(false)
expect(recordedValues).toEqual([false])
}
)

describe('Vue Event Emission', () => {
it('emits Vue event when toggled from false to true', async () => {
const widget = createToggleWidget(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@
"
>
<Switch
v-model="modelValue"
:model-value
:disabled="Boolean(widget.options?.disabled)"
:readonly="Boolean(widget.options?.read_only)"
:aria-label="widget.label || widget.name"
@update:model-value="updateValue"
/>
</div>
</WidgetLayoutField>
Expand All @@ -47,6 +48,7 @@ import { useI18n } from 'vue-i18n'

import Switch from '@/components/ui/switch/Switch.vue'
import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group'
import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore'
import type { IWidgetOptions } from '@/lib/litegraph/src/types/widgets'
import type { SimplifiedWidget } from '@/types/simplifiedWidget'
import { useHideLayoutField } from '@/types/widgetTypes'
Expand All @@ -70,7 +72,12 @@ const hasLabels = computed(() => {

function handleOptionChange(value: string | undefined) {
if (value) {
modelValue.value = value === 'on'
updateValue(value === 'on')
}
}

function updateValue(value: boolean) {
modelValue.value = value
useWorkflowStore().activeWorkflow?.changeTracker.captureCanvasState()
}
</script>
Loading