Skip to content
Draft
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
41 changes: 41 additions & 0 deletions browser_tests/tests/selectionToolbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,47 @@ test.describe('Selection Toolbox', { tag: ['@screenshot', '@ui'] }, () => {
})
})

test('aligns the selection to its top edge from the align bar and from More Options', async ({
comfyPage
}) => {
const { page } = comfyPage
await comfyPage.canvasOps.pan({ x: -300, y: 0 }, { x: 600, y: 60 })
const titles = ['Empty Latent Image', 'KSampler']
const nodes = await Promise.all(
titles.map((title) => comfyPage.nodeOps.getNodeRefByTitle(title))
)
const tops = () =>
Promise.all(
nodes.map(async (node) => (await node.getProperty<number[]>('pos'))[1])
)
const before = await tops()
const selectionTop = Math.min(...before)
await comfyPage.nodeOps.selectNodes(titles)

await test.step('align from the align bar', async () => {
await page.getByRole('button', { name: 'Align and distribute' }).click()
await page.getByRole('button', { name: 'Align top', exact: true }).click()
await expect.poll(tops).toEqual([selectionTop, selectionTop])
})

await test.step('undo restores the original rows', async () => {
await comfyPage.keyboard.undo()
await expect.poll(tops).toEqual(before)
})

await test.step('align from the More Options menu', async () => {
await comfyPage.canvasOps.clickEmptySpace()
await comfyPage.nodeOps.selectNodes(titles)
await page.getByTestId('more-options-button').click()
await comfyPage.contextMenu.menuItem('Arrange').click()
const arrange = page.getByRole('menu', { name: 'Arrange', exact: true })
await arrange
.getByRole('menuitem', { name: 'Align top', exact: true })
.click()
await expect.poll(tops).toEqual([selectionTop, selectionTop])
})
})

test('shows selection toolbox', async ({ comfyPage }) => {
const selectedTitles = ['KSampler', 'CLIP Text Encode (Prompt)']
await expect(comfyPage.selectionToolbox).toBeHidden()
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ test.describe(
const menu = comfyPage.contextMenu.ariaMenu
await menu
.getByRole('menuitem', {
name: 'Align Selected To',
name: 'Arrange',
exact: true
})
.hover()

const topItem = menu
.getByRole('menuitem', { name: 'Top', exact: true })
.getByRole('menuitem', { name: 'Align top', exact: true })
.last()
await expect(topItem).toBeVisible()
await topItem.click()
Expand All @@ -180,7 +180,7 @@ test.describe(
})
})

test('should distribute selected nodes via Distribute Nodes submenu', async ({
test('should distribute selected nodes via the Arrange submenu', async ({
comfyPage
}) => {
const threeNodes = ['Load Checkpoint', 'KSampler', 'Empty Latent Image']
Expand All @@ -190,14 +190,14 @@ test.describe(
const menu = comfyPage.contextMenu.ariaMenu
await menu
.getByRole('menuitem', {
name: 'Distribute Nodes',
name: 'Arrange',
exact: true
})
.hover()

const horizontalItem = menu
.getByRole('menuitem', {
name: 'Horizontal',
name: 'Distribute horizontally',
exact: true
})
.last()
Expand Down
4 changes: 4 additions & 0 deletions docs/architecture/domains/boundaries.json
Original file line number Diff line number Diff line change
Expand Up @@ -2693,6 +2693,8 @@
"src/components/graph/SelectionToolbox.vue",
"src/components/graph/selectionGrid/SelectionGapHandles.test.ts",
"src/components/graph/selectionGrid/SelectionGapHandles.vue",
"src/components/graph/selectionToolbox/AlignButton.test.ts",
"src/components/graph/selectionToolbox/AlignButton.vue",
"src/components/graph/selectionToolbox/BypassButton.test.ts",
"src/components/graph/selectionToolbox/BypassButton.vue",
"src/components/graph/selectionToolbox/ColorPickerButton.test.ts",
Expand All @@ -2712,6 +2714,8 @@
"src/components/graph/selectionToolbox/NodeOptionsButton.vue",
"src/components/graph/selectionToolbox/RefreshSelectionButton.vue",
"src/components/graph/selectionToolbox/SaveToSubgraphLibrary.vue",
"src/components/graph/selectionToolbox/SelectionToolboxBar.vue",
"src/components/graph/selectionToolbox/selectionToolboxBar.ts",
"src/components/graph/selectionToolbox/TidyUpButton.test.ts",
"src/components/graph/selectionToolbox/TidyUpButton.vue"
]
Expand Down
17 changes: 17 additions & 0 deletions docs/architecture/domains/records/selection-toolbox.domain.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@
"path": "src/components/graph/selectionGrid/useTidySession.ts",
"role": "integration"
},
{
"path": "src/components/graph/selectionToolbox/AlignButton.test.ts",
"role": "presentation"
},
{
"path": "src/components/graph/selectionToolbox/AlignButton.vue",
"role": "presentation"
},
{
"path": "src/components/graph/selectionToolbox/BypassButton.test.ts",
"role": "presentation"
Expand Down Expand Up @@ -135,6 +143,14 @@
"path": "src/components/graph/selectionToolbox/SaveToSubgraphLibrary.vue",
"role": "presentation"
},
{
"path": "src/components/graph/selectionToolbox/SelectionToolboxBar.vue",
"role": "presentation"
},
{
"path": "src/components/graph/selectionToolbox/selectionToolboxBar.ts",
"role": "presentation"
},
{
"path": "src/components/graph/selectionToolbox/TidyUpButton.test.ts",
"role": "presentation"
Expand Down Expand Up @@ -286,6 +302,7 @@
"src/components/graph/selectionToolbox/InfoButton.test.ts",
"src/components/graph/selectionToolbox/MaskEditorButton.test.ts",
"src/components/graph/selectionToolbox/TidyUpButton.test.ts",
"src/components/graph/selectionToolbox/AlignButton.test.ts",
"src/components/graph/selectionGrid/SelectionGapHandles.test.ts"
]
},
Expand Down
32 changes: 31 additions & 1 deletion src/components/graph/NodeContextMenu.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render, screen, waitFor } from '@testing-library/vue'
import { render, screen, waitFor, within } from '@testing-library/vue'
import userEvent from '@testing-library/user-event'
import { fromPartial } from '@total-typescript/shoehorn'
import { beforeEach, describe, expect, it } from 'vitest'
Expand All @@ -9,7 +9,9 @@
showNodeOptions,
toggleNodeOptions
} from '@/composables/graph/useMoreOptionsMenu'
import { LGraphNode } from '@/lib/litegraph/src/litegraph'

Check warning on line 12 in src/components/graph/NodeContextMenu.test.ts

View workflow job for this annotation

GitHub Actions / fallow / fallow

Boundary violation

Import from zone 'selection-toolbox/presentation' to zone 'litegraph-api/integration' is not allowed. src/components/graph/NodeContextMenu.test.ts -> src/lib/litegraph/src/litegraph.ts Route the import through an allowed zone or restructure the dependency.
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
import { setCanvasSelection } from '@/utils/__tests__/canvasSelectionTestUtils'

Check warning on line 14 in src/components/graph/NodeContextMenu.test.ts

View workflow job for this annotation

GitHub Actions / fallow / fallow

Boundary violation

Import from zone 'selection-toolbox/presentation' to zone 'test-support/integration/outer-1' is not allowed. src/components/graph/NodeContextMenu.test.ts -> src/utils/__tests__/canvasSelectionTestUtils.ts Route the import through an allowed zone or restructure the dependency.

import NodeContextMenu from './NodeContextMenu.vue'

Expand Down Expand Up @@ -97,6 +99,34 @@
expect(await screen.findByRole('menu')).toBeVisible()
})

it('groups Tidy up, the align options and the distribute options in the Arrange submenu', async () => {
setCanvasSelection([new LGraphNode('First'), new LGraphNode('Second')])
render(NodeContextMenu, { global: { plugins: [i18n] } })
const user = userEvent.setup({ pointerEventsCheck: 0 })

toggleNodeOptions(new MouseEvent('click', { clientX: 100, clientY: 120 }))
await user.click(
await screen.findByRole('menuitem', { name: 'contextMenu.Arrange' })
)

await waitFor(() => expect(screen.getAllByRole('menu')).toHaveLength(2))
const submenu = screen.getAllByRole('menu')[1]
expect(
within(submenu)
.getAllByRole('menuitem')
.map((item) => item.textContent)
).toEqual([
'g.tidyUp',
'contextMenu.Align top',
'contextMenu.Align bottom',
'contextMenu.Align left',
'contextMenu.Align right',
'contextMenu.Distribute horizontally',
'contextMenu.Distribute vertically'
])
expect(within(submenu).getAllByRole('separator')).toHaveLength(2)
})

it('reopens at another control when its press dismisses the menu', async () => {
renderWithControls()
const user = userEvent.setup({ pointerEventsCheck: 0 })
Expand Down
22 changes: 14 additions & 8 deletions src/components/graph/NodeContextMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
registerNodeOptionsInstance,
useMoreOptionsMenu
} from '@/composables/graph/useMoreOptionsMenu'
import { isSubMenuOption } from '@/composables/graph/menuOption'
import type { MenuOption } from '@/composables/graph/menuOption'
import { useNodeCustomization } from '@/composables/graph/useNodeCustomization'
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
Expand Down Expand Up @@ -104,7 +105,7 @@ function convertToMenuItem(option: MenuOption): NodeMenuItem {
icon: option.icon,
radioGroup: {
value: getCurrentShape()?.localizedName ?? '',
options: option.submenu.map((sub) => ({
options: option.submenu.filter(isSubMenuOption).map((sub) => ({
value: sub.label,
label: sub.label,
command: sub.action
Expand All @@ -119,13 +120,18 @@ function convertToMenuItem(option: MenuOption): NodeMenuItem {
icon: option.icon,
disabled: option.disabled,
shortcut: option.shortcut,
items: option.submenu.map((sub) => ({
label: sub.label,
icon: sub.icon,
color: sub.color,
disabled: sub.disabled,
command: sub.action
}))
items: option.submenu.map(
(sub): NodeMenuItem =>
isSubMenuOption(sub)
? {
label: sub.label,
icon: sub.icon,
color: sub.color,
disabled: sub.disabled,
command: sub.action
}
: { separator: true }
)
}
}

Expand Down
87 changes: 84 additions & 3 deletions src/components/graph/SelectionToolbox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
import { fireEvent, render, screen } from '@testing-library/vue'
import userEvent from '@testing-library/user-event'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { defineComponent } from 'vue'
import { defineComponent, h, watch } from 'vue'
import type { Component } from 'vue'
import { createI18n } from 'vue-i18n'

import SelectionToolbox from '@/components/graph/SelectionToolbox.vue'
import { useSelectionToolboxPosition } from '@/composables/canvas/useSelectionToolboxPosition'

Check warning on line 10 in src/components/graph/SelectionToolbox.test.ts

View workflow job for this annotation

GitHub Actions / fallow / fallow

Boundary violation

Import from zone 'selection-toolbox/presentation' to zone 'selection-toolbox/integration/outer-1' is not allowed. src/components/graph/SelectionToolbox.test.ts -> src/composables/canvas/useSelectionToolboxPosition.ts Route the import through an allowed zone or restructure the dependency.
import { LGraphNode } from '@/lib/litegraph/src/LGraphNode'
import { useSettingStore } from '@/platform/settings/settingStore'
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
Expand Down Expand Up @@ -114,6 +116,7 @@
info: 'Node Info',
bookmark: 'Save to Library',
frameNodes: 'Frame Nodes',
alignAndDistribute: 'Align and distribute',
moreOptions: 'More Options',
refreshNode: 'Refresh Node'
}
Expand All @@ -136,7 +139,10 @@
mockSettingValues()
})

function renderComponent(props = {}): { container: Element } {
function renderComponent(
props = {},
barStubs: Record<string, Component> = {}
): { container: Element } {
const { container } = render(SelectionToolbox, {
props,
global: {
Expand Down Expand Up @@ -185,7 +191,8 @@
MoreOptions: {
template:
'<button data-testid="more-options-button" class="more-options" />'
}
},
...barStubs
}
}
})
Expand Down Expand Up @@ -290,6 +297,23 @@
expect(container2.querySelector('.frame-nodes')).toBeTruthy()
})

it.for([
{ nodes: 1, shown: false },
{ nodes: 2, shown: true }
])(
'shows the align button: $shown, for $nodes selected nodes',
({ nodes, shown }) => {
setCanvasSelection(
Array.from({ length: nodes }, () => new LGraphNode('Test Node'))
)
renderComponent()
expect(
screen.queryByRole('button', { name: 'Align and distribute' }) !==
null
).toBe(shown)
}
)

it('should show bypass button for appropriate selections', () => {
// Single node selection
setCanvasSelection([new LGraphNode('Test Node')])
Expand Down Expand Up @@ -483,6 +507,63 @@
})
})

describe('Selection bars', () => {
const BAR_LIFT = 48
const barButton = (name: string) =>
defineComponent({
props: { open: Boolean, lift: Number },
emits: ['update:open', 'update:lift'],
setup(props, { emit }) {
watch(
() => props.open,
(open) => emit('update:lift', open ? BAR_LIFT : 0)
)
return () =>
h(
'button',
{
'aria-expanded': String(props.open),
onClick: () => emit('update:open', true)
},
name
)
}
})

beforeEach(() => {
vi.mocked(useExtensionService).mockReturnValue(
createMockExtensionService()
)
})

it('opens one bar at a time and stays lifted while switching between them', async () => {
const user = userEvent.setup()
setCanvasSelection([
new LGraphNode('Test Node'),
new LGraphNode('Test Node')
])
renderComponent(
{},
{
TidyUpButton: barButton('Tidy up'),
AlignButton: barButton('Align and distribute')
}
)
const lift = vi.mocked(useSelectionToolboxPosition).mock.lastCall![1]
const tidyUp = screen.getByRole('button', { name: 'Tidy up' })
const align = screen.getByRole('button', { name: 'Align and distribute' })

await user.click(tidyUp)
expect(tidyUp).toHaveAttribute('aria-expanded', 'true')
expect(lift.value).toBe(BAR_LIFT)

await user.click(align)
expect(tidyUp).toHaveAttribute('aria-expanded', 'false')
expect(align).toHaveAttribute('aria-expanded', 'true')
expect(lift.value).toBe(BAR_LIFT)
})
})

describe('Tooltips', () => {
beforeEach(() => {
vi.mocked(useExtensionService).mockReturnValue(
Expand Down
Loading
Loading