mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-20 06:20:11 +00:00
test: migrate 132 test files from @vue/test-utils to @testing-library/vue (#10965)
## Summary Migrate 132 test files from `@vue/test-utils` (VTU) to `@testing-library/vue` (VTL) with `@testing-library/user-event`, adopting user-centric behavioral testing patterns across the codebase. ## Changes - **What**: Systematic migration of component/unit tests from VTU's `mount`/`wrapper` API to VTL's `render`/`screen`/`userEvent` API across 132 files in `src/` - **Breaking**: None — test-only changes, no production code affected ### Migration breakdown | Batch | Files | Description | |-------|-------|-------------| | 1 | 19 | Simple render/assert tests | | 2A | 16 | Interactive tests with user events | | 2B-1 | 14 | Interactive tests (continued) | | 2B-2 | 32 | Interactive tests (continued) | | 3A–3E | 51 | Complex tests (stores, composables, heavy mocking) | | Lint fix | 7 | `await` on `fireEvent` calls for `no-floating-promises` | | Review fixes | 15 | Address CodeRabbit feedback (3 rounds) | ### Review feedback addressed - Removed class-based assertions (`text-ellipsis`, `pr-3`, `.pi-save`, `.skeleton`, `.bg-black\/15`, Tailwind utilities) in favor of behavioral/accessible queries - Added null guards before `querySelector` casts - Added `expect(roots).toHaveLength(N)` guards before indexed NodeList access - Wrapped fake timer tests in `try/finally` for guaranteed cleanup - Split double-render tests into focused single-render tests - Replaced CSS class selectors with `screen.getByText`/`screen.getByRole` queries - Updated stubs to use semantic `role`/`aria-label` instead of CSS classes - Consolidated redundant edge-case tests - Removed manual `document.body.appendChild` in favor of VTL container management - Used distinct mock return values to verify command wiring ### VTU holdouts (2 files) These files intentionally retain `@vue/test-utils` because their components use `<script setup>` without `defineExpose`, making internal computed properties and methods inaccessible via VTL: 1. **`NodeWidgets.test.ts`** — partial VTU for `vm.processedWidgets` 2. **`WidgetSelectDropdown.test.ts`** — full VTU for heavy `wrapper.vm.*` access ## Follow-up Deferred items (`ComponentProps` typing, camelCase listener props) tracked in #10966. ## Review Focus - Test correctness: all migrated tests preserve original behavioral coverage - VTL idioms: proper use of `screen` queries, `userEvent`, and accessibility-based selectors - The 2 VTU holdout files are intentional, not oversights ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-10965-test-migrate-132-test-files-from-vue-test-utils-to-testing-library-vue-33c6d73d36508199a6a7e513cf5d8296) by [Unito](https://www.unito.io) --------- Co-authored-by: Amp <amp@ampcode.com> Co-authored-by: Christian Byrne <cbyrne@comfy.org>
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
/* eslint-disable testing-library/no-container */
|
||||
/* eslint-disable testing-library/no-node-access */
|
||||
import { createTestingPinia } from '@pinia/testing'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import type { MenuItem } from 'primevue/menuitem'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { computed, defineComponent, h, nextTick, onMounted, ref } from 'vue'
|
||||
@@ -8,8 +11,6 @@ import { createI18n } from 'vue-i18n'
|
||||
|
||||
import TopMenuSection from '@/components/TopMenuSection.vue'
|
||||
import QueueNotificationBannerHost from '@/components/queue/QueueNotificationBannerHost.vue'
|
||||
import CurrentUserButton from '@/components/topbar/CurrentUserButton.vue'
|
||||
import LoginButton from '@/components/topbar/LoginButton.vue'
|
||||
import type {
|
||||
JobListItem,
|
||||
JobStatus
|
||||
@@ -114,8 +115,9 @@ function createWrapper({
|
||||
}
|
||||
})
|
||||
|
||||
return mount(TopMenuSection, {
|
||||
attachTo,
|
||||
const user = userEvent.setup()
|
||||
|
||||
const renderOptions: Record<string, unknown> = {
|
||||
global: {
|
||||
plugins: [pinia, i18n],
|
||||
stubs: {
|
||||
@@ -128,7 +130,8 @@ function createWrapper({
|
||||
ContextMenu: {
|
||||
name: 'ContextMenu',
|
||||
props: ['model'],
|
||||
template: '<div />'
|
||||
template:
|
||||
'<div data-testid="context-menu" :data-model="JSON.stringify(model)" />'
|
||||
},
|
||||
...stubs
|
||||
},
|
||||
@@ -136,15 +139,23 @@ function createWrapper({
|
||||
tooltip: () => {}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (attachTo) {
|
||||
renderOptions.container = attachTo.appendChild(
|
||||
document.createElement('div')
|
||||
)
|
||||
}
|
||||
|
||||
const { container, unmount } = render(TopMenuSection, renderOptions)
|
||||
|
||||
return { container, unmount, user }
|
||||
}
|
||||
|
||||
function getLegacyCommandsContainer(
|
||||
wrapper: ReturnType<typeof createWrapper>
|
||||
): HTMLElement {
|
||||
const legacyContainer = wrapper.find(
|
||||
function getLegacyCommandsContainer(container: Element): HTMLElement {
|
||||
const legacyContainer = container.querySelector(
|
||||
'[data-testid="legacy-topbar-container"]'
|
||||
).element
|
||||
)
|
||||
if (!(legacyContainer instanceof HTMLElement)) {
|
||||
throw new Error('Expected legacy commands container to be present')
|
||||
}
|
||||
@@ -201,9 +212,11 @@ describe('TopMenuSection', () => {
|
||||
})
|
||||
|
||||
it('should display CurrentUserButton and not display LoginButton', () => {
|
||||
const wrapper = createLegacyTabBarWrapper()
|
||||
expect(wrapper.findComponent(CurrentUserButton).exists()).toBe(true)
|
||||
expect(wrapper.findComponent(LoginButton).exists()).toBe(false)
|
||||
const { container } = createLegacyTabBarWrapper()
|
||||
expect(
|
||||
container.querySelector('current-user-button-stub')
|
||||
).not.toBeNull()
|
||||
expect(container.querySelector('login-button-stub')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -215,24 +228,24 @@ describe('TopMenuSection', () => {
|
||||
describe('on desktop platform', () => {
|
||||
it('should display LoginButton and not display CurrentUserButton', () => {
|
||||
mockData.isDesktop = true
|
||||
const wrapper = createLegacyTabBarWrapper()
|
||||
expect(wrapper.findComponent(LoginButton).exists()).toBe(true)
|
||||
expect(wrapper.findComponent(CurrentUserButton).exists()).toBe(false)
|
||||
const { container } = createLegacyTabBarWrapper()
|
||||
expect(container.querySelector('login-button-stub')).not.toBeNull()
|
||||
expect(container.querySelector('current-user-button-stub')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('on web platform', () => {
|
||||
it('should not display CurrentUserButton and not display LoginButton', () => {
|
||||
const wrapper = createLegacyTabBarWrapper()
|
||||
expect(wrapper.findComponent(CurrentUserButton).exists()).toBe(false)
|
||||
expect(wrapper.findComponent(LoginButton).exists()).toBe(false)
|
||||
const { container } = createLegacyTabBarWrapper()
|
||||
expect(container.querySelector('current-user-button-stub')).toBeNull()
|
||||
expect(container.querySelector('login-button-stub')).toBeNull()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('shows the active jobs label with the current count', async () => {
|
||||
const wrapper = createWrapper()
|
||||
createWrapper()
|
||||
const queueStore = useQueueStore()
|
||||
queueStore.pendingTasks = [createTask('pending-1', 'pending')]
|
||||
queueStore.runningTasks = [
|
||||
@@ -242,19 +255,15 @@ describe('TopMenuSection', () => {
|
||||
|
||||
await nextTick()
|
||||
|
||||
const queueButton = wrapper.find('[data-testid="queue-overlay-toggle"]')
|
||||
expect(queueButton.text()).toContain('3 active')
|
||||
expect(wrapper.find('[data-testid="active-jobs-indicator"]').exists()).toBe(
|
||||
true
|
||||
)
|
||||
const queueButton = screen.getByTestId('queue-overlay-toggle')
|
||||
expect(queueButton.textContent).toContain('3 active')
|
||||
expect(screen.getByTestId('active-jobs-indicator')).toBeTruthy()
|
||||
})
|
||||
|
||||
it('hides the active jobs indicator when no jobs are active', () => {
|
||||
const wrapper = createWrapper()
|
||||
createWrapper()
|
||||
|
||||
expect(wrapper.find('[data-testid="active-jobs-indicator"]').exists()).toBe(
|
||||
false
|
||||
)
|
||||
expect(screen.queryByTestId('active-jobs-indicator')).toBeNull()
|
||||
})
|
||||
|
||||
it('hides queue progress overlay when QPO V2 is enabled', async () => {
|
||||
@@ -263,16 +272,12 @@ describe('TopMenuSection', () => {
|
||||
vi.mocked(settingStore.get).mockImplementation((key) =>
|
||||
key === 'Comfy.Queue.QPOV2' ? true : undefined
|
||||
)
|
||||
const wrapper = createWrapper({ pinia })
|
||||
const { container } = createWrapper({ pinia })
|
||||
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.find('[data-testid="queue-overlay-toggle"]').exists()).toBe(
|
||||
true
|
||||
)
|
||||
expect(
|
||||
wrapper.findComponent({ name: 'QueueProgressOverlay' }).exists()
|
||||
).toBe(false)
|
||||
expect(screen.getByTestId('queue-overlay-toggle')).toBeTruthy()
|
||||
expect(container.querySelector('queue-progress-overlay-stub')).toBeNull()
|
||||
})
|
||||
|
||||
it('toggles the queue progress overlay when QPO V2 is disabled', async () => {
|
||||
@@ -281,10 +286,10 @@ describe('TopMenuSection', () => {
|
||||
vi.mocked(settingStore.get).mockImplementation((key) =>
|
||||
key === 'Comfy.Queue.QPOV2' ? false : undefined
|
||||
)
|
||||
const wrapper = createWrapper({ pinia })
|
||||
const { user } = createWrapper({ pinia })
|
||||
const commandStore = useCommandStore(pinia)
|
||||
|
||||
await wrapper.find('[data-testid="queue-overlay-toggle"]').trigger('click')
|
||||
await user.click(screen.getByTestId('queue-overlay-toggle'))
|
||||
|
||||
expect(commandStore.execute).toHaveBeenCalledWith(
|
||||
'Comfy.Queue.ToggleOverlay'
|
||||
@@ -297,10 +302,10 @@ describe('TopMenuSection', () => {
|
||||
vi.mocked(settingStore.get).mockImplementation((key) =>
|
||||
key === 'Comfy.Queue.QPOV2' ? true : undefined
|
||||
)
|
||||
const wrapper = createWrapper({ pinia })
|
||||
const { user } = createWrapper({ pinia })
|
||||
const sidebarTabStore = useSidebarTabStore(pinia)
|
||||
|
||||
await wrapper.find('[data-testid="queue-overlay-toggle"]').trigger('click')
|
||||
await user.click(screen.getByTestId('queue-overlay-toggle'))
|
||||
|
||||
expect(sidebarTabStore.activeSidebarTabId).toBe('job-history')
|
||||
})
|
||||
@@ -311,14 +316,14 @@ describe('TopMenuSection', () => {
|
||||
vi.mocked(settingStore.get).mockImplementation((key) =>
|
||||
key === 'Comfy.Queue.QPOV2' ? true : undefined
|
||||
)
|
||||
const wrapper = createWrapper({ pinia })
|
||||
const { user } = createWrapper({ pinia })
|
||||
const sidebarTabStore = useSidebarTabStore(pinia)
|
||||
const toggleButton = wrapper.find('[data-testid="queue-overlay-toggle"]')
|
||||
const toggleButton = screen.getByTestId('queue-overlay-toggle')
|
||||
|
||||
await toggleButton.trigger('click')
|
||||
await user.click(toggleButton)
|
||||
expect(sidebarTabStore.activeSidebarTabId).toBe('job-history')
|
||||
|
||||
await toggleButton.trigger('click')
|
||||
await user.click(toggleButton)
|
||||
expect(sidebarTabStore.activeSidebarTabId).toBe(null)
|
||||
})
|
||||
|
||||
@@ -341,39 +346,39 @@ describe('TopMenuSection', () => {
|
||||
const pinia = createTestingPinia({ createSpy: vi.fn })
|
||||
configureSettings(pinia, true)
|
||||
|
||||
const wrapper = createWrapper({ pinia })
|
||||
const { container } = createWrapper({ pinia })
|
||||
|
||||
await nextTick()
|
||||
|
||||
expect(
|
||||
wrapper.findComponent({ name: 'QueueInlineProgressSummary' }).exists()
|
||||
).toBe(true)
|
||||
container.querySelector('queue-inline-progress-summary-stub')
|
||||
).not.toBeNull()
|
||||
})
|
||||
|
||||
it('does not render inline progress summary when QPO V2 is disabled', async () => {
|
||||
const pinia = createTestingPinia({ createSpy: vi.fn })
|
||||
configureSettings(pinia, false)
|
||||
|
||||
const wrapper = createWrapper({ pinia })
|
||||
const { container } = createWrapper({ pinia })
|
||||
|
||||
await nextTick()
|
||||
|
||||
expect(
|
||||
wrapper.findComponent({ name: 'QueueInlineProgressSummary' }).exists()
|
||||
).toBe(false)
|
||||
container.querySelector('queue-inline-progress-summary-stub')
|
||||
).toBeNull()
|
||||
})
|
||||
|
||||
it('does not render inline progress summary when run progress bar is disabled', async () => {
|
||||
const pinia = createTestingPinia({ createSpy: vi.fn })
|
||||
configureSettings(pinia, true, false)
|
||||
|
||||
const wrapper = createWrapper({ pinia })
|
||||
const { container } = createWrapper({ pinia })
|
||||
|
||||
await nextTick()
|
||||
|
||||
expect(
|
||||
wrapper.findComponent({ name: 'QueueInlineProgressSummary' }).exists()
|
||||
).toBe(false)
|
||||
container.querySelector('queue-inline-progress-summary-stub')
|
||||
).toBeNull()
|
||||
})
|
||||
|
||||
it('teleports inline progress summary when actionbar is floating', async () => {
|
||||
@@ -387,7 +392,7 @@ describe('TopMenuSection', () => {
|
||||
|
||||
const ComfyActionbarStub = createComfyActionbarStub(actionbarTarget)
|
||||
|
||||
const wrapper = createWrapper({
|
||||
const { unmount } = createWrapper({
|
||||
pinia,
|
||||
attachTo: document.body,
|
||||
stubs: {
|
||||
@@ -401,7 +406,7 @@ describe('TopMenuSection', () => {
|
||||
|
||||
expect(actionbarTarget.querySelector('[role="status"]')).not.toBeNull()
|
||||
} finally {
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
actionbarTarget.remove()
|
||||
}
|
||||
})
|
||||
@@ -424,36 +429,36 @@ describe('TopMenuSection', () => {
|
||||
const pinia = createTestingPinia({ createSpy: vi.fn })
|
||||
configureSettings(pinia, true)
|
||||
|
||||
const wrapper = createWrapper({ pinia })
|
||||
const { container } = createWrapper({ pinia })
|
||||
|
||||
await nextTick()
|
||||
|
||||
expect(
|
||||
wrapper.findComponent({ name: 'QueueNotificationBannerHost' }).exists()
|
||||
).toBe(true)
|
||||
container.querySelector('queue-notification-banner-host-stub')
|
||||
).not.toBeNull()
|
||||
})
|
||||
|
||||
it('renders queue notification banners when QPO V2 is disabled', async () => {
|
||||
const pinia = createTestingPinia({ createSpy: vi.fn })
|
||||
configureSettings(pinia, false)
|
||||
|
||||
const wrapper = createWrapper({ pinia })
|
||||
const { container } = createWrapper({ pinia })
|
||||
|
||||
await nextTick()
|
||||
|
||||
expect(
|
||||
wrapper.findComponent({ name: 'QueueNotificationBannerHost' }).exists()
|
||||
).toBe(true)
|
||||
container.querySelector('queue-notification-banner-host-stub')
|
||||
).not.toBeNull()
|
||||
})
|
||||
|
||||
it('renders inline summary above banners when both are visible', async () => {
|
||||
const pinia = createTestingPinia({ createSpy: vi.fn })
|
||||
configureSettings(pinia, true)
|
||||
const wrapper = createWrapper({ pinia })
|
||||
const { container } = createWrapper({ pinia })
|
||||
|
||||
await nextTick()
|
||||
|
||||
const html = wrapper.html()
|
||||
const html = container.innerHTML
|
||||
const inlineSummaryIndex = html.indexOf(
|
||||
'queue-inline-progress-summary-stub'
|
||||
)
|
||||
@@ -477,7 +482,7 @@ describe('TopMenuSection', () => {
|
||||
|
||||
const ComfyActionbarStub = createComfyActionbarStub(actionbarTarget)
|
||||
|
||||
const wrapper = createWrapper({
|
||||
const { container, unmount } = createWrapper({
|
||||
pinia,
|
||||
attachTo: document.body,
|
||||
stubs: {
|
||||
@@ -493,47 +498,49 @@ describe('TopMenuSection', () => {
|
||||
actionbarTarget.querySelector('queue-notification-banner-host-stub')
|
||||
).toBeNull()
|
||||
expect(
|
||||
wrapper
|
||||
.findComponent({ name: 'QueueNotificationBannerHost' })
|
||||
.exists()
|
||||
).toBe(true)
|
||||
container.querySelector('queue-notification-banner-host-stub')
|
||||
).not.toBeNull()
|
||||
} finally {
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
actionbarTarget.remove()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('disables the clear queue context menu item when no queued jobs exist', () => {
|
||||
const wrapper = createWrapper()
|
||||
const menu = wrapper.findComponent({ name: 'ContextMenu' })
|
||||
const model = menu.props('model') as MenuItem[]
|
||||
const { container } = createWrapper()
|
||||
const menuEl = container.querySelector('[data-testid="context-menu"]')
|
||||
const model = JSON.parse(
|
||||
menuEl?.getAttribute('data-model') ?? '[]'
|
||||
) as MenuItem[]
|
||||
expect(model[0]?.label).toBe('Clear queue')
|
||||
expect(model[0]?.disabled).toBe(true)
|
||||
})
|
||||
|
||||
it('enables the clear queue context menu item when queued jobs exist', async () => {
|
||||
const wrapper = createWrapper()
|
||||
const { container } = createWrapper()
|
||||
const queueStore = useQueueStore()
|
||||
queueStore.pendingTasks = [createTask('pending-1', 'pending')]
|
||||
|
||||
await nextTick()
|
||||
|
||||
const menu = wrapper.findComponent({ name: 'ContextMenu' })
|
||||
const model = menu.props('model') as MenuItem[]
|
||||
const menuEl = container.querySelector('[data-testid="context-menu"]')
|
||||
const model = JSON.parse(
|
||||
menuEl?.getAttribute('data-model') ?? '[]'
|
||||
) as MenuItem[]
|
||||
expect(model[0]?.disabled).toBe(false)
|
||||
})
|
||||
|
||||
it('shows manager red dot only for manager conflicts', async () => {
|
||||
const wrapper = createWrapper()
|
||||
const { container } = createWrapper()
|
||||
|
||||
// Release red dot is mocked as true globally for this test file.
|
||||
expect(wrapper.find('span.bg-red-500').exists()).toBe(false)
|
||||
expect(container.querySelector('span.bg-red-500')).toBeNull()
|
||||
|
||||
mockData.setShowConflictRedDot(true)
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.find('span.bg-red-500').exists()).toBe(true)
|
||||
expect(container.querySelector('span.bg-red-500')).not.toBeNull()
|
||||
})
|
||||
|
||||
it('coalesces legacy topbar mutation scans to one check per frame', async () => {
|
||||
@@ -555,15 +562,19 @@ describe('TopMenuSection', () => {
|
||||
return undefined
|
||||
})
|
||||
|
||||
const wrapper = createWrapper({ pinia, attachTo: document.body })
|
||||
const { container, unmount } = createWrapper({
|
||||
pinia,
|
||||
attachTo: document.body
|
||||
})
|
||||
|
||||
try {
|
||||
await nextTick()
|
||||
|
||||
const actionbarContainer = wrapper.find('.actionbar-container')
|
||||
expect(actionbarContainer.classes()).toContain('w-0')
|
||||
const actionbarContainer = container.querySelector('.actionbar-container')
|
||||
expect(actionbarContainer).not.toBeNull()
|
||||
expect(actionbarContainer!.classList).toContain('w-0')
|
||||
|
||||
const legacyContainer = getLegacyCommandsContainer(wrapper)
|
||||
const legacyContainer = getLegacyCommandsContainer(container)
|
||||
const querySpy = vi.spyOn(legacyContainer, 'querySelector')
|
||||
|
||||
if (rafCallbacks.length > 0) {
|
||||
@@ -594,9 +605,9 @@ describe('TopMenuSection', () => {
|
||||
await nextTick()
|
||||
|
||||
expect(querySpy).toHaveBeenCalledTimes(1)
|
||||
expect(actionbarContainer.classes()).toContain('px-2')
|
||||
expect(actionbarContainer!.classList).toContain('px-2')
|
||||
} finally {
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
vi.unstubAllGlobals()
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import { createPinia, setActivePinia } from 'pinia'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import EssentialsPanel from '@/components/bottomPanel/tabs/shortcuts/EssentialsPanel.vue'
|
||||
import ShortcutsList from '@/components/bottomPanel/tabs/shortcuts/ShortcutsList.vue'
|
||||
import type { ComfyCommandImpl } from '@/stores/commandStore'
|
||||
|
||||
// Mock ShortcutsList component
|
||||
@@ -12,7 +10,7 @@ vi.mock('@/components/bottomPanel/tabs/shortcuts/ShortcutsList.vue', () => ({
|
||||
name: 'ShortcutsList',
|
||||
props: ['commands', 'subcategories', 'columns'],
|
||||
template:
|
||||
'<div class="shortcuts-list-mock">{{ commands.length }} commands</div>'
|
||||
'<div data-testid="shortcuts-list">{{ JSON.stringify(subcategories) }}</div>'
|
||||
}
|
||||
}))
|
||||
|
||||
@@ -56,25 +54,34 @@ describe('EssentialsPanel', () => {
|
||||
setActivePinia(createPinia())
|
||||
})
|
||||
|
||||
it('should render ShortcutsList with essentials commands', () => {
|
||||
const wrapper = mount(EssentialsPanel)
|
||||
it('should render ShortcutsList with essentials commands', async () => {
|
||||
const { default: EssentialsPanel } =
|
||||
await import('@/components/bottomPanel/tabs/shortcuts/EssentialsPanel.vue')
|
||||
render(EssentialsPanel)
|
||||
|
||||
const shortcutsList = wrapper.findComponent(ShortcutsList)
|
||||
expect(shortcutsList.exists()).toBe(true)
|
||||
expect(screen.getByTestId('shortcuts-list')).toBeTruthy()
|
||||
})
|
||||
|
||||
it('should categorize commands into subcategories', () => {
|
||||
const wrapper = mount(EssentialsPanel)
|
||||
it('should categorize commands into subcategories', async () => {
|
||||
const { default: EssentialsPanel } =
|
||||
await import('@/components/bottomPanel/tabs/shortcuts/EssentialsPanel.vue')
|
||||
render(EssentialsPanel)
|
||||
|
||||
const shortcutsList = wrapper.findComponent(ShortcutsList)
|
||||
const subcategories = shortcutsList.props('subcategories')
|
||||
const el = screen.getByTestId('shortcuts-list')
|
||||
const subcategories = JSON.parse(el.textContent ?? '{}')
|
||||
|
||||
expect(subcategories).toHaveProperty('workflow')
|
||||
expect(subcategories).toHaveProperty('node')
|
||||
expect(subcategories).toHaveProperty('queue')
|
||||
|
||||
expect(subcategories.workflow).toContain(mockCommands[0])
|
||||
expect(subcategories.node).toContain(mockCommands[1])
|
||||
expect(subcategories.queue).toContain(mockCommands[2])
|
||||
expect(subcategories.workflow).toContainEqual(
|
||||
expect.objectContaining({ id: 'Workflow.New' })
|
||||
)
|
||||
expect(subcategories.node).toContainEqual(
|
||||
expect.objectContaining({ id: 'Node.Add' })
|
||||
)
|
||||
expect(subcategories.queue).toContainEqual(
|
||||
expect.objectContaining({ id: 'Queue.Clear' })
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
|
||||
import ShortcutsList from '@/components/bottomPanel/tabs/shortcuts/ShortcutsList.vue'
|
||||
import type { ComfyCommandImpl } from '@/stores/commandStore'
|
||||
|
||||
@@ -64,36 +65,31 @@ describe('ShortcutsList', () => {
|
||||
}
|
||||
|
||||
it('should render shortcuts organized by subcategories', () => {
|
||||
const wrapper = mount(ShortcutsList, {
|
||||
render(ShortcutsList, {
|
||||
props: {
|
||||
commands: mockCommands,
|
||||
subcategories: mockSubcategories
|
||||
}
|
||||
})
|
||||
|
||||
// Check that subcategories are rendered
|
||||
expect(wrapper.text()).toContain('Workflow')
|
||||
expect(wrapper.text()).toContain('Node')
|
||||
expect(wrapper.text()).toContain('Queue')
|
||||
|
||||
// Check that commands are rendered
|
||||
expect(wrapper.text()).toContain('New Blank Workflow')
|
||||
expect(screen.getByText('Workflow')).toBeInTheDocument()
|
||||
expect(screen.getByText('Node')).toBeInTheDocument()
|
||||
expect(screen.getByText('Queue')).toBeInTheDocument()
|
||||
expect(screen.getByText('New Blank Workflow')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should format keyboard shortcuts correctly', () => {
|
||||
const wrapper = mount(ShortcutsList, {
|
||||
const { container } = render(ShortcutsList, {
|
||||
props: {
|
||||
commands: mockCommands,
|
||||
subcategories: mockSubcategories
|
||||
}
|
||||
})
|
||||
|
||||
// Check for formatted keys
|
||||
expect(wrapper.text()).toContain('Ctrl')
|
||||
expect(wrapper.text()).toContain('n')
|
||||
expect(wrapper.text()).toContain('Shift')
|
||||
expect(wrapper.text()).toContain('a')
|
||||
expect(wrapper.text()).toContain('c')
|
||||
const text = container.textContent!
|
||||
expect(text).toContain('Ctrl')
|
||||
expect(text).toContain('n')
|
||||
expect(text).toContain('Shift')
|
||||
expect(text).toContain('a')
|
||||
expect(text).toContain('c')
|
||||
})
|
||||
|
||||
it('should filter out commands without keybindings', () => {
|
||||
@@ -107,9 +103,8 @@ describe('ShortcutsList', () => {
|
||||
} as ComfyCommandImpl
|
||||
]
|
||||
|
||||
const wrapper = mount(ShortcutsList, {
|
||||
render(ShortcutsList, {
|
||||
props: {
|
||||
commands: commandsWithoutKeybinding,
|
||||
subcategories: {
|
||||
...mockSubcategories,
|
||||
other: [commandsWithoutKeybinding[3]]
|
||||
@@ -117,7 +112,7 @@ describe('ShortcutsList', () => {
|
||||
}
|
||||
})
|
||||
|
||||
expect(wrapper.text()).not.toContain('No Keybinding')
|
||||
expect(screen.queryByText('No Keybinding')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should handle special key formatting', () => {
|
||||
@@ -132,16 +127,15 @@ describe('ShortcutsList', () => {
|
||||
}
|
||||
} as ComfyCommandImpl
|
||||
|
||||
const wrapper = mount(ShortcutsList, {
|
||||
const { container } = render(ShortcutsList, {
|
||||
props: {
|
||||
commands: [specialKeyCommand],
|
||||
subcategories: {
|
||||
special: [specialKeyCommand]
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const text = wrapper.text()
|
||||
const text = container.textContent!
|
||||
expect(text).toContain('Cmd') // Meta -> Cmd
|
||||
expect(text).toContain('↑') // ArrowUp -> ↑
|
||||
expect(text).toContain('↵') // Enter -> ↵
|
||||
@@ -150,15 +144,14 @@ describe('ShortcutsList', () => {
|
||||
})
|
||||
|
||||
it('should use fallback subcategory titles', () => {
|
||||
const wrapper = mount(ShortcutsList, {
|
||||
render(ShortcutsList, {
|
||||
props: {
|
||||
commands: mockCommands,
|
||||
subcategories: {
|
||||
unknown: [mockCommands[0]]
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
expect(wrapper.text()).toContain('unknown')
|
||||
expect(screen.getByText('unknown')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
/* eslint-disable testing-library/no-node-access */
|
||||
/* eslint-disable testing-library/prefer-user-event */
|
||||
import { createTestingPinia } from '@pinia/testing'
|
||||
import type { VueWrapper } from '@vue/test-utils'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { fireEvent, render, screen } from '@testing-library/vue'
|
||||
import type { Mock } from 'vitest'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { nextTick } from 'vue'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
@@ -67,9 +68,10 @@ vi.mock('@/platform/distribution/types', () => ({
|
||||
}))
|
||||
|
||||
// Mock clipboard API
|
||||
const mockWriteText = vi.fn().mockResolvedValue(undefined)
|
||||
Object.defineProperty(navigator, 'clipboard', {
|
||||
value: {
|
||||
writeText: vi.fn().mockResolvedValue(undefined)
|
||||
writeText: mockWriteText
|
||||
},
|
||||
configurable: true
|
||||
})
|
||||
@@ -87,8 +89,9 @@ const i18n = createI18n({
|
||||
}
|
||||
})
|
||||
|
||||
const mountBaseTerminal = () => {
|
||||
return mount(BaseTerminal, {
|
||||
function renderBaseTerminal(props: Record<string, unknown> = {}) {
|
||||
return render(BaseTerminal, {
|
||||
props,
|
||||
global: {
|
||||
plugins: [
|
||||
createTestingPinia({
|
||||
@@ -107,68 +110,60 @@ const mountBaseTerminal = () => {
|
||||
}
|
||||
|
||||
describe('BaseTerminal', () => {
|
||||
let wrapper: VueWrapper<InstanceType<typeof BaseTerminal>> | undefined
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
wrapper?.unmount()
|
||||
})
|
||||
|
||||
it('emits created event on mount', () => {
|
||||
wrapper = mountBaseTerminal()
|
||||
const onCreated = vi.fn()
|
||||
renderBaseTerminal({ onCreated })
|
||||
|
||||
expect(wrapper.emitted('created')).toBeTruthy()
|
||||
expect(wrapper.emitted('created')![0]).toHaveLength(2)
|
||||
expect(onCreated).toHaveBeenCalled()
|
||||
expect(onCreated.mock.calls[0]).toHaveLength(2)
|
||||
})
|
||||
|
||||
it('emits unmounted event on unmount', () => {
|
||||
wrapper = mountBaseTerminal()
|
||||
wrapper.unmount()
|
||||
const onUnmounted = vi.fn()
|
||||
const { unmount } = renderBaseTerminal({ onUnmounted })
|
||||
unmount()
|
||||
|
||||
expect(wrapper.emitted('unmounted')).toBeTruthy()
|
||||
expect(onUnmounted).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('button exists and has correct initial state', async () => {
|
||||
wrapper = mountBaseTerminal()
|
||||
it('button exists and has correct initial state', () => {
|
||||
renderBaseTerminal()
|
||||
|
||||
const button = wrapper.find('button[aria-label]')
|
||||
expect(button.exists()).toBe(true)
|
||||
|
||||
expect(button.classes()).toContain('opacity-0')
|
||||
expect(button.classes()).toContain('pointer-events-none')
|
||||
const button = screen.getByRole('button')
|
||||
expect(button).toHaveClass('opacity-0', 'pointer-events-none')
|
||||
})
|
||||
|
||||
it('shows correct tooltip when no selection', async () => {
|
||||
mockTerminal.hasSelection.mockReturnValue(false)
|
||||
wrapper = mountBaseTerminal()
|
||||
const { container } = renderBaseTerminal()
|
||||
|
||||
await wrapper.trigger('mouseenter')
|
||||
await fireEvent.mouseEnter(container.firstElementChild!)
|
||||
await nextTick()
|
||||
|
||||
const button = wrapper.find('button[aria-label]')
|
||||
expect(button.attributes('aria-label')).toBe('Copy all')
|
||||
const button = screen.getByRole('button')
|
||||
expect(button).toHaveAttribute('aria-label', 'Copy all')
|
||||
})
|
||||
|
||||
it('shows correct tooltip when selection exists', async () => {
|
||||
mockTerminal.hasSelection.mockReturnValue(true)
|
||||
wrapper = mountBaseTerminal()
|
||||
const { container } = renderBaseTerminal()
|
||||
|
||||
// Trigger the selection change callback that was registered during mount
|
||||
expect(mockTerminal.onSelectionChange).toHaveBeenCalled()
|
||||
// Access the mock calls - TypeScript can't infer the mock structure dynamically
|
||||
const mockCalls = (mockTerminal.onSelectionChange as Mock).mock.calls
|
||||
const selectionCallback = mockCalls[0][0] as () => void
|
||||
selectionCallback()
|
||||
await nextTick()
|
||||
|
||||
await wrapper.trigger('mouseenter')
|
||||
await fireEvent.mouseEnter(container.firstElementChild!)
|
||||
await nextTick()
|
||||
|
||||
const button = wrapper.find('button[aria-label]')
|
||||
expect(button.attributes('aria-label')).toBe('Copy selection')
|
||||
const button = screen.getByRole('button')
|
||||
expect(button).toHaveAttribute('aria-label', 'Copy selection')
|
||||
})
|
||||
|
||||
it('copies selected text when selection exists', async () => {
|
||||
@@ -176,16 +171,17 @@ describe('BaseTerminal', () => {
|
||||
mockTerminal.hasSelection.mockReturnValue(true)
|
||||
mockTerminal.getSelection.mockReturnValue(selectedText)
|
||||
|
||||
wrapper = mountBaseTerminal()
|
||||
const { container } = renderBaseTerminal()
|
||||
|
||||
await wrapper.trigger('mouseenter')
|
||||
await fireEvent.mouseEnter(container.firstElementChild!)
|
||||
await nextTick()
|
||||
|
||||
const button = wrapper.find('button[aria-label]')
|
||||
await button.trigger('click')
|
||||
const button = screen.getByRole('button')
|
||||
await fireEvent.click(button)
|
||||
await nextTick()
|
||||
|
||||
expect(mockTerminal.selectAll).not.toHaveBeenCalled()
|
||||
expect(navigator.clipboard.writeText).toHaveBeenCalledWith(selectedText)
|
||||
expect(mockWriteText).toHaveBeenCalledWith(selectedText)
|
||||
expect(mockTerminal.clearSelection).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
@@ -196,16 +192,17 @@ describe('BaseTerminal', () => {
|
||||
.mockReturnValueOnce('') // First call returns empty (no selection)
|
||||
.mockReturnValueOnce(allText) // Second call after selectAll returns all text
|
||||
|
||||
wrapper = mountBaseTerminal()
|
||||
const { container } = renderBaseTerminal()
|
||||
|
||||
await wrapper.trigger('mouseenter')
|
||||
await fireEvent.mouseEnter(container.firstElementChild!)
|
||||
await nextTick()
|
||||
|
||||
const button = wrapper.find('button[aria-label]')
|
||||
await button.trigger('click')
|
||||
const button = screen.getByRole('button')
|
||||
await fireEvent.click(button)
|
||||
await nextTick()
|
||||
|
||||
expect(mockTerminal.selectAll).toHaveBeenCalled()
|
||||
expect(navigator.clipboard.writeText).toHaveBeenCalledWith(allText)
|
||||
expect(mockWriteText).toHaveBeenCalledWith(allText)
|
||||
expect(mockTerminal.clearSelection).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
@@ -213,15 +210,16 @@ describe('BaseTerminal', () => {
|
||||
mockTerminal.hasSelection.mockReturnValue(false)
|
||||
mockTerminal.getSelection.mockReturnValue('')
|
||||
|
||||
wrapper = mountBaseTerminal()
|
||||
const { container } = renderBaseTerminal()
|
||||
|
||||
await wrapper.trigger('mouseenter')
|
||||
await fireEvent.mouseEnter(container.firstElementChild!)
|
||||
await nextTick()
|
||||
|
||||
const button = wrapper.find('button[aria-label]')
|
||||
await button.trigger('click')
|
||||
const button = screen.getByRole('button')
|
||||
await fireEvent.click(button)
|
||||
await nextTick()
|
||||
|
||||
expect(mockTerminal.selectAll).toHaveBeenCalled()
|
||||
expect(navigator.clipboard.writeText).not.toHaveBeenCalled()
|
||||
expect(mockWriteText).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
|
||||
import Badge from './Badge.vue'
|
||||
import { badgeVariants } from './badge.variants'
|
||||
|
||||
describe('Badge', () => {
|
||||
it('renders label text', () => {
|
||||
const wrapper = mount(Badge, { props: { label: 'NEW' } })
|
||||
expect(wrapper.text()).toBe('NEW')
|
||||
render(Badge, { props: { label: 'NEW' } })
|
||||
expect(screen.getByText('NEW')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders numeric label', () => {
|
||||
const wrapper = mount(Badge, { props: { label: 5 } })
|
||||
expect(wrapper.text()).toBe('5')
|
||||
render(Badge, { props: { label: 5 } })
|
||||
expect(screen.getByText('5')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('defaults to dot variant when no label is provided', () => {
|
||||
const wrapper = mount(Badge)
|
||||
expect(wrapper.classes()).toContain('size-2')
|
||||
const { container } = render(Badge)
|
||||
// eslint-disable-next-line testing-library/no-node-access -- dot badge has no text/role to query
|
||||
expect(container.firstElementChild).toHaveClass('size-2')
|
||||
})
|
||||
|
||||
it('defaults to label variant when label is provided', () => {
|
||||
const wrapper = mount(Badge, { props: { label: 'NEW' } })
|
||||
expect(wrapper.classes()).toContain('font-semibold')
|
||||
expect(wrapper.classes()).toContain('uppercase')
|
||||
render(Badge, { props: { label: 'NEW' } })
|
||||
const el = screen.getByText('NEW')
|
||||
expect(el).toHaveClass('font-semibold')
|
||||
expect(el).toHaveClass('uppercase')
|
||||
})
|
||||
|
||||
it('applies circle variant', () => {
|
||||
const wrapper = mount(Badge, {
|
||||
props: { label: '3', variant: 'circle' }
|
||||
})
|
||||
expect(wrapper.classes()).toContain('size-3.5')
|
||||
render(Badge, { props: { label: '3', variant: 'circle' } })
|
||||
expect(screen.getByText('3')).toHaveClass('size-3.5')
|
||||
})
|
||||
|
||||
it('merges custom class via cn()', () => {
|
||||
const wrapper = mount(Badge, {
|
||||
props: { label: 'Test', class: 'ml-2' }
|
||||
})
|
||||
expect(wrapper.classes()).toContain('ml-2')
|
||||
expect(wrapper.classes()).toContain('rounded-full')
|
||||
render(Badge, { props: { label: 'Test', class: 'ml-2' } })
|
||||
const el = screen.getByText('Test')
|
||||
expect(el).toHaveClass('ml-2')
|
||||
expect(el).toHaveClass('rounded-full')
|
||||
})
|
||||
|
||||
describe('twMerge preserves color alongside text-3xs font size', () => {
|
||||
@@ -58,12 +58,10 @@ describe('Badge', () => {
|
||||
)
|
||||
|
||||
it('cn() does not clobber text-white when merging with text-3xs', () => {
|
||||
const wrapper = mount(Badge, {
|
||||
props: { label: 'Test', severity: 'danger' }
|
||||
})
|
||||
const classList = wrapper.classes()
|
||||
expect(classList).toContain('text-white')
|
||||
expect(classList).toContain('text-3xs')
|
||||
render(Badge, { props: { label: 'Test', severity: 'danger' } })
|
||||
const el = screen.getByText('Test')
|
||||
expect(el).toHaveClass('text-white')
|
||||
expect(el).toHaveClass('text-3xs')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
|
||||
import MarqueeLine from './MarqueeLine.vue'
|
||||
|
||||
describe(MarqueeLine, () => {
|
||||
it('renders slot content', () => {
|
||||
const wrapper = mount(MarqueeLine, {
|
||||
render(MarqueeLine, {
|
||||
slots: { default: 'Hello World' }
|
||||
})
|
||||
expect(wrapper.text()).toBe('Hello World')
|
||||
expect(screen.getByText('Hello World')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders content inside a span within the container', () => {
|
||||
const wrapper = mount(MarqueeLine, {
|
||||
render(MarqueeLine, {
|
||||
slots: { default: 'Test Text' }
|
||||
})
|
||||
const span = wrapper.find('span')
|
||||
expect(span.exists()).toBe(true)
|
||||
expect(span.text()).toBe('Test Text')
|
||||
const el = screen.getByText('Test Text')
|
||||
expect(el.tagName).toBe('SPAN')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import type { ComponentProps } from 'vue-component-type-helpers'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
import NotificationPopup from './NotificationPopup.vue'
|
||||
@@ -13,13 +13,11 @@ const i18n = createI18n({
|
||||
}
|
||||
})
|
||||
|
||||
function mountPopup(
|
||||
props: ComponentProps<typeof NotificationPopup> = {
|
||||
title: 'Test'
|
||||
},
|
||||
function renderPopup(
|
||||
props: { title: string; [key: string]: unknown } = { title: 'Test' },
|
||||
slots: Record<string, string> = {}
|
||||
) {
|
||||
return mount(NotificationPopup, {
|
||||
return render(NotificationPopup, {
|
||||
global: { plugins: [i18n] },
|
||||
props,
|
||||
slots
|
||||
@@ -28,51 +26,58 @@ function mountPopup(
|
||||
|
||||
describe('NotificationPopup', () => {
|
||||
it('renders title', () => {
|
||||
const wrapper = mountPopup({ title: 'Hello World' })
|
||||
expect(wrapper.text()).toContain('Hello World')
|
||||
renderPopup({ title: 'Hello World' })
|
||||
expect(screen.getByRole('status')).toHaveTextContent('Hello World')
|
||||
})
|
||||
|
||||
it('has role="status" for accessibility', () => {
|
||||
const wrapper = mountPopup()
|
||||
expect(wrapper.find('[role="status"]').exists()).toBe(true)
|
||||
renderPopup()
|
||||
expect(screen.getByRole('status')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders subtitle when provided', () => {
|
||||
const wrapper = mountPopup({ title: 'T', subtitle: 'v1.2.3' })
|
||||
expect(wrapper.text()).toContain('v1.2.3')
|
||||
renderPopup({ title: 'T', subtitle: 'v1.2.3' })
|
||||
expect(screen.getByRole('status')).toHaveTextContent('v1.2.3')
|
||||
})
|
||||
|
||||
it('renders icon when provided', () => {
|
||||
const wrapper = mountPopup({
|
||||
const { container } = renderPopup({
|
||||
title: 'T',
|
||||
icon: 'icon-[lucide--rocket]'
|
||||
})
|
||||
expect(wrapper.find('i.icon-\\[lucide--rocket\\]').exists()).toBe(true)
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
const icon = container.querySelector('i.icon-\\[lucide--rocket\\]')
|
||||
expect(icon).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('emits close when close button clicked', async () => {
|
||||
const wrapper = mountPopup({ title: 'T', showClose: true })
|
||||
await wrapper.find('[aria-label="Close"]').trigger('click')
|
||||
expect(wrapper.emitted('close')).toHaveLength(1)
|
||||
const user = userEvent.setup()
|
||||
const closeSpy = vi.fn()
|
||||
renderPopup({ title: 'T', showClose: true, onClose: closeSpy })
|
||||
await user.click(screen.getByRole('button', { name: 'Close' }))
|
||||
expect(closeSpy).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it('renders default slot content', () => {
|
||||
const wrapper = mountPopup({ title: 'T' }, { default: 'Body text here' })
|
||||
expect(wrapper.text()).toContain('Body text here')
|
||||
renderPopup({ title: 'T' }, { default: 'Body text here' })
|
||||
expect(screen.getByRole('status')).toHaveTextContent('Body text here')
|
||||
})
|
||||
|
||||
it('renders footer slots', () => {
|
||||
const wrapper = mountPopup(
|
||||
renderPopup(
|
||||
{ title: 'T' },
|
||||
{ 'footer-start': 'Left side', 'footer-end': 'Right side' }
|
||||
)
|
||||
expect(wrapper.text()).toContain('Left side')
|
||||
expect(wrapper.text()).toContain('Right side')
|
||||
const status = screen.getByRole('status')
|
||||
expect(status).toHaveTextContent('Left side')
|
||||
expect(status).toHaveTextContent('Right side')
|
||||
})
|
||||
|
||||
it('positions bottom-right when specified', () => {
|
||||
const wrapper = mountPopup({ title: 'T', position: 'bottom-right' })
|
||||
const root = wrapper.find('[role="status"]')
|
||||
expect(root.attributes('data-position')).toBe('bottom-right')
|
||||
renderPopup({ title: 'T', position: 'bottom-right' })
|
||||
expect(screen.getByRole('status')).toHaveAttribute(
|
||||
'data-position',
|
||||
'bottom-right'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { nextTick } from 'vue'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
@@ -13,7 +14,8 @@ function mockScrollWidth(el: HTMLElement, scrollWidth: number) {
|
||||
|
||||
describe(TextTicker, () => {
|
||||
let rafCallbacks: ((time: number) => void)[]
|
||||
let wrapper: ReturnType<typeof mount>
|
||||
let user: ReturnType<typeof userEvent.setup>
|
||||
let cleanup: (() => void) | undefined
|
||||
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers()
|
||||
@@ -23,32 +25,35 @@ describe(TextTicker, () => {
|
||||
return rafCallbacks.length
|
||||
})
|
||||
vi.spyOn(window, 'cancelAnimationFrame').mockImplementation(() => {})
|
||||
user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime })
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
wrapper?.unmount()
|
||||
cleanup?.()
|
||||
vi.useRealTimers()
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('renders slot content', () => {
|
||||
wrapper = mount(TextTicker, {
|
||||
const { unmount } = render(TextTicker, {
|
||||
slots: { default: 'Hello World' }
|
||||
})
|
||||
expect(wrapper.text()).toBe('Hello World')
|
||||
cleanup = unmount
|
||||
expect(screen.getByText('Hello World')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('scrolls on hover after delay', async () => {
|
||||
wrapper = mount(TextTicker, {
|
||||
const { unmount } = render(TextTicker, {
|
||||
slots: { default: 'Very long text that overflows' },
|
||||
props: { speed: 100 }
|
||||
})
|
||||
cleanup = unmount
|
||||
|
||||
const el = wrapper.element as HTMLElement
|
||||
const el = screen.getByText('Very long text that overflows')
|
||||
mockScrollWidth(el, 300)
|
||||
|
||||
await nextTick()
|
||||
await wrapper.trigger('mouseenter')
|
||||
await user.hover(el)
|
||||
await nextTick()
|
||||
|
||||
expect(rafCallbacks.length).toBe(0)
|
||||
@@ -62,19 +67,21 @@ describe(TextTicker, () => {
|
||||
})
|
||||
|
||||
it('cancels delayed scroll on mouse leave before delay elapses', async () => {
|
||||
wrapper = mount(TextTicker, {
|
||||
const { unmount } = render(TextTicker, {
|
||||
slots: { default: 'Very long text that overflows' },
|
||||
props: { speed: 100 }
|
||||
})
|
||||
cleanup = unmount
|
||||
|
||||
mockScrollWidth(wrapper.element as HTMLElement, 300)
|
||||
const el = screen.getByText('Very long text that overflows')
|
||||
mockScrollWidth(el, 300)
|
||||
|
||||
await nextTick()
|
||||
await wrapper.trigger('mouseenter')
|
||||
await user.hover(el)
|
||||
await nextTick()
|
||||
|
||||
vi.advanceTimersByTime(200)
|
||||
await wrapper.trigger('mouseleave')
|
||||
await user.unhover(el)
|
||||
await nextTick()
|
||||
|
||||
vi.advanceTimersByTime(350)
|
||||
@@ -83,16 +90,17 @@ describe(TextTicker, () => {
|
||||
})
|
||||
|
||||
it('resets scroll position on mouse leave', async () => {
|
||||
wrapper = mount(TextTicker, {
|
||||
const { unmount } = render(TextTicker, {
|
||||
slots: { default: 'Very long text that overflows' },
|
||||
props: { speed: 100 }
|
||||
})
|
||||
cleanup = unmount
|
||||
|
||||
const el = wrapper.element as HTMLElement
|
||||
const el = screen.getByText('Very long text that overflows')
|
||||
mockScrollWidth(el, 300)
|
||||
|
||||
await nextTick()
|
||||
await wrapper.trigger('mouseenter')
|
||||
await user.hover(el)
|
||||
await nextTick()
|
||||
vi.advanceTimersByTime(350)
|
||||
await nextTick()
|
||||
@@ -100,19 +108,22 @@ describe(TextTicker, () => {
|
||||
rafCallbacks[0](performance.now() + 500)
|
||||
expect(el.scrollLeft).toBeGreaterThan(0)
|
||||
|
||||
await wrapper.trigger('mouseleave')
|
||||
await user.unhover(el)
|
||||
await nextTick()
|
||||
|
||||
expect(el.scrollLeft).toBe(0)
|
||||
})
|
||||
|
||||
it('does not scroll when content fits', async () => {
|
||||
wrapper = mount(TextTicker, {
|
||||
const { unmount } = render(TextTicker, {
|
||||
slots: { default: 'Short' }
|
||||
})
|
||||
cleanup = unmount
|
||||
|
||||
const el = screen.getByText('Short')
|
||||
|
||||
await nextTick()
|
||||
await wrapper.trigger('mouseenter')
|
||||
await user.hover(el)
|
||||
await nextTick()
|
||||
vi.advanceTimersByTime(350)
|
||||
await nextTick()
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import { nextTick } from 'vue'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import MarqueeLine from './MarqueeLine.vue'
|
||||
import TextTickerMultiLine from './TextTickerMultiLine.vue'
|
||||
|
||||
type Callback = () => void
|
||||
@@ -41,23 +40,38 @@ function mockElementSize(
|
||||
}
|
||||
|
||||
describe(TextTickerMultiLine, () => {
|
||||
let wrapper: ReturnType<typeof mount>
|
||||
let unmountFn: () => void
|
||||
|
||||
afterEach(() => {
|
||||
wrapper?.unmount()
|
||||
unmountFn?.()
|
||||
resizeCallbacks.length = 0
|
||||
mutationCallbacks.length = 0
|
||||
})
|
||||
|
||||
function mountComponent(text: string) {
|
||||
wrapper = mount(TextTickerMultiLine, {
|
||||
function renderComponent(text: string) {
|
||||
const result = render(TextTickerMultiLine, {
|
||||
slots: { default: text }
|
||||
})
|
||||
return wrapper
|
||||
unmountFn = result.unmount
|
||||
return {
|
||||
...result,
|
||||
container: result.container as HTMLElement
|
||||
}
|
||||
}
|
||||
|
||||
function getMeasureEl(): HTMLElement {
|
||||
return wrapper.find('[aria-hidden="true"]').element as HTMLElement
|
||||
function getMeasureEl(container: HTMLElement): HTMLElement {
|
||||
// eslint-disable-next-line testing-library/no-node-access
|
||||
return container.querySelector('[aria-hidden="true"]') as HTMLElement
|
||||
}
|
||||
|
||||
function getVisibleLines(container: HTMLElement): HTMLElement[] {
|
||||
/* eslint-disable testing-library/no-node-access */
|
||||
return Array.from(
|
||||
container.querySelectorAll<HTMLElement>(
|
||||
'div.overflow-hidden:not([aria-hidden])'
|
||||
)
|
||||
)
|
||||
/* eslint-enable testing-library/no-node-access */
|
||||
}
|
||||
|
||||
async function triggerSplitLines() {
|
||||
@@ -66,40 +80,42 @@ describe(TextTickerMultiLine, () => {
|
||||
}
|
||||
|
||||
it('renders slot content', () => {
|
||||
mountComponent('Load Checkpoint')
|
||||
expect(wrapper.text()).toContain('Load Checkpoint')
|
||||
renderComponent('Load Checkpoint')
|
||||
expect(
|
||||
screen.getAllByText('Load Checkpoint').length
|
||||
).toBeGreaterThanOrEqual(1)
|
||||
})
|
||||
|
||||
it('renders a single MarqueeLine when text fits', async () => {
|
||||
mountComponent('Short')
|
||||
mockElementSize(getMeasureEl(), 200, 100)
|
||||
it('renders a single line when text fits', async () => {
|
||||
const { container } = renderComponent('Short')
|
||||
mockElementSize(getMeasureEl(container), 200, 100)
|
||||
await triggerSplitLines()
|
||||
|
||||
expect(wrapper.findAllComponents(MarqueeLine)).toHaveLength(1)
|
||||
expect(getVisibleLines(container)).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('renders two MarqueeLines when text overflows', async () => {
|
||||
mountComponent('Load Checkpoint Loader Simple')
|
||||
mockElementSize(getMeasureEl(), 100, 300)
|
||||
it('renders two lines when text overflows', async () => {
|
||||
const { container } = renderComponent('Load Checkpoint Loader Simple')
|
||||
mockElementSize(getMeasureEl(container), 100, 300)
|
||||
await triggerSplitLines()
|
||||
|
||||
expect(wrapper.findAllComponents(MarqueeLine)).toHaveLength(2)
|
||||
expect(getVisibleLines(container)).toHaveLength(2)
|
||||
})
|
||||
|
||||
it('splits text at word boundary when overflowing', async () => {
|
||||
mountComponent('Load Checkpoint Loader')
|
||||
mockElementSize(getMeasureEl(), 100, 200)
|
||||
const { container } = renderComponent('Load Checkpoint Loader')
|
||||
mockElementSize(getMeasureEl(container), 100, 200)
|
||||
await triggerSplitLines()
|
||||
|
||||
const lines = wrapper.findAllComponents(MarqueeLine)
|
||||
expect(lines[0].text()).toBe('Load')
|
||||
expect(lines[1].text()).toBe('Checkpoint Loader')
|
||||
const lines = getVisibleLines(container)
|
||||
expect(lines[0].textContent).toBe('Load')
|
||||
expect(lines[1].textContent).toBe('Checkpoint Loader')
|
||||
})
|
||||
|
||||
it('has hidden measurement element with aria-hidden', () => {
|
||||
mountComponent('Test')
|
||||
const measureEl = wrapper.find('[aria-hidden="true"]')
|
||||
expect(measureEl.exists()).toBe(true)
|
||||
expect(measureEl.classes()).toContain('invisible')
|
||||
const { container } = renderComponent('Test')
|
||||
const measureEl = getMeasureEl(container)
|
||||
expect(measureEl).toBeInTheDocument()
|
||||
expect(measureEl).toHaveClass('invisible')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { fireEvent, render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import type { FlattenedItem } from 'reka-ui'
|
||||
import { ref } from 'vue'
|
||||
import { nextTick, ref } from 'vue'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
@@ -92,7 +93,7 @@ describe('TreeExplorerV2Node', () => {
|
||||
}
|
||||
}
|
||||
|
||||
function mountComponent(
|
||||
function renderComponent(
|
||||
props: Record<string, unknown> = {},
|
||||
options: {
|
||||
provide?: Record<string, unknown>
|
||||
@@ -100,68 +101,76 @@ describe('TreeExplorerV2Node', () => {
|
||||
} = {}
|
||||
) {
|
||||
const treeItemStub = options.treeItemStub ?? createTreeItemStub()
|
||||
return {
|
||||
wrapper: mount(TreeExplorerV2Node, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
stubs: {
|
||||
TreeItem: treeItemStub.stub,
|
||||
Teleport: { template: '<div />' }
|
||||
},
|
||||
provide: {
|
||||
...options.provide
|
||||
}
|
||||
const onNodeClick = vi.fn()
|
||||
const { container } = render(TreeExplorerV2Node, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
stubs: {
|
||||
TreeItem: treeItemStub.stub,
|
||||
Teleport: { template: '<div />' }
|
||||
},
|
||||
props: {
|
||||
item: createMockItem('node'),
|
||||
...props
|
||||
provide: {
|
||||
...options.provide
|
||||
}
|
||||
}),
|
||||
treeItemStub
|
||||
}
|
||||
},
|
||||
props: {
|
||||
item: createMockItem('node'),
|
||||
onNodeClick,
|
||||
...props
|
||||
}
|
||||
})
|
||||
return { container, treeItemStub, onNodeClick }
|
||||
}
|
||||
|
||||
function getTreeNode(container: Element) {
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
return container.querySelector('div.group\\/tree-node')! as HTMLElement
|
||||
}
|
||||
|
||||
describe('handleClick', () => {
|
||||
it('emits nodeClick event when clicked', async () => {
|
||||
const { wrapper } = mountComponent({
|
||||
const user = userEvent.setup()
|
||||
const { container, onNodeClick } = renderComponent({
|
||||
item: createMockItem('node')
|
||||
})
|
||||
|
||||
const nodeDiv = wrapper.find('div.group\\/tree-node')
|
||||
await nodeDiv.trigger('click')
|
||||
const nodeDiv = getTreeNode(container)
|
||||
await user.click(nodeDiv)
|
||||
|
||||
expect(wrapper.emitted('nodeClick')).toBeTruthy()
|
||||
expect(wrapper.emitted('nodeClick')?.[0]?.[0]).toMatchObject({
|
||||
expect(onNodeClick).toHaveBeenCalled()
|
||||
expect(onNodeClick.mock.calls[0][0]).toMatchObject({
|
||||
type: 'node',
|
||||
label: 'Test Label'
|
||||
})
|
||||
})
|
||||
|
||||
it('calls handleToggle for folder items', async () => {
|
||||
const user = userEvent.setup()
|
||||
const treeItemStub = createTreeItemStub()
|
||||
const { wrapper } = mountComponent(
|
||||
const { container, onNodeClick } = renderComponent(
|
||||
{ item: createMockItem('folder') },
|
||||
{ treeItemStub }
|
||||
)
|
||||
|
||||
const folderDiv = wrapper.find('div.group\\/tree-node')
|
||||
await folderDiv.trigger('click')
|
||||
const folderDiv = getTreeNode(container)
|
||||
await user.click(folderDiv)
|
||||
|
||||
expect(wrapper.emitted('nodeClick')).toBeTruthy()
|
||||
expect(onNodeClick).toHaveBeenCalled()
|
||||
expect(treeItemStub.handleToggle).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not call handleToggle for node items', async () => {
|
||||
const user = userEvent.setup()
|
||||
const treeItemStub = createTreeItemStub()
|
||||
const { wrapper } = mountComponent(
|
||||
const { container, onNodeClick } = renderComponent(
|
||||
{ item: createMockItem('node') },
|
||||
{ treeItemStub }
|
||||
)
|
||||
|
||||
const nodeDiv = wrapper.find('div.group\\/tree-node')
|
||||
await nodeDiv.trigger('click')
|
||||
const nodeDiv = getTreeNode(container)
|
||||
await user.click(nodeDiv)
|
||||
|
||||
expect(wrapper.emitted('nodeClick')).toBeTruthy()
|
||||
expect(onNodeClick).toHaveBeenCalled()
|
||||
expect(treeItemStub.handleToggle).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -171,7 +180,7 @@ describe('TreeExplorerV2Node', () => {
|
||||
const contextMenuNode = ref<RenderedTreeExplorerNode | null>(null)
|
||||
const nodeItem = createMockItem('node')
|
||||
|
||||
const { wrapper } = mountComponent(
|
||||
const { container } = renderComponent(
|
||||
{ item: nodeItem },
|
||||
{
|
||||
provide: {
|
||||
@@ -180,8 +189,8 @@ describe('TreeExplorerV2Node', () => {
|
||||
}
|
||||
)
|
||||
|
||||
const nodeDiv = wrapper.find('div.group\\/tree-node')
|
||||
await nodeDiv.trigger('contextmenu')
|
||||
const nodeDiv = getTreeNode(container)
|
||||
await fireEvent.contextMenu(nodeDiv)
|
||||
|
||||
expect(contextMenuNode.value).toEqual(nodeItem.value)
|
||||
})
|
||||
@@ -193,7 +202,7 @@ describe('TreeExplorerV2Node', () => {
|
||||
label: 'Stale'
|
||||
} as RenderedTreeExplorerNode)
|
||||
|
||||
const { wrapper } = mountComponent(
|
||||
const { container } = renderComponent(
|
||||
{ item: createMockItem('folder') },
|
||||
{
|
||||
provide: {
|
||||
@@ -202,8 +211,8 @@ describe('TreeExplorerV2Node', () => {
|
||||
}
|
||||
)
|
||||
|
||||
const folderDiv = wrapper.find('div.group\\/tree-node')
|
||||
await folderDiv.trigger('contextmenu')
|
||||
const folderDiv = getTreeNode(container)
|
||||
await fireEvent.contextMenu(folderDiv)
|
||||
|
||||
expect(contextMenuNode.value).toBeNull()
|
||||
})
|
||||
@@ -216,47 +225,53 @@ describe('TreeExplorerV2Node', () => {
|
||||
|
||||
it('shows delete button for user blueprints', () => {
|
||||
mockIsUserBlueprint.mockReturnValue(true)
|
||||
const { wrapper } = mountComponent({
|
||||
renderComponent({
|
||||
item: createMockItem('node', {
|
||||
data: { name: 'SubgraphBlueprint.test' }
|
||||
})
|
||||
})
|
||||
|
||||
expect(wrapper.find('[aria-label="Delete"]').exists()).toBe(true)
|
||||
expect(screen.getByRole('button', { name: 'Delete' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('hides delete button for non-blueprint nodes', () => {
|
||||
mockIsUserBlueprint.mockReturnValue(false)
|
||||
const { wrapper } = mountComponent({
|
||||
renderComponent({
|
||||
item: createMockItem('node', {
|
||||
data: { name: 'KSampler' }
|
||||
})
|
||||
})
|
||||
|
||||
expect(wrapper.find('[aria-label="Delete"]').exists()).toBe(false)
|
||||
expect(
|
||||
screen.queryByRole('button', { name: 'Delete' })
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('always shows bookmark button', () => {
|
||||
mockIsUserBlueprint.mockReturnValue(true)
|
||||
const { wrapper } = mountComponent({
|
||||
renderComponent({
|
||||
item: createMockItem('node', {
|
||||
data: { name: 'SubgraphBlueprint.test' }
|
||||
})
|
||||
})
|
||||
|
||||
expect(wrapper.find('[aria-label="icon.bookmark"]').exists()).toBe(true)
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'icon.bookmark' })
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('calls deleteBlueprint when delete button is clicked', async () => {
|
||||
const user = userEvent.setup()
|
||||
mockIsUserBlueprint.mockReturnValue(true)
|
||||
const nodeName = 'SubgraphBlueprint.test'
|
||||
const { wrapper } = mountComponent({
|
||||
renderComponent({
|
||||
item: createMockItem('node', {
|
||||
data: { name: nodeName }
|
||||
})
|
||||
})
|
||||
|
||||
await wrapper.find('[aria-label="Delete"]').trigger('click')
|
||||
const deleteButton = screen.getByRole('button', { name: 'Delete' })
|
||||
await user.click(deleteButton)
|
||||
|
||||
expect(mockDeleteBlueprint).toHaveBeenCalledWith(nodeName)
|
||||
})
|
||||
@@ -264,40 +279,47 @@ describe('TreeExplorerV2Node', () => {
|
||||
|
||||
describe('rendering', () => {
|
||||
it('renders node icon for node type', () => {
|
||||
const { wrapper } = mountComponent({
|
||||
const { container } = renderComponent({
|
||||
item: createMockItem('node')
|
||||
})
|
||||
|
||||
expect(wrapper.find('i.icon-\\[comfy--node\\]').exists()).toBe(true)
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
expect(container.querySelector('i.icon-\\[comfy--node\\]')).toBeTruthy()
|
||||
})
|
||||
|
||||
it('renders folder icon for folder type', () => {
|
||||
const { wrapper } = mountComponent({
|
||||
const { container } = renderComponent({
|
||||
item: createMockItem('folder', { icon: 'icon-[lucide--folder]' })
|
||||
})
|
||||
|
||||
expect(wrapper.find('i.icon-\\[lucide--folder\\]').exists()).toBe(true)
|
||||
/* eslint-disable testing-library/no-container, testing-library/no-node-access */
|
||||
expect(
|
||||
container.querySelector('i.icon-\\[lucide--folder\\]')
|
||||
).toBeTruthy()
|
||||
/* eslint-enable testing-library/no-container, testing-library/no-node-access */
|
||||
})
|
||||
|
||||
it('renders label text', () => {
|
||||
const { wrapper } = mountComponent({
|
||||
renderComponent({
|
||||
item: createMockItem('node', { label: 'My Node' })
|
||||
})
|
||||
|
||||
expect(wrapper.text()).toContain('My Node')
|
||||
expect(screen.getByText('My Node')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders chevron for folder with children', () => {
|
||||
const { wrapper } = mountComponent({
|
||||
const { container } = renderComponent({
|
||||
item: {
|
||||
...createMockItem('folder'),
|
||||
hasChildren: true
|
||||
}
|
||||
})
|
||||
|
||||
expect(wrapper.find('i.icon-\\[lucide--chevron-down\\]').exists()).toBe(
|
||||
true
|
||||
)
|
||||
/* eslint-disable testing-library/no-container, testing-library/no-node-access */
|
||||
expect(
|
||||
container.querySelector('i.icon-\\[lucide--chevron-down\\]')
|
||||
).toBeTruthy()
|
||||
/* eslint-enable testing-library/no-container, testing-library/no-node-access */
|
||||
})
|
||||
})
|
||||
|
||||
@@ -307,75 +329,75 @@ describe('TreeExplorerV2Node', () => {
|
||||
})
|
||||
|
||||
it('sets draggable attribute on node items', () => {
|
||||
const { wrapper } = mountComponent({
|
||||
const { container } = renderComponent({
|
||||
item: createMockItem('node')
|
||||
})
|
||||
|
||||
const nodeDiv = wrapper.find('div.group\\/tree-node')
|
||||
expect(nodeDiv.attributes('draggable')).toBe('true')
|
||||
const nodeDiv = getTreeNode(container)
|
||||
expect(nodeDiv.getAttribute('draggable')).toBe('true')
|
||||
})
|
||||
|
||||
it('does not set draggable on folder items', () => {
|
||||
const { wrapper } = mountComponent({
|
||||
const { container } = renderComponent({
|
||||
item: createMockItem('folder')
|
||||
})
|
||||
|
||||
const folderDiv = wrapper.find('div.group\\/tree-node')
|
||||
expect(folderDiv.attributes('draggable')).toBeUndefined()
|
||||
const folderDiv = getTreeNode(container)
|
||||
expect(folderDiv.getAttribute('draggable')).toBeNull()
|
||||
})
|
||||
|
||||
it('calls startDrag with native mode on dragstart', async () => {
|
||||
const mockData = { name: 'TestNode' }
|
||||
const { wrapper } = mountComponent({
|
||||
const { container } = renderComponent({
|
||||
item: createMockItem('node', { data: mockData })
|
||||
})
|
||||
|
||||
const nodeDiv = wrapper.find('div.group\\/tree-node')
|
||||
await nodeDiv.trigger('dragstart')
|
||||
const nodeDiv = getTreeNode(container)
|
||||
await fireEvent.dragStart(nodeDiv)
|
||||
|
||||
expect(mockStartDrag).toHaveBeenCalledWith(mockData, 'native')
|
||||
})
|
||||
|
||||
it('does not call startDrag for folder items on dragstart', async () => {
|
||||
const { wrapper } = mountComponent({
|
||||
const { container } = renderComponent({
|
||||
item: createMockItem('folder')
|
||||
})
|
||||
|
||||
const folderDiv = wrapper.find('div.group\\/tree-node')
|
||||
await folderDiv.trigger('dragstart')
|
||||
const folderDiv = getTreeNode(container)
|
||||
await fireEvent.dragStart(folderDiv)
|
||||
|
||||
expect(mockStartDrag).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('calls handleNativeDrop on dragend with drop coordinates', async () => {
|
||||
const mockData = { name: 'TestNode' }
|
||||
const { wrapper } = mountComponent({
|
||||
const { container } = renderComponent({
|
||||
item: createMockItem('node', { data: mockData })
|
||||
})
|
||||
|
||||
const nodeDiv = wrapper.find('div.group\\/tree-node')
|
||||
const nodeDiv = getTreeNode(container)
|
||||
|
||||
await nodeDiv.trigger('dragstart')
|
||||
await fireEvent.dragStart(nodeDiv)
|
||||
|
||||
const dragEndEvent = new DragEvent('dragend', { bubbles: true })
|
||||
Object.defineProperty(dragEndEvent, 'clientX', { value: 100 })
|
||||
Object.defineProperty(dragEndEvent, 'clientY', { value: 200 })
|
||||
|
||||
await nodeDiv.element.dispatchEvent(dragEndEvent)
|
||||
await wrapper.vm.$nextTick()
|
||||
nodeDiv.dispatchEvent(dragEndEvent)
|
||||
await nextTick()
|
||||
|
||||
expect(mockHandleNativeDrop).toHaveBeenCalledWith(100, 200)
|
||||
})
|
||||
|
||||
it('calls handleNativeDrop regardless of dropEffect', async () => {
|
||||
const mockData = { name: 'TestNode' }
|
||||
const { wrapper } = mountComponent({
|
||||
const { container } = renderComponent({
|
||||
item: createMockItem('node', { data: mockData })
|
||||
})
|
||||
|
||||
const nodeDiv = wrapper.find('div.group\\/tree-node')
|
||||
const nodeDiv = getTreeNode(container)
|
||||
|
||||
await nodeDiv.trigger('dragstart')
|
||||
await fireEvent.dragStart(nodeDiv)
|
||||
mockHandleNativeDrop.mockClear()
|
||||
|
||||
const dragEndEvent = new DragEvent('dragend', { bubbles: true })
|
||||
@@ -385,8 +407,8 @@ describe('TreeExplorerV2Node', () => {
|
||||
value: { dropEffect: 'none' }
|
||||
})
|
||||
|
||||
await nodeDiv.element.dispatchEvent(dragEndEvent)
|
||||
await wrapper.vm.$nextTick()
|
||||
nodeDiv.dispatchEvent(dragEndEvent)
|
||||
await nextTick()
|
||||
|
||||
expect(mockHandleNativeDrop).toHaveBeenCalledWith(300, 400)
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import type { Ref } from 'vue'
|
||||
import { nextTick, ref } from 'vue'
|
||||
@@ -46,7 +46,7 @@ describe('VirtualGrid', () => {
|
||||
mockedHeight.value = 200
|
||||
mockedScrollY.value = 0
|
||||
|
||||
const wrapper = mount(VirtualGrid<TestItem>, {
|
||||
render(VirtualGrid, {
|
||||
props: {
|
||||
items,
|
||||
gridStyle: defaultGridStyle,
|
||||
@@ -60,16 +60,14 @@ describe('VirtualGrid', () => {
|
||||
<div class="test-item">{{ item.name }}</div>
|
||||
</template>`
|
||||
},
|
||||
attachTo: document.body
|
||||
container: document.body.appendChild(document.createElement('div'))
|
||||
})
|
||||
|
||||
await nextTick()
|
||||
|
||||
const renderedItems = wrapper.findAll('.test-item')
|
||||
const renderedItems = screen.getAllByText(/^Item \d+$/)
|
||||
expect(renderedItems.length).toBeGreaterThan(0)
|
||||
expect(renderedItems.length).toBeLessThan(items.length)
|
||||
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('provides correct index in slot props', async () => {
|
||||
@@ -79,7 +77,7 @@ describe('VirtualGrid', () => {
|
||||
mockedHeight.value = 200
|
||||
mockedScrollY.value = 0
|
||||
|
||||
const wrapper = mount(VirtualGrid<TestItem>, {
|
||||
render(VirtualGrid, {
|
||||
props: {
|
||||
items,
|
||||
gridStyle: defaultGridStyle,
|
||||
@@ -94,7 +92,7 @@ describe('VirtualGrid', () => {
|
||||
return null
|
||||
}
|
||||
},
|
||||
attachTo: document.body
|
||||
container: document.body.appendChild(document.createElement('div'))
|
||||
})
|
||||
|
||||
await nextTick()
|
||||
@@ -104,8 +102,6 @@ describe('VirtualGrid', () => {
|
||||
for (let i = 1; i < receivedIndices.length; i++) {
|
||||
expect(receivedIndices[i]).toBe(receivedIndices[i - 1] + 1)
|
||||
}
|
||||
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('respects maxColumns prop', async () => {
|
||||
@@ -114,28 +110,29 @@ describe('VirtualGrid', () => {
|
||||
mockedHeight.value = 200
|
||||
mockedScrollY.value = 0
|
||||
|
||||
const wrapper = mount(VirtualGrid<TestItem>, {
|
||||
const { container } = render(VirtualGrid, {
|
||||
props: {
|
||||
items,
|
||||
gridStyle: defaultGridStyle,
|
||||
maxColumns: 2
|
||||
},
|
||||
attachTo: document.body
|
||||
container: document.body.appendChild(document.createElement('div'))
|
||||
})
|
||||
|
||||
await nextTick()
|
||||
|
||||
const gridElement = wrapper.find('[style*="display: grid"]')
|
||||
expect(gridElement.exists()).toBe(true)
|
||||
|
||||
const gridEl = gridElement.element as HTMLElement
|
||||
expect(gridEl.style.gridTemplateColumns).toBe('repeat(2, minmax(0, 1fr))')
|
||||
|
||||
wrapper.unmount()
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
const gridElement = container.querySelector(
|
||||
'[style*="display: grid"]'
|
||||
) as HTMLElement
|
||||
expect(gridElement).not.toBeNull()
|
||||
expect(gridElement.style.gridTemplateColumns).toBe(
|
||||
'repeat(2, minmax(0, 1fr))'
|
||||
)
|
||||
})
|
||||
|
||||
it('renders empty when no items provided', async () => {
|
||||
const wrapper = mount(VirtualGrid<TestItem>, {
|
||||
render(VirtualGrid, {
|
||||
props: {
|
||||
items: [],
|
||||
gridStyle: defaultGridStyle
|
||||
@@ -149,10 +146,8 @@ describe('VirtualGrid', () => {
|
||||
|
||||
await nextTick()
|
||||
|
||||
const renderedItems = wrapper.findAll('.test-item')
|
||||
const renderedItems = screen.queryAllByText(/^Item \d+$/)
|
||||
expect(renderedItems.length).toBe(0)
|
||||
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('emits approach-end for single-column list when scrolled near bottom', async () => {
|
||||
@@ -161,7 +156,9 @@ describe('VirtualGrid', () => {
|
||||
mockedHeight.value = 600
|
||||
mockedScrollY.value = 0
|
||||
|
||||
const wrapper = mount(VirtualGrid<TestItem>, {
|
||||
const onApproachEnd = vi.fn()
|
||||
|
||||
render(VirtualGrid, {
|
||||
props: {
|
||||
items,
|
||||
gridStyle: {
|
||||
@@ -171,19 +168,20 @@ describe('VirtualGrid', () => {
|
||||
defaultItemHeight: 48,
|
||||
defaultItemWidth: 200,
|
||||
maxColumns: 1,
|
||||
bufferRows: 1
|
||||
bufferRows: 1,
|
||||
onApproachEnd
|
||||
},
|
||||
slots: {
|
||||
item: `<template #item="{ item }">
|
||||
<div class="test-item">{{ item.name }}</div>
|
||||
</template>`
|
||||
},
|
||||
attachTo: document.body
|
||||
container: document.body.appendChild(document.createElement('div'))
|
||||
})
|
||||
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.emitted('approach-end')).toBeUndefined()
|
||||
expect(onApproachEnd).not.toHaveBeenCalled()
|
||||
|
||||
// Scroll near the end: 50 items * 48px = 2400px total
|
||||
// viewRows = ceil(600/48) = 13, buffer = 1
|
||||
@@ -195,9 +193,7 @@ describe('VirtualGrid', () => {
|
||||
mockedScrollY.value = 1680
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.emitted('approach-end')).toBeDefined()
|
||||
|
||||
wrapper.unmount()
|
||||
expect(onApproachEnd).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not emit approach-end without maxColumns in single-column layout', async () => {
|
||||
@@ -208,7 +204,9 @@ describe('VirtualGrid', () => {
|
||||
mockedHeight.value = 600
|
||||
mockedScrollY.value = 0
|
||||
|
||||
const wrapper = mount(VirtualGrid<TestItem>, {
|
||||
const onApproachEnd = vi.fn()
|
||||
|
||||
render(VirtualGrid, {
|
||||
props: {
|
||||
items,
|
||||
gridStyle: {
|
||||
@@ -218,14 +216,15 @@ describe('VirtualGrid', () => {
|
||||
defaultItemHeight: 48,
|
||||
defaultItemWidth: 200,
|
||||
// No maxColumns — cols will be floor(400/200) = 2
|
||||
bufferRows: 1
|
||||
bufferRows: 1,
|
||||
onApproachEnd
|
||||
},
|
||||
slots: {
|
||||
item: `<template #item="{ item }">
|
||||
<div class="test-item">{{ item.name }}</div>
|
||||
</template>`
|
||||
},
|
||||
attachTo: document.body
|
||||
container: document.body.appendChild(document.createElement('div'))
|
||||
})
|
||||
|
||||
await nextTick()
|
||||
@@ -237,9 +236,7 @@ describe('VirtualGrid', () => {
|
||||
// With cols=2, toCol = (35+1+13)*2 = 98, which exceeds items.length (50)
|
||||
// remainingCol = 50-98 = -48, hasMoreToRender = false → isNearEnd = false
|
||||
// The approach-end never fires at the correct scroll position
|
||||
expect(wrapper.emitted('approach-end')).toBeUndefined()
|
||||
|
||||
wrapper.unmount()
|
||||
expect(onApproachEnd).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('forces cols to maxColumns when maxColumns is finite', async () => {
|
||||
@@ -248,7 +245,7 @@ describe('VirtualGrid', () => {
|
||||
mockedScrollY.value = 0
|
||||
|
||||
const items = createItems(20)
|
||||
const wrapper = mount(VirtualGrid<TestItem>, {
|
||||
render(VirtualGrid, {
|
||||
props: {
|
||||
items,
|
||||
gridStyle: defaultGridStyle,
|
||||
@@ -262,15 +259,13 @@ describe('VirtualGrid', () => {
|
||||
<div class="test-item">{{ item.name }}</div>
|
||||
</template>`
|
||||
},
|
||||
attachTo: document.body
|
||||
container: document.body.appendChild(document.createElement('div'))
|
||||
})
|
||||
|
||||
await nextTick()
|
||||
|
||||
const renderedItems = wrapper.findAll('.test-item')
|
||||
const renderedItems = screen.getAllByText(/^Item \d+$/)
|
||||
expect(renderedItems.length).toBeGreaterThan(0)
|
||||
expect(renderedItems.length % 4).toBe(0)
|
||||
|
||||
wrapper.unmount()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { shallowMount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import WorkflowActionsList from '@/components/common/WorkflowActionsList.vue'
|
||||
@@ -7,10 +8,23 @@ import type {
|
||||
WorkflowMenuItem
|
||||
} from '@/types/workflowMenuItem'
|
||||
|
||||
function createWrapper(items: WorkflowMenuItem[]) {
|
||||
return shallowMount(WorkflowActionsList, {
|
||||
props: { items },
|
||||
global: { renderStubDefaultSlot: true }
|
||||
const MenuItemStub = {
|
||||
template:
|
||||
'<div data-testid="menu-item" @click="$emit(\'select\')"><slot /></div>',
|
||||
emits: ['select']
|
||||
}
|
||||
|
||||
const SeparatorStub = {
|
||||
template: '<hr data-testid="menu-separator" />'
|
||||
}
|
||||
|
||||
function renderList(items: WorkflowMenuItem[]) {
|
||||
return render(WorkflowActionsList, {
|
||||
props: {
|
||||
items,
|
||||
itemComponent: MenuItemStub,
|
||||
separatorComponent: SeparatorStub
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -20,10 +34,9 @@ describe('WorkflowActionsList', () => {
|
||||
{ id: 'save', label: 'Save', icon: 'pi pi-save', command: vi.fn() }
|
||||
]
|
||||
|
||||
const wrapper = createWrapper(items)
|
||||
renderList(items)
|
||||
|
||||
expect(wrapper.text()).toContain('Save')
|
||||
expect(wrapper.find('.pi-save').exists()).toBe(true)
|
||||
expect(screen.getByText('Save')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders separator items', () => {
|
||||
@@ -33,24 +46,23 @@ describe('WorkflowActionsList', () => {
|
||||
{ id: 'after', label: 'After', icon: 'pi pi-b', command: vi.fn() }
|
||||
]
|
||||
|
||||
const wrapper = createWrapper(items)
|
||||
const html = wrapper.html()
|
||||
renderList(items)
|
||||
|
||||
expect(html).toContain('dropdown-menu-separator-stub')
|
||||
expect(wrapper.text()).toContain('Before')
|
||||
expect(wrapper.text()).toContain('After')
|
||||
screen.getByTestId('menu-separator')
|
||||
screen.getByText('Before')
|
||||
screen.getByText('After')
|
||||
})
|
||||
|
||||
it('dispatches command on select', async () => {
|
||||
const user = userEvent.setup()
|
||||
const command = vi.fn()
|
||||
const items: WorkflowMenuItem[] = [
|
||||
{ id: 'action', label: 'Action', icon: 'pi pi-play', command }
|
||||
]
|
||||
|
||||
const wrapper = createWrapper(items)
|
||||
const item = wrapper.findComponent({ name: 'DropdownMenuItem' })
|
||||
await item.vm.$emit('select')
|
||||
renderList(items)
|
||||
|
||||
await user.click(screen.getByTestId('menu-item'))
|
||||
expect(command).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
@@ -65,9 +77,9 @@ describe('WorkflowActionsList', () => {
|
||||
}
|
||||
]
|
||||
|
||||
const wrapper = createWrapper(items)
|
||||
renderList(items)
|
||||
|
||||
expect(wrapper.text()).toContain('NEW')
|
||||
screen.getByText('NEW')
|
||||
})
|
||||
|
||||
it('does not render items with visible set to false', () => {
|
||||
@@ -82,10 +94,10 @@ describe('WorkflowActionsList', () => {
|
||||
{ id: 'shown', label: 'Shown Item', icon: 'pi pi-eye', command: vi.fn() }
|
||||
]
|
||||
|
||||
const wrapper = createWrapper(items)
|
||||
renderList(items)
|
||||
|
||||
expect(wrapper.text()).not.toContain('Hidden Item')
|
||||
expect(wrapper.text()).toContain('Shown Item')
|
||||
expect(screen.queryByText('Hidden Item')).toBeNull()
|
||||
screen.getByText('Shown Item')
|
||||
})
|
||||
|
||||
it('does not render badge when absent', () => {
|
||||
@@ -93,8 +105,8 @@ describe('WorkflowActionsList', () => {
|
||||
{ id: 'plain', label: 'Plain', icon: 'pi pi-check', command: vi.fn() }
|
||||
]
|
||||
|
||||
const wrapper = createWrapper(items)
|
||||
renderList(items)
|
||||
|
||||
expect(wrapper.text()).not.toContain('NEW')
|
||||
expect(screen.queryByText('NEW')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,86 +1,91 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { fireEvent, render, screen } from '@testing-library/vue'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import type { CurvePoint } from './types'
|
||||
|
||||
import CurveEditor from './CurveEditor.vue'
|
||||
|
||||
function mountEditor(points: CurvePoint[], extraProps = {}) {
|
||||
return mount(CurveEditor, {
|
||||
function renderEditor(points: CurvePoint[], extraProps = {}) {
|
||||
const { container } = render(CurveEditor, {
|
||||
props: { modelValue: points, ...extraProps }
|
||||
})
|
||||
return { container }
|
||||
}
|
||||
|
||||
function getCurvePath(wrapper: ReturnType<typeof mount>) {
|
||||
return wrapper.find('[data-testid="curve-path"]')
|
||||
function getCurvePath() {
|
||||
return screen.getByTestId('curve-path')
|
||||
}
|
||||
|
||||
describe('CurveEditor', () => {
|
||||
it('renders SVG with curve path', () => {
|
||||
const wrapper = mountEditor([
|
||||
const { container } = renderEditor([
|
||||
[0, 0],
|
||||
[1, 1]
|
||||
])
|
||||
expect(wrapper.find('svg').exists()).toBe(true)
|
||||
const curvePath = getCurvePath(wrapper)
|
||||
expect(curvePath.exists()).toBe(true)
|
||||
expect(curvePath.attributes('d')).toBeTruthy()
|
||||
/* eslint-disable testing-library/no-container, testing-library/no-node-access */
|
||||
expect(container.querySelector('svg')).toBeInTheDocument()
|
||||
/* eslint-enable testing-library/no-container, testing-library/no-node-access */
|
||||
const curvePath = getCurvePath()
|
||||
expect(curvePath).toBeInTheDocument()
|
||||
expect(curvePath.getAttribute('d')).toBeTruthy()
|
||||
})
|
||||
|
||||
it('renders a circle for each control point', () => {
|
||||
const wrapper = mountEditor([
|
||||
const { container } = renderEditor([
|
||||
[0, 0],
|
||||
[0.5, 0.7],
|
||||
[1, 1]
|
||||
])
|
||||
expect(wrapper.findAll('circle')).toHaveLength(3)
|
||||
/* eslint-disable testing-library/no-container, testing-library/no-node-access */
|
||||
expect(container.querySelectorAll('circle')).toHaveLength(3)
|
||||
/* eslint-enable testing-library/no-container, testing-library/no-node-access */
|
||||
})
|
||||
|
||||
it('renders histogram path when provided', () => {
|
||||
const histogram = new Uint32Array(256)
|
||||
for (let i = 0; i < 256; i++) histogram[i] = i + 1
|
||||
const wrapper = mountEditor(
|
||||
renderEditor(
|
||||
[
|
||||
[0, 0],
|
||||
[1, 1]
|
||||
],
|
||||
{ histogram }
|
||||
)
|
||||
const histogramPath = wrapper.find('[data-testid="histogram-path"]')
|
||||
expect(histogramPath.exists()).toBe(true)
|
||||
expect(histogramPath.attributes('d')).toContain('M0,1')
|
||||
const histogramPath = screen.getByTestId('histogram-path')
|
||||
expect(histogramPath).toBeInTheDocument()
|
||||
expect(histogramPath.getAttribute('d')).toContain('M0,1')
|
||||
})
|
||||
|
||||
it('does not render histogram path when not provided', () => {
|
||||
const wrapper = mountEditor([
|
||||
renderEditor([
|
||||
[0, 0],
|
||||
[1, 1]
|
||||
])
|
||||
expect(wrapper.find('[data-testid="histogram-path"]').exists()).toBe(false)
|
||||
expect(screen.queryByTestId('histogram-path')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('returns empty path with fewer than 2 points', () => {
|
||||
const wrapper = mountEditor([[0.5, 0.5]])
|
||||
expect(getCurvePath(wrapper).attributes('d')).toBe('')
|
||||
renderEditor([[0.5, 0.5]])
|
||||
expect(getCurvePath().getAttribute('d')).toBe('')
|
||||
})
|
||||
|
||||
it('generates path starting with M and containing L segments', () => {
|
||||
const wrapper = mountEditor([
|
||||
renderEditor([
|
||||
[0, 0],
|
||||
[0.5, 0.8],
|
||||
[1, 1]
|
||||
])
|
||||
const d = getCurvePath(wrapper).attributes('d')!
|
||||
const d = getCurvePath().getAttribute('d')!
|
||||
expect(d).toMatch(/^M/)
|
||||
expect(d).toContain('L')
|
||||
})
|
||||
|
||||
it('curve path only spans the x-range of control points', () => {
|
||||
const wrapper = mountEditor([
|
||||
renderEditor([
|
||||
[0.2, 0.3],
|
||||
[0.8, 0.9]
|
||||
])
|
||||
const d = getCurvePath(wrapper).attributes('d')!
|
||||
const d = getCurvePath().getAttribute('d')!
|
||||
const xValues = d
|
||||
.split(/[ML]/)
|
||||
.filter(Boolean)
|
||||
@@ -95,19 +100,22 @@ describe('CurveEditor', () => {
|
||||
[0.5, 0.5],
|
||||
[1, 1]
|
||||
]
|
||||
const wrapper = mountEditor(points)
|
||||
expect(wrapper.findAll('circle')).toHaveLength(3)
|
||||
const { container } = renderEditor(points)
|
||||
|
||||
await wrapper.findAll('circle')[1].trigger('pointerdown', {
|
||||
/* eslint-disable testing-library/no-container, testing-library/no-node-access, testing-library/prefer-user-event */
|
||||
expect(container.querySelectorAll('circle')).toHaveLength(3)
|
||||
|
||||
await fireEvent.pointerDown(container.querySelectorAll('circle')[1], {
|
||||
button: 2,
|
||||
pointerId: 1
|
||||
})
|
||||
expect(wrapper.findAll('circle')).toHaveLength(2)
|
||||
expect(container.querySelectorAll('circle')).toHaveLength(2)
|
||||
|
||||
await wrapper.findAll('circle')[0].trigger('pointerdown', {
|
||||
await fireEvent.pointerDown(container.querySelectorAll('circle')[0], {
|
||||
button: 2,
|
||||
pointerId: 1
|
||||
})
|
||||
expect(wrapper.findAll('circle')).toHaveLength(2)
|
||||
expect(container.querySelectorAll('circle')).toHaveLength(2)
|
||||
/* eslint-enable testing-library/no-container, testing-library/no-node-access */
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import CreditTopUpOption from '@/components/dialog/content/credit/CreditTopUpOption.vue'
|
||||
|
||||
@@ -10,10 +11,16 @@ const i18n = createI18n({
|
||||
messages: { en: {} }
|
||||
})
|
||||
|
||||
const mountOption = (
|
||||
props?: Partial<{ credits: number; description: string; selected: boolean }>
|
||||
) =>
|
||||
mount(CreditTopUpOption, {
|
||||
function renderOption(
|
||||
props?: Partial<{
|
||||
credits: number
|
||||
description: string
|
||||
selected: boolean
|
||||
onSelect: () => void
|
||||
}>
|
||||
) {
|
||||
const user = userEvent.setup()
|
||||
const result = render(CreditTopUpOption, {
|
||||
props: {
|
||||
credits: 1000,
|
||||
description: '~100 videos*',
|
||||
@@ -24,25 +31,30 @@ const mountOption = (
|
||||
plugins: [i18n]
|
||||
}
|
||||
})
|
||||
return { user, ...result }
|
||||
}
|
||||
|
||||
describe('CreditTopUpOption', () => {
|
||||
it('renders credit amount and description', () => {
|
||||
const wrapper = mountOption({ credits: 5000, description: '~500 videos*' })
|
||||
expect(wrapper.text()).toContain('5,000')
|
||||
expect(wrapper.text()).toContain('~500 videos*')
|
||||
renderOption({ credits: 5000, description: '~500 videos*' })
|
||||
expect(screen.getByText('5,000')).toBeInTheDocument()
|
||||
expect(screen.getByText('~500 videos*')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('applies unselected styling when not selected', () => {
|
||||
const wrapper = mountOption({ selected: false })
|
||||
expect(wrapper.find('div').classes()).toContain(
|
||||
'bg-component-node-disabled'
|
||||
const { container } = renderOption({ selected: false })
|
||||
// eslint-disable-next-line testing-library/no-node-access
|
||||
const rootDiv = container.firstElementChild as HTMLElement
|
||||
expect(rootDiv).toHaveClass(
|
||||
'bg-component-node-disabled',
|
||||
'border-transparent'
|
||||
)
|
||||
expect(wrapper.find('div').classes()).toContain('border-transparent')
|
||||
})
|
||||
|
||||
it('emits select event when clicked', async () => {
|
||||
const wrapper = mountOption()
|
||||
await wrapper.find('div').trigger('click')
|
||||
expect(wrapper.emitted('select')).toHaveLength(1)
|
||||
const selectSpy = vi.fn()
|
||||
const { user } = renderOption({ onSelect: selectSpy })
|
||||
await user.click(screen.getByText('1,000'))
|
||||
expect(selectSpy).toHaveBeenCalledOnce()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render } from '@testing-library/vue'
|
||||
import { fromAny } from '@total-typescript/shoehorn'
|
||||
import { createPinia } from 'pinia'
|
||||
import PrimeVue from 'primevue/config'
|
||||
import Tag from 'primevue/tag'
|
||||
import Tooltip from 'primevue/tooltip'
|
||||
import { defineComponent, h } from 'vue'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
import SettingItem from '@/platform/settings/components/SettingItem.vue'
|
||||
import type { SettingParams } from '@/platform/settings/types'
|
||||
|
||||
const i18n = createI18n({
|
||||
legacy: false,
|
||||
@@ -17,60 +20,72 @@ vi.mock('@/utils/formatUtil', () => ({
|
||||
normalizeI18nKey: vi.fn()
|
||||
}))
|
||||
|
||||
const FormItemStub = defineComponent({
|
||||
name: 'FormItem',
|
||||
props: {
|
||||
item: { type: Object, default: () => ({}) },
|
||||
id: { type: String, default: undefined },
|
||||
formValue: { type: null, default: undefined }
|
||||
},
|
||||
setup(props) {
|
||||
return () =>
|
||||
h('div', { 'data-testid': 'form-item-data' }, JSON.stringify(props.item))
|
||||
}
|
||||
})
|
||||
|
||||
describe('SettingItem', () => {
|
||||
const mountComponent = (props: Record<string, unknown>, options = {}) => {
|
||||
return mount(SettingItem, {
|
||||
function renderComponent(setting: SettingParams) {
|
||||
return render(SettingItem, {
|
||||
global: {
|
||||
plugins: [PrimeVue, i18n, createPinia()],
|
||||
components: {
|
||||
Tag
|
||||
},
|
||||
directives: {
|
||||
tooltip: Tooltip
|
||||
},
|
||||
components: { Tag },
|
||||
stubs: {
|
||||
FormItem: FormItemStub,
|
||||
'i-material-symbols:experiment-outline': true
|
||||
}
|
||||
},
|
||||
directives: { tooltip: Tooltip }
|
||||
},
|
||||
// @ts-expect-error - Test utility accepts flexible props for testing edge cases
|
||||
props,
|
||||
...options
|
||||
props: { setting }
|
||||
})
|
||||
}
|
||||
|
||||
function getFormItemData(container: Element) {
|
||||
// eslint-disable-next-line testing-library/no-node-access
|
||||
const el = container.querySelector('[data-testid="form-item-data"]')
|
||||
return JSON.parse(el!.textContent!)
|
||||
}
|
||||
|
||||
it('translates options that use legacy type', () => {
|
||||
const wrapper = mountComponent({
|
||||
setting: {
|
||||
const { container } = renderComponent(
|
||||
fromAny({
|
||||
id: 'Comfy.NodeInputConversionSubmenus',
|
||||
name: 'Node Input Conversion Submenus',
|
||||
type: 'combo',
|
||||
value: 'Top',
|
||||
defaultValue: 'Top',
|
||||
options: () => ['Correctly Translated']
|
||||
}
|
||||
})
|
||||
})
|
||||
)
|
||||
|
||||
// Check the FormItem component's item prop for the options
|
||||
const formItem = wrapper.findComponent({ name: 'FormItem' })
|
||||
const options = formItem.props('item').options
|
||||
expect(options).toEqual([
|
||||
const data = getFormItemData(container)
|
||||
expect(data.options).toEqual([
|
||||
{ text: 'Correctly Translated', value: 'Correctly Translated' }
|
||||
])
|
||||
})
|
||||
|
||||
it('handles tooltips with @ symbols without errors', () => {
|
||||
const wrapper = mountComponent({
|
||||
setting: {
|
||||
id: 'TestSetting',
|
||||
const { container } = renderComponent(
|
||||
fromAny({
|
||||
id: 'Comfy.NodeInputConversionSubmenus',
|
||||
name: 'Test Setting',
|
||||
type: 'boolean',
|
||||
defaultValue: false,
|
||||
tooltip:
|
||||
'This will load a larger version of @mtb/markdown-parser that bundles shiki'
|
||||
}
|
||||
})
|
||||
})
|
||||
)
|
||||
|
||||
// Should not throw an error and tooltip should be preserved as-is
|
||||
const formItem = wrapper.findComponent({ name: 'FormItem' })
|
||||
expect(formItem.props('item').tooltip).toBe(
|
||||
const data = getFormItemData(container)
|
||||
expect(data.tooltip).toBe(
|
||||
'This will load a larger version of @mtb/markdown-parser that bundles shiki'
|
||||
)
|
||||
})
|
||||
|
||||
@@ -1,40 +1,17 @@
|
||||
import { createTestingPinia } from '@pinia/testing'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import Badge from 'primevue/badge'
|
||||
import Button from '@/components/ui/button/Button.vue'
|
||||
import Column from 'primevue/column'
|
||||
import PrimeVue from 'primevue/config'
|
||||
import DataTable from 'primevue/datatable'
|
||||
import Message from 'primevue/message'
|
||||
import ProgressSpinner from 'primevue/progressspinner'
|
||||
import Tooltip from 'primevue/tooltip'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { nextTick } from 'vue'
|
||||
import { defineComponent, onMounted, ref } from 'vue'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
import { render, screen, waitFor } from '@testing-library/vue'
|
||||
|
||||
import type { AuditLog } from '@/services/customerEventsService'
|
||||
import { EventType } from '@/services/customerEventsService'
|
||||
|
||||
import UsageLogsTable from './UsageLogsTable.vue'
|
||||
|
||||
type ComponentInstance = InstanceType<typeof UsageLogsTable> & {
|
||||
loading: boolean
|
||||
error: string | null
|
||||
events: Partial<AuditLog>[]
|
||||
pagination: {
|
||||
page: number
|
||||
limit: number
|
||||
total: number
|
||||
totalPages: number
|
||||
}
|
||||
dataTableFirst: number
|
||||
tooltipContentMap: Map<string, string>
|
||||
loadEvents: () => Promise<void>
|
||||
refresh: () => Promise<void>
|
||||
onPageChange: (event: { page: number }) => void
|
||||
}
|
||||
|
||||
// Mock the customerEventsService
|
||||
const mockCustomerEventsService = vi.hoisted(() => ({
|
||||
getMyEvents: vi.fn(),
|
||||
formatEventType: vi.fn(),
|
||||
@@ -43,7 +20,7 @@ const mockCustomerEventsService = vi.hoisted(() => ({
|
||||
formatDate: vi.fn(),
|
||||
hasAdditionalInfo: vi.fn(),
|
||||
getTooltipContent: vi.fn(),
|
||||
error: { value: null },
|
||||
error: { value: null as string | null },
|
||||
isLoading: { value: false }
|
||||
}))
|
||||
|
||||
@@ -57,7 +34,10 @@ vi.mock('@/services/customerEventsService', () => ({
|
||||
}
|
||||
}))
|
||||
|
||||
// Create i18n instance
|
||||
vi.mock('@/platform/telemetry', () => ({
|
||||
useTelemetry: () => null
|
||||
}))
|
||||
|
||||
const i18n = createI18n({
|
||||
legacy: false,
|
||||
locale: 'en',
|
||||
@@ -76,78 +56,115 @@ const i18n = createI18n({
|
||||
}
|
||||
})
|
||||
|
||||
describe('UsageLogsTable', () => {
|
||||
const mockEventsResponse = {
|
||||
events: [
|
||||
{
|
||||
event_id: 'event-1',
|
||||
event_type: 'credit_added',
|
||||
params: {
|
||||
amount: 1000,
|
||||
transaction_id: 'txn-123'
|
||||
},
|
||||
createdAt: '2024-01-01T10:00:00Z'
|
||||
},
|
||||
{
|
||||
event_id: 'event-2',
|
||||
event_type: 'api_usage_completed',
|
||||
params: {
|
||||
api_name: 'Image Generation',
|
||||
model: 'sdxl-base',
|
||||
duration: 5000
|
||||
},
|
||||
createdAt: '2024-01-02T10:00:00Z'
|
||||
}
|
||||
],
|
||||
total: 2,
|
||||
const globalConfig = {
|
||||
plugins: [PrimeVue, i18n, createTestingPinia()],
|
||||
directives: { tooltip: Tooltip }
|
||||
}
|
||||
|
||||
/**
|
||||
* The component starts with loading=true and only loads data when refresh()
|
||||
* is called via template ref. This wrapper auto-calls refresh on mount.
|
||||
*/
|
||||
const AutoRefreshWrapper = defineComponent({
|
||||
components: { UsageLogsTable },
|
||||
setup() {
|
||||
const tableRef = ref<InstanceType<typeof UsageLogsTable> | null>(null)
|
||||
onMounted(async () => {
|
||||
await tableRef.value?.refresh()
|
||||
})
|
||||
return { tableRef }
|
||||
},
|
||||
template: '<UsageLogsTable ref="tableRef" />'
|
||||
})
|
||||
|
||||
function makeEventsResponse(
|
||||
events: Partial<AuditLog>[],
|
||||
overrides: Record<string, unknown> = {}
|
||||
) {
|
||||
return {
|
||||
events,
|
||||
total: events.length,
|
||||
page: 1,
|
||||
limit: 7,
|
||||
totalPages: 1
|
||||
totalPages: 1,
|
||||
...overrides
|
||||
}
|
||||
}
|
||||
|
||||
describe('UsageLogsTable', () => {
|
||||
const mockEventsResponse = makeEventsResponse([
|
||||
{
|
||||
event_id: 'event-1',
|
||||
event_type: 'credit_added',
|
||||
params: {
|
||||
amount: 1000,
|
||||
transaction_id: 'txn-123'
|
||||
},
|
||||
createdAt: '2024-01-01T10:00:00Z'
|
||||
},
|
||||
{
|
||||
event_id: 'event-2',
|
||||
event_type: 'api_usage_completed',
|
||||
params: {
|
||||
api_name: 'Image Generation',
|
||||
model: 'sdxl-base',
|
||||
duration: 5000
|
||||
},
|
||||
createdAt: '2024-01-02T10:00:00Z'
|
||||
}
|
||||
])
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
|
||||
// Setup default service mock implementations
|
||||
mockCustomerEventsService.getMyEvents.mockResolvedValue(mockEventsResponse)
|
||||
mockCustomerEventsService.formatEventType.mockImplementation((type) => {
|
||||
switch (type) {
|
||||
case EventType.CREDIT_ADDED:
|
||||
return 'Credits Added'
|
||||
case EventType.ACCOUNT_CREATED:
|
||||
return 'Account Created'
|
||||
case EventType.API_USAGE_COMPLETED:
|
||||
return 'API Usage'
|
||||
default:
|
||||
return type
|
||||
mockCustomerEventsService.formatEventType.mockImplementation(
|
||||
(type: string) => {
|
||||
switch (type) {
|
||||
case EventType.CREDIT_ADDED:
|
||||
return 'Credits Added'
|
||||
case EventType.ACCOUNT_CREATED:
|
||||
return 'Account Created'
|
||||
case EventType.API_USAGE_COMPLETED:
|
||||
return 'API Usage'
|
||||
default:
|
||||
return type
|
||||
}
|
||||
}
|
||||
})
|
||||
mockCustomerEventsService.getEventSeverity.mockImplementation((type) => {
|
||||
switch (type) {
|
||||
case EventType.CREDIT_ADDED:
|
||||
return 'success'
|
||||
case EventType.ACCOUNT_CREATED:
|
||||
return 'info'
|
||||
case EventType.API_USAGE_COMPLETED:
|
||||
return 'warning'
|
||||
default:
|
||||
return 'info'
|
||||
)
|
||||
mockCustomerEventsService.getEventSeverity.mockImplementation(
|
||||
(type: string) => {
|
||||
switch (type) {
|
||||
case EventType.CREDIT_ADDED:
|
||||
return 'success'
|
||||
case EventType.ACCOUNT_CREATED:
|
||||
return 'info'
|
||||
case EventType.API_USAGE_COMPLETED:
|
||||
return 'warning'
|
||||
default:
|
||||
return 'info'
|
||||
}
|
||||
}
|
||||
})
|
||||
mockCustomerEventsService.formatAmount.mockImplementation((amount) => {
|
||||
if (!amount) return '0.00'
|
||||
return (amount / 100).toFixed(2)
|
||||
})
|
||||
mockCustomerEventsService.formatDate.mockImplementation((dateString) => {
|
||||
return new Date(dateString).toLocaleDateString()
|
||||
})
|
||||
mockCustomerEventsService.hasAdditionalInfo.mockImplementation((event) => {
|
||||
const { amount, api_name, model, ...otherParams } = event.params || {}
|
||||
return Object.keys(otherParams).length > 0
|
||||
})
|
||||
mockCustomerEventsService.getTooltipContent.mockImplementation(() => {
|
||||
return '<strong>Transaction Id:</strong> txn-123'
|
||||
})
|
||||
)
|
||||
mockCustomerEventsService.formatAmount.mockImplementation(
|
||||
(amount: number) => {
|
||||
if (!amount) return '0.00'
|
||||
return (amount / 100).toFixed(2)
|
||||
}
|
||||
)
|
||||
mockCustomerEventsService.formatDate.mockImplementation(
|
||||
(dateString: string) => new Date(dateString).toLocaleDateString()
|
||||
)
|
||||
mockCustomerEventsService.hasAdditionalInfo.mockImplementation(
|
||||
(event: AuditLog) => {
|
||||
const { amount, api_name, model, ...otherParams } =
|
||||
(event.params as Record<string, unknown>) ?? {}
|
||||
return Object.keys(otherParams).length > 0
|
||||
}
|
||||
)
|
||||
mockCustomerEventsService.getTooltipContent.mockImplementation(
|
||||
() => '<strong>Transaction Id:</strong> txn-123'
|
||||
)
|
||||
mockCustomerEventsService.error.value = null
|
||||
mockCustomerEventsService.isLoading.value = false
|
||||
})
|
||||
@@ -156,200 +173,146 @@ describe('UsageLogsTable', () => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
const mountComponent = (options = {}) => {
|
||||
return mount(UsageLogsTable, {
|
||||
global: {
|
||||
plugins: [PrimeVue, i18n, createTestingPinia()],
|
||||
components: {
|
||||
DataTable,
|
||||
Column,
|
||||
Badge,
|
||||
Button,
|
||||
Message,
|
||||
ProgressSpinner
|
||||
},
|
||||
directives: {
|
||||
tooltip: Tooltip
|
||||
}
|
||||
},
|
||||
...options
|
||||
function renderComponent() {
|
||||
return render(UsageLogsTable, { global: globalConfig })
|
||||
}
|
||||
|
||||
function renderWithAutoRefresh() {
|
||||
return render(AutoRefreshWrapper, { global: globalConfig })
|
||||
}
|
||||
|
||||
async function renderLoaded() {
|
||||
const result = renderWithAutoRefresh()
|
||||
await waitFor(() => {
|
||||
expect(screen.getByRole('table')).toBeInTheDocument()
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
describe('loading states', () => {
|
||||
it('shows loading spinner when loading is true', async () => {
|
||||
const wrapper = mountComponent()
|
||||
const vm = wrapper.vm as ComponentInstance
|
||||
vm.loading = true
|
||||
await nextTick()
|
||||
it('shows loading spinner before refresh is called', () => {
|
||||
renderComponent()
|
||||
|
||||
expect(wrapper.findComponent(ProgressSpinner).exists()).toBe(true)
|
||||
expect(wrapper.findComponent(DataTable).exists()).toBe(false)
|
||||
expect(screen.getByRole('progressbar')).toBeInTheDocument()
|
||||
expect(screen.queryByRole('table')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows error message when error exists', async () => {
|
||||
const wrapper = mountComponent()
|
||||
const vm = wrapper.vm as ComponentInstance
|
||||
vm.error = 'Failed to load events'
|
||||
vm.loading = false
|
||||
await nextTick()
|
||||
it('shows error message when service returns null', async () => {
|
||||
mockCustomerEventsService.getMyEvents.mockResolvedValue(null)
|
||||
mockCustomerEventsService.error.value = 'Failed to load events'
|
||||
|
||||
const messageComponent = wrapper.findComponent(Message)
|
||||
expect(messageComponent.exists()).toBe(true)
|
||||
expect(messageComponent.props('severity')).toBe('error')
|
||||
expect(messageComponent.text()).toContain('Failed to load events')
|
||||
renderWithAutoRefresh()
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('Failed to load events')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('shows data table when loaded successfully', async () => {
|
||||
const wrapper = mountComponent()
|
||||
it('shows error message when service throws', async () => {
|
||||
mockCustomerEventsService.getMyEvents.mockRejectedValue(
|
||||
new Error('Network error')
|
||||
)
|
||||
|
||||
const vm = wrapper.vm as ComponentInstance
|
||||
// Wait for component to mount and load data
|
||||
await wrapper.vm.$nextTick()
|
||||
await new Promise((resolve) => setTimeout(resolve, 0))
|
||||
renderWithAutoRefresh()
|
||||
|
||||
vm.loading = false
|
||||
vm.events = mockEventsResponse.events
|
||||
await nextTick()
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('Network error')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
expect(wrapper.findComponent(DataTable).exists()).toBe(true)
|
||||
expect(wrapper.findComponent(ProgressSpinner).exists()).toBe(false)
|
||||
expect(wrapper.findComponent(Message).exists()).toBe(false)
|
||||
it('shows data table after loading completes', async () => {
|
||||
await renderLoaded()
|
||||
|
||||
expect(
|
||||
screen.queryByText('Failed to load events')
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('data rendering', () => {
|
||||
it('renders events data correctly', async () => {
|
||||
const wrapper = mountComponent()
|
||||
const vm = wrapper.vm as ComponentInstance
|
||||
vm.loading = false
|
||||
vm.events = mockEventsResponse.events
|
||||
await nextTick()
|
||||
it('renders event type badges', async () => {
|
||||
await renderLoaded()
|
||||
|
||||
const dataTable = wrapper.findComponent(DataTable)
|
||||
expect(dataTable.props('value')).toEqual(mockEventsResponse.events)
|
||||
expect(dataTable.props('rows')).toBe(7)
|
||||
expect(dataTable.props('paginator')).toBe(true)
|
||||
expect(dataTable.props('lazy')).toBe(true)
|
||||
})
|
||||
|
||||
it('renders badge for event types correctly', async () => {
|
||||
const wrapper = mountComponent()
|
||||
const vm = wrapper.vm as ComponentInstance
|
||||
vm.loading = false
|
||||
vm.events = mockEventsResponse.events
|
||||
await nextTick()
|
||||
|
||||
const badges = wrapper.findAllComponents(Badge)
|
||||
expect(badges.length).toBeGreaterThan(0)
|
||||
|
||||
// Check if formatEventType and getEventSeverity are called
|
||||
expect(mockCustomerEventsService.formatEventType).toHaveBeenCalled()
|
||||
expect(mockCustomerEventsService.getEventSeverity).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('renders different event details based on event type', async () => {
|
||||
const wrapper = mountComponent()
|
||||
const vm = wrapper.vm as ComponentInstance
|
||||
vm.loading = false
|
||||
vm.events = mockEventsResponse.events
|
||||
await nextTick()
|
||||
it('renders credit added details with formatted amount', async () => {
|
||||
await renderLoaded()
|
||||
|
||||
// Check if formatAmount is called for credit_added events
|
||||
expect(screen.getByText(/Added \$/)).toBeInTheDocument()
|
||||
expect(mockCustomerEventsService.formatAmount).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('renders tooltip buttons for events with additional info', async () => {
|
||||
it('renders API usage details with api name and model', async () => {
|
||||
await renderLoaded()
|
||||
|
||||
expect(screen.getByText('Image Generation')).toBeInTheDocument()
|
||||
expect(screen.getByText(/sdxl-base/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders account created details', async () => {
|
||||
mockCustomerEventsService.getMyEvents.mockResolvedValue(
|
||||
makeEventsResponse([
|
||||
{
|
||||
event_id: 'event-3',
|
||||
event_type: 'account_created',
|
||||
params: {},
|
||||
createdAt: '2024-01-01T10:00:00Z'
|
||||
}
|
||||
])
|
||||
)
|
||||
|
||||
renderWithAutoRefresh()
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('Account initialized')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('renders formatted dates', async () => {
|
||||
await renderLoaded()
|
||||
|
||||
expect(mockCustomerEventsService.formatDate).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('renders info buttons for events with additional info', async () => {
|
||||
mockCustomerEventsService.hasAdditionalInfo.mockReturnValue(true)
|
||||
|
||||
const wrapper = mountComponent()
|
||||
const vm = wrapper.vm as ComponentInstance
|
||||
vm.loading = false
|
||||
vm.events = mockEventsResponse.events
|
||||
await nextTick()
|
||||
await renderLoaded()
|
||||
|
||||
expect(mockCustomerEventsService.hasAdditionalInfo).toHaveBeenCalled()
|
||||
const infoButtons = screen.getAllByRole('button', {
|
||||
name: 'Additional Info'
|
||||
})
|
||||
expect(infoButtons.length).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
it('does not render info buttons when no additional info', async () => {
|
||||
mockCustomerEventsService.hasAdditionalInfo.mockReturnValue(false)
|
||||
|
||||
await renderLoaded()
|
||||
|
||||
expect(
|
||||
screen.queryByRole('button', { name: 'Additional Info' })
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('pagination', () => {
|
||||
it('handles page change correctly', async () => {
|
||||
const wrapper = mountComponent()
|
||||
const vm = wrapper.vm as ComponentInstance
|
||||
vm.loading = false
|
||||
vm.events = mockEventsResponse.events
|
||||
await nextTick()
|
||||
it('calls getMyEvents with initial page params', async () => {
|
||||
await renderLoaded()
|
||||
|
||||
// Simulate page change
|
||||
const dataTable = wrapper.findComponent(DataTable)
|
||||
await dataTable.vm.$emit('page', { page: 1 })
|
||||
|
||||
expect(vm.pagination.page).toBe(1) // page + 1
|
||||
expect(mockCustomerEventsService.getMyEvents).toHaveBeenCalledWith({
|
||||
page: 2,
|
||||
page: 1,
|
||||
limit: 7
|
||||
})
|
||||
})
|
||||
|
||||
it('calculates dataTableFirst correctly', async () => {
|
||||
const wrapper = mountComponent()
|
||||
const vm = wrapper.vm as ComponentInstance
|
||||
vm.pagination = { page: 2, limit: 7, total: 20, totalPages: 3 }
|
||||
await nextTick()
|
||||
|
||||
expect(vm.dataTableFirst).toBe(7) // (2-1) * 7
|
||||
})
|
||||
})
|
||||
|
||||
describe('tooltip functionality', () => {
|
||||
it('generates tooltip content map correctly', async () => {
|
||||
mockCustomerEventsService.hasAdditionalInfo.mockReturnValue(true)
|
||||
mockCustomerEventsService.getTooltipContent.mockReturnValue(
|
||||
'<strong>Test:</strong> value'
|
||||
)
|
||||
|
||||
const wrapper = mountComponent()
|
||||
const vm = wrapper.vm as ComponentInstance
|
||||
|
||||
vm.loading = false
|
||||
vm.events = mockEventsResponse.events
|
||||
await nextTick()
|
||||
|
||||
const tooltipMap = vm.tooltipContentMap
|
||||
expect(tooltipMap.get('event-1')).toBe('<strong>Test:</strong> value')
|
||||
})
|
||||
|
||||
it('excludes events without additional info from tooltip map', async () => {
|
||||
mockCustomerEventsService.hasAdditionalInfo.mockReturnValue(false)
|
||||
|
||||
const wrapper = mountComponent()
|
||||
const vm = wrapper.vm as ComponentInstance
|
||||
|
||||
vm.loading = false
|
||||
vm.events = mockEventsResponse.events
|
||||
await nextTick()
|
||||
|
||||
const tooltipMap = vm.tooltipContentMap
|
||||
expect(tooltipMap.size).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('component methods', () => {
|
||||
it('exposes refresh method', () => {
|
||||
const wrapper = mountComponent()
|
||||
it('calls getMyEvents on refresh with page 1', async () => {
|
||||
await renderLoaded()
|
||||
|
||||
expect(typeof wrapper.vm.refresh).toBe('function')
|
||||
})
|
||||
|
||||
it('resets to first page on refresh', async () => {
|
||||
const wrapper = mountComponent()
|
||||
const vm = wrapper.vm as ComponentInstance
|
||||
|
||||
vm.pagination.page = 3
|
||||
|
||||
await vm.refresh()
|
||||
|
||||
expect(vm.pagination.page).toBe(1)
|
||||
expect(mockCustomerEventsService.getMyEvents).toHaveBeenCalledWith({
|
||||
page: 1,
|
||||
limit: 7
|
||||
@@ -357,44 +320,41 @@ describe('UsageLogsTable', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('component lifecycle', () => {
|
||||
it('initializes with correct default values', () => {
|
||||
const wrapper = mountComponent()
|
||||
|
||||
const vm = wrapper.vm as ComponentInstance
|
||||
|
||||
expect(vm.events).toEqual([])
|
||||
expect(vm.loading).toBe(true)
|
||||
expect(vm.error).toBeNull()
|
||||
expect(vm.pagination).toEqual({
|
||||
page: 1,
|
||||
limit: 7,
|
||||
total: 0,
|
||||
totalPages: 0
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('EventType integration', () => {
|
||||
it('uses EventType enum in template conditions', async () => {
|
||||
const wrapper = mountComponent()
|
||||
const vm = wrapper.vm as ComponentInstance
|
||||
it('renders credit_added event with correct detail template', async () => {
|
||||
mockCustomerEventsService.getMyEvents.mockResolvedValue(
|
||||
makeEventsResponse([
|
||||
{
|
||||
event_id: 'event-1',
|
||||
event_type: EventType.CREDIT_ADDED,
|
||||
params: { amount: 1000 },
|
||||
createdAt: '2024-01-01T10:00:00Z'
|
||||
}
|
||||
])
|
||||
)
|
||||
|
||||
vm.loading = false
|
||||
vm.events = [
|
||||
{
|
||||
event_id: 'event-1',
|
||||
event_type: EventType.CREDIT_ADDED,
|
||||
params: { amount: 1000 },
|
||||
createdAt: '2024-01-01T10:00:00Z'
|
||||
}
|
||||
]
|
||||
await nextTick()
|
||||
await renderLoaded()
|
||||
|
||||
// Verify that the component can access EventType enum
|
||||
expect(EventType.CREDIT_ADDED).toBe('credit_added')
|
||||
expect(EventType.ACCOUNT_CREATED).toBe('account_created')
|
||||
expect(EventType.API_USAGE_COMPLETED).toBe('api_usage_completed')
|
||||
expect(screen.getByText(/Added \$/)).toBeInTheDocument()
|
||||
expect(mockCustomerEventsService.formatAmount).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('renders api_usage_completed event with correct detail template', async () => {
|
||||
mockCustomerEventsService.getMyEvents.mockResolvedValue(
|
||||
makeEventsResponse([
|
||||
{
|
||||
event_id: 'event-2',
|
||||
event_type: EventType.API_USAGE_COMPLETED,
|
||||
params: { api_name: 'Test API', model: 'test-model' },
|
||||
createdAt: '2024-01-02T10:00:00Z'
|
||||
}
|
||||
])
|
||||
)
|
||||
|
||||
await renderLoaded()
|
||||
|
||||
expect(screen.getByText('Test API')).toBeInTheDocument()
|
||||
expect(screen.getByText(/test-model/)).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
import type { ComponentProps } from 'vue-component-type-helpers'
|
||||
|
||||
import { Form } from '@primevue/forms'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { createPinia } from 'pinia'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import Button from '@/components/ui/button/Button.vue'
|
||||
import PrimeVue from 'primevue/config'
|
||||
import InputText from 'primevue/inputtext'
|
||||
import Message from 'primevue/message'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { createApp } from 'vue'
|
||||
import { ref } from 'vue'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
import { getComfyPlatformBaseUrl } from '@/config/comfyApi'
|
||||
@@ -16,11 +14,13 @@ import { getComfyPlatformBaseUrl } from '@/config/comfyApi'
|
||||
import ApiKeyForm from './ApiKeyForm.vue'
|
||||
|
||||
const mockStoreApiKey = vi.fn()
|
||||
const mockLoading = vi.fn(() => false)
|
||||
const mockLoadingRef = ref(false)
|
||||
|
||||
vi.mock('@/stores/authStore', () => ({
|
||||
useAuthStore: vi.fn(() => ({
|
||||
loading: mockLoading()
|
||||
get loading() {
|
||||
return mockLoadingRef.value
|
||||
}
|
||||
}))
|
||||
}))
|
||||
|
||||
@@ -58,62 +58,57 @@ const i18n = createI18n({
|
||||
|
||||
describe('ApiKeyForm', () => {
|
||||
beforeEach(() => {
|
||||
const app = createApp({})
|
||||
app.use(PrimeVue)
|
||||
vi.clearAllMocks()
|
||||
mockStoreApiKey.mockReset()
|
||||
mockLoading.mockReset()
|
||||
mockLoadingRef.value = false
|
||||
})
|
||||
|
||||
const mountComponent = (props: ComponentProps<typeof ApiKeyForm> = {}) => {
|
||||
return mount(ApiKeyForm, {
|
||||
function renderComponent(props: Record<string, unknown> = {}) {
|
||||
const user = userEvent.setup()
|
||||
const result = render(ApiKeyForm, {
|
||||
global: {
|
||||
plugins: [PrimeVue, createPinia(), i18n],
|
||||
plugins: [PrimeVue, i18n],
|
||||
components: { Button, Form, InputText, Message }
|
||||
},
|
||||
props
|
||||
})
|
||||
return { ...result, user }
|
||||
}
|
||||
|
||||
it('renders correctly with all required elements', () => {
|
||||
const wrapper = mountComponent()
|
||||
renderComponent()
|
||||
|
||||
expect(wrapper.find('h1').text()).toBe('API Key')
|
||||
expect(wrapper.find('label').text()).toBe('API Key')
|
||||
expect(wrapper.findComponent(InputText).exists()).toBe(true)
|
||||
expect(wrapper.findComponent(Button).exists()).toBe(true)
|
||||
expect(screen.getByRole('heading', { name: 'API Key' })).toBeInTheDocument()
|
||||
expect(screen.getByLabelText('API Key')).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Save' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('emits back event when back button is clicked', async () => {
|
||||
const wrapper = mountComponent()
|
||||
const onBack = vi.fn()
|
||||
const { user } = renderComponent({ onBack })
|
||||
|
||||
await wrapper.findComponent(Button).trigger('click')
|
||||
expect(wrapper.emitted('back')).toBeTruthy()
|
||||
await user.click(screen.getByRole('button', { name: 'Back' }))
|
||||
|
||||
expect(onBack).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('shows loading state when submitting', async () => {
|
||||
mockLoading.mockReturnValue(true)
|
||||
const wrapper = mountComponent()
|
||||
const input = wrapper.findComponent(InputText)
|
||||
it('shows loading state when submitting', () => {
|
||||
mockLoadingRef.value = true
|
||||
const { container } = renderComponent()
|
||||
|
||||
await input.setValue(
|
||||
'comfyui-123456789012345678901234567890123456789012345678901234567890123456789012'
|
||||
)
|
||||
await wrapper.find('form').trigger('submit')
|
||||
|
||||
const buttons = wrapper.findAllComponents(Button)
|
||||
const submitButton = buttons.find(
|
||||
(btn) => btn.attributes('type') === 'submit'
|
||||
)
|
||||
expect(submitButton?.props('loading')).toBe(true)
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
const submitButton = container.querySelector('button[type="submit"]')
|
||||
expect(submitButton).toBeDisabled()
|
||||
})
|
||||
|
||||
it('displays help text and links correctly', () => {
|
||||
const wrapper = mountComponent()
|
||||
renderComponent()
|
||||
|
||||
const helpText = wrapper.find('small')
|
||||
expect(helpText.text()).toContain('Need an API key?')
|
||||
expect(helpText.find('a').attributes('href')).toBe(
|
||||
expect(
|
||||
screen.getByText('Need an API key?', { exact: false })
|
||||
).toBeInTheDocument()
|
||||
expect(screen.getByRole('link', { name: 'Get one here' })).toHaveAttribute(
|
||||
'href',
|
||||
`${getComfyPlatformBaseUrl()}/login`
|
||||
)
|
||||
})
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import GradientSlider from './GradientSlider.vue'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
|
||||
import type { ColorStop } from '@/lib/litegraph/src/interfaces'
|
||||
|
||||
import GradientSlider from './GradientSlider.vue'
|
||||
import { interpolateStops, stopsToGradient } from './gradients'
|
||||
|
||||
const TEST_STOPS: ColorStop[] = [
|
||||
@@ -10,40 +12,44 @@ const TEST_STOPS: ColorStop[] = [
|
||||
{ offset: 1, color: [255, 255, 255] }
|
||||
]
|
||||
|
||||
function mountSlider(props: {
|
||||
function renderSlider(props: {
|
||||
stops?: ColorStop[]
|
||||
modelValue: number
|
||||
min?: number
|
||||
max?: number
|
||||
step?: number
|
||||
}) {
|
||||
return mount(GradientSlider, {
|
||||
return render(GradientSlider, {
|
||||
props: { stops: TEST_STOPS, ...props }
|
||||
})
|
||||
}
|
||||
|
||||
describe('GradientSlider', () => {
|
||||
it('passes min, max, step to SliderRoot', () => {
|
||||
const wrapper = mountSlider({
|
||||
it('passes min and max to SliderRoot', () => {
|
||||
renderSlider({
|
||||
modelValue: 50,
|
||||
min: -100,
|
||||
max: 100,
|
||||
step: 5
|
||||
})
|
||||
const thumb = wrapper.find('[role="slider"]')
|
||||
expect(thumb.attributes('aria-valuemin')).toBe('-100')
|
||||
expect(thumb.attributes('aria-valuemax')).toBe('100')
|
||||
const thumb = screen.getByRole('slider', { hidden: true })
|
||||
expect(thumb).toBeInTheDocument()
|
||||
expect(thumb).toHaveAttribute('aria-valuemin', '-100')
|
||||
expect(thumb).toHaveAttribute('aria-valuemax', '100')
|
||||
})
|
||||
|
||||
it('renders slider root with track and thumb', () => {
|
||||
const wrapper = mountSlider({ modelValue: 0 })
|
||||
expect(wrapper.find('[data-slider-impl]').exists()).toBe(true)
|
||||
expect(wrapper.find('[role="slider"]').exists()).toBe(true)
|
||||
const { container } = renderSlider({ modelValue: 0 })
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
expect(container.querySelector('[data-slider-impl]')).toBeInTheDocument()
|
||||
expect(screen.getByRole('slider', { hidden: true })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('does not render SliderRange', () => {
|
||||
const wrapper = mountSlider({ modelValue: 50 })
|
||||
expect(wrapper.find('[data-slot="slider-range"]').exists()).toBe(false)
|
||||
const { container } = renderSlider({ modelValue: 50 })
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
const range = container.querySelector('[data-slot="slider-range"]')
|
||||
expect(range).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
import CanvasModeSelector from '@/components/graph/CanvasModeSelector.vue'
|
||||
@@ -44,8 +45,9 @@ const i18n = createI18n({
|
||||
|
||||
const mockPopoverHide = vi.fn()
|
||||
|
||||
function createWrapper() {
|
||||
return mount(CanvasModeSelector, {
|
||||
function renderComponent() {
|
||||
const user = userEvent.setup()
|
||||
render(CanvasModeSelector, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
stubs: {
|
||||
@@ -59,94 +61,98 @@ function createWrapper() {
|
||||
}
|
||||
}
|
||||
})
|
||||
return { user }
|
||||
}
|
||||
|
||||
describe('CanvasModeSelector', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('should render menu with menuitemradio roles and aria-checked', () => {
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
|
||||
const menu = wrapper.find('[role="menu"]')
|
||||
expect(menu.exists()).toBe(true)
|
||||
expect(screen.getByRole('menu')).toBeInTheDocument()
|
||||
|
||||
const menuItems = wrapper.findAll('[role="menuitemradio"]')
|
||||
const menuItems = screen.getAllByRole('menuitemradio')
|
||||
expect(menuItems).toHaveLength(2)
|
||||
|
||||
// Select mode is active (read_only: false), so select is checked
|
||||
expect(menuItems[0].attributes('aria-checked')).toBe('true')
|
||||
expect(menuItems[1].attributes('aria-checked')).toBe('false')
|
||||
expect(menuItems[0]).toHaveAttribute('aria-checked', 'true')
|
||||
expect(menuItems[1]).toHaveAttribute('aria-checked', 'false')
|
||||
})
|
||||
|
||||
it('should render menu items as buttons with aria-labels', () => {
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
|
||||
const menuItems = wrapper.findAll('[role="menuitemradio"]')
|
||||
menuItems.forEach((btn) => {
|
||||
expect(btn.element.tagName).toBe('BUTTON')
|
||||
expect(btn.attributes('type')).toBe('button')
|
||||
const menuItems = screen.getAllByRole('menuitemradio')
|
||||
menuItems.forEach((item) => {
|
||||
expect(item.tagName).toBe('BUTTON')
|
||||
expect(item).toHaveAttribute('type', 'button')
|
||||
})
|
||||
expect(menuItems[0].attributes('aria-label')).toBe('Select')
|
||||
expect(menuItems[1].attributes('aria-label')).toBe('Hand')
|
||||
expect(menuItems[0]).toHaveAttribute('aria-label', 'Select')
|
||||
expect(menuItems[1]).toHaveAttribute('aria-label', 'Hand')
|
||||
})
|
||||
|
||||
it('should use roving tabindex based on active mode', () => {
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
|
||||
const menuItems = wrapper.findAll('[role="menuitemradio"]')
|
||||
// Select is active (read_only: false) → tabindex 0
|
||||
expect(menuItems[0].attributes('tabindex')).toBe('0')
|
||||
// Hand is inactive → tabindex -1
|
||||
expect(menuItems[1].attributes('tabindex')).toBe('-1')
|
||||
const menuItems = screen.getAllByRole('menuitemradio')
|
||||
expect(menuItems[0]).toHaveAttribute('tabindex', '0')
|
||||
expect(menuItems[1]).toHaveAttribute('tabindex', '-1')
|
||||
})
|
||||
|
||||
it('should mark icons as aria-hidden', () => {
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
|
||||
const icons = wrapper.findAll('[role="menuitemradio"] i')
|
||||
icons.forEach((icon) => {
|
||||
expect(icon.attributes('aria-hidden')).toBe('true')
|
||||
const menuItems = screen.getAllByRole('menuitemradio')
|
||||
menuItems.forEach((item) => {
|
||||
// eslint-disable-next-line testing-library/no-node-access
|
||||
const icons = item.querySelectorAll('i')
|
||||
icons.forEach((icon) => {
|
||||
expect(icon).toHaveAttribute('aria-hidden', 'true')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('should expose trigger button with aria-haspopup and aria-expanded', () => {
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
|
||||
const trigger = wrapper.find('[aria-haspopup="menu"]')
|
||||
expect(trigger.exists()).toBe(true)
|
||||
expect(trigger.attributes('aria-label')).toBe('Canvas Mode')
|
||||
expect(trigger.attributes('aria-expanded')).toBe('false')
|
||||
const trigger = screen.getByRole('button', { name: 'Canvas Mode' })
|
||||
expect(trigger).toHaveAttribute('aria-haspopup', 'menu')
|
||||
expect(trigger).toHaveAttribute('aria-expanded', 'false')
|
||||
})
|
||||
|
||||
it('should call focus on next item when ArrowDown is pressed', async () => {
|
||||
const wrapper = createWrapper()
|
||||
const { user } = renderComponent()
|
||||
|
||||
const menuItems = wrapper.findAll('[role="menuitemradio"]')
|
||||
const secondItemEl = menuItems[1].element as HTMLElement
|
||||
const focusSpy = vi.spyOn(secondItemEl, 'focus')
|
||||
const menuItems = screen.getAllByRole('menuitemradio')
|
||||
const focusSpy = vi.spyOn(menuItems[1], 'focus')
|
||||
|
||||
await menuItems[0].trigger('keydown', { key: 'ArrowDown' })
|
||||
menuItems[0].focus()
|
||||
await user.keyboard('{ArrowDown}')
|
||||
expect(focusSpy).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should call focus on previous item when ArrowUp is pressed', async () => {
|
||||
const wrapper = createWrapper()
|
||||
const { user } = renderComponent()
|
||||
|
||||
const menuItems = wrapper.findAll('[role="menuitemradio"]')
|
||||
const firstItemEl = menuItems[0].element as HTMLElement
|
||||
const focusSpy = vi.spyOn(firstItemEl, 'focus')
|
||||
const menuItems = screen.getAllByRole('menuitemradio')
|
||||
const focusSpy = vi.spyOn(menuItems[0], 'focus')
|
||||
|
||||
await menuItems[1].trigger('keydown', { key: 'ArrowUp' })
|
||||
menuItems[1].focus()
|
||||
await user.keyboard('{ArrowUp}')
|
||||
expect(focusSpy).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should close popover on Escape and restore focus to trigger', async () => {
|
||||
const wrapper = createWrapper()
|
||||
const { user } = renderComponent()
|
||||
|
||||
const menuItems = wrapper.findAll('[role="menuitemradio"]')
|
||||
const trigger = wrapper.find('[aria-haspopup="menu"]')
|
||||
const triggerEl = trigger.element as HTMLElement
|
||||
const focusSpy = vi.spyOn(triggerEl, 'focus')
|
||||
const menuItems = screen.getAllByRole('menuitemradio')
|
||||
const trigger = screen.getByRole('button', { name: 'Canvas Mode' })
|
||||
const focusSpy = vi.spyOn(trigger, 'focus')
|
||||
|
||||
await menuItems[0].trigger('keydown', { key: 'Escape' })
|
||||
menuItems[0].focus()
|
||||
await user.keyboard('{Escape}')
|
||||
expect(mockPopoverHide).toHaveBeenCalled()
|
||||
expect(focusSpy).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { createTestingPinia } from '@pinia/testing'
|
||||
import { fromPartial } from '@total-typescript/shoehorn'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render } from '@testing-library/vue'
|
||||
import { setActivePinia } from 'pinia'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
@@ -89,7 +89,7 @@ describe('DomWidgets transition grace characterization', () => {
|
||||
const canvas = createCanvas(graphA)
|
||||
canvasStore.canvas = canvas
|
||||
|
||||
mount(DomWidgets, {
|
||||
render(DomWidgets, {
|
||||
global: {
|
||||
stubs: {
|
||||
DomWidget: true
|
||||
@@ -134,7 +134,7 @@ describe('DomWidgets transition grace characterization', () => {
|
||||
const canvas = createCanvas(graphB)
|
||||
canvasStore.canvas = canvas
|
||||
|
||||
mount(DomWidgets, {
|
||||
render(DomWidgets, {
|
||||
global: {
|
||||
stubs: {
|
||||
DomWidget: true
|
||||
@@ -160,7 +160,7 @@ describe('DomWidgets transition grace characterization', () => {
|
||||
const canvas = createCanvas(graphA)
|
||||
canvasStore.canvas = canvas
|
||||
|
||||
mount(DomWidgets, {
|
||||
render(DomWidgets, {
|
||||
global: {
|
||||
stubs: {
|
||||
DomWidget: true
|
||||
|
||||
@@ -1,19 +1,37 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
import ZoomControlsModal from '@/components/graph/modals/ZoomControlsModal.vue'
|
||||
|
||||
// Mock functions
|
||||
const mockExecute = vi.fn()
|
||||
const mockGetCommand = vi.fn().mockReturnValue({
|
||||
const mockGetCommand = vi.fn().mockImplementation((commandId: string) => ({
|
||||
keybinding: {
|
||||
combo: {
|
||||
getKeySequences: () => ['Ctrl', '+']
|
||||
getKeySequences: () => [
|
||||
'Ctrl',
|
||||
commandId === 'Comfy.Canvas.ZoomIn'
|
||||
? '+'
|
||||
: commandId === 'Comfy.Canvas.ZoomOut'
|
||||
? '-'
|
||||
: '0'
|
||||
]
|
||||
}
|
||||
}
|
||||
})
|
||||
const mockFormatKeySequence = vi.fn().mockReturnValue('Ctrl+')
|
||||
}))
|
||||
const mockFormatKeySequence = vi
|
||||
.fn()
|
||||
.mockImplementation(
|
||||
(command: {
|
||||
keybinding: { combo: { getKeySequences: () => string[] } }
|
||||
}) => {
|
||||
const seq = command.keybinding.combo.getKeySequences()
|
||||
if (seq.includes('+')) return 'Ctrl+'
|
||||
if (seq.includes('-')) return 'Ctrl-'
|
||||
return 'Ctrl+0'
|
||||
}
|
||||
)
|
||||
const mockSetAppZoom = vi.fn()
|
||||
const mockSettingGet = vi.fn().mockReturnValue(true)
|
||||
|
||||
@@ -23,11 +41,11 @@ const i18n = createI18n({
|
||||
messages: { en: {} }
|
||||
})
|
||||
|
||||
// Mock dependencies
|
||||
|
||||
vi.mock('@/renderer/extensions/minimap/composables/useMinimap', () => ({
|
||||
useMinimap: () => ({
|
||||
containerStyles: { value: { backgroundColor: '#fff', borderRadius: '8px' } }
|
||||
containerStyles: {
|
||||
value: { backgroundColor: '#fff', borderRadius: '8px' }
|
||||
}
|
||||
})
|
||||
}))
|
||||
|
||||
@@ -52,8 +70,8 @@ vi.mock('@/platform/settings/settingStore', () => ({
|
||||
})
|
||||
}))
|
||||
|
||||
const createWrapper = (props = {}) => {
|
||||
return mount(ZoomControlsModal, {
|
||||
function renderComponent(props = {}) {
|
||||
return render(ZoomControlsModal, {
|
||||
props: {
|
||||
visible: true,
|
||||
...props
|
||||
@@ -70,90 +88,89 @@ const createWrapper = (props = {}) => {
|
||||
|
||||
describe('ZoomControlsModal', () => {
|
||||
beforeEach(() => {
|
||||
vi.resetAllMocks()
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('should execute zoom in command when zoom in button is clicked', async () => {
|
||||
const wrapper = createWrapper()
|
||||
const user = userEvent.setup()
|
||||
renderComponent()
|
||||
|
||||
const buttons = wrapper.findAll('.cursor-pointer')
|
||||
const zoomInButton = buttons.find((btn) =>
|
||||
btn.text().includes('graphCanvasMenu.zoomIn')
|
||||
)
|
||||
|
||||
expect(zoomInButton).toBeDefined()
|
||||
await zoomInButton!.trigger('mousedown')
|
||||
const zoomInButton = screen.getByTestId('zoom-in-action')
|
||||
await user.click(zoomInButton)
|
||||
|
||||
expect(mockExecute).toHaveBeenCalledWith('Comfy.Canvas.ZoomIn')
|
||||
})
|
||||
|
||||
it('should execute zoom out command when zoom out button is clicked', async () => {
|
||||
const wrapper = createWrapper()
|
||||
const user = userEvent.setup()
|
||||
renderComponent()
|
||||
|
||||
const buttons = wrapper.findAll('.cursor-pointer')
|
||||
const zoomOutButton = buttons.find((btn) =>
|
||||
btn.text().includes('graphCanvasMenu.zoomOut')
|
||||
)
|
||||
|
||||
expect(zoomOutButton).toBeDefined()
|
||||
await zoomOutButton!.trigger('mousedown')
|
||||
const zoomOutButton = screen.getByTestId('zoom-out-action')
|
||||
await user.click(zoomOutButton)
|
||||
|
||||
expect(mockExecute).toHaveBeenCalledWith('Comfy.Canvas.ZoomOut')
|
||||
})
|
||||
|
||||
it('should execute fit view command when fit view button is clicked', async () => {
|
||||
const wrapper = createWrapper()
|
||||
const user = userEvent.setup()
|
||||
renderComponent()
|
||||
|
||||
const buttons = wrapper.findAll('.cursor-pointer')
|
||||
const fitViewButton = buttons.find((btn) =>
|
||||
btn.text().includes('zoomControls.zoomToFit')
|
||||
)
|
||||
|
||||
expect(fitViewButton).toBeDefined()
|
||||
await fitViewButton!.trigger('click')
|
||||
const fitViewButton = screen.getByTestId('zoom-to-fit-action')
|
||||
await user.click(fitViewButton)
|
||||
|
||||
expect(mockExecute).toHaveBeenCalledWith('Comfy.Canvas.FitView')
|
||||
})
|
||||
|
||||
it('should call setAppZoomFromPercentage with valid zoom input values', async () => {
|
||||
const wrapper = createWrapper()
|
||||
const user = userEvent.setup()
|
||||
renderComponent()
|
||||
|
||||
const inputNumber = wrapper.findComponent({ name: 'InputNumber' })
|
||||
expect(inputNumber.exists()).toBe(true)
|
||||
|
||||
// Emit the input event with PrimeVue's InputNumberInputEvent structure
|
||||
await inputNumber.vm.$emit('input', { value: 150 })
|
||||
const input = screen.getByRole('spinbutton')
|
||||
await user.tripleClick(input)
|
||||
await user.keyboard('150')
|
||||
|
||||
expect(mockSetAppZoom).toHaveBeenCalledWith(150)
|
||||
})
|
||||
|
||||
it('should not call setAppZoomFromPercentage with invalid zoom input values', async () => {
|
||||
const wrapper = createWrapper()
|
||||
it('should not call setAppZoomFromPercentage when value is below minimum', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderComponent()
|
||||
|
||||
const inputNumber = wrapper.findComponent({ name: 'InputNumber' })
|
||||
expect(inputNumber.exists()).toBe(true)
|
||||
const input = screen.getByRole('spinbutton')
|
||||
await user.tripleClick(input)
|
||||
await user.keyboard('0')
|
||||
|
||||
// Test out of range values
|
||||
await inputNumber.vm.$emit('input', { value: 0 })
|
||||
expect(mockSetAppZoom).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should not apply zoom values exceeding the maximum', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderComponent()
|
||||
|
||||
const input = screen.getByRole('spinbutton')
|
||||
await user.tripleClick(input)
|
||||
await user.keyboard('100')
|
||||
mockSetAppZoom.mockClear()
|
||||
|
||||
await user.keyboard('1')
|
||||
|
||||
await inputNumber.vm.$emit('input', { value: 1001 })
|
||||
expect(mockSetAppZoom).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should display keyboard shortcuts for commands', () => {
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
|
||||
const buttons = wrapper.findAll('.cursor-pointer')
|
||||
expect(buttons.length).toBeGreaterThan(0)
|
||||
|
||||
// Each command button should show the keyboard shortcut
|
||||
expect(mockFormatKeySequence).toHaveBeenCalled()
|
||||
expect(screen.getByText('Ctrl+')).toBeInTheDocument()
|
||||
expect(screen.getByText('Ctrl-')).toBeInTheDocument()
|
||||
expect(screen.getByText('Ctrl+0')).toBeInTheDocument()
|
||||
expect(mockGetCommand).toHaveBeenCalledWith('Comfy.Canvas.ZoomIn')
|
||||
expect(mockGetCommand).toHaveBeenCalledWith('Comfy.Canvas.ZoomOut')
|
||||
expect(mockGetCommand).toHaveBeenCalledWith('Comfy.Canvas.FitView')
|
||||
})
|
||||
|
||||
it('should not be visible when visible prop is false', () => {
|
||||
const wrapper = createWrapper({ visible: false })
|
||||
renderComponent({ visible: false })
|
||||
|
||||
expect(wrapper.find('.absolute').exists()).toBe(false)
|
||||
expect(screen.queryByTestId('zoom-in-action')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { Mock } from 'vitest'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { createPinia, setActivePinia } from 'pinia'
|
||||
import PrimeVue from 'primevue/config'
|
||||
import Tooltip from 'primevue/tooltip'
|
||||
@@ -105,8 +106,10 @@ describe('ColorPickerButton', () => {
|
||||
workflowStore.activeWorkflow = createMockWorkflow()
|
||||
})
|
||||
|
||||
const createWrapper = () => {
|
||||
return mount(ColorPickerButton, {
|
||||
function renderComponent() {
|
||||
const user = userEvent.setup()
|
||||
|
||||
render(ColorPickerButton, {
|
||||
global: {
|
||||
plugins: [PrimeVue, i18n],
|
||||
directives: {
|
||||
@@ -114,28 +117,30 @@ describe('ColorPickerButton', () => {
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return { user }
|
||||
}
|
||||
|
||||
it('should render when nodes are selected', () => {
|
||||
// Add a mock node to selectedItems
|
||||
canvasStore.selectedItems = [createMockPositionable()]
|
||||
const wrapper = createWrapper()
|
||||
expect(wrapper.find('button').exists()).toBe(true)
|
||||
renderComponent()
|
||||
expect(screen.getByTestId('color-picker-button')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should toggle color picker visibility on button click', async () => {
|
||||
canvasStore.selectedItems = [createMockPositionable()]
|
||||
const wrapper = createWrapper()
|
||||
const button = wrapper.find('button')
|
||||
const { user } = renderComponent()
|
||||
const button = screen.getByTestId('color-picker-button')
|
||||
|
||||
expect(wrapper.findComponent({ name: 'SelectButton' }).exists()).toBe(false)
|
||||
expect(screen.queryByTestId('noColor')).not.toBeInTheDocument()
|
||||
|
||||
await button.trigger('click')
|
||||
const picker = wrapper.findComponent({ name: 'SelectButton' })
|
||||
expect(picker.exists()).toBe(true)
|
||||
expect(picker.findAll('button').length).toBeGreaterThan(0)
|
||||
await user.click(button)
|
||||
expect(screen.getByTestId('noColor')).toBeInTheDocument()
|
||||
expect(screen.getByTestId('red')).toBeInTheDocument()
|
||||
expect(screen.getByTestId('green')).toBeInTheDocument()
|
||||
expect(screen.getByTestId('blue')).toBeInTheDocument()
|
||||
|
||||
await button.trigger('click')
|
||||
expect(wrapper.findComponent({ name: 'SelectButton' }).exists()).toBe(false)
|
||||
await user.click(button)
|
||||
expect(screen.queryByTestId('noColor')).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { createTestingPinia } from '@pinia/testing'
|
||||
import { setActivePinia } from 'pinia'
|
||||
import PrimeVue from 'primevue/config'
|
||||
@@ -12,7 +13,6 @@ import type { LGraphCanvas, LGraphNode } from '@/lib/litegraph/src/litegraph'
|
||||
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
|
||||
import { useCommandStore } from '@/stores/commandStore'
|
||||
|
||||
// Mock the utils
|
||||
vi.mock('@/utils/litegraphUtil', () => ({
|
||||
isLGraphNode: vi.fn((node) => !!node?.type)
|
||||
}))
|
||||
@@ -21,7 +21,6 @@ vi.mock('@/utils/nodeFilterUtil', () => ({
|
||||
isOutputNode: vi.fn((node) => !!node?.constructor?.nodeData?.output_node)
|
||||
}))
|
||||
|
||||
// Mock the composables
|
||||
vi.mock('@/composables/graph/useSelectionState', () => ({
|
||||
useSelectionState: vi.fn(() => ({
|
||||
selectedNodes: {
|
||||
@@ -49,14 +48,12 @@ describe('ExecuteButton', () => {
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
// Set up Pinia with testing utilities
|
||||
setActivePinia(
|
||||
createTestingPinia({
|
||||
createSpy: vi.fn
|
||||
})
|
||||
)
|
||||
|
||||
// Reset mocks
|
||||
const partialCanvas: Partial<LGraphCanvas> = {
|
||||
setDirty: vi.fn()
|
||||
}
|
||||
@@ -64,14 +61,12 @@ describe('ExecuteButton', () => {
|
||||
|
||||
mockSelectedNodes = []
|
||||
|
||||
// Get store instances and mock methods
|
||||
const canvasStore = useCanvasStore()
|
||||
const commandStore = useCommandStore()
|
||||
|
||||
vi.spyOn(canvasStore, 'getCanvas').mockReturnValue(mockCanvas)
|
||||
vi.spyOn(commandStore, 'execute').mockResolvedValue()
|
||||
|
||||
// Update the useSelectionState mock
|
||||
vi.mocked(useSelectionState).mockReturnValue({
|
||||
selectedNodes: {
|
||||
value: mockSelectedNodes
|
||||
@@ -81,33 +76,33 @@ describe('ExecuteButton', () => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
const mountComponent = () => {
|
||||
return mount(ExecuteButton, {
|
||||
const renderComponent = () => {
|
||||
return render(ExecuteButton, {
|
||||
global: {
|
||||
plugins: [i18n, PrimeVue],
|
||||
directives: { tooltip: Tooltip },
|
||||
stubs: {
|
||||
'i-lucide:play': { template: '<div class="play-icon" />' }
|
||||
}
|
||||
directives: { tooltip: Tooltip }
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
describe('Rendering', () => {
|
||||
it('should be able to render', () => {
|
||||
const wrapper = mountComponent()
|
||||
const button = wrapper.find('button')
|
||||
expect(button.exists()).toBe(true)
|
||||
renderComponent()
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Execute selected nodes' })
|
||||
).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Click Handler', () => {
|
||||
it('should execute Comfy.QueueSelectedOutputNodes command on click', async () => {
|
||||
const commandStore = useCommandStore()
|
||||
const wrapper = mountComponent()
|
||||
const button = wrapper.find('button')
|
||||
const user = userEvent.setup()
|
||||
renderComponent()
|
||||
|
||||
await button.trigger('click')
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Execute selected nodes' })
|
||||
)
|
||||
|
||||
expect(commandStore.execute).toHaveBeenCalledWith(
|
||||
'Comfy.QueueSelectedOutputNodes'
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { createPinia, setActivePinia } from 'pinia'
|
||||
import PrimeVue from 'primevue/config'
|
||||
import Tooltip from 'primevue/tooltip'
|
||||
@@ -18,6 +19,12 @@ vi.mock('@/stores/workspace/rightSidePanelStore', () => ({
|
||||
})
|
||||
}))
|
||||
|
||||
vi.mock('@/platform/telemetry', () => ({
|
||||
useTelemetry: () => ({
|
||||
trackUiButtonClicked: vi.fn()
|
||||
})
|
||||
}))
|
||||
|
||||
describe('InfoButton', () => {
|
||||
const i18n = createI18n({
|
||||
legacy: false,
|
||||
@@ -36,8 +43,8 @@ describe('InfoButton', () => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
const mountComponent = () => {
|
||||
return mount(InfoButton, {
|
||||
const renderComponent = () => {
|
||||
return render(InfoButton, {
|
||||
global: {
|
||||
plugins: [i18n, PrimeVue],
|
||||
directives: { tooltip: Tooltip },
|
||||
@@ -47,9 +54,11 @@ describe('InfoButton', () => {
|
||||
}
|
||||
|
||||
it('should open the info panel on click', async () => {
|
||||
const wrapper = mountComponent()
|
||||
const button = wrapper.find('[data-testid="info-button"]')
|
||||
await button.trigger('click')
|
||||
const user = userEvent.setup()
|
||||
renderComponent()
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Node Info' }))
|
||||
|
||||
expect(openPanelMock).toHaveBeenCalledWith('info')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { createTestingPinia } from '@pinia/testing'
|
||||
import { render } from '@testing-library/vue'
|
||||
import { fromPartial } from '@total-typescript/shoehorn'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { setActivePinia } from 'pinia'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { reactive } from 'vue'
|
||||
import { nextTick, reactive } from 'vue'
|
||||
|
||||
import type { BaseDOMWidget } from '@/scripts/domWidget'
|
||||
import type { DomWidgetState } from '@/stores/domWidgetStore'
|
||||
@@ -100,16 +100,17 @@ describe('DomWidget disabled style', () => {
|
||||
|
||||
it('uses disabled style when promoted override widget is computedDisabled', async () => {
|
||||
const widgetState = createWidgetState(true)
|
||||
const wrapper = mount(DomWidget, {
|
||||
const { container } = render(DomWidget, {
|
||||
props: {
|
||||
widgetState
|
||||
}
|
||||
})
|
||||
|
||||
widgetState.zIndex = 3
|
||||
await wrapper.vm.$nextTick()
|
||||
await nextTick()
|
||||
|
||||
const root = wrapper.get('.dom-widget').element as HTMLElement
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
const root = container.querySelector('.dom-widget') as HTMLElement
|
||||
expect(root.style.pointerEvents).toBe('none')
|
||||
expect(root.style.opacity).toBe('0.5')
|
||||
})
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { VueWrapper } from '@vue/test-utils'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { defineComponent, h, nextTick, ref } from 'vue'
|
||||
|
||||
@@ -11,10 +11,11 @@ describe('HoneyToast', () => {
|
||||
document.body.innerHTML = ''
|
||||
})
|
||||
|
||||
function mountComponent(
|
||||
function renderComponent(
|
||||
props: { visible: boolean; expanded?: boolean } = { visible: true }
|
||||
): VueWrapper {
|
||||
return mount(HoneyToast, {
|
||||
) {
|
||||
const user = userEvent.setup()
|
||||
const { unmount } = render(HoneyToast, {
|
||||
props,
|
||||
slots: {
|
||||
default: (slotProps: { isExpanded: boolean }) =>
|
||||
@@ -33,48 +34,45 @@ describe('HoneyToast', () => {
|
||||
slotProps.isExpanded ? 'Collapse' : 'Expand'
|
||||
)
|
||||
},
|
||||
attachTo: document.body
|
||||
container: document.body.appendChild(document.createElement('div'))
|
||||
})
|
||||
return { user, unmount }
|
||||
}
|
||||
|
||||
it('renders when visible is true', async () => {
|
||||
const wrapper = mountComponent({ visible: true })
|
||||
const { unmount } = renderComponent({ visible: true })
|
||||
await nextTick()
|
||||
|
||||
const toast = document.body.querySelector('[role="status"]')
|
||||
expect(toast).toBeTruthy()
|
||||
expect(screen.getByRole('status')).toBeInTheDocument()
|
||||
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
})
|
||||
|
||||
it('does not render when visible is false', async () => {
|
||||
const wrapper = mountComponent({ visible: false })
|
||||
const { unmount } = renderComponent({ visible: false })
|
||||
await nextTick()
|
||||
|
||||
const toast = document.body.querySelector('[role="status"]')
|
||||
expect(toast).toBeFalsy()
|
||||
expect(screen.queryByRole('status')).not.toBeInTheDocument()
|
||||
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
})
|
||||
|
||||
it('passes is-expanded=false to slots by default', async () => {
|
||||
const wrapper = mountComponent({ visible: true })
|
||||
const { unmount } = renderComponent({ visible: true })
|
||||
await nextTick()
|
||||
|
||||
const content = document.body.querySelector('[data-testid="content"]')
|
||||
expect(content?.textContent).toBe('collapsed')
|
||||
expect(screen.getByTestId('content')).toHaveTextContent('collapsed')
|
||||
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
})
|
||||
|
||||
it('has aria-live="polite" for accessibility', async () => {
|
||||
const wrapper = mountComponent({ visible: true })
|
||||
const { unmount } = renderComponent({ visible: true })
|
||||
await nextTick()
|
||||
|
||||
const toast = document.body.querySelector('[role="status"]')
|
||||
expect(toast?.getAttribute('aria-live')).toBe('polite')
|
||||
expect(screen.getByRole('status')).toHaveAttribute('aria-live', 'polite')
|
||||
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
})
|
||||
|
||||
it('supports v-model:expanded with reactive parent state', async () => {
|
||||
@@ -98,23 +96,21 @@ describe('HoneyToast', () => {
|
||||
`
|
||||
})
|
||||
|
||||
const wrapper = mount(TestWrapper, { attachTo: document.body })
|
||||
const user = userEvent.setup()
|
||||
const { unmount } = render(TestWrapper, {
|
||||
container: document.body.appendChild(document.createElement('div'))
|
||||
})
|
||||
await nextTick()
|
||||
|
||||
const content = document.body.querySelector('[data-testid="content"]')
|
||||
expect(content?.textContent).toBe('collapsed')
|
||||
expect(screen.getByTestId('content')).toHaveTextContent('collapsed')
|
||||
expect(screen.getByTestId('toggle-btn')).toHaveTextContent('Expand')
|
||||
|
||||
const toggleBtn = document.body.querySelector(
|
||||
'[data-testid="toggle-btn"]'
|
||||
) as HTMLButtonElement
|
||||
expect(toggleBtn?.textContent?.trim()).toBe('Expand')
|
||||
|
||||
toggleBtn?.click()
|
||||
await user.click(screen.getByTestId('toggle-btn'))
|
||||
await nextTick()
|
||||
|
||||
expect(content?.textContent).toBe('expanded')
|
||||
expect(toggleBtn?.textContent?.trim()).toBe('Collapse')
|
||||
expect(screen.getByTestId('content')).toHaveTextContent('expanded')
|
||||
expect(screen.getByTestId('toggle-btn')).toHaveTextContent('Collapse')
|
||||
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { nextTick, ref } from 'vue'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
@@ -27,7 +28,7 @@ const options = [
|
||||
{ name: 'Option C', value: 'c' }
|
||||
]
|
||||
|
||||
function mountInParent(
|
||||
function renderInParent(
|
||||
multiSelectProps: Record<string, unknown> = {},
|
||||
modelValue: { name: string; value: string }[] = []
|
||||
) {
|
||||
@@ -49,12 +50,12 @@ function mountInParent(
|
||||
}
|
||||
}
|
||||
|
||||
const wrapper = mount(Parent, {
|
||||
attachTo: document.body,
|
||||
const { unmount } = render(Parent, {
|
||||
container: document.body.appendChild(document.createElement('div')),
|
||||
global: { plugins: [i18n] }
|
||||
})
|
||||
|
||||
return { wrapper, parentEscapeCount }
|
||||
return { unmount, parentEscapeCount }
|
||||
}
|
||||
|
||||
function dispatchEscape(element: Element) {
|
||||
@@ -73,30 +74,32 @@ function findContentElement(): HTMLElement | null {
|
||||
|
||||
describe('MultiSelect', () => {
|
||||
it('keeps open-state border styling available while the dropdown is open', async () => {
|
||||
const { wrapper } = mountInParent()
|
||||
const user = userEvent.setup()
|
||||
const { unmount } = renderInParent()
|
||||
|
||||
const trigger = wrapper.get('button[aria-haspopup="listbox"]')
|
||||
const trigger = screen.getByRole('button')
|
||||
|
||||
expect(trigger.classes()).toContain(
|
||||
expect(trigger).toHaveClass(
|
||||
'data-[state=open]:border-node-component-border'
|
||||
)
|
||||
expect(trigger.attributes('aria-expanded')).toBe('false')
|
||||
expect(trigger).toHaveAttribute('aria-expanded', 'false')
|
||||
|
||||
await trigger.trigger('click')
|
||||
await user.click(trigger)
|
||||
await nextTick()
|
||||
|
||||
expect(trigger.attributes('aria-expanded')).toBe('true')
|
||||
expect(trigger.attributes('data-state')).toBe('open')
|
||||
expect(trigger).toHaveAttribute('aria-expanded', 'true')
|
||||
expect(trigger).toHaveAttribute('data-state', 'open')
|
||||
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
})
|
||||
|
||||
describe('Escape key propagation', () => {
|
||||
it('stops Escape from propagating to parent when popover is open', async () => {
|
||||
const { wrapper, parentEscapeCount } = mountInParent()
|
||||
const user = userEvent.setup()
|
||||
const { unmount, parentEscapeCount } = renderInParent()
|
||||
|
||||
const trigger = wrapper.find('button[aria-haspopup="listbox"]')
|
||||
await trigger.trigger('click')
|
||||
const trigger = screen.getByRole('button')
|
||||
await user.click(trigger)
|
||||
await nextTick()
|
||||
|
||||
const content = findContentElement()
|
||||
@@ -107,48 +110,46 @@ describe('MultiSelect', () => {
|
||||
|
||||
expect(parentEscapeCount.value).toBe(0)
|
||||
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
})
|
||||
|
||||
it('closes the popover when Escape is pressed', async () => {
|
||||
const { wrapper } = mountInParent()
|
||||
const user = userEvent.setup()
|
||||
const { unmount } = renderInParent()
|
||||
|
||||
const trigger = wrapper.find('button[aria-haspopup="listbox"]')
|
||||
await trigger.trigger('click')
|
||||
const trigger = screen.getByRole('button')
|
||||
await user.click(trigger)
|
||||
await nextTick()
|
||||
expect(trigger.attributes('data-state')).toBe('open')
|
||||
expect(trigger).toHaveAttribute('data-state', 'open')
|
||||
|
||||
const content = findContentElement()
|
||||
dispatchEscape(content!)
|
||||
await nextTick()
|
||||
|
||||
expect(trigger.attributes('data-state')).toBe('closed')
|
||||
expect(trigger).toHaveAttribute('data-state', 'closed')
|
||||
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
})
|
||||
})
|
||||
|
||||
describe('selected count badge', () => {
|
||||
it('shows selected count when items are selected', () => {
|
||||
const { wrapper } = mountInParent({}, [
|
||||
const { unmount } = renderInParent({}, [
|
||||
{ name: 'Option A', value: 'a' },
|
||||
{ name: 'Option B', value: 'b' }
|
||||
])
|
||||
|
||||
expect(wrapper.text()).toContain('2')
|
||||
expect(screen.getByText('2')).toBeInTheDocument()
|
||||
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
})
|
||||
|
||||
it('does not show count badge when no items are selected', () => {
|
||||
const { wrapper } = mountInParent()
|
||||
const multiSelect = wrapper.findComponent(MultiSelect)
|
||||
const spans = multiSelect.findAll('span')
|
||||
const countBadge = spans.find((s) => /^\d+$/.test(s.text().trim()))
|
||||
const { unmount } = renderInParent()
|
||||
|
||||
expect(countBadge).toBeUndefined()
|
||||
expect(screen.queryByText(/^\d+$/)).not.toBeInTheDocument()
|
||||
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { nextTick, ref } from 'vue'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
@@ -37,7 +37,7 @@ function findContentElement(): HTMLElement | null {
|
||||
return document.querySelector('[data-dismissable-layer]')
|
||||
}
|
||||
|
||||
function mountInParent(modelValue?: string) {
|
||||
function renderInParent(modelValue?: string) {
|
||||
const parentEscapeCount = { value: 0 }
|
||||
|
||||
const Parent = {
|
||||
@@ -55,12 +55,12 @@ function mountInParent(modelValue?: string) {
|
||||
}
|
||||
}
|
||||
|
||||
const wrapper = mount(Parent, {
|
||||
attachTo: document.body,
|
||||
const { unmount } = render(Parent, {
|
||||
container: document.body.appendChild(document.createElement('div')),
|
||||
global: { plugins: [i18n] }
|
||||
})
|
||||
|
||||
return { wrapper, parentEscapeCount }
|
||||
return { unmount, parentEscapeCount }
|
||||
}
|
||||
|
||||
async function openSelect(triggerEl: HTMLElement) {
|
||||
@@ -81,10 +81,10 @@ async function openSelect(triggerEl: HTMLElement) {
|
||||
describe('SingleSelect', () => {
|
||||
describe('Escape key propagation', () => {
|
||||
it('stops Escape from propagating to parent when popover is open', async () => {
|
||||
const { wrapper, parentEscapeCount } = mountInParent()
|
||||
const { unmount, parentEscapeCount } = renderInParent()
|
||||
|
||||
const trigger = wrapper.find('button[role="combobox"]')
|
||||
await openSelect(trigger.element as HTMLElement)
|
||||
const trigger = screen.getByRole('combobox')
|
||||
await openSelect(trigger)
|
||||
|
||||
const content = findContentElement()
|
||||
expect(content).not.toBeNull()
|
||||
@@ -94,23 +94,23 @@ describe('SingleSelect', () => {
|
||||
|
||||
expect(parentEscapeCount.value).toBe(0)
|
||||
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
})
|
||||
|
||||
it('closes the popover when Escape is pressed', async () => {
|
||||
const { wrapper } = mountInParent()
|
||||
const { unmount } = renderInParent()
|
||||
|
||||
const trigger = wrapper.find('button[role="combobox"]')
|
||||
await openSelect(trigger.element as HTMLElement)
|
||||
expect(trigger.attributes('data-state')).toBe('open')
|
||||
const trigger = screen.getByRole('combobox')
|
||||
await openSelect(trigger)
|
||||
expect(trigger).toHaveAttribute('data-state', 'open')
|
||||
|
||||
const content = findContentElement()
|
||||
dispatchEscape(content!)
|
||||
await nextTick()
|
||||
|
||||
expect(trigger.attributes('data-state')).toBe('closed')
|
||||
expect(trigger).toHaveAttribute('data-state', 'closed')
|
||||
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { createPinia } from 'pinia'
|
||||
import PrimeVue from 'primevue/config'
|
||||
import { beforeAll, describe, expect, it, vi } from 'vitest'
|
||||
import { createApp } from 'vue'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
|
||||
import type { ComfyNodeDef as ComfyNodeDefV2 } from '@/schemas/nodeDef/nodeDefSchemaV2'
|
||||
import * as markdownRendererUtil from '@/utils/markdownRendererUtil'
|
||||
|
||||
@@ -54,13 +55,11 @@ describe('NodePreview', () => {
|
||||
description: 'Test node description'
|
||||
}
|
||||
|
||||
const mountComponent = (nodeDef: ComfyNodeDefV2 = mockNodeDef) => {
|
||||
return mount(NodePreview, {
|
||||
function renderComponent(nodeDef: ComfyNodeDefV2 = mockNodeDef) {
|
||||
return render(NodePreview, {
|
||||
global: {
|
||||
plugins: [PrimeVue, i18n, pinia],
|
||||
stubs: {
|
||||
// Stub stores if needed
|
||||
}
|
||||
stubs: {}
|
||||
},
|
||||
props: {
|
||||
nodeDef
|
||||
@@ -69,18 +68,18 @@ describe('NodePreview', () => {
|
||||
}
|
||||
|
||||
it('renders node preview with correct structure', () => {
|
||||
const wrapper = mountComponent()
|
||||
renderComponent()
|
||||
|
||||
expect(wrapper.find('._sb_node_preview').exists()).toBe(true)
|
||||
expect(wrapper.find('.node_header').exists()).toBe(true)
|
||||
expect(wrapper.find('._sb_preview_badge').text()).toBe('Preview')
|
||||
expect(screen.getByTestId('node-preview')).toBeInTheDocument()
|
||||
expect(screen.getByTestId('node-header')).toBeInTheDocument()
|
||||
expect(screen.getByText('Preview')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('sets title attribute on node header with full display name', () => {
|
||||
const wrapper = mountComponent()
|
||||
const nodeHeader = wrapper.find('.node_header')
|
||||
renderComponent()
|
||||
const nodeHeader = screen.getByTestId('node-header')
|
||||
|
||||
expect(nodeHeader.attributes('title')).toBe(mockNodeDef.display_name)
|
||||
expect(nodeHeader).toHaveAttribute('title', mockNodeDef.display_name)
|
||||
})
|
||||
|
||||
it('displays truncated long node names with ellipsis', () => {
|
||||
@@ -90,17 +89,11 @@ describe('NodePreview', () => {
|
||||
'This Is An Extremely Long Node Name That Should Definitely Be Truncated With Ellipsis To Prevent Layout Issues'
|
||||
}
|
||||
|
||||
const wrapper = mountComponent(longNameNodeDef)
|
||||
const nodeHeader = wrapper.find('.node_header')
|
||||
renderComponent(longNameNodeDef)
|
||||
const nodeHeader = screen.getByTestId('node-header')
|
||||
|
||||
// Verify the title attribute contains the full name
|
||||
expect(nodeHeader.attributes('title')).toBe(longNameNodeDef.display_name)
|
||||
|
||||
// Verify overflow handling classes are applied
|
||||
expect(nodeHeader.classes()).toContain('text-ellipsis')
|
||||
|
||||
// The actual text content should still be the full name (CSS handles truncation)
|
||||
expect(nodeHeader.text()).toContain(longNameNodeDef.display_name)
|
||||
expect(nodeHeader).toHaveAttribute('title', longNameNodeDef.display_name)
|
||||
expect(nodeHeader).toHaveTextContent(longNameNodeDef.display_name!)
|
||||
})
|
||||
|
||||
it('handles short node names without issues', () => {
|
||||
@@ -109,18 +102,18 @@ describe('NodePreview', () => {
|
||||
display_name: 'Short'
|
||||
}
|
||||
|
||||
const wrapper = mountComponent(shortNameNodeDef)
|
||||
const nodeHeader = wrapper.find('.node_header')
|
||||
renderComponent(shortNameNodeDef)
|
||||
const nodeHeader = screen.getByTestId('node-header')
|
||||
|
||||
expect(nodeHeader.attributes('title')).toBe('Short')
|
||||
expect(nodeHeader.text()).toContain('Short')
|
||||
expect(nodeHeader).toHaveAttribute('title', 'Short')
|
||||
expect(nodeHeader).toHaveTextContent('Short')
|
||||
})
|
||||
|
||||
it('applies proper spacing to the dot element', () => {
|
||||
const wrapper = mountComponent()
|
||||
const headdot = wrapper.find('.headdot')
|
||||
renderComponent()
|
||||
const headdot = screen.getByTestId('head-dot')
|
||||
|
||||
expect(headdot.classes()).toContain('pr-3')
|
||||
expect(headdot).toBeInTheDocument()
|
||||
})
|
||||
|
||||
describe('Description Rendering', () => {
|
||||
@@ -130,11 +123,13 @@ describe('NodePreview', () => {
|
||||
description: 'This is a plain text description'
|
||||
}
|
||||
|
||||
const wrapper = mountComponent(plainTextNodeDef)
|
||||
const description = wrapper.find('._sb_description')
|
||||
renderComponent(plainTextNodeDef)
|
||||
const description = screen.getByTestId('node-description')
|
||||
|
||||
expect(description.exists()).toBe(true)
|
||||
expect(description.html()).toContain('This is a plain text description')
|
||||
expect(description).toBeInTheDocument()
|
||||
expect(description.innerHTML).toContain(
|
||||
'This is a plain text description'
|
||||
)
|
||||
})
|
||||
|
||||
it('renders markdown description with formatting', () => {
|
||||
@@ -143,13 +138,13 @@ describe('NodePreview', () => {
|
||||
description: '**Bold text** and *italic text* with `code`'
|
||||
}
|
||||
|
||||
const wrapper = mountComponent(markdownNodeDef)
|
||||
const description = wrapper.find('._sb_description')
|
||||
renderComponent(markdownNodeDef)
|
||||
const description = screen.getByTestId('node-description')
|
||||
|
||||
expect(description.exists()).toBe(true)
|
||||
expect(description.html()).toContain('<strong>Bold text</strong>')
|
||||
expect(description.html()).toContain('<em>italic text</em>')
|
||||
expect(description.html()).toContain('<code>code</code>')
|
||||
expect(description).toBeInTheDocument()
|
||||
expect(description.innerHTML).toContain('<strong>Bold text</strong>')
|
||||
expect(description.innerHTML).toContain('<em>italic text</em>')
|
||||
expect(description.innerHTML).toContain('<code>code</code>')
|
||||
})
|
||||
|
||||
it('does not render description element when description is empty', () => {
|
||||
@@ -158,20 +153,16 @@ describe('NodePreview', () => {
|
||||
description: ''
|
||||
}
|
||||
|
||||
const wrapper = mountComponent(noDescriptionNodeDef)
|
||||
const description = wrapper.find('._sb_description')
|
||||
renderComponent(noDescriptionNodeDef)
|
||||
|
||||
expect(description.exists()).toBe(false)
|
||||
expect(screen.queryByTestId('node-description')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('does not render description element when description is undefined', () => {
|
||||
const { description, ...nodeDefWithoutDescription } = mockNodeDef
|
||||
const wrapper = mountComponent(
|
||||
nodeDefWithoutDescription as ComfyNodeDefV2
|
||||
)
|
||||
const descriptionElement = wrapper.find('._sb_description')
|
||||
renderComponent(nodeDefWithoutDescription as ComfyNodeDefV2)
|
||||
|
||||
expect(descriptionElement.exists()).toBe(false)
|
||||
expect(screen.queryByTestId('node-description')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('calls renderMarkdownToHtml utility function', () => {
|
||||
@@ -183,7 +174,7 @@ describe('NodePreview', () => {
|
||||
description: testDescription
|
||||
}
|
||||
|
||||
mountComponent(nodeDefWithDescription)
|
||||
renderComponent(nodeDefWithDescription)
|
||||
|
||||
expect(spy).toHaveBeenCalledWith(testDescription)
|
||||
spy.mockRestore()
|
||||
@@ -196,21 +187,13 @@ describe('NodePreview', () => {
|
||||
'Safe **markdown** content <script>alert("xss")</script> with `code` blocks'
|
||||
}
|
||||
|
||||
const wrapper = mountComponent(unsafeNodeDef)
|
||||
const description = wrapper.find('._sb_description')
|
||||
renderComponent(unsafeNodeDef)
|
||||
const description = screen.getByTestId('node-description')
|
||||
|
||||
// The description should still exist because there's safe content
|
||||
if (description.exists()) {
|
||||
// Should not contain script tags (sanitized by DOMPurify)
|
||||
expect(description.html()).not.toContain('<script>')
|
||||
expect(description.html()).not.toContain('alert("xss")')
|
||||
// Should contain the safe markdown content rendered as HTML
|
||||
expect(description.html()).toContain('<strong>markdown</strong>')
|
||||
expect(description.html()).toContain('<code>code</code>')
|
||||
} else {
|
||||
// If DOMPurify removes everything, that's also acceptable for security
|
||||
expect(description.exists()).toBe(false)
|
||||
}
|
||||
expect(description.innerHTML).not.toContain('<script>')
|
||||
expect(description.innerHTML).not.toContain('alert("xss")')
|
||||
expect(description.innerHTML).toContain('<strong>markdown</strong>')
|
||||
expect(description.innerHTML).toContain('<code>code</code>')
|
||||
})
|
||||
|
||||
it('handles markdown with line breaks', () => {
|
||||
@@ -219,12 +202,11 @@ describe('NodePreview', () => {
|
||||
description: 'Line 1\n\nLine 3 after empty line'
|
||||
}
|
||||
|
||||
const wrapper = mountComponent(multilineNodeDef)
|
||||
const description = wrapper.find('._sb_description')
|
||||
renderComponent(multilineNodeDef)
|
||||
const description = screen.getByTestId('node-description')
|
||||
|
||||
expect(description.exists()).toBe(true)
|
||||
// Should contain paragraph tags for proper line break handling
|
||||
expect(description.html()).toContain('<p>')
|
||||
expect(description).toBeInTheDocument()
|
||||
expect(description.innerHTML).toContain('<p>')
|
||||
})
|
||||
|
||||
it('handles markdown lists', () => {
|
||||
@@ -233,19 +215,19 @@ describe('NodePreview', () => {
|
||||
description: '- Item 1\n- Item 2\n- Item 3'
|
||||
}
|
||||
|
||||
const wrapper = mountComponent(listNodeDef)
|
||||
const description = wrapper.find('._sb_description')
|
||||
renderComponent(listNodeDef)
|
||||
const description = screen.getByTestId('node-description')
|
||||
|
||||
expect(description.exists()).toBe(true)
|
||||
expect(description.html()).toContain('<ul>')
|
||||
expect(description.html()).toContain('<li>')
|
||||
expect(description).toBeInTheDocument()
|
||||
expect(description.innerHTML).toContain('<ul>')
|
||||
expect(description.innerHTML).toContain('<li>')
|
||||
})
|
||||
|
||||
it('applies correct styling classes to description', () => {
|
||||
const wrapper = mountComponent()
|
||||
const description = wrapper.find('._sb_description')
|
||||
it('renders description element', () => {
|
||||
renderComponent()
|
||||
const description = screen.getByTestId('node-description')
|
||||
|
||||
expect(description.classes()).toContain('_sb_description')
|
||||
expect(description).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('uses v-html directive for rendered content', () => {
|
||||
@@ -254,12 +236,11 @@ describe('NodePreview', () => {
|
||||
description: 'Content with **bold** text'
|
||||
}
|
||||
|
||||
const wrapper = mountComponent(htmlNodeDef)
|
||||
const description = wrapper.find('._sb_description')
|
||||
renderComponent(htmlNodeDef)
|
||||
const description = screen.getByTestId('node-description')
|
||||
|
||||
// The component should render the HTML, not escape it
|
||||
expect(description.html()).toContain('<strong>bold</strong>')
|
||||
expect(description.html()).not.toContain('<strong>')
|
||||
expect(description.innerHTML).toContain('<strong>bold</strong>')
|
||||
expect(description.innerHTML).not.toContain('<strong>')
|
||||
})
|
||||
|
||||
it('prevents XSS attacks by sanitizing dangerous HTML elements', () => {
|
||||
@@ -269,17 +250,12 @@ describe('NodePreview', () => {
|
||||
'Normal text <img src="x" onerror="alert(\'XSS\')" /> and **bold** text'
|
||||
}
|
||||
|
||||
const wrapper = mountComponent(maliciousNodeDef)
|
||||
const description = wrapper.find('._sb_description')
|
||||
renderComponent(maliciousNodeDef)
|
||||
const description = screen.getByTestId('node-description')
|
||||
|
||||
if (description.exists()) {
|
||||
// Should not contain dangerous event handlers
|
||||
expect(description.html()).not.toContain('onerror')
|
||||
expect(description.html()).not.toContain('alert(')
|
||||
// Should still contain safe markdown content
|
||||
expect(description.html()).toContain('<strong>bold</strong>')
|
||||
// May or may not contain img tag depending on DOMPurify config
|
||||
}
|
||||
expect(description.innerHTML).not.toContain('onerror')
|
||||
expect(description.innerHTML).not.toContain('alert(')
|
||||
expect(description.innerHTML).toContain('<strong>bold</strong>')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -7,17 +7,22 @@ https://github.com/Nuked88/ComfyUI-N-Sidebar/blob/7ae7da4a9761009fb6629bc04c6830
|
||||
:node-def="nodeDef"
|
||||
:position="position"
|
||||
/>
|
||||
<div v-else class="_sb_node_preview bg-component-node-background">
|
||||
<div
|
||||
v-else
|
||||
class="_sb_node_preview bg-component-node-background"
|
||||
data-testid="node-preview"
|
||||
>
|
||||
<div class="_sb_table">
|
||||
<div
|
||||
class="node_header text-ellipsis"
|
||||
data-testid="node-header"
|
||||
:title="nodeDef.display_name"
|
||||
:style="{
|
||||
backgroundColor: litegraphColors.NODE_DEFAULT_COLOR,
|
||||
color: litegraphColors.NODE_TITLE_COLOR
|
||||
}"
|
||||
>
|
||||
<div class="_sb_dot headdot pr-3" />
|
||||
<div class="_sb_dot headdot pr-3" data-testid="head-dot" />
|
||||
{{ nodeDef.display_name }}
|
||||
</div>
|
||||
<div class="_sb_preview_badge">{{ $t('g.preview') }}</div>
|
||||
@@ -76,6 +81,7 @@ https://github.com/Nuked88/ComfyUI-N-Sidebar/blob/7ae7da4a9761009fb6629bc04c6830
|
||||
<div
|
||||
v-if="renderedDescription"
|
||||
class="_sb_description"
|
||||
data-testid="node-description"
|
||||
:style="{
|
||||
color: litegraphColors.WIDGET_SECONDARY_TEXT_COLOR,
|
||||
backgroundColor: litegraphColors.WIDGET_BGCOLOR
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { defineComponent, h } from 'vue'
|
||||
|
||||
import { i18n } from '@/i18n'
|
||||
import JobHistoryActionsMenu from '@/components/queue/JobHistoryActionsMenu.vue'
|
||||
|
||||
const popoverCloseSpy = vi.fn()
|
||||
|
||||
@@ -52,8 +52,10 @@ vi.mock('@/stores/workspace/sidebarTabStore', () => ({
|
||||
useSidebarTabStore: () => mockSidebarTabStore
|
||||
}))
|
||||
|
||||
const mountMenu = () =>
|
||||
mount(JobHistoryActionsMenu, {
|
||||
import JobHistoryActionsMenu from '@/components/queue/JobHistoryActionsMenu.vue'
|
||||
|
||||
const renderMenu = () =>
|
||||
render(JobHistoryActionsMenu, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
directives: { tooltip: () => {} }
|
||||
@@ -75,12 +77,11 @@ describe('JobHistoryActionsMenu', () => {
|
||||
})
|
||||
|
||||
it('toggles show run progress bar setting from the menu', async () => {
|
||||
const wrapper = mountMenu()
|
||||
const user = userEvent.setup()
|
||||
|
||||
const showRunProgressBarButton = wrapper.get(
|
||||
'[data-testid="show-run-progress-bar-action"]'
|
||||
)
|
||||
await showRunProgressBarButton.trigger('click')
|
||||
renderMenu()
|
||||
|
||||
await user.click(screen.getByTestId('show-run-progress-bar-action'))
|
||||
|
||||
expect(mockSetSetting).toHaveBeenCalledTimes(1)
|
||||
expect(mockSetSetting).toHaveBeenCalledWith(
|
||||
@@ -90,17 +91,16 @@ describe('JobHistoryActionsMenu', () => {
|
||||
})
|
||||
|
||||
it('opens docked job history sidebar when enabling from the menu', async () => {
|
||||
const user = userEvent.setup()
|
||||
mockGetSetting.mockImplementation((key: string) => {
|
||||
if (key === 'Comfy.Queue.QPOV2') return false
|
||||
if (key === 'Comfy.Queue.ShowRunProgressBar') return true
|
||||
return undefined
|
||||
})
|
||||
const wrapper = mountMenu()
|
||||
|
||||
const dockedJobHistoryButton = wrapper.get(
|
||||
'[data-testid="docked-job-history-action"]'
|
||||
)
|
||||
await dockedJobHistoryButton.trigger('click')
|
||||
renderMenu()
|
||||
|
||||
await user.click(screen.getByTestId('docked-job-history-action'))
|
||||
|
||||
expect(popoverCloseSpy).toHaveBeenCalledTimes(1)
|
||||
expect(mockSetSetting).toHaveBeenCalledTimes(1)
|
||||
@@ -110,14 +110,20 @@ describe('JobHistoryActionsMenu', () => {
|
||||
})
|
||||
|
||||
it('emits clear history from the menu', async () => {
|
||||
const wrapper = mountMenu()
|
||||
const user = userEvent.setup()
|
||||
const clearHistorySpy = vi.fn()
|
||||
|
||||
const clearHistoryButton = wrapper.get(
|
||||
'[data-testid="clear-history-action"]'
|
||||
)
|
||||
await clearHistoryButton.trigger('click')
|
||||
render(JobHistoryActionsMenu, {
|
||||
props: { onClearHistory: clearHistorySpy },
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
directives: { tooltip: () => {} }
|
||||
}
|
||||
})
|
||||
|
||||
await user.click(screen.getByTestId('clear-history-action'))
|
||||
|
||||
expect(popoverCloseSpy).toHaveBeenCalledTimes(1)
|
||||
expect(wrapper.emitted('clearHistory')).toHaveLength(1)
|
||||
expect(clearHistorySpy).toHaveBeenCalledOnce()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
@@ -32,30 +33,20 @@ const tooltipDirectiveStub = {
|
||||
updated: vi.fn()
|
||||
}
|
||||
|
||||
const SELECTORS = {
|
||||
interruptAllButton: 'button[aria-label="Interrupt all running jobs"]',
|
||||
clearQueuedButton: 'button[aria-label="Clear queued"]',
|
||||
summaryRow: '.flex.items-center.gap-2',
|
||||
currentNodeRow: '.flex.items-center.gap-1.text-text-secondary'
|
||||
const defaultProps = {
|
||||
totalProgressStyle: { width: '65%' },
|
||||
currentNodeProgressStyle: { width: '40%' },
|
||||
totalPercentFormatted: '65%',
|
||||
currentNodePercentFormatted: '40%',
|
||||
currentNodeName: 'Sampler',
|
||||
runningCount: 1,
|
||||
queuedCount: 2,
|
||||
bottomRowClass: 'flex custom-bottom-row'
|
||||
}
|
||||
|
||||
const COPY = {
|
||||
viewAllJobs: 'View all jobs'
|
||||
}
|
||||
|
||||
const mountComponent = (props: Record<string, unknown> = {}) =>
|
||||
mount(QueueOverlayActive, {
|
||||
props: {
|
||||
totalProgressStyle: { width: '65%' },
|
||||
currentNodeProgressStyle: { width: '40%' },
|
||||
totalPercentFormatted: '65%',
|
||||
currentNodePercentFormatted: '40%',
|
||||
currentNodeName: 'Sampler',
|
||||
runningCount: 1,
|
||||
queuedCount: 2,
|
||||
bottomRowClass: 'flex custom-bottom-row',
|
||||
...props
|
||||
},
|
||||
const renderComponent = (props: Record<string, unknown> = {}) =>
|
||||
render(QueueOverlayActive, {
|
||||
props: { ...defaultProps, ...props },
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
directives: {
|
||||
@@ -66,58 +57,65 @@ const mountComponent = (props: Record<string, unknown> = {}) =>
|
||||
|
||||
describe('QueueOverlayActive', () => {
|
||||
it('renders progress metrics and emits actions when buttons clicked', async () => {
|
||||
const wrapper = mountComponent({ runningCount: 2, queuedCount: 3 })
|
||||
const user = userEvent.setup()
|
||||
const interruptAllSpy = vi.fn()
|
||||
const clearQueuedSpy = vi.fn()
|
||||
const viewAllJobsSpy = vi.fn()
|
||||
|
||||
const progressBars = wrapper.findAll('.absolute.inset-0')
|
||||
expect(progressBars[0].attributes('style')).toContain('width: 65%')
|
||||
expect(progressBars[1].attributes('style')).toContain('width: 40%')
|
||||
const { container } = renderComponent({
|
||||
runningCount: 2,
|
||||
queuedCount: 3,
|
||||
onInterruptAll: interruptAllSpy,
|
||||
onClearQueued: clearQueuedSpy,
|
||||
onViewAllJobs: viewAllJobsSpy
|
||||
})
|
||||
|
||||
const content = wrapper.text().replace(/\s+/g, ' ')
|
||||
expect(content).toContain('Total: 65%')
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
const progressBars = container.querySelectorAll('.absolute.inset-0')
|
||||
expect(progressBars[0]).toHaveStyle({ width: '65%' })
|
||||
expect(progressBars[1]).toHaveStyle({ width: '40%' })
|
||||
|
||||
const [runningSection, queuedSection] = wrapper.findAll(
|
||||
SELECTORS.summaryRow
|
||||
expect(screen.getByText('65%')).toBeInTheDocument()
|
||||
|
||||
expect(screen.getByText('2')).toBeInTheDocument()
|
||||
expect(screen.getByText('running')).toBeInTheDocument()
|
||||
expect(screen.getByText('3')).toBeInTheDocument()
|
||||
expect(screen.getByText('queued')).toBeInTheDocument()
|
||||
|
||||
expect(screen.getByText('Current node:')).toBeInTheDocument()
|
||||
expect(screen.getByText('Sampler')).toBeInTheDocument()
|
||||
expect(screen.getByText('40%')).toBeInTheDocument()
|
||||
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Interrupt all running jobs' })
|
||||
)
|
||||
expect(runningSection.text()).toContain('2')
|
||||
expect(runningSection.text()).toContain('running')
|
||||
expect(queuedSection.text()).toContain('3')
|
||||
expect(queuedSection.text()).toContain('queued')
|
||||
expect(interruptAllSpy).toHaveBeenCalledOnce()
|
||||
|
||||
const currentNodeSection = wrapper.find(SELECTORS.currentNodeRow)
|
||||
expect(currentNodeSection.text()).toContain('Current node:')
|
||||
expect(currentNodeSection.text()).toContain('Sampler')
|
||||
expect(currentNodeSection.text()).toContain('40%')
|
||||
await user.click(screen.getByRole('button', { name: 'Clear queued' }))
|
||||
expect(clearQueuedSpy).toHaveBeenCalledOnce()
|
||||
|
||||
const interruptButton = wrapper.get(SELECTORS.interruptAllButton)
|
||||
await interruptButton.trigger('click')
|
||||
expect(wrapper.emitted('interruptAll')).toHaveLength(1)
|
||||
await user.click(screen.getByRole('button', { name: 'View all jobs' }))
|
||||
expect(viewAllJobsSpy).toHaveBeenCalledOnce()
|
||||
|
||||
const clearQueuedButton = wrapper.get(SELECTORS.clearQueuedButton)
|
||||
await clearQueuedButton.trigger('click')
|
||||
expect(wrapper.emitted('clearQueued')).toHaveLength(1)
|
||||
|
||||
const buttons = wrapper.findAll('button')
|
||||
const viewAllButton = buttons.find((btn) =>
|
||||
btn.text().includes(COPY.viewAllJobs)
|
||||
)
|
||||
expect(viewAllButton).toBeDefined()
|
||||
await viewAllButton!.trigger('click')
|
||||
expect(wrapper.emitted('viewAllJobs')).toHaveLength(1)
|
||||
|
||||
expect(wrapper.find('.custom-bottom-row').exists()).toBe(true)
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
expect(container.querySelector('.custom-bottom-row')).toBeTruthy()
|
||||
})
|
||||
|
||||
it('hides action buttons when counts are zero', () => {
|
||||
const wrapper = mountComponent({ runningCount: 0, queuedCount: 0 })
|
||||
renderComponent({ runningCount: 0, queuedCount: 0 })
|
||||
|
||||
expect(wrapper.find(SELECTORS.interruptAllButton).exists()).toBe(false)
|
||||
expect(wrapper.find(SELECTORS.clearQueuedButton).exists()).toBe(false)
|
||||
expect(
|
||||
screen.queryByRole('button', { name: 'Interrupt all running jobs' })
|
||||
).not.toBeInTheDocument()
|
||||
expect(
|
||||
screen.queryByRole('button', { name: 'Clear queued' })
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('builds tooltip configs with translated strings', () => {
|
||||
const spy = vi.spyOn(tooltipConfig, 'buildTooltipConfig')
|
||||
|
||||
mountComponent()
|
||||
renderComponent()
|
||||
|
||||
expect(spy).toHaveBeenCalledWith('Cancel job')
|
||||
expect(spy).toHaveBeenCalledWith('Clear queue')
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { defineComponent, h } from 'vue'
|
||||
|
||||
@@ -55,8 +56,8 @@ const tooltipDirectiveStub = {
|
||||
updated: vi.fn()
|
||||
}
|
||||
|
||||
const mountHeader = (props = {}) =>
|
||||
mount(QueueOverlayHeader, {
|
||||
const renderHeader = (props = {}) =>
|
||||
render(QueueOverlayHeader, {
|
||||
props: {
|
||||
headerTitle: 'Job queue',
|
||||
queuedCount: 3,
|
||||
@@ -81,54 +82,53 @@ describe('QueueOverlayHeader', () => {
|
||||
})
|
||||
|
||||
it('renders header title', () => {
|
||||
const wrapper = mountHeader()
|
||||
expect(wrapper.text()).toContain('Job queue')
|
||||
renderHeader()
|
||||
expect(screen.getByText('Job queue')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows clear queue text and emits clear queued', async () => {
|
||||
const wrapper = mountHeader({ queuedCount: 4 })
|
||||
const user = userEvent.setup()
|
||||
const clearQueuedSpy = vi.fn()
|
||||
|
||||
expect(wrapper.text()).toContain('Clear queue')
|
||||
expect(wrapper.text()).not.toContain('4 queued')
|
||||
renderHeader({ queuedCount: 4, onClearQueued: clearQueuedSpy })
|
||||
|
||||
const clearQueuedButton = wrapper.get('button[aria-label="Clear queued"]')
|
||||
await clearQueuedButton.trigger('click')
|
||||
expect(wrapper.emitted('clearQueued')).toHaveLength(1)
|
||||
expect(screen.getByText('Clear queue')).toBeInTheDocument()
|
||||
expect(screen.queryByText('4 queued')).not.toBeInTheDocument()
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Clear queued' }))
|
||||
expect(clearQueuedSpy).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it('disables clear queued button when queued count is zero', () => {
|
||||
const wrapper = mountHeader({ queuedCount: 0 })
|
||||
const clearQueuedButton = wrapper.get('button[aria-label="Clear queued"]')
|
||||
renderHeader({ queuedCount: 0 })
|
||||
|
||||
expect(clearQueuedButton.attributes('disabled')).toBeDefined()
|
||||
expect(wrapper.text()).toContain('Clear queue')
|
||||
expect(screen.getByRole('button', { name: 'Clear queued' })).toBeDisabled()
|
||||
expect(screen.getByText('Clear queue')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('emits clear history from the menu', async () => {
|
||||
const user = userEvent.setup()
|
||||
const spy = vi.spyOn(tooltipConfig, 'buildTooltipConfig')
|
||||
const clearHistorySpy = vi.fn()
|
||||
|
||||
const wrapper = mountHeader()
|
||||
renderHeader({ onClearHistory: clearHistorySpy })
|
||||
|
||||
expect(wrapper.find('button[aria-label="More options"]').exists()).toBe(
|
||||
true
|
||||
)
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'More options' })
|
||||
).toBeInTheDocument()
|
||||
expect(spy).toHaveBeenCalledWith('More')
|
||||
|
||||
const clearHistoryButton = wrapper.get(
|
||||
'[data-testid="clear-history-action"]'
|
||||
)
|
||||
await clearHistoryButton.trigger('click')
|
||||
await user.click(screen.getByTestId('clear-history-action'))
|
||||
expect(popoverCloseSpy).toHaveBeenCalledTimes(1)
|
||||
expect(wrapper.emitted('clearHistory')).toHaveLength(1)
|
||||
expect(clearHistorySpy).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it('opens floating queue progress overlay when disabling from the menu', async () => {
|
||||
const wrapper = mountHeader()
|
||||
const user = userEvent.setup()
|
||||
|
||||
const dockedJobHistoryButton = wrapper.get(
|
||||
'[data-testid="docked-job-history-action"]'
|
||||
)
|
||||
await dockedJobHistoryButton.trigger('click')
|
||||
renderHeader()
|
||||
|
||||
await user.click(screen.getByTestId('docked-job-history-action'))
|
||||
|
||||
expect(popoverCloseSpy).toHaveBeenCalledTimes(1)
|
||||
expect(mockSetMany).toHaveBeenCalledTimes(1)
|
||||
@@ -141,15 +141,14 @@ describe('QueueOverlayHeader', () => {
|
||||
})
|
||||
|
||||
it('opens docked job history sidebar when enabling from the menu', async () => {
|
||||
const user = userEvent.setup()
|
||||
mockGetSetting.mockImplementation((key: string) =>
|
||||
key === 'Comfy.Queue.QPOV2' ? false : undefined
|
||||
)
|
||||
const wrapper = mountHeader()
|
||||
|
||||
const dockedJobHistoryButton = wrapper.get(
|
||||
'[data-testid="docked-job-history-action"]'
|
||||
)
|
||||
await dockedJobHistoryButton.trigger('click')
|
||||
renderHeader()
|
||||
|
||||
await user.click(screen.getByTestId('docked-job-history-action'))
|
||||
|
||||
expect(popoverCloseSpy).toHaveBeenCalledTimes(1)
|
||||
expect(mockSetSetting).toHaveBeenCalledTimes(1)
|
||||
@@ -159,16 +158,15 @@ describe('QueueOverlayHeader', () => {
|
||||
})
|
||||
|
||||
it('keeps docked target open even when enabling persistence fails', async () => {
|
||||
const user = userEvent.setup()
|
||||
mockGetSetting.mockImplementation((key: string) =>
|
||||
key === 'Comfy.Queue.QPOV2' ? false : undefined
|
||||
)
|
||||
mockSetSetting.mockRejectedValueOnce(new Error('persistence failed'))
|
||||
const wrapper = mountHeader()
|
||||
|
||||
const dockedJobHistoryButton = wrapper.get(
|
||||
'[data-testid="docked-job-history-action"]'
|
||||
)
|
||||
await dockedJobHistoryButton.trigger('click')
|
||||
renderHeader()
|
||||
|
||||
await user.click(screen.getByTestId('docked-job-history-action'))
|
||||
|
||||
expect(popoverCloseSpy).toHaveBeenCalledTimes(1)
|
||||
expect(mockSetSetting).toHaveBeenCalledWith('Comfy.Queue.QPOV2', true)
|
||||
@@ -176,13 +174,12 @@ describe('QueueOverlayHeader', () => {
|
||||
})
|
||||
|
||||
it('closes the menu when disabling persistence fails', async () => {
|
||||
const user = userEvent.setup()
|
||||
mockSetMany.mockRejectedValueOnce(new Error('persistence failed'))
|
||||
const wrapper = mountHeader()
|
||||
|
||||
const dockedJobHistoryButton = wrapper.get(
|
||||
'[data-testid="docked-job-history-action"]'
|
||||
)
|
||||
await dockedJobHistoryButton.trigger('click')
|
||||
renderHeader()
|
||||
|
||||
await user.click(screen.getByTestId('docked-job-history-action'))
|
||||
|
||||
expect(popoverCloseSpy).toHaveBeenCalledTimes(1)
|
||||
expect(mockSetMany).toHaveBeenCalledWith({
|
||||
@@ -192,12 +189,11 @@ describe('QueueOverlayHeader', () => {
|
||||
})
|
||||
|
||||
it('toggles show run progress bar setting from the menu', async () => {
|
||||
const wrapper = mountHeader()
|
||||
const user = userEvent.setup()
|
||||
|
||||
const showRunProgressBarButton = wrapper.get(
|
||||
'[data-testid="show-run-progress-bar-action"]'
|
||||
)
|
||||
await showRunProgressBarButton.trigger('click')
|
||||
renderHeader()
|
||||
|
||||
await user.click(screen.getByTestId('show-run-progress-bar-action'))
|
||||
|
||||
expect(mockSetSetting).toHaveBeenCalledTimes(1)
|
||||
expect(mockSetSetting).toHaveBeenCalledWith(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { fireEvent, render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { defineComponent, nextTick } from 'vue'
|
||||
import { defineComponent, nextTick, ref } from 'vue'
|
||||
|
||||
import JobContextMenu from '@/components/queue/job/JobContextMenu.vue'
|
||||
import type { MenuEntry } from '@/composables/queue/useJobMenu'
|
||||
@@ -28,7 +29,6 @@ const popoverStub = defineComponent({
|
||||
this.hide()
|
||||
return
|
||||
}
|
||||
|
||||
this.show(event, target)
|
||||
},
|
||||
show(event: Event, target?: EventTarget | null) {
|
||||
@@ -43,7 +43,7 @@ const popoverStub = defineComponent({
|
||||
}
|
||||
},
|
||||
template: `
|
||||
<div v-if="visible" ref="container" class="popover-stub">
|
||||
<div v-if="visible" ref="container" data-testid="popover">
|
||||
<slot />
|
||||
</div>
|
||||
`
|
||||
@@ -51,21 +51,18 @@ const popoverStub = defineComponent({
|
||||
|
||||
const buttonStub = {
|
||||
props: {
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
disabled: { type: Boolean, default: false },
|
||||
ariaLabel: { type: String, default: undefined }
|
||||
},
|
||||
template: `
|
||||
<div
|
||||
class="button-stub"
|
||||
:data-disabled="String(disabled)"
|
||||
>
|
||||
<button :disabled="disabled" :aria-label="ariaLabel">
|
||||
<slot />
|
||||
</div>
|
||||
</button>
|
||||
`
|
||||
}
|
||||
|
||||
type MenuHandle = { open: (e: Event) => Promise<void>; hide: () => void }
|
||||
|
||||
const createEntries = (): MenuEntry[] => [
|
||||
{ key: 'enabled', label: 'Enabled action', onClick: vi.fn() },
|
||||
{
|
||||
@@ -77,17 +74,6 @@ const createEntries = (): MenuEntry[] => [
|
||||
{ kind: 'divider', key: 'divider-1' }
|
||||
]
|
||||
|
||||
const mountComponent = (entries: MenuEntry[]) =>
|
||||
mount(JobContextMenu, {
|
||||
props: { entries },
|
||||
global: {
|
||||
stubs: {
|
||||
Popover: popoverStub,
|
||||
Button: buttonStub
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const createTriggerEvent = (type: string, currentTarget: EventTarget) =>
|
||||
({
|
||||
type,
|
||||
@@ -95,13 +81,37 @@ const createTriggerEvent = (type: string, currentTarget: EventTarget) =>
|
||||
target: currentTarget
|
||||
}) as Event
|
||||
|
||||
const openMenu = async (
|
||||
wrapper: ReturnType<typeof mountComponent>,
|
||||
function renderMenu(entries: MenuEntry[], onAction?: ReturnType<typeof vi.fn>) {
|
||||
const menuRef = ref<MenuHandle | null>(null)
|
||||
|
||||
const Wrapper = {
|
||||
components: { JobContextMenu },
|
||||
setup() {
|
||||
return { menuRef, entries }
|
||||
},
|
||||
template:
|
||||
'<JobContextMenu ref="menuRef" :entries="entries" @action="$emit(\'action\', $event)" />'
|
||||
}
|
||||
|
||||
const user = userEvent.setup()
|
||||
const actionSpy = onAction ?? vi.fn()
|
||||
const { unmount } = render(Wrapper, {
|
||||
props: { onAction: actionSpy },
|
||||
global: {
|
||||
stubs: { Popover: popoverStub, Button: buttonStub }
|
||||
}
|
||||
})
|
||||
|
||||
return { user, menuRef, onAction: actionSpy, unmount }
|
||||
}
|
||||
|
||||
async function openMenu(
|
||||
menuRef: ReturnType<typeof ref<MenuHandle | null>>,
|
||||
type: string = 'click'
|
||||
) => {
|
||||
) {
|
||||
const trigger = document.createElement('button')
|
||||
document.body.append(trigger)
|
||||
await wrapper.vm.open(createTriggerEvent(type, trigger))
|
||||
await menuRef.value!.open(createTriggerEvent(type, trigger))
|
||||
await nextTick()
|
||||
return trigger
|
||||
}
|
||||
@@ -112,31 +122,33 @@ afterEach(() => {
|
||||
|
||||
describe('JobContextMenu', () => {
|
||||
it('passes disabled state to action buttons', async () => {
|
||||
const wrapper = mountComponent(createEntries())
|
||||
await openMenu(wrapper)
|
||||
const { menuRef, unmount } = renderMenu(createEntries())
|
||||
await openMenu(menuRef)
|
||||
|
||||
const buttons = wrapper.findAll('.button-stub')
|
||||
expect(buttons).toHaveLength(2)
|
||||
expect(buttons[0].attributes('data-disabled')).toBe('false')
|
||||
expect(buttons[1].attributes('data-disabled')).toBe('true')
|
||||
const enabledBtn = screen.getByRole('button', { name: 'Enabled action' })
|
||||
const disabledBtn = screen.getByRole('button', {
|
||||
name: 'Disabled action'
|
||||
})
|
||||
expect(enabledBtn).not.toBeDisabled()
|
||||
expect(disabledBtn).toBeDisabled()
|
||||
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
})
|
||||
|
||||
it('emits action for enabled entries', async () => {
|
||||
const entries = createEntries()
|
||||
const wrapper = mountComponent(entries)
|
||||
await openMenu(wrapper)
|
||||
const { user, menuRef, onAction, unmount } = renderMenu(entries)
|
||||
await openMenu(menuRef)
|
||||
|
||||
await wrapper.findAll('.button-stub')[0].trigger('click')
|
||||
await user.click(screen.getByRole('button', { name: 'Enabled action' }))
|
||||
|
||||
expect(wrapper.emitted('action')).toEqual([[entries[0]]])
|
||||
expect(onAction).toHaveBeenCalledWith(entries[0])
|
||||
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
})
|
||||
|
||||
it('does not emit action for disabled entries', async () => {
|
||||
const wrapper = mountComponent([
|
||||
const { user, menuRef, onAction, unmount } = renderMenu([
|
||||
{
|
||||
key: 'disabled',
|
||||
label: 'Disabled action',
|
||||
@@ -144,52 +156,54 @@ describe('JobContextMenu', () => {
|
||||
onClick: vi.fn()
|
||||
}
|
||||
])
|
||||
await openMenu(wrapper)
|
||||
await openMenu(menuRef)
|
||||
|
||||
await wrapper.get('.button-stub').trigger('click')
|
||||
await user.click(screen.getByRole('button', { name: 'Disabled action' }))
|
||||
|
||||
expect(wrapper.emitted('action')).toBeUndefined()
|
||||
expect(onAction).not.toHaveBeenCalled()
|
||||
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
})
|
||||
|
||||
it('hides on pointerdown outside the popover', async () => {
|
||||
const wrapper = mountComponent(createEntries())
|
||||
const { menuRef, unmount } = renderMenu(createEntries())
|
||||
|
||||
const trigger = document.createElement('button')
|
||||
const outside = document.createElement('div')
|
||||
document.body.append(trigger, outside)
|
||||
|
||||
await wrapper.vm.open(createTriggerEvent('contextmenu', trigger))
|
||||
await menuRef.value!.open(createTriggerEvent('contextmenu', trigger))
|
||||
await nextTick()
|
||||
expect(wrapper.find('.popover-stub').exists()).toBe(true)
|
||||
expect(screen.getByTestId('popover')).toBeInTheDocument()
|
||||
|
||||
outside.dispatchEvent(new Event('pointerdown', { bubbles: true }))
|
||||
// eslint-disable-next-line testing-library/prefer-user-event
|
||||
await fireEvent.pointerDown(outside)
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.find('.popover-stub').exists()).toBe(false)
|
||||
expect(screen.queryByTestId('popover')).not.toBeInTheDocument()
|
||||
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
})
|
||||
|
||||
it('keeps the menu open through trigger pointerdown and closes on same trigger click', async () => {
|
||||
const wrapper = mountComponent(createEntries())
|
||||
const { menuRef, unmount } = renderMenu(createEntries())
|
||||
|
||||
const trigger = document.createElement('button')
|
||||
document.body.append(trigger)
|
||||
|
||||
await wrapper.vm.open(createTriggerEvent('click', trigger))
|
||||
await menuRef.value!.open(createTriggerEvent('click', trigger))
|
||||
await nextTick()
|
||||
expect(wrapper.find('.popover-stub').exists()).toBe(true)
|
||||
expect(screen.getByTestId('popover')).toBeInTheDocument()
|
||||
|
||||
trigger.dispatchEvent(new Event('pointerdown', { bubbles: true }))
|
||||
// eslint-disable-next-line testing-library/prefer-user-event
|
||||
await fireEvent.pointerDown(trigger)
|
||||
await nextTick()
|
||||
expect(screen.getByTestId('popover')).toBeInTheDocument()
|
||||
|
||||
expect(wrapper.find('.popover-stub').exists()).toBe(true)
|
||||
|
||||
await wrapper.vm.open(createTriggerEvent('click', trigger))
|
||||
await menuRef.value!.open(createTriggerEvent('click', trigger))
|
||||
await nextTick()
|
||||
expect(screen.queryByTestId('popover')).not.toBeInTheDocument()
|
||||
|
||||
expect(wrapper.find('.popover-stub').exists()).toBe(false)
|
||||
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
import { defineComponent } from 'vue'
|
||||
@@ -56,12 +57,16 @@ const i18n = createI18n({
|
||||
|
||||
describe('JobFiltersBar', () => {
|
||||
it('emits showAssets when the assets icon button is clicked', async () => {
|
||||
const wrapper = mount(JobFiltersBar, {
|
||||
const user = userEvent.setup()
|
||||
const showAssetsSpy = vi.fn()
|
||||
|
||||
render(JobFiltersBar, {
|
||||
props: {
|
||||
selectedJobTab: 'All',
|
||||
selectedWorkflowFilter: 'all',
|
||||
selectedSortMode: 'mostRecent',
|
||||
hasFailedJobs: false
|
||||
hasFailedJobs: false,
|
||||
onShowAssets: showAssetsSpy
|
||||
},
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
@@ -69,16 +74,13 @@ describe('JobFiltersBar', () => {
|
||||
}
|
||||
})
|
||||
|
||||
const showAssetsButton = wrapper.get(
|
||||
'button[aria-label="Show assets panel"]'
|
||||
)
|
||||
await showAssetsButton.trigger('click')
|
||||
await user.click(screen.getByRole('button', { name: 'Show assets panel' }))
|
||||
|
||||
expect(wrapper.emitted('showAssets')).toHaveLength(1)
|
||||
expect(showAssetsSpy).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it('hides the assets icon button when hideShowAssetsAction is true', () => {
|
||||
const wrapper = mount(JobFiltersBar, {
|
||||
render(JobFiltersBar, {
|
||||
props: {
|
||||
selectedJobTab: 'All',
|
||||
selectedWorkflowFilter: 'all',
|
||||
@@ -93,7 +95,7 @@ describe('JobFiltersBar', () => {
|
||||
})
|
||||
|
||||
expect(
|
||||
wrapper.find('button[aria-label="Show assets panel"]').exists()
|
||||
).toBe(false)
|
||||
screen.queryByRole('button', { name: 'Show assets panel' })
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { fireEvent, render, screen } from '@testing-library/vue'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { defineComponent, nextTick } from 'vue'
|
||||
|
||||
@@ -23,7 +23,12 @@ const QueueJobItemStub = defineComponent({
|
||||
runningNodeName: { type: String, default: undefined },
|
||||
activeDetailsId: { type: String, default: null }
|
||||
},
|
||||
template: '<div class="queue-job-item-stub"></div>'
|
||||
template: `
|
||||
<div class="queue-job-item-stub" :data-job-id="jobId" :data-active-details-id="activeDetailsId">
|
||||
<div :data-testid="'enter-' + jobId" @click="$emit('details-enter', jobId)" />
|
||||
<div :data-testid="'leave-' + jobId" @click="$emit('details-leave', jobId)" />
|
||||
</div>
|
||||
`
|
||||
})
|
||||
|
||||
const createJobItem = (overrides: Partial<JobListItem> = {}): JobListItem => {
|
||||
@@ -46,8 +51,16 @@ const createJobItem = (overrides: Partial<JobListItem> = {}): JobListItem => {
|
||||
}
|
||||
}
|
||||
|
||||
const mountComponent = (groups: JobGroup[]) =>
|
||||
mount(JobGroupsList, {
|
||||
function getActiveDetailsId(container: Element, jobId: string): string | null {
|
||||
return (
|
||||
container
|
||||
.querySelector(`[data-job-id="${jobId}"]`)
|
||||
?.getAttribute('data-active-details-id') ?? null
|
||||
)
|
||||
}
|
||||
|
||||
const renderComponent = (groups: JobGroup[]) =>
|
||||
render(JobGroupsList, {
|
||||
props: { displayedJobGroups: groups },
|
||||
global: {
|
||||
stubs: {
|
||||
@@ -64,64 +77,60 @@ describe('JobGroupsList hover behavior', () => {
|
||||
it('delays showing and hiding details while hovering over job rows', async () => {
|
||||
vi.useFakeTimers()
|
||||
const job = createJobItem({ id: 'job-d' })
|
||||
const wrapper = mountComponent([
|
||||
const { container } = renderComponent([
|
||||
{ key: 'today', label: 'Today', items: [job] }
|
||||
])
|
||||
const jobItem = wrapper.findComponent(QueueJobItemStub)
|
||||
|
||||
jobItem.vm.$emit('details-enter', job.id)
|
||||
// eslint-disable-next-line testing-library/prefer-user-event
|
||||
await fireEvent.click(screen.getByTestId('enter-job-d'))
|
||||
vi.advanceTimersByTime(199)
|
||||
await nextTick()
|
||||
expect(
|
||||
wrapper.findComponent(QueueJobItemStub).props('activeDetailsId')
|
||||
).toBeNull()
|
||||
expect(getActiveDetailsId(container, 'job-d')).toBeNull()
|
||||
|
||||
vi.advanceTimersByTime(1)
|
||||
await nextTick()
|
||||
expect(
|
||||
wrapper.findComponent(QueueJobItemStub).props('activeDetailsId')
|
||||
).toBe(job.id)
|
||||
expect(getActiveDetailsId(container, 'job-d')).toBe(job.id)
|
||||
|
||||
wrapper.findComponent(QueueJobItemStub).vm.$emit('details-leave', job.id)
|
||||
// eslint-disable-next-line testing-library/prefer-user-event
|
||||
await fireEvent.click(screen.getByTestId('leave-job-d'))
|
||||
vi.advanceTimersByTime(149)
|
||||
await nextTick()
|
||||
expect(
|
||||
wrapper.findComponent(QueueJobItemStub).props('activeDetailsId')
|
||||
).toBe(job.id)
|
||||
expect(getActiveDetailsId(container, 'job-d')).toBe(job.id)
|
||||
|
||||
vi.advanceTimersByTime(1)
|
||||
await nextTick()
|
||||
expect(
|
||||
wrapper.findComponent(QueueJobItemStub).props('activeDetailsId')
|
||||
).toBeNull()
|
||||
expect(getActiveDetailsId(container, 'job-d')).toBeNull()
|
||||
})
|
||||
|
||||
it('clears the previous popover when hovering a new row briefly and leaving', async () => {
|
||||
vi.useFakeTimers()
|
||||
const firstJob = createJobItem({ id: 'job-1', title: 'First job' })
|
||||
const secondJob = createJobItem({ id: 'job-2', title: 'Second job' })
|
||||
const wrapper = mountComponent([
|
||||
const { container } = renderComponent([
|
||||
{ key: 'today', label: 'Today', items: [firstJob, secondJob] }
|
||||
])
|
||||
const jobItems = wrapper.findAllComponents(QueueJobItemStub)
|
||||
|
||||
jobItems[0].vm.$emit('details-enter', firstJob.id)
|
||||
// eslint-disable-next-line testing-library/prefer-user-event
|
||||
await fireEvent.click(screen.getByTestId('enter-job-1'))
|
||||
vi.advanceTimersByTime(200)
|
||||
await nextTick()
|
||||
expect(jobItems[0].props('activeDetailsId')).toBe(firstJob.id)
|
||||
expect(getActiveDetailsId(container, 'job-1')).toBe(firstJob.id)
|
||||
|
||||
jobItems[0].vm.$emit('details-leave', firstJob.id)
|
||||
jobItems[1].vm.$emit('details-enter', secondJob.id)
|
||||
// eslint-disable-next-line testing-library/prefer-user-event
|
||||
await fireEvent.click(screen.getByTestId('leave-job-1'))
|
||||
// eslint-disable-next-line testing-library/prefer-user-event
|
||||
await fireEvent.click(screen.getByTestId('enter-job-2'))
|
||||
vi.advanceTimersByTime(100)
|
||||
await nextTick()
|
||||
jobItems[1].vm.$emit('details-leave', secondJob.id)
|
||||
// eslint-disable-next-line testing-library/prefer-user-event
|
||||
await fireEvent.click(screen.getByTestId('leave-job-2'))
|
||||
|
||||
vi.advanceTimersByTime(50)
|
||||
await nextTick()
|
||||
expect(jobItems[0].props('activeDetailsId')).toBeNull()
|
||||
expect(getActiveDetailsId(container, 'job-1')).toBeNull()
|
||||
|
||||
vi.advanceTimersByTime(50)
|
||||
await nextTick()
|
||||
expect(jobItems[1].props('activeDetailsId')).toBeNull()
|
||||
expect(getActiveDetailsId(container, 'job-2')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { mount, flushPromises } from '@vue/test-utils'
|
||||
import { createTestingPinia } from '@pinia/testing'
|
||||
import { render, screen, waitFor } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import PrimeVue from 'primevue/config'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
@@ -89,16 +90,21 @@ describe('ErrorNodeCard.vue', () => {
|
||||
})
|
||||
})
|
||||
|
||||
function mountCard(card: ErrorCardData) {
|
||||
return mount(ErrorNodeCard, {
|
||||
props: { card },
|
||||
function renderCard(
|
||||
card: ErrorCardData,
|
||||
options: { initialState?: Record<string, unknown> } = {}
|
||||
) {
|
||||
const user = userEvent.setup()
|
||||
const onCopyToClipboard = vi.fn()
|
||||
render(ErrorNodeCard, {
|
||||
props: { card, onCopyToClipboard },
|
||||
global: {
|
||||
plugins: [
|
||||
PrimeVue,
|
||||
i18n,
|
||||
createTestingPinia({
|
||||
createSpy: vi.fn,
|
||||
initialState: {
|
||||
initialState: options.initialState ?? {
|
||||
systemStats: {
|
||||
systemStats: {
|
||||
system: {
|
||||
@@ -132,6 +138,7 @@ describe('ErrorNodeCard.vue', () => {
|
||||
}
|
||||
}
|
||||
})
|
||||
return { user, onCopyToClipboard }
|
||||
}
|
||||
|
||||
let cardIdCounter = 0
|
||||
@@ -173,76 +180,82 @@ describe('ErrorNodeCard.vue', () => {
|
||||
'# ComfyUI Error Report\n## System Information\n- OS: Linux'
|
||||
mockGenerateErrorReport.mockReturnValue(reportText)
|
||||
|
||||
const wrapper = mountCard(makeRuntimeErrorCard())
|
||||
await flushPromises()
|
||||
renderCard(makeRuntimeErrorCard())
|
||||
|
||||
expect(wrapper.text()).toContain('ComfyUI Error Report')
|
||||
expect(wrapper.text()).toContain('System Information')
|
||||
expect(wrapper.text()).toContain('OS: Linux')
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText(/ComfyUI Error Report/)).toBeInTheDocument()
|
||||
})
|
||||
expect(screen.getByText(/System Information/)).toBeInTheDocument()
|
||||
expect(screen.getByText(/OS: Linux/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('does not generate report for non-runtime errors', async () => {
|
||||
mountCard(makeValidationErrorCard())
|
||||
await flushPromises()
|
||||
renderCard(makeValidationErrorCard())
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('Input: text')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
expect(mockGetLogs).not.toHaveBeenCalled()
|
||||
expect(mockGenerateErrorReport).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('displays original details for non-runtime errors', async () => {
|
||||
const wrapper = mountCard(makeValidationErrorCard())
|
||||
await flushPromises()
|
||||
renderCard(makeValidationErrorCard())
|
||||
|
||||
expect(wrapper.text()).toContain('Input: text')
|
||||
expect(wrapper.text()).not.toContain('ComfyUI Error Report')
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('Input: text')).toBeInTheDocument()
|
||||
})
|
||||
expect(screen.queryByText(/ComfyUI Error Report/)).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('copies enriched report when copy button is clicked for runtime error', async () => {
|
||||
const reportText = '# Full Report Content'
|
||||
mockGenerateErrorReport.mockReturnValue(reportText)
|
||||
|
||||
const wrapper = mountCard(makeRuntimeErrorCard())
|
||||
await flushPromises()
|
||||
const { user, onCopyToClipboard } = renderCard(makeRuntimeErrorCard())
|
||||
|
||||
const copyButton = wrapper
|
||||
.findAll('button')
|
||||
.find((btn) => btn.text().includes('Copy'))!
|
||||
expect(copyButton.exists()).toBe(true)
|
||||
await copyButton.trigger('click')
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText(/Full Report Content/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
const emitted = wrapper.emitted('copyToClipboard')
|
||||
expect(emitted).toHaveLength(1)
|
||||
expect(emitted![0][0]).toContain('# Full Report Content')
|
||||
await user.click(screen.getByRole('button', { name: /Copy/ }))
|
||||
|
||||
expect(onCopyToClipboard).toHaveBeenCalledTimes(1)
|
||||
expect(onCopyToClipboard.mock.calls[0][0]).toContain(
|
||||
'# Full Report Content'
|
||||
)
|
||||
})
|
||||
|
||||
it('copies original details when copy button is clicked for validation error', async () => {
|
||||
const wrapper = mountCard(makeValidationErrorCard())
|
||||
await flushPromises()
|
||||
const { user, onCopyToClipboard } = renderCard(makeValidationErrorCard())
|
||||
|
||||
const copyButton = wrapper
|
||||
.findAll('button')
|
||||
.find((btn) => btn.text().includes('Copy'))!
|
||||
await copyButton.trigger('click')
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('Input: text')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
const emitted = wrapper.emitted('copyToClipboard')
|
||||
expect(emitted).toHaveLength(1)
|
||||
expect(emitted![0][0]).toBe('Required input is missing\n\nInput: text')
|
||||
await user.click(screen.getByRole('button', { name: /Copy/ }))
|
||||
|
||||
expect(onCopyToClipboard).toHaveBeenCalledTimes(1)
|
||||
expect(onCopyToClipboard.mock.calls[0][0]).toBe(
|
||||
'Required input is missing\n\nInput: text'
|
||||
)
|
||||
})
|
||||
|
||||
it('generates report with fallback logs when getLogs fails', async () => {
|
||||
mockGetLogs.mockRejectedValue(new Error('Network error'))
|
||||
|
||||
const wrapper = mountCard(makeRuntimeErrorCard())
|
||||
await flushPromises()
|
||||
renderCard(makeRuntimeErrorCard())
|
||||
|
||||
// Report is still generated with fallback log message
|
||||
expect(mockGenerateErrorReport).toHaveBeenCalledOnce()
|
||||
await waitFor(() => {
|
||||
expect(mockGenerateErrorReport).toHaveBeenCalledOnce()
|
||||
})
|
||||
expect(mockGenerateErrorReport).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
serverLogs: 'Failed to retrieve server logs'
|
||||
})
|
||||
)
|
||||
expect(wrapper.text()).toContain('ComfyUI Error Report')
|
||||
expect(screen.getByText(/ComfyUI Error Report/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('falls back to original details when generateErrorReport throws', async () => {
|
||||
@@ -250,24 +263,25 @@ describe('ErrorNodeCard.vue', () => {
|
||||
throw new Error('Serialization error')
|
||||
})
|
||||
|
||||
const wrapper = mountCard(makeRuntimeErrorCard())
|
||||
await flushPromises()
|
||||
renderCard(makeRuntimeErrorCard())
|
||||
|
||||
expect(wrapper.text()).toContain('Traceback line 1')
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText(/Traceback line 1/)).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('opens GitHub issues search when Find Issue button is clicked', async () => {
|
||||
const openSpy = vi.spyOn(window, 'open').mockImplementation(() => null)
|
||||
|
||||
const wrapper = mountCard(makeRuntimeErrorCard())
|
||||
await flushPromises()
|
||||
const { user } = renderCard(makeRuntimeErrorCard())
|
||||
|
||||
const findIssuesButton = wrapper
|
||||
.findAll('button')
|
||||
.find((btn) => btn.text().includes('Find on GitHub'))!
|
||||
expect(findIssuesButton.exists()).toBe(true)
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
screen.getByRole('button', { name: /Find on GitHub/ })
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
await findIssuesButton.trigger('click')
|
||||
await user.click(screen.getByRole('button', { name: /Find on GitHub/ }))
|
||||
|
||||
expect(openSpy).toHaveBeenCalledWith(
|
||||
expect.stringContaining('github.com/comfyanonymous/ComfyUI/issues?q='),
|
||||
@@ -284,15 +298,15 @@ describe('ErrorNodeCard.vue', () => {
|
||||
})
|
||||
|
||||
it('executes ContactSupport command when Get Help button is clicked', async () => {
|
||||
const wrapper = mountCard(makeRuntimeErrorCard())
|
||||
await flushPromises()
|
||||
const { user } = renderCard(makeRuntimeErrorCard())
|
||||
|
||||
const getHelpButton = wrapper
|
||||
.findAll('button')
|
||||
.find((btn) => btn.text().includes('Get Help'))!
|
||||
expect(getHelpButton.exists()).toBe(true)
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
screen.getByRole('button', { name: /Get Help/ })
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
await getHelpButton.trigger('click')
|
||||
await user.click(screen.getByRole('button', { name: /Get Help/ }))
|
||||
|
||||
expect(mockExecuteCommand).toHaveBeenCalledWith('Comfy.ContactSupport')
|
||||
expect(mockTrackHelpResourceClicked).toHaveBeenCalledWith(
|
||||
@@ -304,9 +318,11 @@ describe('ErrorNodeCard.vue', () => {
|
||||
})
|
||||
|
||||
it('passes exceptionType from error item to report generator', async () => {
|
||||
mountCard(makeRuntimeErrorCard())
|
||||
await flushPromises()
|
||||
renderCard(makeRuntimeErrorCard())
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockGenerateErrorReport).toHaveBeenCalledOnce()
|
||||
})
|
||||
expect(mockGenerateErrorReport).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
exceptionType: 'RuntimeError'
|
||||
@@ -329,9 +345,11 @@ describe('ErrorNodeCard.vue', () => {
|
||||
]
|
||||
}
|
||||
|
||||
mountCard(card)
|
||||
await flushPromises()
|
||||
renderCard(card)
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockGenerateErrorReport).toHaveBeenCalledOnce()
|
||||
})
|
||||
expect(mockGenerateErrorReport).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
exceptionType: 'Runtime Error'
|
||||
@@ -340,30 +358,16 @@ describe('ErrorNodeCard.vue', () => {
|
||||
})
|
||||
|
||||
it('falls back to original details when systemStats is unavailable', async () => {
|
||||
const wrapper = mount(ErrorNodeCard, {
|
||||
props: { card: makeRuntimeErrorCard() },
|
||||
global: {
|
||||
plugins: [
|
||||
PrimeVue,
|
||||
i18n,
|
||||
createTestingPinia({
|
||||
createSpy: vi.fn,
|
||||
initialState: {
|
||||
systemStats: { systemStats: null }
|
||||
}
|
||||
})
|
||||
],
|
||||
stubs: {
|
||||
Button: {
|
||||
template:
|
||||
'<button :aria-label="$attrs[\'aria-label\']"><slot /></button>'
|
||||
}
|
||||
}
|
||||
renderCard(makeRuntimeErrorCard(), {
|
||||
initialState: {
|
||||
systemStats: { systemStats: null }
|
||||
}
|
||||
})
|
||||
await flushPromises()
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText(/Traceback line 1/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
expect(mockGenerateErrorReport).not.toHaveBeenCalled()
|
||||
expect(wrapper.text()).toContain('Traceback line 1')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { createTestingPinia } from '@pinia/testing'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
@@ -68,7 +69,13 @@ vi.mock('@/workbench/extensions/manager/composables/useManagerState', () => ({
|
||||
vi.mock('./MissingPackGroupRow.vue', () => ({
|
||||
default: {
|
||||
name: 'MissingPackGroupRow',
|
||||
template: '<div class="pack-row" />',
|
||||
template: `<div class="pack-row" data-testid="pack-row"
|
||||
:data-show-info-button="String(showInfoButton)"
|
||||
:data-show-node-id-badge="String(showNodeIdBadge)"
|
||||
>
|
||||
<button data-testid="locate-node" @click="$emit('locate-node', group.nodeTypes[0]?.nodeId)" />
|
||||
<button data-testid="open-manager-info" @click="$emit('open-manager-info', group.packId)" />
|
||||
</div>`,
|
||||
props: ['group', 'showInfoButton', 'showNodeIdBadge'],
|
||||
emits: ['locate-node', 'open-manager-info']
|
||||
}
|
||||
@@ -95,7 +102,8 @@ const i18n = createI18n({
|
||||
'Some nodes require a newer version of ComfyUI (current: {version}).',
|
||||
outdatedVersionGeneric:
|
||||
'Some nodes require a newer version of ComfyUI.',
|
||||
coreNodesFromVersion: 'Requires ComfyUI {version}:'
|
||||
coreNodesFromVersion: 'Requires ComfyUI {version}:',
|
||||
unknownVersion: 'unknown'
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -113,14 +121,15 @@ function makePackGroups(count = 2): MissingPackGroup[] {
|
||||
}))
|
||||
}
|
||||
|
||||
function mountCard(
|
||||
function renderCard(
|
||||
props: Partial<{
|
||||
showInfoButton: boolean
|
||||
showNodeIdBadge: boolean
|
||||
missingPackGroups: MissingPackGroup[]
|
||||
}> = {}
|
||||
) {
|
||||
return mount(MissingNodeCard, {
|
||||
const user = userEvent.setup()
|
||||
const result = render(MissingNodeCard, {
|
||||
props: {
|
||||
showInfoButton: false,
|
||||
showNodeIdBadge: false,
|
||||
@@ -134,6 +143,7 @@ function mountCard(
|
||||
}
|
||||
}
|
||||
})
|
||||
return { ...result, user }
|
||||
}
|
||||
|
||||
describe('MissingNodeCard', () => {
|
||||
@@ -151,131 +161,163 @@ describe('MissingNodeCard', () => {
|
||||
describe('Rendering & Props', () => {
|
||||
it('renders cloud message when isCloud is true', () => {
|
||||
mockIsCloud.value = true
|
||||
const wrapper = mountCard()
|
||||
expect(wrapper.text()).toContain('Unsupported node packs detected')
|
||||
renderCard()
|
||||
expect(
|
||||
screen.getByText('Unsupported node packs detected.')
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders OSS message when isCloud is false', () => {
|
||||
const wrapper = mountCard()
|
||||
expect(wrapper.text()).toContain('Missing node packs detected')
|
||||
renderCard()
|
||||
expect(
|
||||
screen.getByText('Missing node packs detected. Install them.')
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders correct number of MissingPackGroupRow components', () => {
|
||||
const wrapper = mountCard({ missingPackGroups: makePackGroups(3) })
|
||||
expect(
|
||||
wrapper.findAllComponents({ name: 'MissingPackGroupRow' })
|
||||
).toHaveLength(3)
|
||||
renderCard({ missingPackGroups: makePackGroups(3) })
|
||||
expect(screen.getAllByTestId('pack-row')).toHaveLength(3)
|
||||
})
|
||||
|
||||
it('renders zero rows when missingPackGroups is empty', () => {
|
||||
const wrapper = mountCard({ missingPackGroups: [] })
|
||||
expect(
|
||||
wrapper.findAllComponents({ name: 'MissingPackGroupRow' })
|
||||
).toHaveLength(0)
|
||||
renderCard({ missingPackGroups: [] })
|
||||
expect(screen.queryAllByTestId('pack-row')).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('passes props correctly to MissingPackGroupRow children', () => {
|
||||
const wrapper = mountCard({
|
||||
renderCard({
|
||||
showInfoButton: true,
|
||||
showNodeIdBadge: true
|
||||
})
|
||||
const row = wrapper.findComponent({ name: 'MissingPackGroupRow' })
|
||||
expect(row.props('showInfoButton')).toBe(true)
|
||||
expect(row.props('showNodeIdBadge')).toBe(true)
|
||||
const row = screen.getAllByTestId('pack-row')[0]
|
||||
expect(row.getAttribute('data-show-info-button')).toBe('true')
|
||||
expect(row.getAttribute('data-show-node-id-badge')).toBe('true')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Manager Disabled Hint', () => {
|
||||
it('shows hint when OSS and manager is disabled (showInfoButton false)', () => {
|
||||
mockIsCloud.value = false
|
||||
const wrapper = mountCard({ showInfoButton: false })
|
||||
expect(wrapper.text()).toContain('pip install -U --pre comfyui-manager')
|
||||
expect(wrapper.text()).toContain('--enable-manager')
|
||||
renderCard({ showInfoButton: false })
|
||||
expect(
|
||||
screen.getByText('pip install -U --pre comfyui-manager')
|
||||
).toBeInTheDocument()
|
||||
expect(screen.getByText('--enable-manager')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('hides hint when manager is enabled (showInfoButton true)', () => {
|
||||
mockIsCloud.value = false
|
||||
const wrapper = mountCard({ showInfoButton: true })
|
||||
expect(wrapper.text()).not.toContain('--enable-manager')
|
||||
renderCard({ showInfoButton: true })
|
||||
expect(screen.queryByText('--enable-manager')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('hides hint on Cloud even when showInfoButton is false', () => {
|
||||
mockIsCloud.value = true
|
||||
const wrapper = mountCard({ showInfoButton: false })
|
||||
expect(wrapper.text()).not.toContain('--enable-manager')
|
||||
renderCard({ showInfoButton: false })
|
||||
expect(screen.queryByText('--enable-manager')).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Apply Changes Section', () => {
|
||||
it('hides Apply Changes when manager is not enabled', () => {
|
||||
mockShouldShowManagerButtons.value = false
|
||||
const wrapper = mountCard()
|
||||
expect(wrapper.text()).not.toContain('Apply Changes')
|
||||
renderCard()
|
||||
expect(screen.queryByText('Apply Changes')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('hides Apply Changes when manager enabled but no packs pending', () => {
|
||||
mockShouldShowManagerButtons.value = true
|
||||
mockIsPackInstalled.mockReturnValue(false)
|
||||
const wrapper = mountCard()
|
||||
expect(wrapper.text()).not.toContain('Apply Changes')
|
||||
renderCard()
|
||||
expect(screen.queryByText('Apply Changes')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows Apply Changes when at least one pack is pending restart', () => {
|
||||
mockShouldShowManagerButtons.value = true
|
||||
mockIsPackInstalled.mockReturnValue(true)
|
||||
const wrapper = mountCard()
|
||||
expect(wrapper.text()).toContain('Apply Changes')
|
||||
renderCard()
|
||||
expect(screen.getByText('Apply Changes')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('displays spinner during restart', () => {
|
||||
mockShouldShowManagerButtons.value = true
|
||||
mockIsPackInstalled.mockReturnValue(true)
|
||||
mockIsRestarting.value = true
|
||||
const wrapper = mountCard()
|
||||
expect(wrapper.find('[role="status"]').exists()).toBe(true)
|
||||
renderCard()
|
||||
expect(screen.getByRole('status')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('disables button during restart', () => {
|
||||
mockShouldShowManagerButtons.value = true
|
||||
mockIsPackInstalled.mockReturnValue(true)
|
||||
mockIsRestarting.value = true
|
||||
const wrapper = mountCard()
|
||||
const btn = wrapper.find('button')
|
||||
expect(btn.attributes('disabled')).toBeDefined()
|
||||
renderCard()
|
||||
expect(
|
||||
screen.getByRole('button', { name: /apply changes/i })
|
||||
).toBeDisabled()
|
||||
})
|
||||
|
||||
it('calls applyChanges when Apply Changes button is clicked', async () => {
|
||||
mockShouldShowManagerButtons.value = true
|
||||
mockIsPackInstalled.mockReturnValue(true)
|
||||
const wrapper = mountCard()
|
||||
const btn = wrapper.find('button')
|
||||
await btn.trigger('click')
|
||||
const { user } = renderCard()
|
||||
await user.click(screen.getByRole('button', { name: /apply changes/i }))
|
||||
expect(mockApplyChanges).toHaveBeenCalledOnce()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Event Handling', () => {
|
||||
it('emits locateNode when child emits locate-node', async () => {
|
||||
const wrapper = mountCard()
|
||||
const row = wrapper.findComponent({ name: 'MissingPackGroupRow' })
|
||||
await row.vm.$emit('locate-node', '42')
|
||||
expect(wrapper.emitted('locateNode')).toBeTruthy()
|
||||
expect(wrapper.emitted('locateNode')?.[0]).toEqual(['42'])
|
||||
const onLocateNode = vi.fn()
|
||||
const user = userEvent.setup()
|
||||
render(MissingNodeCard, {
|
||||
props: {
|
||||
showInfoButton: false,
|
||||
showNodeIdBadge: false,
|
||||
missingPackGroups: makePackGroups(),
|
||||
onLocateNode
|
||||
},
|
||||
global: {
|
||||
plugins: [createTestingPinia({ createSpy: vi.fn }), i18n],
|
||||
stubs: {
|
||||
DotSpinner: {
|
||||
template: '<span role="status" aria-label="loading" />'
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
await user.click(screen.getAllByTestId('locate-node')[0])
|
||||
expect(onLocateNode).toHaveBeenCalledWith('0')
|
||||
})
|
||||
|
||||
it('emits openManagerInfo when child emits open-manager-info', async () => {
|
||||
const wrapper = mountCard()
|
||||
const row = wrapper.findComponent({ name: 'MissingPackGroupRow' })
|
||||
await row.vm.$emit('open-manager-info', 'pack-0')
|
||||
expect(wrapper.emitted('openManagerInfo')).toBeTruthy()
|
||||
expect(wrapper.emitted('openManagerInfo')?.[0]).toEqual(['pack-0'])
|
||||
const onOpenManagerInfo = vi.fn()
|
||||
const user = userEvent.setup()
|
||||
render(MissingNodeCard, {
|
||||
props: {
|
||||
showInfoButton: false,
|
||||
showNodeIdBadge: false,
|
||||
missingPackGroups: makePackGroups(),
|
||||
onOpenManagerInfo
|
||||
},
|
||||
global: {
|
||||
plugins: [createTestingPinia({ createSpy: vi.fn }), i18n],
|
||||
stubs: {
|
||||
DotSpinner: {
|
||||
template: '<span role="status" aria-label="loading" />'
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
await user.click(screen.getAllByTestId('open-manager-info')[0])
|
||||
expect(onOpenManagerInfo).toHaveBeenCalledWith('pack-0')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Core Node Version Warning', () => {
|
||||
it('does not render warning when no missing core nodes', () => {
|
||||
const wrapper = mountCard()
|
||||
expect(wrapper.text()).not.toContain('newer version of ComfyUI')
|
||||
const { container } = renderCard()
|
||||
expect(container.textContent).not.toContain('newer version of ComfyUI')
|
||||
})
|
||||
|
||||
it('renders warning with version when missing core nodes exist', () => {
|
||||
@@ -283,20 +325,20 @@ describe('MissingNodeCard', () => {
|
||||
'1.2.0': [{ type: 'TestNode' }]
|
||||
}
|
||||
mockSystemStats.value = { system: { comfyui_version: '1.0.0' } }
|
||||
const wrapper = mountCard()
|
||||
expect(wrapper.text()).toContain('(current: 1.0.0)')
|
||||
expect(wrapper.text()).toContain('Requires ComfyUI 1.2.0:')
|
||||
expect(wrapper.text()).toContain('TestNode')
|
||||
const { container } = renderCard()
|
||||
expect(container.textContent).toContain('(current: 1.0.0)')
|
||||
expect(container.textContent).toContain('Requires ComfyUI 1.2.0:')
|
||||
expect(container.textContent).toContain('TestNode')
|
||||
})
|
||||
|
||||
it('renders generic message when version is unavailable', () => {
|
||||
mockMissingCoreNodes.value = {
|
||||
'1.2.0': [{ type: 'TestNode' }]
|
||||
}
|
||||
const wrapper = mountCard()
|
||||
expect(wrapper.text()).toContain(
|
||||
'Some nodes require a newer version of ComfyUI.'
|
||||
)
|
||||
renderCard()
|
||||
expect(
|
||||
screen.getByText('Some nodes require a newer version of ComfyUI.')
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('does not render warning on Cloud', () => {
|
||||
@@ -304,8 +346,8 @@ describe('MissingNodeCard', () => {
|
||||
mockMissingCoreNodes.value = {
|
||||
'1.2.0': [{ type: 'TestNode' }]
|
||||
}
|
||||
const wrapper = mountCard()
|
||||
expect(wrapper.text()).not.toContain('newer version of ComfyUI')
|
||||
const { container } = renderCard()
|
||||
expect(container.textContent).not.toContain('newer version of ComfyUI')
|
||||
})
|
||||
|
||||
it('deduplicates and sorts node names within a version', () => {
|
||||
@@ -316,9 +358,10 @@ describe('MissingNodeCard', () => {
|
||||
{ type: 'ZebraNode' }
|
||||
]
|
||||
}
|
||||
const wrapper = mountCard()
|
||||
expect(wrapper.text()).toContain('AlphaNode, ZebraNode')
|
||||
expect(wrapper.text().match(/ZebraNode/g)?.length).toBe(1)
|
||||
const { container } = renderCard()
|
||||
expect(container.textContent).toContain('AlphaNode, ZebraNode')
|
||||
// eslint-disable-next-line testing-library/no-container
|
||||
expect(container.textContent?.match(/ZebraNode/g)).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('sorts versions in descending order', () => {
|
||||
@@ -327,8 +370,8 @@ describe('MissingNodeCard', () => {
|
||||
'1.3.0': [{ type: 'Node3' }],
|
||||
'1.2.0': [{ type: 'Node2' }]
|
||||
}
|
||||
const wrapper = mountCard()
|
||||
const text = wrapper.text()
|
||||
const { container } = renderCard()
|
||||
const text = container.textContent ?? ''
|
||||
const v13 = text.indexOf('1.3.0')
|
||||
const v12 = text.indexOf('1.2.0')
|
||||
const v11 = text.indexOf('1.1.0')
|
||||
@@ -341,11 +384,11 @@ describe('MissingNodeCard', () => {
|
||||
'': [{ type: 'NoVersionNode' }],
|
||||
'1.2.0': [{ type: 'VersionedNode' }]
|
||||
}
|
||||
const wrapper = mountCard()
|
||||
expect(wrapper.text()).toContain('Requires ComfyUI 1.2.0:')
|
||||
expect(wrapper.text()).toContain('VersionedNode')
|
||||
expect(wrapper.text()).toContain('unknown')
|
||||
expect(wrapper.text()).toContain('NoVersionNode')
|
||||
const { container } = renderCard()
|
||||
expect(container.textContent).toContain('Requires ComfyUI 1.2.0:')
|
||||
expect(container.textContent).toContain('VersionedNode')
|
||||
expect(container.textContent).toContain('unknown')
|
||||
expect(container.textContent).toContain('NoVersionNode')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { createTestingPinia } from '@pinia/testing'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import PrimeVue from 'primevue/config'
|
||||
import { ref } from 'vue'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
@@ -95,18 +96,23 @@ function makeGroup(
|
||||
}
|
||||
}
|
||||
|
||||
function mountRow(
|
||||
function renderRow(
|
||||
props: Partial<{
|
||||
group: MissingPackGroup
|
||||
showInfoButton: boolean
|
||||
showNodeIdBadge: boolean
|
||||
}> = {}
|
||||
) {
|
||||
return mount(MissingPackGroupRow, {
|
||||
const user = userEvent.setup()
|
||||
const onLocateNode = vi.fn()
|
||||
const onOpenManagerInfo = vi.fn()
|
||||
render(MissingPackGroupRow, {
|
||||
props: {
|
||||
group: makeGroup(),
|
||||
showInfoButton: false,
|
||||
showNodeIdBadge: false,
|
||||
onLocateNode,
|
||||
onOpenManagerInfo,
|
||||
...props
|
||||
},
|
||||
global: {
|
||||
@@ -119,6 +125,7 @@ function mountRow(
|
||||
}
|
||||
}
|
||||
})
|
||||
return { user, onLocateNode, onOpenManagerInfo }
|
||||
}
|
||||
|
||||
describe('MissingPackGroupRow', () => {
|
||||
@@ -135,27 +142,27 @@ describe('MissingPackGroupRow', () => {
|
||||
|
||||
describe('Basic Rendering', () => {
|
||||
it('renders pack name from packId', () => {
|
||||
const wrapper = mountRow()
|
||||
expect(wrapper.text()).toContain('my-pack')
|
||||
renderRow()
|
||||
expect(screen.getByText(/my-pack/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders "Unknown pack" when packId is null', () => {
|
||||
const wrapper = mountRow({ group: makeGroup({ packId: null }) })
|
||||
expect(wrapper.text()).toContain('Unknown pack')
|
||||
renderRow({ group: makeGroup({ packId: null }) })
|
||||
expect(screen.getByText(/Unknown pack/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders loading text when isResolving is true', () => {
|
||||
const wrapper = mountRow({ group: makeGroup({ isResolving: true }) })
|
||||
expect(wrapper.text()).toContain('Loading')
|
||||
renderRow({ group: makeGroup({ isResolving: true }) })
|
||||
expect(screen.getByText(/Loading/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders node count', () => {
|
||||
const wrapper = mountRow()
|
||||
expect(wrapper.text()).toContain('(2)')
|
||||
renderRow()
|
||||
expect(screen.getByText(/\(2\)/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders count of 5 for 5 nodeTypes', () => {
|
||||
const wrapper = mountRow({
|
||||
renderRow({
|
||||
group: makeGroup({
|
||||
nodeTypes: Array.from({ length: 5 }, (_, i) => ({
|
||||
type: `Node${i}`,
|
||||
@@ -164,39 +171,39 @@ describe('MissingPackGroupRow', () => {
|
||||
}))
|
||||
})
|
||||
})
|
||||
expect(wrapper.text()).toContain('(5)')
|
||||
expect(screen.getByText(/\(5\)/)).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Expand / Collapse', () => {
|
||||
it('starts collapsed', () => {
|
||||
const wrapper = mountRow()
|
||||
expect(wrapper.text()).not.toContain('MissingA')
|
||||
renderRow()
|
||||
expect(screen.queryByText('MissingA')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('expands when chevron is clicked', async () => {
|
||||
const wrapper = mountRow()
|
||||
await wrapper.get('button[aria-label="Expand"]').trigger('click')
|
||||
expect(wrapper.text()).toContain('MissingA')
|
||||
expect(wrapper.text()).toContain('MissingB')
|
||||
const { user } = renderRow()
|
||||
await user.click(screen.getByRole('button', { name: 'Expand' }))
|
||||
expect(screen.getByText('MissingA')).toBeInTheDocument()
|
||||
expect(screen.getByText('MissingB')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('collapses when chevron is clicked again', async () => {
|
||||
const wrapper = mountRow()
|
||||
await wrapper.get('button[aria-label="Expand"]').trigger('click')
|
||||
expect(wrapper.text()).toContain('MissingA')
|
||||
await wrapper.get('button[aria-label="Collapse"]').trigger('click')
|
||||
expect(wrapper.text()).not.toContain('MissingA')
|
||||
const { user } = renderRow()
|
||||
await user.click(screen.getByRole('button', { name: 'Expand' }))
|
||||
expect(screen.getByText('MissingA')).toBeInTheDocument()
|
||||
await user.click(screen.getByRole('button', { name: 'Collapse' }))
|
||||
expect(screen.queryByText('MissingA')).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Node Type List', () => {
|
||||
async function expand(wrapper: ReturnType<typeof mountRow>) {
|
||||
await wrapper.get('button[aria-label="Expand"]').trigger('click')
|
||||
async function expand(user: ReturnType<typeof userEvent.setup>) {
|
||||
await user.click(screen.getByRole('button', { name: 'Expand' }))
|
||||
}
|
||||
|
||||
it('renders all nodeTypes when expanded', async () => {
|
||||
const wrapper = mountRow({
|
||||
const { user } = renderRow({
|
||||
group: makeGroup({
|
||||
nodeTypes: [
|
||||
{ type: 'NodeA', nodeId: '1', isReplaceable: false },
|
||||
@@ -205,48 +212,47 @@ describe('MissingPackGroupRow', () => {
|
||||
]
|
||||
})
|
||||
})
|
||||
await expand(wrapper)
|
||||
expect(wrapper.text()).toContain('NodeA')
|
||||
expect(wrapper.text()).toContain('NodeB')
|
||||
expect(wrapper.text()).toContain('NodeC')
|
||||
await expand(user)
|
||||
expect(screen.getByText('NodeA')).toBeInTheDocument()
|
||||
expect(screen.getByText('NodeB')).toBeInTheDocument()
|
||||
expect(screen.getByText('NodeC')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows nodeId badge when showNodeIdBadge is true', async () => {
|
||||
const wrapper = mountRow({ showNodeIdBadge: true })
|
||||
await expand(wrapper)
|
||||
expect(wrapper.text()).toContain('#10')
|
||||
const { user } = renderRow({ showNodeIdBadge: true })
|
||||
await expand(user)
|
||||
expect(screen.getByText('#10')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('hides nodeId badge when showNodeIdBadge is false', async () => {
|
||||
const wrapper = mountRow({ showNodeIdBadge: false })
|
||||
await expand(wrapper)
|
||||
expect(wrapper.text()).not.toContain('#10')
|
||||
const { user } = renderRow({ showNodeIdBadge: false })
|
||||
await expand(user)
|
||||
expect(screen.queryByText('#10')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('emits locateNode when Locate button is clicked', async () => {
|
||||
const wrapper = mountRow({ showNodeIdBadge: true })
|
||||
await expand(wrapper)
|
||||
await wrapper
|
||||
.get('button[aria-label="Locate node on canvas"]')
|
||||
.trigger('click')
|
||||
expect(wrapper.emitted('locateNode')).toBeTruthy()
|
||||
expect(wrapper.emitted('locateNode')?.[0]).toEqual(['10'])
|
||||
const { user, onLocateNode } = renderRow({ showNodeIdBadge: true })
|
||||
await expand(user)
|
||||
await user.click(
|
||||
screen.getAllByRole('button', { name: 'Locate node on canvas' })[0]
|
||||
)
|
||||
expect(onLocateNode).toHaveBeenCalledWith('10')
|
||||
})
|
||||
|
||||
it('does not show Locate for nodeType without nodeId', async () => {
|
||||
const wrapper = mountRow({
|
||||
const { user } = renderRow({
|
||||
group: makeGroup({
|
||||
nodeTypes: [{ type: 'NoId', isReplaceable: false } as never]
|
||||
})
|
||||
})
|
||||
await expand(wrapper)
|
||||
await expand(user)
|
||||
expect(
|
||||
wrapper.find('button[aria-label="Locate node on canvas"]').exists()
|
||||
).toBe(false)
|
||||
screen.queryByRole('button', { name: 'Locate node on canvas' })
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('handles mixed nodeTypes with and without nodeId', async () => {
|
||||
const wrapper = mountRow({
|
||||
const { user } = renderRow({
|
||||
showNodeIdBadge: true,
|
||||
group: makeGroup({
|
||||
nodeTypes: [
|
||||
@@ -255,11 +261,11 @@ describe('MissingPackGroupRow', () => {
|
||||
]
|
||||
})
|
||||
})
|
||||
await expand(wrapper)
|
||||
expect(wrapper.text()).toContain('WithId')
|
||||
expect(wrapper.text()).toContain('WithoutId')
|
||||
await expand(user)
|
||||
expect(screen.getByText('WithId')).toBeInTheDocument()
|
||||
expect(screen.getByText('WithoutId')).toBeInTheDocument()
|
||||
expect(
|
||||
wrapper.findAll('button[aria-label="Locate node on canvas"]')
|
||||
screen.getAllByRole('button', { name: 'Locate node on canvas' })
|
||||
).toHaveLength(1)
|
||||
})
|
||||
})
|
||||
@@ -267,102 +273,103 @@ describe('MissingPackGroupRow', () => {
|
||||
describe('Manager Integration', () => {
|
||||
it('hides install UI when shouldShowManagerButtons is false', () => {
|
||||
mockShouldShowManagerButtons.value = false
|
||||
const wrapper = mountRow()
|
||||
expect(wrapper.text()).not.toContain('Install node pack')
|
||||
renderRow()
|
||||
expect(screen.queryByText('Install node pack')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('hides install UI when packId is null', () => {
|
||||
mockShouldShowManagerButtons.value = true
|
||||
const wrapper = mountRow({ group: makeGroup({ packId: null }) })
|
||||
expect(wrapper.text()).not.toContain('Install node pack')
|
||||
renderRow({ group: makeGroup({ packId: null }) })
|
||||
expect(screen.queryByText('Install node pack')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows "Search in Node Manager" when packId exists but pack not in registry', () => {
|
||||
mockShouldShowManagerButtons.value = true
|
||||
mockIsPackInstalled.mockReturnValue(false)
|
||||
mockMissingNodePacks.value = []
|
||||
const wrapper = mountRow()
|
||||
expect(wrapper.text()).toContain('Search in Node Manager')
|
||||
renderRow()
|
||||
expect(screen.getByText('Search in Node Manager')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows "Installed" state when pack is installed', () => {
|
||||
mockShouldShowManagerButtons.value = true
|
||||
mockIsPackInstalled.mockReturnValue(true)
|
||||
mockMissingNodePacks.value = [{ id: 'my-pack', name: 'My Pack' }]
|
||||
const wrapper = mountRow()
|
||||
expect(wrapper.text()).toContain('Installed')
|
||||
renderRow()
|
||||
expect(screen.getByText('Installed')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows spinner when installing', () => {
|
||||
mockShouldShowManagerButtons.value = true
|
||||
mockIsInstalling.value = true
|
||||
mockMissingNodePacks.value = [{ id: 'my-pack', name: 'My Pack' }]
|
||||
const wrapper = mountRow()
|
||||
expect(wrapper.find('[role="status"]').exists()).toBe(true)
|
||||
renderRow()
|
||||
expect(screen.getByRole('status')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows install button when not installed and pack found', () => {
|
||||
mockShouldShowManagerButtons.value = true
|
||||
mockIsPackInstalled.mockReturnValue(false)
|
||||
mockMissingNodePacks.value = [{ id: 'my-pack', name: 'My Pack' }]
|
||||
const wrapper = mountRow()
|
||||
expect(wrapper.text()).toContain('Install node pack')
|
||||
renderRow()
|
||||
expect(screen.getByText('Install node pack')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('calls installAllPacks when Install button is clicked', async () => {
|
||||
mockShouldShowManagerButtons.value = true
|
||||
mockIsPackInstalled.mockReturnValue(false)
|
||||
mockMissingNodePacks.value = [{ id: 'my-pack', name: 'My Pack' }]
|
||||
const wrapper = mountRow()
|
||||
await wrapper.get('button:not([aria-label])').trigger('click')
|
||||
const { user } = renderRow()
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: /Install node pack/ })
|
||||
)
|
||||
expect(mockInstallAllPacks).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it('shows loading spinner when registry is loading', () => {
|
||||
mockShouldShowManagerButtons.value = true
|
||||
mockIsLoading.value = true
|
||||
const wrapper = mountRow()
|
||||
expect(wrapper.find('[role="status"]').exists()).toBe(true)
|
||||
renderRow()
|
||||
expect(screen.getByRole('status')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Info Button', () => {
|
||||
it('shows Info button when showInfoButton true and packId not null', () => {
|
||||
const wrapper = mountRow({ showInfoButton: true })
|
||||
renderRow({ showInfoButton: true })
|
||||
expect(
|
||||
wrapper.find('button[aria-label="View in Manager"]').exists()
|
||||
).toBe(true)
|
||||
screen.getByRole('button', { name: 'View in Manager' })
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('hides Info button when showInfoButton is false', () => {
|
||||
const wrapper = mountRow({ showInfoButton: false })
|
||||
renderRow({ showInfoButton: false })
|
||||
expect(
|
||||
wrapper.find('button[aria-label="View in Manager"]').exists()
|
||||
).toBe(false)
|
||||
screen.queryByRole('button', { name: 'View in Manager' })
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('hides Info button when packId is null', () => {
|
||||
const wrapper = mountRow({
|
||||
renderRow({
|
||||
showInfoButton: true,
|
||||
group: makeGroup({ packId: null })
|
||||
})
|
||||
expect(
|
||||
wrapper.find('button[aria-label="View in Manager"]').exists()
|
||||
).toBe(false)
|
||||
screen.queryByRole('button', { name: 'View in Manager' })
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('emits openManagerInfo when Info button is clicked', async () => {
|
||||
const wrapper = mountRow({ showInfoButton: true })
|
||||
await wrapper.get('button[aria-label="View in Manager"]').trigger('click')
|
||||
expect(wrapper.emitted('openManagerInfo')).toBeTruthy()
|
||||
expect(wrapper.emitted('openManagerInfo')?.[0]).toEqual(['my-pack'])
|
||||
const { user, onOpenManagerInfo } = renderRow({ showInfoButton: true })
|
||||
await user.click(screen.getByRole('button', { name: 'View in Manager' }))
|
||||
expect(onOpenManagerInfo).toHaveBeenCalledWith('my-pack')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Edge Cases', () => {
|
||||
it('handles empty nodeTypes array', () => {
|
||||
const wrapper = mountRow({ group: makeGroup({ nodeTypes: [] }) })
|
||||
expect(wrapper.text()).toContain('(0)')
|
||||
renderRow({ group: makeGroup({ nodeTypes: [] }) })
|
||||
expect(screen.getByText(/\(0\)/)).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { createTestingPinia } from '@pinia/testing'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import PrimeVue from 'primevue/config'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
import TabErrors from './TabErrors.vue'
|
||||
|
||||
// Mock dependencies
|
||||
vi.mock('@/scripts/app', () => ({
|
||||
app: {
|
||||
rootGraph: {
|
||||
@@ -61,8 +61,9 @@ describe('TabErrors.vue', () => {
|
||||
})
|
||||
})
|
||||
|
||||
function mountComponent(initialState = {}) {
|
||||
return mount(TabErrors, {
|
||||
function renderComponent(initialState = {}) {
|
||||
const user = userEvent.setup()
|
||||
render(TabErrors, {
|
||||
global: {
|
||||
plugins: [
|
||||
PrimeVue,
|
||||
@@ -86,15 +87,16 @@ describe('TabErrors.vue', () => {
|
||||
}
|
||||
}
|
||||
})
|
||||
return { user }
|
||||
}
|
||||
|
||||
it('renders "no errors" state when store is empty', () => {
|
||||
const wrapper = mountComponent()
|
||||
expect(wrapper.text()).toContain('No errors')
|
||||
renderComponent()
|
||||
expect(screen.getByText('No errors')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders prompt-level errors (Group title = error message)', async () => {
|
||||
const wrapper = mountComponent({
|
||||
renderComponent({
|
||||
executionError: {
|
||||
lastPromptError: {
|
||||
type: 'prompt_no_outputs',
|
||||
@@ -104,12 +106,9 @@ describe('TabErrors.vue', () => {
|
||||
}
|
||||
})
|
||||
|
||||
// Group title should be the raw message from store
|
||||
expect(wrapper.text()).toContain('Server Error: No outputs')
|
||||
// Item message should be localized desc
|
||||
expect(wrapper.text()).toContain('Prompt has no outputs')
|
||||
// Details should not be rendered for prompt errors
|
||||
expect(wrapper.text()).not.toContain('Error details')
|
||||
expect(screen.getByText('Server Error: No outputs')).toBeInTheDocument()
|
||||
expect(screen.getByText('Prompt has no outputs')).toBeInTheDocument()
|
||||
expect(screen.queryByText('Error details')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders node validation errors grouped by class_type', async () => {
|
||||
@@ -118,7 +117,7 @@ describe('TabErrors.vue', () => {
|
||||
title: 'CLIP Text Encode'
|
||||
} as ReturnType<typeof getNodeByExecutionId>)
|
||||
|
||||
const wrapper = mountComponent({
|
||||
renderComponent({
|
||||
executionError: {
|
||||
lastNodeErrors: {
|
||||
'6': {
|
||||
@@ -131,10 +130,10 @@ describe('TabErrors.vue', () => {
|
||||
}
|
||||
})
|
||||
|
||||
expect(wrapper.text()).toContain('CLIPTextEncode')
|
||||
expect(wrapper.text()).toContain('#6')
|
||||
expect(wrapper.text()).toContain('CLIP Text Encode')
|
||||
expect(wrapper.text()).toContain('Required input is missing')
|
||||
expect(screen.getByText('CLIPTextEncode')).toBeInTheDocument()
|
||||
expect(screen.getByText('#6')).toBeInTheDocument()
|
||||
expect(screen.getByText('CLIP Text Encode')).toBeInTheDocument()
|
||||
expect(screen.getByText('Required input is missing')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders runtime execution errors from WebSocket', async () => {
|
||||
@@ -143,7 +142,7 @@ describe('TabErrors.vue', () => {
|
||||
title: 'KSampler'
|
||||
} as ReturnType<typeof getNodeByExecutionId>)
|
||||
|
||||
const wrapper = mountComponent({
|
||||
renderComponent({
|
||||
executionError: {
|
||||
lastExecutionError: {
|
||||
prompt_id: 'abc',
|
||||
@@ -157,17 +156,17 @@ describe('TabErrors.vue', () => {
|
||||
}
|
||||
})
|
||||
|
||||
expect(wrapper.text()).toContain('KSampler')
|
||||
expect(wrapper.text()).toContain('#10')
|
||||
expect(wrapper.text()).toContain('RuntimeError: Out of memory')
|
||||
expect(wrapper.text()).toContain('Line 1')
|
||||
expect(screen.getAllByText('KSampler').length).toBeGreaterThanOrEqual(1)
|
||||
expect(screen.getByText('#10')).toBeInTheDocument()
|
||||
expect(screen.getByText('RuntimeError: Out of memory')).toBeInTheDocument()
|
||||
expect(screen.getByText(/Line 1/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('filters errors based on search query', async () => {
|
||||
const { getNodeByExecutionId } = await import('@/utils/graphTraversalUtil')
|
||||
vi.mocked(getNodeByExecutionId).mockReturnValue(null)
|
||||
|
||||
const wrapper = mountComponent({
|
||||
const { user } = renderComponent({
|
||||
executionError: {
|
||||
lastNodeErrors: {
|
||||
'1': {
|
||||
@@ -182,14 +181,17 @@ describe('TabErrors.vue', () => {
|
||||
}
|
||||
})
|
||||
|
||||
expect(wrapper.text()).toContain('CLIPTextEncode')
|
||||
expect(wrapper.text()).toContain('KSampler')
|
||||
expect(screen.getAllByText('CLIPTextEncode').length).toBeGreaterThanOrEqual(
|
||||
1
|
||||
)
|
||||
expect(screen.getAllByText('KSampler').length).toBeGreaterThanOrEqual(1)
|
||||
|
||||
const searchInput = wrapper.find('input')
|
||||
await searchInput.setValue('Missing text input')
|
||||
await user.type(screen.getByRole('textbox'), 'Missing text input')
|
||||
|
||||
expect(wrapper.text()).toContain('CLIPTextEncode')
|
||||
expect(wrapper.text()).not.toContain('KSampler')
|
||||
expect(screen.getAllByText('CLIPTextEncode').length).toBeGreaterThanOrEqual(
|
||||
1
|
||||
)
|
||||
expect(screen.queryByText('KSampler')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('calls copyToClipboard when copy button is clicked', async () => {
|
||||
@@ -198,7 +200,7 @@ describe('TabErrors.vue', () => {
|
||||
const mockCopy = vi.fn()
|
||||
vi.mocked(useCopyToClipboard).mockReturnValue({ copyToClipboard: mockCopy })
|
||||
|
||||
const wrapper = mountComponent({
|
||||
const { user } = renderComponent({
|
||||
executionError: {
|
||||
lastNodeErrors: {
|
||||
'1': {
|
||||
@@ -209,9 +211,7 @@ describe('TabErrors.vue', () => {
|
||||
}
|
||||
})
|
||||
|
||||
const copyButton = wrapper.find('[data-testid="error-card-copy"]')
|
||||
expect(copyButton.exists()).toBe(true)
|
||||
await copyButton.trigger('click')
|
||||
await user.click(screen.getByTestId('error-card-copy'))
|
||||
|
||||
expect(mockCopy).toHaveBeenCalledWith('Test message\n\nTest details')
|
||||
})
|
||||
@@ -222,7 +222,7 @@ describe('TabErrors.vue', () => {
|
||||
title: 'KSampler'
|
||||
} as ReturnType<typeof getNodeByExecutionId>)
|
||||
|
||||
const wrapper = mountComponent({
|
||||
renderComponent({
|
||||
executionError: {
|
||||
lastExecutionError: {
|
||||
prompt_id: 'abc',
|
||||
@@ -236,15 +236,9 @@ describe('TabErrors.vue', () => {
|
||||
}
|
||||
})
|
||||
|
||||
// Runtime error panel title should show class type
|
||||
expect(wrapper.text()).toContain('KSampler')
|
||||
expect(wrapper.text()).toContain('RuntimeError: Out of memory')
|
||||
// Should render in the dedicated runtime error panel, not inside accordion
|
||||
const runtimePanel = wrapper.find('[data-testid="runtime-error-panel"]')
|
||||
expect(runtimePanel.exists()).toBe(true)
|
||||
// Verify the error message appears exactly once (not duplicated in accordion)
|
||||
expect(
|
||||
wrapper.text().match(/RuntimeError: Out of memory/g) ?? []
|
||||
).toHaveLength(1)
|
||||
expect(screen.getAllByText('KSampler').length).toBeGreaterThanOrEqual(1)
|
||||
expect(screen.getByText('RuntimeError: Out of memory')).toBeInTheDocument()
|
||||
expect(screen.getByTestId('runtime-error-panel')).toBeInTheDocument()
|
||||
expect(screen.getAllByText('RuntimeError: Out of memory')).toHaveLength(1)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { createTestingPinia } from '@pinia/testing'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { fromAny } from '@total-typescript/shoehorn'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { setActivePinia } from 'pinia'
|
||||
import type { Slots } from 'vue'
|
||||
import { h } from 'vue'
|
||||
@@ -103,58 +104,56 @@ describe('WidgetActions', () => {
|
||||
})
|
||||
}
|
||||
|
||||
function mountWidgetActions(widget: IBaseWidget, node: LGraphNode) {
|
||||
return mount(WidgetActions, {
|
||||
function renderWidgetActions(
|
||||
widget: IBaseWidget,
|
||||
node: LGraphNode,
|
||||
extraProps: Record<string, unknown> = {}
|
||||
) {
|
||||
const user = userEvent.setup()
|
||||
const onResetToDefault = vi.fn()
|
||||
render(WidgetActions, {
|
||||
props: {
|
||||
widget,
|
||||
node,
|
||||
label: 'Test Widget'
|
||||
label: 'Test Widget',
|
||||
onResetToDefault,
|
||||
...extraProps
|
||||
},
|
||||
global: {
|
||||
plugins: [i18n]
|
||||
}
|
||||
})
|
||||
return { user, onResetToDefault }
|
||||
}
|
||||
|
||||
it('shows reset button when widget has default value', () => {
|
||||
const widget = createMockWidget()
|
||||
const node = createMockNode()
|
||||
|
||||
const wrapper = mountWidgetActions(widget, node)
|
||||
renderWidgetActions(widget, node)
|
||||
|
||||
const resetButton = wrapper
|
||||
.findAll('button')
|
||||
.find((b) => b.text().includes('Reset'))
|
||||
expect(resetButton).toBeDefined()
|
||||
expect(screen.getByRole('button', { name: /Reset/ })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('emits resetToDefault with default value when reset button clicked', async () => {
|
||||
const widget = createMockWidget(100)
|
||||
const node = createMockNode()
|
||||
|
||||
const wrapper = mountWidgetActions(widget, node)
|
||||
const { user, onResetToDefault } = renderWidgetActions(widget, node)
|
||||
|
||||
const resetButton = wrapper
|
||||
.findAll('button')
|
||||
.find((b) => b.text().includes('Reset'))
|
||||
await user.click(screen.getByRole('button', { name: /Reset/ }))
|
||||
|
||||
await resetButton?.trigger('click')
|
||||
|
||||
expect(wrapper.emitted('resetToDefault')).toHaveLength(1)
|
||||
expect(wrapper.emitted('resetToDefault')![0]).toEqual([42])
|
||||
expect(onResetToDefault).toHaveBeenCalledTimes(1)
|
||||
expect(onResetToDefault).toHaveBeenCalledWith(42)
|
||||
})
|
||||
|
||||
it('disables reset button when value equals default', () => {
|
||||
const widget = createMockWidget(42)
|
||||
const node = createMockNode()
|
||||
|
||||
const wrapper = mountWidgetActions(widget, node)
|
||||
renderWidgetActions(widget, node)
|
||||
|
||||
const resetButton = wrapper
|
||||
.findAll('button')
|
||||
.find((b) => b.text().includes('Reset'))
|
||||
|
||||
expect(resetButton?.attributes('disabled')).toBeDefined()
|
||||
expect(screen.getByRole('button', { name: /Reset/ })).toBeDisabled()
|
||||
})
|
||||
|
||||
it('does not show reset button when no default value exists', () => {
|
||||
@@ -165,13 +164,11 @@ describe('WidgetActions', () => {
|
||||
const widget = createMockWidget(100)
|
||||
const node = createMockNode()
|
||||
|
||||
const wrapper = mountWidgetActions(widget, node)
|
||||
renderWidgetActions(widget, node)
|
||||
|
||||
const resetButton = wrapper
|
||||
.findAll('button')
|
||||
.find((b) => b.text().includes('Reset'))
|
||||
|
||||
expect(resetButton).toBeUndefined()
|
||||
expect(
|
||||
screen.queryByRole('button', { name: /Reset/ })
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('uses fallback default for INT type without explicit default', async () => {
|
||||
@@ -182,15 +179,11 @@ describe('WidgetActions', () => {
|
||||
const widget = createMockWidget(100)
|
||||
const node = createMockNode()
|
||||
|
||||
const wrapper = mountWidgetActions(widget, node)
|
||||
const { user, onResetToDefault } = renderWidgetActions(widget, node)
|
||||
|
||||
const resetButton = wrapper
|
||||
.findAll('button')
|
||||
.find((b) => b.text().includes('Reset'))
|
||||
await user.click(screen.getByRole('button', { name: /Reset/ }))
|
||||
|
||||
await resetButton?.trigger('click')
|
||||
|
||||
expect(wrapper.emitted('resetToDefault')![0]).toEqual([0])
|
||||
expect(onResetToDefault).toHaveBeenCalledWith(0)
|
||||
})
|
||||
|
||||
it('uses first option as default for combo without explicit default', async () => {
|
||||
@@ -202,15 +195,11 @@ describe('WidgetActions', () => {
|
||||
const widget = createMockWidget(100)
|
||||
const node = createMockNode()
|
||||
|
||||
const wrapper = mountWidgetActions(widget, node)
|
||||
const { user, onResetToDefault } = renderWidgetActions(widget, node)
|
||||
|
||||
const resetButton = wrapper
|
||||
.findAll('button')
|
||||
.find((b) => b.text().includes('Reset'))
|
||||
await user.click(screen.getByRole('button', { name: /Reset/ }))
|
||||
|
||||
await resetButton?.trigger('click')
|
||||
|
||||
expect(wrapper.emitted('resetToDefault')![0]).toEqual(['option1'])
|
||||
expect(onResetToDefault).toHaveBeenCalledWith('option1')
|
||||
})
|
||||
|
||||
it('demotes promoted widgets by immediate interior node identity when shown from parent context', async () => {
|
||||
@@ -248,7 +237,8 @@ describe('WidgetActions', () => {
|
||||
disambiguatingSourceNodeId: '1'
|
||||
})
|
||||
|
||||
const wrapper = mount(WidgetActions, {
|
||||
const user = userEvent.setup()
|
||||
render(WidgetActions, {
|
||||
props: {
|
||||
widget,
|
||||
node,
|
||||
@@ -261,11 +251,7 @@ describe('WidgetActions', () => {
|
||||
}
|
||||
})
|
||||
|
||||
const hideButton = wrapper
|
||||
.findAll('button')
|
||||
.find((button) => button.text().includes('Hide input'))
|
||||
expect(hideButton).toBeDefined()
|
||||
await hideButton?.trigger('click')
|
||||
await user.click(screen.getByRole('button', { name: /Hide input/ }))
|
||||
|
||||
expect(
|
||||
promotionStore.isPromoted('graph-test', 4, {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { createTestingPinia } from '@pinia/testing'
|
||||
import { render } from '@testing-library/vue'
|
||||
import { fromAny } from '@total-typescript/shoehorn'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { setActivePinia } from 'pinia'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
@@ -14,7 +14,8 @@ const { mockGetInputSpecForWidget, StubWidgetComponent } = vi.hoisted(() => ({
|
||||
StubWidgetComponent: {
|
||||
name: 'StubWidget',
|
||||
props: ['widget', 'modelValue', 'nodeId', 'nodeType'],
|
||||
template: '<div class="stub-widget" />'
|
||||
template:
|
||||
'<div class="stub-widget" :data-widget-options="JSON.stringify(widget?.options)" :data-widget-type="widget?.type" :data-widget-name="widget?.name" :data-widget-value="String(widget?.value)" />'
|
||||
}
|
||||
}))
|
||||
|
||||
@@ -132,11 +133,11 @@ function createMockPromotedWidgetView(
|
||||
return fromAny<IBaseWidget, unknown>(new MockPromotedWidgetView())
|
||||
}
|
||||
|
||||
function mountWidgetItem(
|
||||
function renderWidgetItem(
|
||||
widget: IBaseWidget,
|
||||
node: LGraphNode = createMockNode()
|
||||
) {
|
||||
return mount(WidgetItem, {
|
||||
return render(WidgetItem, {
|
||||
props: { widget, node },
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
@@ -148,6 +149,18 @@ function mountWidgetItem(
|
||||
})
|
||||
}
|
||||
|
||||
function getStubWidget(container: Element) {
|
||||
// eslint-disable-next-line testing-library/no-node-access
|
||||
const el = container.querySelector('.stub-widget')
|
||||
if (!el) throw new Error('stub-widget not found')
|
||||
return {
|
||||
options: JSON.parse(el.getAttribute('data-widget-options') ?? 'null'),
|
||||
type: el.getAttribute('data-widget-type'),
|
||||
name: el.getAttribute('data-widget-name'),
|
||||
value: el.getAttribute('data-widget-value')
|
||||
}
|
||||
}
|
||||
|
||||
describe('WidgetItem', () => {
|
||||
beforeEach(() => {
|
||||
setActivePinia(createTestingPinia({ stubActions: false }))
|
||||
@@ -159,10 +172,10 @@ describe('WidgetItem', () => {
|
||||
const widget = createMockWidget({
|
||||
options: { values: ['a', 'b', 'c'] }
|
||||
})
|
||||
const wrapper = mountWidgetItem(widget)
|
||||
const stub = wrapper.findComponent(StubWidgetComponent)
|
||||
const { container } = renderWidgetItem(widget)
|
||||
const stub = getStubWidget(container)
|
||||
|
||||
expect(stub.props('widget').options).toEqual({
|
||||
expect(stub.options).toEqual({
|
||||
values: ['a', 'b', 'c']
|
||||
})
|
||||
})
|
||||
@@ -172,34 +185,34 @@ describe('WidgetItem', () => {
|
||||
values: ['model_a.safetensors', 'model_b.safetensors']
|
||||
}
|
||||
const widget = createMockPromotedWidgetView(expectedOptions)
|
||||
const wrapper = mountWidgetItem(widget)
|
||||
const stub = wrapper.findComponent(StubWidgetComponent)
|
||||
const { container } = renderWidgetItem(widget)
|
||||
const stub = getStubWidget(container)
|
||||
|
||||
expect(stub.props('widget').options).toEqual(expectedOptions)
|
||||
expect(stub.options).toEqual(expectedOptions)
|
||||
})
|
||||
|
||||
it('passes type from a PromotedWidgetView to the widget component', () => {
|
||||
const widget = createMockPromotedWidgetView()
|
||||
const wrapper = mountWidgetItem(widget)
|
||||
const stub = wrapper.findComponent(StubWidgetComponent)
|
||||
const { container } = renderWidgetItem(widget)
|
||||
const stub = getStubWidget(container)
|
||||
|
||||
expect(stub.props('widget').type).toBe('combo')
|
||||
expect(stub.type).toBe('combo')
|
||||
})
|
||||
|
||||
it('passes name from a PromotedWidgetView to the widget component', () => {
|
||||
const widget = createMockPromotedWidgetView()
|
||||
const wrapper = mountWidgetItem(widget)
|
||||
const stub = wrapper.findComponent(StubWidgetComponent)
|
||||
const { container } = renderWidgetItem(widget)
|
||||
const stub = getStubWidget(container)
|
||||
|
||||
expect(stub.props('widget').name).toBe('ckpt_name')
|
||||
expect(stub.name).toBe('ckpt_name')
|
||||
})
|
||||
|
||||
it('passes value from a PromotedWidgetView to the widget component', () => {
|
||||
const widget = createMockPromotedWidgetView()
|
||||
const wrapper = mountWidgetItem(widget)
|
||||
const stub = wrapper.findComponent(StubWidgetComponent)
|
||||
const { container } = renderWidgetItem(widget)
|
||||
const stub = getStubWidget(container)
|
||||
|
||||
expect(stub.props('widget').value).toBe('model_a.safetensors')
|
||||
expect(stub.value).toBe('model_a.safetensors')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen, waitFor } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { nextTick } from 'vue'
|
||||
|
||||
@@ -23,25 +24,48 @@ describe('NodeSearchCategorySidebar', () => {
|
||||
setupTestPinia()
|
||||
})
|
||||
|
||||
async function createWrapper(props = {}) {
|
||||
const wrapper = mount(NodeSearchCategorySidebar, {
|
||||
props: { selectedCategory: 'most-relevant', ...props },
|
||||
async function createRender(props = {}) {
|
||||
const user = userEvent.setup()
|
||||
const onUpdateSelectedCategory = vi.fn()
|
||||
const baseProps = { selectedCategory: 'most-relevant', ...props }
|
||||
|
||||
let currentProps = { ...baseProps }
|
||||
let rerenderFn: (
|
||||
p: typeof baseProps & Record<string, unknown>
|
||||
) => void = () => {}
|
||||
|
||||
function makeProps(overrides = {}) {
|
||||
const merged = { ...currentProps, ...overrides }
|
||||
return {
|
||||
...merged,
|
||||
'onUpdate:selectedCategory': (val: string) => {
|
||||
onUpdateSelectedCategory(val)
|
||||
currentProps = { ...currentProps, selectedCategory: val }
|
||||
rerenderFn(makeProps())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const result = render(NodeSearchCategorySidebar, {
|
||||
props: makeProps(),
|
||||
global: { plugins: [testI18n] }
|
||||
})
|
||||
rerenderFn = (p) => result.rerender(p)
|
||||
await nextTick()
|
||||
return wrapper
|
||||
return { user, onUpdateSelectedCategory }
|
||||
}
|
||||
|
||||
async function clickCategory(
|
||||
wrapper: ReturnType<typeof mount>,
|
||||
user: ReturnType<typeof userEvent.setup>,
|
||||
text: string,
|
||||
exact = false
|
||||
) {
|
||||
const btn = wrapper
|
||||
.findAll('button')
|
||||
.find((b) => (exact ? b.text().trim() === text : b.text().includes(text)))
|
||||
const buttons = screen.getAllByRole('button')
|
||||
const btn = buttons.find((b) =>
|
||||
exact ? b.textContent?.trim() === text : b.textContent?.includes(text)
|
||||
)
|
||||
expect(btn, `Expected to find a button with text "${text}"`).toBeDefined()
|
||||
await btn!.trigger('click')
|
||||
await user.click(btn!)
|
||||
await nextTick()
|
||||
}
|
||||
|
||||
@@ -56,37 +80,35 @@ describe('NodeSearchCategorySidebar', () => {
|
||||
])
|
||||
await nextTick()
|
||||
|
||||
const wrapper = await createWrapper()
|
||||
await createRender()
|
||||
|
||||
expect(wrapper.text()).toContain('Most relevant')
|
||||
expect(wrapper.text()).toContain('Recents')
|
||||
expect(wrapper.text()).toContain('Favorites')
|
||||
expect(wrapper.text()).toContain('Essentials')
|
||||
expect(wrapper.text()).toContain('Blueprints')
|
||||
expect(wrapper.text()).toContain('Partner')
|
||||
expect(wrapper.text()).toContain('Comfy')
|
||||
expect(wrapper.text()).toContain('Extensions')
|
||||
expect(screen.getByText('Most relevant')).toBeInTheDocument()
|
||||
expect(screen.getByText('Recents')).toBeInTheDocument()
|
||||
expect(screen.getByText('Favorites')).toBeInTheDocument()
|
||||
expect(screen.getByText('Essentials')).toBeInTheDocument()
|
||||
expect(screen.getByText('Blueprints')).toBeInTheDocument()
|
||||
expect(screen.getByText('Partner')).toBeInTheDocument()
|
||||
expect(screen.getByText('Comfy')).toBeInTheDocument()
|
||||
expect(screen.getByText('Extensions')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should mark the selected preset category as selected', async () => {
|
||||
const wrapper = await createWrapper({ selectedCategory: 'most-relevant' })
|
||||
await createRender({ selectedCategory: 'most-relevant' })
|
||||
|
||||
const mostRelevantBtn = wrapper.find(
|
||||
'[data-testid="category-most-relevant"]'
|
||||
expect(screen.getByTestId('category-most-relevant')).toHaveAttribute(
|
||||
'aria-current',
|
||||
'true'
|
||||
)
|
||||
|
||||
expect(mostRelevantBtn.attributes('aria-current')).toBe('true')
|
||||
})
|
||||
|
||||
it('should emit update:selectedCategory when preset is clicked', async () => {
|
||||
const wrapper = await createWrapper({ selectedCategory: 'most-relevant' })
|
||||
const { user, onUpdateSelectedCategory } = await createRender({
|
||||
selectedCategory: 'most-relevant'
|
||||
})
|
||||
|
||||
await clickCategory(wrapper, 'Favorites')
|
||||
await clickCategory(user, 'Favorites')
|
||||
|
||||
expect(wrapper.emitted('update:selectedCategory')).toBeTruthy()
|
||||
expect(wrapper.emitted('update:selectedCategory')![0]).toEqual([
|
||||
'favorites'
|
||||
])
|
||||
expect(onUpdateSelectedCategory).toHaveBeenCalledWith('favorites')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -99,11 +121,11 @@ describe('NodeSearchCategorySidebar', () => {
|
||||
])
|
||||
await nextTick()
|
||||
|
||||
const wrapper = await createWrapper()
|
||||
await createRender()
|
||||
|
||||
expect(wrapper.text()).toContain('sampling')
|
||||
expect(wrapper.text()).toContain('loaders')
|
||||
expect(wrapper.text()).toContain('conditioning')
|
||||
expect(screen.getByText('sampling')).toBeInTheDocument()
|
||||
expect(screen.getByText('loaders')).toBeInTheDocument()
|
||||
expect(screen.getByText('conditioning')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should emit update:selectedCategory when category is clicked', async () => {
|
||||
@@ -112,13 +134,11 @@ describe('NodeSearchCategorySidebar', () => {
|
||||
])
|
||||
await nextTick()
|
||||
|
||||
const wrapper = await createWrapper()
|
||||
const { user, onUpdateSelectedCategory } = await createRender()
|
||||
|
||||
await clickCategory(wrapper, 'sampling')
|
||||
await clickCategory(user, 'sampling')
|
||||
|
||||
expect(wrapper.emitted('update:selectedCategory')![0]).toEqual([
|
||||
'sampling'
|
||||
])
|
||||
expect(onUpdateSelectedCategory).toHaveBeenCalledWith('sampling')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -131,14 +151,16 @@ describe('NodeSearchCategorySidebar', () => {
|
||||
])
|
||||
await nextTick()
|
||||
|
||||
const wrapper = await createWrapper()
|
||||
const { user } = await createRender()
|
||||
|
||||
expect(wrapper.text()).not.toContain('advanced')
|
||||
expect(screen.queryByText('advanced')).not.toBeInTheDocument()
|
||||
|
||||
await clickCategory(wrapper, 'sampling')
|
||||
await clickCategory(user, 'sampling')
|
||||
|
||||
expect(wrapper.text()).toContain('advanced')
|
||||
expect(wrapper.text()).toContain('basic')
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('advanced')).toBeInTheDocument()
|
||||
expect(screen.getByText('basic')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('should collapse sibling category when another is expanded', async () => {
|
||||
@@ -150,17 +172,21 @@ describe('NodeSearchCategorySidebar', () => {
|
||||
])
|
||||
await nextTick()
|
||||
|
||||
const wrapper = await createWrapper()
|
||||
const { user } = await createRender()
|
||||
|
||||
// Expand sampling
|
||||
await clickCategory(wrapper, 'sampling', true)
|
||||
expect(wrapper.text()).toContain('advanced')
|
||||
await clickCategory(user, 'sampling', true)
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('advanced')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
// Expand image — sampling should collapse
|
||||
await clickCategory(wrapper, 'image', true)
|
||||
await clickCategory(user, 'image', true)
|
||||
|
||||
expect(wrapper.text()).toContain('upscale')
|
||||
expect(wrapper.text()).not.toContain('advanced')
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('upscale')).toBeInTheDocument()
|
||||
expect(screen.queryByText('advanced')).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('should emit update:selectedCategory when subcategory is clicked', async () => {
|
||||
@@ -170,16 +196,19 @@ describe('NodeSearchCategorySidebar', () => {
|
||||
])
|
||||
await nextTick()
|
||||
|
||||
const wrapper = await createWrapper()
|
||||
const { user, onUpdateSelectedCategory } = await createRender()
|
||||
|
||||
// Expand sampling category
|
||||
await clickCategory(wrapper, 'sampling', true)
|
||||
await clickCategory(user, 'sampling', true)
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('advanced')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
// Click on advanced subcategory
|
||||
await clickCategory(wrapper, 'advanced')
|
||||
await clickCategory(user, 'advanced')
|
||||
|
||||
const emitted = wrapper.emitted('update:selectedCategory')!
|
||||
expect(emitted[emitted.length - 1]).toEqual(['sampling/advanced'])
|
||||
const calls = onUpdateSelectedCategory.mock.calls
|
||||
expect(calls[calls.length - 1]).toEqual(['sampling/advanced'])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -190,13 +219,12 @@ describe('NodeSearchCategorySidebar', () => {
|
||||
])
|
||||
await nextTick()
|
||||
|
||||
const wrapper = await createWrapper({ selectedCategory: 'sampling' })
|
||||
await createRender({ selectedCategory: 'sampling' })
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
.find('[data-testid="category-sampling"]')
|
||||
.attributes('aria-current')
|
||||
).toBe('true')
|
||||
expect(screen.getByTestId('category-sampling')).toHaveAttribute(
|
||||
'aria-current',
|
||||
'true'
|
||||
)
|
||||
})
|
||||
|
||||
it('should emit selected subcategory when expanded', async () => {
|
||||
@@ -206,14 +234,19 @@ describe('NodeSearchCategorySidebar', () => {
|
||||
])
|
||||
await nextTick()
|
||||
|
||||
const wrapper = await createWrapper({ selectedCategory: 'most-relevant' })
|
||||
const { user, onUpdateSelectedCategory } = await createRender({
|
||||
selectedCategory: 'most-relevant'
|
||||
})
|
||||
|
||||
// Expand and click subcategory
|
||||
await clickCategory(wrapper, 'sampling', true)
|
||||
await clickCategory(wrapper, 'advanced')
|
||||
await clickCategory(user, 'sampling', true)
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('advanced')).toBeInTheDocument()
|
||||
})
|
||||
await clickCategory(user, 'advanced')
|
||||
|
||||
const emitted = wrapper.emitted('update:selectedCategory')!
|
||||
expect(emitted[emitted.length - 1]).toEqual(['sampling/advanced'])
|
||||
const calls = onUpdateSelectedCategory.mock.calls
|
||||
expect(calls[calls.length - 1]).toEqual(['sampling/advanced'])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -225,29 +258,31 @@ describe('NodeSearchCategorySidebar', () => {
|
||||
])
|
||||
await nextTick()
|
||||
|
||||
const wrapper = await createWrapper()
|
||||
const { user, onUpdateSelectedCategory } = await createRender()
|
||||
|
||||
// Only top-level visible initially
|
||||
expect(wrapper.text()).toContain('api')
|
||||
expect(wrapper.text()).not.toContain('image')
|
||||
expect(wrapper.text()).not.toContain('BFL')
|
||||
expect(screen.getByText('api')).toBeInTheDocument()
|
||||
expect(screen.queryByText('image')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('BFL')).not.toBeInTheDocument()
|
||||
|
||||
// Expand api
|
||||
await clickCategory(wrapper, 'api', true)
|
||||
|
||||
expect(wrapper.text()).toContain('image')
|
||||
expect(wrapper.text()).not.toContain('BFL')
|
||||
await clickCategory(user, 'api', true)
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('image')).toBeInTheDocument()
|
||||
})
|
||||
expect(screen.queryByText('BFL')).not.toBeInTheDocument()
|
||||
|
||||
// Expand image
|
||||
await clickCategory(wrapper, 'image', true)
|
||||
|
||||
expect(wrapper.text()).toContain('BFL')
|
||||
await clickCategory(user, 'image', true)
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('BFL')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
// Click BFL and verify emission
|
||||
await clickCategory(wrapper, 'BFL', true)
|
||||
await clickCategory(user, 'BFL', true)
|
||||
|
||||
const emitted = wrapper.emitted('update:selectedCategory')!
|
||||
expect(emitted[emitted.length - 1]).toEqual(['api/image/BFL'])
|
||||
const calls = onUpdateSelectedCategory.mock.calls
|
||||
expect(calls[calls.length - 1]).toEqual(['api/image/BFL'])
|
||||
})
|
||||
|
||||
it('should emit category without root/ prefix', async () => {
|
||||
@@ -256,10 +291,10 @@ describe('NodeSearchCategorySidebar', () => {
|
||||
])
|
||||
await nextTick()
|
||||
|
||||
const wrapper = await createWrapper()
|
||||
const { user, onUpdateSelectedCategory } = await createRender()
|
||||
|
||||
await clickCategory(wrapper, 'sampling')
|
||||
await clickCategory(user, 'sampling')
|
||||
|
||||
expect(wrapper.emitted('update:selectedCategory')![0][0]).toBe('sampling')
|
||||
expect(onUpdateSelectedCategory).toHaveBeenCalledWith('sampling')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import type { VueWrapper } from '@vue/test-utils'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { nextTick } from 'vue'
|
||||
|
||||
import NodeSearchCategorySidebar from '@/components/searchbox/v2/NodeSearchCategorySidebar.vue'
|
||||
import NodeSearchContent from '@/components/searchbox/v2/NodeSearchContent.vue'
|
||||
import {
|
||||
createMockNodeDef,
|
||||
@@ -32,14 +31,27 @@ describe('NodeSearchContent', () => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
async function createWrapper(props = {}) {
|
||||
const wrapper = mount(NodeSearchContent, {
|
||||
props: { filters: [], ...props },
|
||||
async function renderComponent(props = {}) {
|
||||
const user = userEvent.setup()
|
||||
const onAddNode = vi.fn()
|
||||
const onHoverNode = vi.fn()
|
||||
const onRemoveFilter = vi.fn()
|
||||
const onAddFilter = vi.fn()
|
||||
render(NodeSearchContent, {
|
||||
props: {
|
||||
filters: [],
|
||||
onAddNode,
|
||||
onHoverNode,
|
||||
onRemoveFilter,
|
||||
onAddFilter,
|
||||
...props
|
||||
},
|
||||
global: {
|
||||
plugins: [testI18n],
|
||||
stubs: {
|
||||
NodeSearchListItem: {
|
||||
template: '<div class="node-item">{{ nodeDef.display_name }}</div>',
|
||||
template:
|
||||
'<div class="node-item" data-testid="node-item">{{ nodeDef.display_name }}</div>',
|
||||
props: [
|
||||
'nodeDef',
|
||||
'currentQuery',
|
||||
@@ -52,7 +64,7 @@ describe('NodeSearchContent', () => {
|
||||
}
|
||||
})
|
||||
await nextTick()
|
||||
return wrapper
|
||||
return { user, onAddNode, onHoverNode, onRemoveFilter, onAddFilter }
|
||||
}
|
||||
|
||||
async function setupFavorites(
|
||||
@@ -60,18 +72,10 @@ describe('NodeSearchContent', () => {
|
||||
) {
|
||||
useNodeDefStore().updateNodeDefs(nodes.map(createMockNodeDef))
|
||||
vi.spyOn(useNodeBookmarkStore(), 'isBookmarked').mockReturnValue(true)
|
||||
const wrapper = await createWrapper()
|
||||
await wrapper.find('[data-testid="category-favorites"]').trigger('click')
|
||||
const result = await renderComponent()
|
||||
await result.user.click(screen.getByTestId('category-favorites'))
|
||||
await nextTick()
|
||||
return wrapper
|
||||
}
|
||||
|
||||
function getResultItems(wrapper: VueWrapper) {
|
||||
return wrapper.findAll('[data-testid="result-item"]')
|
||||
}
|
||||
|
||||
function getNodeItems(wrapper: VueWrapper) {
|
||||
return wrapper.findAll('.node-item')
|
||||
return result
|
||||
}
|
||||
|
||||
describe('category selection', () => {
|
||||
@@ -88,11 +92,11 @@ describe('NodeSearchContent', () => {
|
||||
useNodeDefStore().nodeDefsByName['FrequentNode']
|
||||
])
|
||||
|
||||
const wrapper = await createWrapper()
|
||||
await renderComponent()
|
||||
|
||||
const items = getNodeItems(wrapper)
|
||||
const items = screen.getAllByTestId('node-item')
|
||||
expect(items).toHaveLength(1)
|
||||
expect(items[0].text()).toContain('Frequent Node')
|
||||
expect(items[0]).toHaveTextContent('Frequent Node')
|
||||
})
|
||||
|
||||
it('should show only bookmarked nodes when Favorites is selected', async () => {
|
||||
@@ -110,13 +114,13 @@ describe('NodeSearchContent', () => {
|
||||
(node: ComfyNodeDefImpl) => node.name === 'BookmarkedNode'
|
||||
)
|
||||
|
||||
const wrapper = await createWrapper()
|
||||
await wrapper.find('[data-testid="category-favorites"]').trigger('click')
|
||||
const { user } = await renderComponent()
|
||||
await user.click(screen.getByTestId('category-favorites'))
|
||||
await nextTick()
|
||||
|
||||
const items = getNodeItems(wrapper)
|
||||
const items = screen.getAllByTestId('node-item')
|
||||
expect(items).toHaveLength(1)
|
||||
expect(items[0].text()).toContain('Bookmarked')
|
||||
expect(items[0]).toHaveTextContent('Bookmarked')
|
||||
})
|
||||
|
||||
it('should show empty state when no bookmarks exist', async () => {
|
||||
@@ -125,11 +129,11 @@ describe('NodeSearchContent', () => {
|
||||
])
|
||||
vi.spyOn(useNodeBookmarkStore(), 'isBookmarked').mockReturnValue(false)
|
||||
|
||||
const wrapper = await createWrapper()
|
||||
await wrapper.find('[data-testid="category-favorites"]').trigger('click')
|
||||
const { user } = await renderComponent()
|
||||
await user.click(screen.getByTestId('category-favorites'))
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.text()).toContain('No results')
|
||||
expect(screen.getByText('No results')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should show only CustomNodes when Extensions is selected', async () => {
|
||||
@@ -154,13 +158,13 @@ describe('NodeSearchContent', () => {
|
||||
useNodeDefStore().nodeDefsByName['CustomNode'].nodeSource.type
|
||||
).toBe(NodeSourceType.CustomNodes)
|
||||
|
||||
const wrapper = await createWrapper()
|
||||
await wrapper.find('[data-testid="category-extensions"]').trigger('click')
|
||||
const { user } = await renderComponent()
|
||||
await user.click(screen.getByTestId('category-extensions'))
|
||||
await nextTick()
|
||||
|
||||
const items = getNodeItems(wrapper)
|
||||
const items = screen.getAllByTestId('node-item')
|
||||
expect(items).toHaveLength(1)
|
||||
expect(items[0].text()).toContain('Custom Node')
|
||||
expect(items[0]).toHaveTextContent('Custom Node')
|
||||
})
|
||||
|
||||
it('should hide Essentials category when no essential nodes exist', async () => {
|
||||
@@ -171,10 +175,10 @@ describe('NodeSearchContent', () => {
|
||||
})
|
||||
])
|
||||
|
||||
const wrapper = await createWrapper()
|
||||
expect(wrapper.find('[data-testid="category-essentials"]').exists()).toBe(
|
||||
false
|
||||
)
|
||||
await renderComponent()
|
||||
expect(
|
||||
screen.queryByTestId('category-essentials')
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should show only essential nodes when Essentials is selected', async () => {
|
||||
@@ -191,13 +195,13 @@ describe('NodeSearchContent', () => {
|
||||
])
|
||||
await nextTick()
|
||||
|
||||
const wrapper = await createWrapper()
|
||||
await wrapper.find('[data-testid="category-essentials"]').trigger('click')
|
||||
const { user } = await renderComponent()
|
||||
await user.click(screen.getByTestId('category-essentials'))
|
||||
await nextTick()
|
||||
|
||||
const items = getNodeItems(wrapper)
|
||||
const items = screen.getAllByTestId('node-item')
|
||||
expect(items).toHaveLength(1)
|
||||
expect(items[0].text()).toContain('Essential Node')
|
||||
expect(items[0]).toHaveTextContent('Essential Node')
|
||||
})
|
||||
|
||||
it('should include subcategory nodes when parent category is selected', async () => {
|
||||
@@ -219,11 +223,11 @@ describe('NodeSearchContent', () => {
|
||||
})
|
||||
])
|
||||
|
||||
const wrapper = await createWrapper()
|
||||
await wrapper.find('[data-testid="category-sampling"]').trigger('click')
|
||||
const { user } = await renderComponent()
|
||||
await user.click(screen.getByTestId('category-sampling'))
|
||||
await nextTick()
|
||||
|
||||
const texts = getNodeItems(wrapper).map((i) => i.text())
|
||||
const texts = screen.getAllByTestId('node-item').map((i) => i.textContent)
|
||||
expect(texts).toHaveLength(2)
|
||||
expect(texts).toContain('KSampler')
|
||||
expect(texts).toContain('KSampler Advanced')
|
||||
@@ -245,18 +249,18 @@ describe('NodeSearchContent', () => {
|
||||
})
|
||||
])
|
||||
|
||||
const wrapper = await createWrapper()
|
||||
await wrapper.find('[data-testid="category-sampling"]').trigger('click')
|
||||
const { user } = await renderComponent()
|
||||
await user.click(screen.getByTestId('category-sampling'))
|
||||
await nextTick()
|
||||
|
||||
expect(getNodeItems(wrapper)).toHaveLength(1)
|
||||
expect(screen.getAllByTestId('node-item')).toHaveLength(1)
|
||||
|
||||
const input = wrapper.find('input[type="text"]')
|
||||
await input.setValue('Load')
|
||||
const input = screen.getByRole('combobox')
|
||||
await user.type(input, 'Load')
|
||||
await nextTick()
|
||||
|
||||
const texts = getNodeItems(wrapper).map((i) => i.text())
|
||||
expect(texts.some((t) => t.includes('Load Checkpoint'))).toBe(true)
|
||||
const texts = screen.getAllByTestId('node-item').map((i) => i.textContent)
|
||||
expect(texts.some((t) => t?.includes('Load Checkpoint'))).toBe(true)
|
||||
})
|
||||
|
||||
it('should clear search query when category changes', async () => {
|
||||
@@ -264,56 +268,58 @@ describe('NodeSearchContent', () => {
|
||||
createMockNodeDef({ name: 'TestNode', display_name: 'Test Node' })
|
||||
])
|
||||
|
||||
const wrapper = await createWrapper()
|
||||
const { user } = await renderComponent()
|
||||
|
||||
const input = wrapper.find('input[type="text"]')
|
||||
await input.setValue('test query')
|
||||
const input = screen.getByRole('combobox')
|
||||
await user.type(input, 'test query')
|
||||
await nextTick()
|
||||
expect((input.element as HTMLInputElement).value).toBe('test query')
|
||||
expect(input).toHaveValue('test query')
|
||||
|
||||
await wrapper.find('[data-testid="category-favorites"]').trigger('click')
|
||||
await user.click(screen.getByTestId('category-favorites'))
|
||||
await nextTick()
|
||||
expect((input.element as HTMLInputElement).value).toBe('')
|
||||
expect(input).toHaveValue('')
|
||||
})
|
||||
|
||||
it('should reset selected index when search query changes', async () => {
|
||||
const wrapper = await setupFavorites([
|
||||
const { user } = await setupFavorites([
|
||||
{ name: 'Node1', display_name: 'Node One' },
|
||||
{ name: 'Node2', display_name: 'Node Two' }
|
||||
])
|
||||
|
||||
const input = wrapper.find('input[type="text"]')
|
||||
await input.trigger('keydown', { key: 'ArrowDown' })
|
||||
const input = screen.getByRole('combobox')
|
||||
await user.click(input)
|
||||
await user.keyboard('{ArrowDown}')
|
||||
await nextTick()
|
||||
expect(getResultItems(wrapper)[1].attributes('aria-selected')).toBe(
|
||||
expect(screen.getAllByTestId('result-item')[1]).toHaveAttribute(
|
||||
'aria-selected',
|
||||
'true'
|
||||
)
|
||||
|
||||
await input.setValue('Node')
|
||||
await user.type(input, 'Node')
|
||||
await nextTick()
|
||||
expect(getResultItems(wrapper)[0].attributes('aria-selected')).toBe(
|
||||
expect(screen.getAllByTestId('result-item')[0]).toHaveAttribute(
|
||||
'aria-selected',
|
||||
'true'
|
||||
)
|
||||
})
|
||||
|
||||
it('should reset selected index when category changes', async () => {
|
||||
const wrapper = await setupFavorites([
|
||||
const { user } = await setupFavorites([
|
||||
{ name: 'Node1', display_name: 'Node One' },
|
||||
{ name: 'Node2', display_name: 'Node Two' }
|
||||
])
|
||||
|
||||
const input = wrapper.find('input[type="text"]')
|
||||
await input.trigger('keydown', { key: 'ArrowDown' })
|
||||
await user.click(screen.getByRole('combobox'))
|
||||
await user.keyboard('{ArrowDown}')
|
||||
await nextTick()
|
||||
|
||||
await wrapper
|
||||
.find('[data-testid="category-most-relevant"]')
|
||||
.trigger('click')
|
||||
await user.click(screen.getByTestId('category-most-relevant'))
|
||||
await nextTick()
|
||||
await wrapper.find('[data-testid="category-favorites"]').trigger('click')
|
||||
await user.click(screen.getByTestId('category-favorites'))
|
||||
await nextTick()
|
||||
|
||||
expect(getResultItems(wrapper)[0].attributes('aria-selected')).toBe(
|
||||
expect(screen.getAllByTestId('result-item')[0]).toHaveAttribute(
|
||||
'aria-selected',
|
||||
'true'
|
||||
)
|
||||
})
|
||||
@@ -321,106 +327,105 @@ describe('NodeSearchContent', () => {
|
||||
|
||||
describe('keyboard and mouse interaction', () => {
|
||||
it('should navigate results with ArrowDown/ArrowUp and clamp to bounds', async () => {
|
||||
const wrapper = await setupFavorites([
|
||||
const { user } = await setupFavorites([
|
||||
{ name: 'Node1', display_name: 'Node One' },
|
||||
{ name: 'Node2', display_name: 'Node Two' },
|
||||
{ name: 'Node3', display_name: 'Node Three' }
|
||||
])
|
||||
|
||||
const input = wrapper.find('input[type="text"]')
|
||||
await user.click(screen.getByRole('combobox'))
|
||||
const selectedIndex = () =>
|
||||
getResultItems(wrapper).findIndex(
|
||||
(r) => r.attributes('aria-selected') === 'true'
|
||||
)
|
||||
screen
|
||||
.getAllByTestId('result-item')
|
||||
.findIndex((r) => r.getAttribute('aria-selected') === 'true')
|
||||
|
||||
expect(selectedIndex()).toBe(0)
|
||||
|
||||
await input.trigger('keydown', { key: 'ArrowDown' })
|
||||
await user.keyboard('{ArrowDown}')
|
||||
await nextTick()
|
||||
expect(selectedIndex()).toBe(1)
|
||||
|
||||
await input.trigger('keydown', { key: 'ArrowDown' })
|
||||
await user.keyboard('{ArrowDown}')
|
||||
await nextTick()
|
||||
expect(selectedIndex()).toBe(2)
|
||||
|
||||
await input.trigger('keydown', { key: 'ArrowUp' })
|
||||
await user.keyboard('{ArrowUp}')
|
||||
await nextTick()
|
||||
expect(selectedIndex()).toBe(1)
|
||||
|
||||
// Navigate to first, then try going above — should clamp
|
||||
await input.trigger('keydown', { key: 'ArrowUp' })
|
||||
await user.keyboard('{ArrowUp}')
|
||||
await nextTick()
|
||||
expect(selectedIndex()).toBe(0)
|
||||
|
||||
await input.trigger('keydown', { key: 'ArrowUp' })
|
||||
await user.keyboard('{ArrowUp}')
|
||||
await nextTick()
|
||||
expect(selectedIndex()).toBe(0)
|
||||
})
|
||||
|
||||
it('should select current result with Enter key', async () => {
|
||||
const wrapper = await setupFavorites([
|
||||
const { user, onAddNode } = await setupFavorites([
|
||||
{ name: 'TestNode', display_name: 'Test Node' }
|
||||
])
|
||||
|
||||
await wrapper
|
||||
.find('input[type="text"]')
|
||||
.trigger('keydown', { key: 'Enter' })
|
||||
await user.click(screen.getByRole('combobox'))
|
||||
await user.keyboard('{Enter}')
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.emitted('addNode')).toBeTruthy()
|
||||
expect(wrapper.emitted('addNode')![0][0]).toMatchObject({
|
||||
name: 'TestNode'
|
||||
})
|
||||
expect(onAddNode).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ name: 'TestNode' })
|
||||
)
|
||||
})
|
||||
|
||||
it('should select item on hover', async () => {
|
||||
const wrapper = await setupFavorites([
|
||||
const { user } = await setupFavorites([
|
||||
{ name: 'Node1', display_name: 'Node One' },
|
||||
{ name: 'Node2', display_name: 'Node Two' }
|
||||
])
|
||||
|
||||
const results = getResultItems(wrapper)
|
||||
await results[1].trigger('mouseenter')
|
||||
const results = screen.getAllByTestId('result-item')
|
||||
await user.hover(results[1])
|
||||
await nextTick()
|
||||
|
||||
expect(results[1].attributes('aria-selected')).toBe('true')
|
||||
expect(results[1]).toHaveAttribute('aria-selected', 'true')
|
||||
})
|
||||
|
||||
it('should add node on click', async () => {
|
||||
const wrapper = await setupFavorites([
|
||||
const { user, onAddNode } = await setupFavorites([
|
||||
{ name: 'TestNode', display_name: 'Test Node' }
|
||||
])
|
||||
|
||||
await getResultItems(wrapper)[0].trigger('click')
|
||||
await user.click(screen.getAllByTestId('result-item')[0])
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.emitted('addNode')![0][0]).toMatchObject({
|
||||
name: 'TestNode'
|
||||
})
|
||||
expect(onAddNode).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ name: 'TestNode' }),
|
||||
expect.any(PointerEvent)
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('hoverNode emission', () => {
|
||||
it('should emit hoverNode with the currently selected node', async () => {
|
||||
const wrapper = await setupFavorites([
|
||||
const { onHoverNode } = await setupFavorites([
|
||||
{ name: 'HoverNode', display_name: 'Hover Node' }
|
||||
])
|
||||
|
||||
const emitted = wrapper.emitted('hoverNode')!
|
||||
expect(emitted[emitted.length - 1][0]).toMatchObject({
|
||||
const calls = onHoverNode.mock.calls
|
||||
expect(calls[calls.length - 1][0]).toMatchObject({
|
||||
name: 'HoverNode'
|
||||
})
|
||||
})
|
||||
|
||||
it('should emit null hoverNode when no results', async () => {
|
||||
const wrapper = await createWrapper()
|
||||
const { user, onHoverNode } = await renderComponent()
|
||||
|
||||
vi.spyOn(useNodeBookmarkStore(), 'isBookmarked').mockReturnValue(false)
|
||||
await wrapper.find('[data-testid="category-favorites"]').trigger('click')
|
||||
await user.click(screen.getByTestId('category-favorites'))
|
||||
await nextTick()
|
||||
|
||||
const emitted = wrapper.emitted('hoverNode')!
|
||||
expect(emitted[emitted.length - 1][0]).toBeNull()
|
||||
const calls = onHoverNode.mock.calls
|
||||
expect(calls[calls.length - 1][0]).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -434,7 +439,7 @@ describe('NodeSearchContent', () => {
|
||||
})
|
||||
])
|
||||
|
||||
const wrapper = await createWrapper({
|
||||
await renderComponent({
|
||||
filters: [
|
||||
{
|
||||
filterDef: useNodeDefStore().nodeSearchService.inputTypeFilter,
|
||||
@@ -443,9 +448,7 @@ describe('NodeSearchContent', () => {
|
||||
]
|
||||
})
|
||||
|
||||
expect(
|
||||
wrapper.findAll('[data-testid="filter-chip"]').length
|
||||
).toBeGreaterThan(0)
|
||||
expect(screen.getAllByTestId('filter-chip').length).toBeGreaterThan(0)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -471,42 +474,41 @@ describe('NodeSearchContent', () => {
|
||||
|
||||
it('should emit removeFilter on backspace', async () => {
|
||||
const filters = createFilters(1)
|
||||
const wrapper = await createWrapper({ filters })
|
||||
const { user, onRemoveFilter } = await renderComponent({ filters })
|
||||
|
||||
const input = wrapper.find('input[type="text"]')
|
||||
await input.trigger('keydown', { key: 'Backspace' })
|
||||
await user.click(screen.getByRole('combobox'))
|
||||
await user.keyboard('{Backspace}')
|
||||
await nextTick()
|
||||
await input.trigger('keydown', { key: 'Backspace' })
|
||||
await user.keyboard('{Backspace}')
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.emitted('removeFilter')).toHaveLength(1)
|
||||
expect(wrapper.emitted('removeFilter')![0][0]).toMatchObject({
|
||||
value: 'IMAGE'
|
||||
})
|
||||
expect(onRemoveFilter).toHaveBeenCalledTimes(1)
|
||||
expect(onRemoveFilter).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ value: 'IMAGE' })
|
||||
)
|
||||
})
|
||||
|
||||
it('should not interact with chips when no filters exist', async () => {
|
||||
const wrapper = await createWrapper({ filters: [] })
|
||||
const { user, onRemoveFilter } = await renderComponent({ filters: [] })
|
||||
|
||||
const input = wrapper.find('input[type="text"]')
|
||||
await input.trigger('keydown', { key: 'Backspace' })
|
||||
await user.click(screen.getByRole('combobox'))
|
||||
await user.keyboard('{Backspace}')
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.emitted('removeFilter')).toBeUndefined()
|
||||
expect(onRemoveFilter).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should remove chip when clicking its delete button', async () => {
|
||||
const filters = createFilters(1)
|
||||
const wrapper = await createWrapper({ filters })
|
||||
const { user, onRemoveFilter } = await renderComponent({ filters })
|
||||
|
||||
const deleteBtn = wrapper.find('[data-testid="chip-delete"]')
|
||||
await deleteBtn.trigger('click')
|
||||
await user.click(screen.getByTestId('chip-delete'))
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.emitted('removeFilter')).toHaveLength(1)
|
||||
expect(wrapper.emitted('removeFilter')![0][0]).toMatchObject({
|
||||
value: 'IMAGE'
|
||||
})
|
||||
expect(onRemoveFilter).toHaveBeenCalledTimes(1)
|
||||
expect(onRemoveFilter).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ value: 'IMAGE' })
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -534,54 +536,46 @@ describe('NodeSearchContent', () => {
|
||||
])
|
||||
}
|
||||
|
||||
function findFilterBarButton(wrapper: VueWrapper, label: string) {
|
||||
return wrapper
|
||||
.findAll('button[aria-pressed]')
|
||||
.find((b) => b.text() === label)
|
||||
function findFilterBarButton(label: string) {
|
||||
return screen.getAllByRole('button').find((b) => b.textContent === label)
|
||||
}
|
||||
|
||||
async function enterFilterMode(wrapper: VueWrapper) {
|
||||
await findFilterBarButton(wrapper, 'Input')!.trigger('click')
|
||||
async function enterFilterMode(user: ReturnType<typeof userEvent.setup>) {
|
||||
const btn = findFilterBarButton('Input')
|
||||
expect(btn).toBeDefined()
|
||||
await user.click(btn!)
|
||||
await nextTick()
|
||||
}
|
||||
|
||||
function getFilterOptions(wrapper: VueWrapper) {
|
||||
return wrapper.findAll('[data-testid="filter-option"]')
|
||||
}
|
||||
|
||||
function getFilterOptionTexts(wrapper: VueWrapper) {
|
||||
return getFilterOptions(wrapper).map(
|
||||
(o) =>
|
||||
o
|
||||
.findAll('span')[0]
|
||||
?.text()
|
||||
.replace(/^[•·]\s*/, '')
|
||||
.trim() ?? ''
|
||||
)
|
||||
}
|
||||
|
||||
function hasSidebar(wrapper: VueWrapper) {
|
||||
return wrapper.findComponent(NodeSearchCategorySidebar).exists()
|
||||
function hasSidebar() {
|
||||
return screen.queryByTestId('category-most-relevant') !== null
|
||||
}
|
||||
|
||||
it('should enter filter mode when a filter chip is selected', async () => {
|
||||
setupNodesWithTypes()
|
||||
const wrapper = await createWrapper()
|
||||
const { user } = await renderComponent()
|
||||
|
||||
expect(hasSidebar(wrapper)).toBe(true)
|
||||
expect(hasSidebar()).toBe(true)
|
||||
|
||||
await enterFilterMode(wrapper)
|
||||
await enterFilterMode(user)
|
||||
|
||||
expect(hasSidebar(wrapper)).toBe(false)
|
||||
expect(getFilterOptions(wrapper).length).toBeGreaterThan(0)
|
||||
expect(hasSidebar()).toBe(false)
|
||||
expect(screen.getAllByTestId('filter-option').length).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
it('should show available filter options sorted alphabetically', async () => {
|
||||
setupNodesWithTypes()
|
||||
const wrapper = await createWrapper()
|
||||
await enterFilterMode(wrapper)
|
||||
const { user } = await renderComponent()
|
||||
await enterFilterMode(user)
|
||||
|
||||
const texts = getFilterOptionTexts(wrapper)
|
||||
const texts = screen.getAllByTestId('filter-option').map(
|
||||
(o) =>
|
||||
/* eslint-disable testing-library/no-node-access */
|
||||
(o.querySelectorAll('span')[0] as HTMLElement)?.textContent
|
||||
?.replace(/^[•·]\s*/, '')
|
||||
.trim() ?? ''
|
||||
/* eslint-enable testing-library/no-node-access */
|
||||
)
|
||||
expect(texts).toContain('IMAGE')
|
||||
expect(texts).toContain('LATENT')
|
||||
expect(texts).toContain('MODEL')
|
||||
@@ -590,140 +584,152 @@ describe('NodeSearchContent', () => {
|
||||
|
||||
it('should filter options when typing in filter mode', async () => {
|
||||
setupNodesWithTypes()
|
||||
const wrapper = await createWrapper()
|
||||
await enterFilterMode(wrapper)
|
||||
const { user } = await renderComponent()
|
||||
await enterFilterMode(user)
|
||||
|
||||
await wrapper.find('input[type="text"]').setValue('IMAGE')
|
||||
await user.type(screen.getByRole('combobox'), 'IMAGE')
|
||||
await nextTick()
|
||||
|
||||
const texts = getFilterOptionTexts(wrapper)
|
||||
const texts = screen.getAllByTestId('filter-option').map(
|
||||
(o) =>
|
||||
/* eslint-disable testing-library/no-node-access */
|
||||
(o.querySelectorAll('span')[0] as HTMLElement)?.textContent
|
||||
?.replace(/^[•·]\s*/, '')
|
||||
.trim() ?? ''
|
||||
/* eslint-enable testing-library/no-node-access */
|
||||
)
|
||||
expect(texts).toContain('IMAGE')
|
||||
expect(texts).not.toContain('MODEL')
|
||||
})
|
||||
|
||||
it('should show no results when filter query has no matches', async () => {
|
||||
setupNodesWithTypes()
|
||||
const wrapper = await createWrapper()
|
||||
await enterFilterMode(wrapper)
|
||||
const { user } = await renderComponent()
|
||||
await enterFilterMode(user)
|
||||
|
||||
await wrapper.find('input[type="text"]').setValue('NONEXISTENT_TYPE')
|
||||
await user.type(screen.getByRole('combobox'), 'NONEXISTENT_TYPE')
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.text()).toContain('No results')
|
||||
expect(screen.getByText('No results')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should emit addFilter when a filter option is clicked', async () => {
|
||||
setupNodesWithTypes()
|
||||
const wrapper = await createWrapper()
|
||||
await enterFilterMode(wrapper)
|
||||
const { user, onAddFilter } = await renderComponent()
|
||||
await enterFilterMode(user)
|
||||
|
||||
const imageOption = getFilterOptions(wrapper).find((o) =>
|
||||
o.text().includes('IMAGE')
|
||||
)
|
||||
await imageOption!.trigger('click')
|
||||
const imageOption = screen
|
||||
.getAllByTestId('filter-option')
|
||||
.find((o) => o.textContent?.includes('IMAGE'))
|
||||
await user.click(imageOption!)
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.emitted('addFilter')![0][0]).toMatchObject({
|
||||
filterDef: expect.objectContaining({ id: 'input' }),
|
||||
value: 'IMAGE'
|
||||
})
|
||||
expect(onAddFilter).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
filterDef: expect.objectContaining({ id: 'input' }),
|
||||
value: 'IMAGE'
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it('should exit filter mode after applying a filter', async () => {
|
||||
setupNodesWithTypes()
|
||||
const wrapper = await createWrapper()
|
||||
await enterFilterMode(wrapper)
|
||||
const { user } = await renderComponent()
|
||||
await enterFilterMode(user)
|
||||
|
||||
await getFilterOptions(wrapper)[0].trigger('click')
|
||||
await user.click(screen.getAllByTestId('filter-option')[0])
|
||||
await nextTick()
|
||||
await nextTick()
|
||||
|
||||
expect(hasSidebar(wrapper)).toBe(true)
|
||||
expect(hasSidebar()).toBe(true)
|
||||
})
|
||||
|
||||
it('should emit addFilter when Enter is pressed on selected option', async () => {
|
||||
setupNodesWithTypes()
|
||||
const wrapper = await createWrapper()
|
||||
await enterFilterMode(wrapper)
|
||||
const { user, onAddFilter } = await renderComponent()
|
||||
await enterFilterMode(user)
|
||||
|
||||
await wrapper
|
||||
.find('input[type="text"]')
|
||||
.trigger('keydown', { key: 'Enter' })
|
||||
await user.click(screen.getByRole('combobox'))
|
||||
await user.keyboard('{Enter}')
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.emitted('addFilter')![0][0]).toMatchObject({
|
||||
filterDef: expect.objectContaining({ id: 'input' }),
|
||||
value: 'IMAGE'
|
||||
})
|
||||
expect(onAddFilter).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
filterDef: expect.objectContaining({ id: 'input' }),
|
||||
value: 'IMAGE'
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it('should navigate filter options with ArrowDown/ArrowUp', async () => {
|
||||
setupNodesWithTypes()
|
||||
const wrapper = await createWrapper()
|
||||
await enterFilterMode(wrapper)
|
||||
const { user } = await renderComponent()
|
||||
await enterFilterMode(user)
|
||||
|
||||
const input = wrapper.find('input[type="text"]')
|
||||
await user.click(screen.getByRole('combobox'))
|
||||
|
||||
expect(getFilterOptions(wrapper)[0].attributes('aria-selected')).toBe(
|
||||
expect(screen.getAllByTestId('filter-option')[0]).toHaveAttribute(
|
||||
'aria-selected',
|
||||
'true'
|
||||
)
|
||||
|
||||
await input.trigger('keydown', { key: 'ArrowDown' })
|
||||
await user.keyboard('{ArrowDown}')
|
||||
await nextTick()
|
||||
expect(getFilterOptions(wrapper)[1].attributes('aria-selected')).toBe(
|
||||
expect(screen.getAllByTestId('filter-option')[1]).toHaveAttribute(
|
||||
'aria-selected',
|
||||
'true'
|
||||
)
|
||||
|
||||
await input.trigger('keydown', { key: 'ArrowUp' })
|
||||
await user.keyboard('{ArrowUp}')
|
||||
await nextTick()
|
||||
expect(getFilterOptions(wrapper)[0].attributes('aria-selected')).toBe(
|
||||
expect(screen.getAllByTestId('filter-option')[0]).toHaveAttribute(
|
||||
'aria-selected',
|
||||
'true'
|
||||
)
|
||||
})
|
||||
|
||||
it('should toggle filter mode off when same chip is clicked again', async () => {
|
||||
setupNodesWithTypes()
|
||||
const wrapper = await createWrapper()
|
||||
await enterFilterMode(wrapper)
|
||||
const { user } = await renderComponent()
|
||||
await enterFilterMode(user)
|
||||
|
||||
await findFilterBarButton(wrapper, 'Input')!.trigger('click')
|
||||
await user.click(findFilterBarButton('Input')!)
|
||||
await nextTick()
|
||||
await nextTick()
|
||||
|
||||
expect(hasSidebar(wrapper)).toBe(true)
|
||||
expect(hasSidebar()).toBe(true)
|
||||
})
|
||||
|
||||
it('should reset filter query when re-entering filter mode', async () => {
|
||||
setupNodesWithTypes()
|
||||
const wrapper = await createWrapper()
|
||||
await enterFilterMode(wrapper)
|
||||
const { user } = await renderComponent()
|
||||
await enterFilterMode(user)
|
||||
|
||||
const input = wrapper.find('input[type="text"]')
|
||||
await input.setValue('IMAGE')
|
||||
const input = screen.getByRole('combobox')
|
||||
await user.type(input, 'IMAGE')
|
||||
await nextTick()
|
||||
|
||||
await findFilterBarButton(wrapper, 'Input')!.trigger('click')
|
||||
await user.click(findFilterBarButton('Input')!)
|
||||
await nextTick()
|
||||
await nextTick()
|
||||
|
||||
await enterFilterMode(wrapper)
|
||||
await enterFilterMode(user)
|
||||
|
||||
expect((input.element as HTMLInputElement).value).toBe('')
|
||||
expect(input).toHaveValue('')
|
||||
})
|
||||
|
||||
it('should exit filter mode when cancel button is clicked', async () => {
|
||||
setupNodesWithTypes()
|
||||
const wrapper = await createWrapper()
|
||||
await enterFilterMode(wrapper)
|
||||
const { user } = await renderComponent()
|
||||
await enterFilterMode(user)
|
||||
|
||||
expect(hasSidebar(wrapper)).toBe(false)
|
||||
expect(hasSidebar()).toBe(false)
|
||||
|
||||
const cancelBtn = wrapper.find('[data-testid="cancel-filter"]')
|
||||
await cancelBtn.trigger('click')
|
||||
await user.click(screen.getByTestId('cancel-filter'))
|
||||
await nextTick()
|
||||
await nextTick()
|
||||
|
||||
expect(hasSidebar(wrapper)).toBe(true)
|
||||
expect(hasSidebar()).toBe(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, within } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { nextTick } from 'vue'
|
||||
|
||||
@@ -30,54 +31,59 @@ describe(NodeSearchFilterBar, () => {
|
||||
])
|
||||
})
|
||||
|
||||
async function createWrapper(props = {}) {
|
||||
const wrapper = mount(NodeSearchFilterBar, {
|
||||
props,
|
||||
async function createRender(props = {}) {
|
||||
const user = userEvent.setup()
|
||||
const onSelectChip = vi.fn()
|
||||
const { container } = render(NodeSearchFilterBar, {
|
||||
props: { onSelectChip, ...props },
|
||||
global: { plugins: [testI18n] }
|
||||
})
|
||||
await nextTick()
|
||||
return wrapper
|
||||
const view = within(container as HTMLElement)
|
||||
return { user, onSelectChip, view }
|
||||
}
|
||||
|
||||
it('should render all filter chips', async () => {
|
||||
const wrapper = await createWrapper()
|
||||
const { view } = await createRender()
|
||||
|
||||
const buttons = wrapper.findAll('button')
|
||||
const buttons = view.getAllByRole('button')
|
||||
expect(buttons).toHaveLength(6)
|
||||
expect(buttons[0].text()).toBe('Blueprints')
|
||||
expect(buttons[1].text()).toBe('Partner Nodes')
|
||||
expect(buttons[2].text()).toBe('Essentials')
|
||||
expect(buttons[3].text()).toBe('Extensions')
|
||||
expect(buttons[4].text()).toBe('Input')
|
||||
expect(buttons[5].text()).toBe('Output')
|
||||
expect(buttons[0]).toHaveTextContent('Blueprints')
|
||||
expect(buttons[1]).toHaveTextContent('Partner Nodes')
|
||||
expect(buttons[2]).toHaveTextContent('Essentials')
|
||||
expect(buttons[3]).toHaveTextContent('Extensions')
|
||||
expect(buttons[4]).toHaveTextContent('Input')
|
||||
expect(buttons[5]).toHaveTextContent('Output')
|
||||
})
|
||||
|
||||
it('should mark active chip as pressed when activeChipKey matches', async () => {
|
||||
const wrapper = await createWrapper({ activeChipKey: 'input' })
|
||||
const { view } = await createRender({ activeChipKey: 'input' })
|
||||
|
||||
const inputBtn = wrapper.findAll('button').find((b) => b.text() === 'Input')
|
||||
expect(inputBtn?.attributes('aria-pressed')).toBe('true')
|
||||
expect(view.getByRole('button', { name: 'Input' })).toHaveAttribute(
|
||||
'aria-pressed',
|
||||
'true'
|
||||
)
|
||||
})
|
||||
|
||||
it('should not mark chips as pressed when activeChipKey does not match', async () => {
|
||||
const wrapper = await createWrapper({ activeChipKey: null })
|
||||
const { view } = await createRender({ activeChipKey: null })
|
||||
|
||||
wrapper.findAll('button').forEach((btn) => {
|
||||
expect(btn.attributes('aria-pressed')).toBe('false')
|
||||
view.getAllByRole('button').forEach((btn) => {
|
||||
expect(btn).toHaveAttribute('aria-pressed', 'false')
|
||||
})
|
||||
})
|
||||
|
||||
it('should emit selectChip with chip data when clicked', async () => {
|
||||
const wrapper = await createWrapper()
|
||||
const { user, onSelectChip, view } = await createRender()
|
||||
|
||||
const inputBtn = wrapper.findAll('button').find((b) => b.text() === 'Input')
|
||||
await inputBtn?.trigger('click')
|
||||
await user.click(view.getByRole('button', { name: 'Input' }))
|
||||
|
||||
const emitted = wrapper.emitted('selectChip')!
|
||||
expect(emitted[0][0]).toMatchObject({
|
||||
key: 'input',
|
||||
label: 'Input',
|
||||
filter: expect.anything()
|
||||
})
|
||||
expect(onSelectChip).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
key: 'input',
|
||||
label: 'Input',
|
||||
filter: expect.anything()
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import type { FilterChip } from '@/components/searchbox/v2/NodeSearchFilterBar.vue'
|
||||
@@ -59,7 +60,7 @@ describe('NodeSearchInput', () => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
function createWrapper(
|
||||
function createRender(
|
||||
props: Partial<{
|
||||
filters: FuseFilterWithValue<ComfyNodeDefImpl, string>[]
|
||||
activeFilter: FilterChip | null
|
||||
@@ -67,101 +68,128 @@ describe('NodeSearchInput', () => {
|
||||
filterQuery: string
|
||||
}> = {}
|
||||
) {
|
||||
return mount(NodeSearchInput, {
|
||||
const user = userEvent.setup()
|
||||
const onUpdateSearchQuery = vi.fn()
|
||||
const onUpdateFilterQuery = vi.fn()
|
||||
const onCancelFilter = vi.fn()
|
||||
const onSelectCurrent = vi.fn()
|
||||
const onNavigateDown = vi.fn()
|
||||
const onNavigateUp = vi.fn()
|
||||
render(NodeSearchInput, {
|
||||
props: {
|
||||
filters: [],
|
||||
activeFilter: null,
|
||||
searchQuery: '',
|
||||
filterQuery: '',
|
||||
'onUpdate:searchQuery': onUpdateSearchQuery,
|
||||
'onUpdate:filterQuery': onUpdateFilterQuery,
|
||||
onCancelFilter,
|
||||
onSelectCurrent,
|
||||
onNavigateDown,
|
||||
onNavigateUp,
|
||||
...props
|
||||
},
|
||||
global: { plugins: [testI18n] }
|
||||
})
|
||||
return {
|
||||
user,
|
||||
onUpdateSearchQuery,
|
||||
onUpdateFilterQuery,
|
||||
onCancelFilter,
|
||||
onSelectCurrent,
|
||||
onNavigateDown,
|
||||
onNavigateUp
|
||||
}
|
||||
}
|
||||
|
||||
it('should route input to searchQuery when no active filter', async () => {
|
||||
const wrapper = createWrapper()
|
||||
await wrapper.find('input').setValue('test search')
|
||||
const { user, onUpdateSearchQuery } = createRender()
|
||||
await user.type(screen.getByRole('combobox'), 'test search')
|
||||
|
||||
expect(wrapper.emitted('update:searchQuery')![0]).toEqual(['test search'])
|
||||
expect(onUpdateSearchQuery).toHaveBeenLastCalledWith('test search')
|
||||
})
|
||||
|
||||
it('should route input to filterQuery when active filter is set', async () => {
|
||||
const wrapper = createWrapper({
|
||||
const { user, onUpdateFilterQuery, onUpdateSearchQuery } = createRender({
|
||||
activeFilter: createActiveFilter('Input')
|
||||
})
|
||||
await wrapper.find('input').setValue('IMAGE')
|
||||
await user.type(screen.getByRole('combobox'), 'IMAGE')
|
||||
|
||||
expect(wrapper.emitted('update:filterQuery')![0]).toEqual(['IMAGE'])
|
||||
expect(wrapper.emitted('update:searchQuery')).toBeUndefined()
|
||||
expect(onUpdateFilterQuery).toHaveBeenLastCalledWith('IMAGE')
|
||||
expect(onUpdateSearchQuery).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should show filter label placeholder when active filter is set', () => {
|
||||
const wrapper = createWrapper({
|
||||
createRender({
|
||||
activeFilter: createActiveFilter('Input')
|
||||
})
|
||||
|
||||
expect(
|
||||
(wrapper.find('input').element as HTMLInputElement).placeholder
|
||||
).toContain('input')
|
||||
expect(screen.getByRole('combobox')).toHaveAttribute(
|
||||
'placeholder',
|
||||
expect.stringContaining('input')
|
||||
)
|
||||
})
|
||||
|
||||
it('should show add node placeholder when no active filter', () => {
|
||||
const wrapper = createWrapper()
|
||||
createRender()
|
||||
|
||||
expect(
|
||||
(wrapper.find('input').element as HTMLInputElement).placeholder
|
||||
).toContain('Add a node')
|
||||
expect(screen.getByRole('combobox')).toHaveAttribute(
|
||||
'placeholder',
|
||||
expect.stringContaining('Add a node')
|
||||
)
|
||||
})
|
||||
|
||||
it('should hide filter chips when active filter is set', () => {
|
||||
const wrapper = createWrapper({
|
||||
createRender({
|
||||
filters: [createFilter('input', 'IMAGE')],
|
||||
activeFilter: createActiveFilter('Input')
|
||||
})
|
||||
|
||||
expect(wrapper.findAll('[data-testid="filter-chip"]')).toHaveLength(0)
|
||||
expect(screen.queryAllByTestId('filter-chip')).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('should show filter chips when no active filter', () => {
|
||||
const wrapper = createWrapper({
|
||||
createRender({
|
||||
filters: [createFilter('input', 'IMAGE')]
|
||||
})
|
||||
|
||||
expect(wrapper.findAll('[data-testid="filter-chip"]')).toHaveLength(1)
|
||||
expect(screen.getAllByTestId('filter-chip')).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('should emit cancelFilter when cancel button is clicked', async () => {
|
||||
const wrapper = createWrapper({
|
||||
const { user, onCancelFilter } = createRender({
|
||||
activeFilter: createActiveFilter('Input')
|
||||
})
|
||||
|
||||
await wrapper.find('[data-testid="cancel-filter"]').trigger('click')
|
||||
await user.click(screen.getByTestId('cancel-filter'))
|
||||
|
||||
expect(wrapper.emitted('cancelFilter')).toHaveLength(1)
|
||||
expect(onCancelFilter).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it('should emit selectCurrent on Enter', async () => {
|
||||
const wrapper = createWrapper()
|
||||
const { user, onSelectCurrent } = createRender()
|
||||
|
||||
await wrapper.find('input').trigger('keydown', { key: 'Enter' })
|
||||
await user.click(screen.getByRole('combobox'))
|
||||
await user.keyboard('{Enter}')
|
||||
|
||||
expect(wrapper.emitted('selectCurrent')).toHaveLength(1)
|
||||
expect(onSelectCurrent).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it('should emit navigateDown on ArrowDown', async () => {
|
||||
const wrapper = createWrapper()
|
||||
const { user, onNavigateDown } = createRender()
|
||||
|
||||
await wrapper.find('input').trigger('keydown', { key: 'ArrowDown' })
|
||||
await user.click(screen.getByRole('combobox'))
|
||||
await user.keyboard('{ArrowDown}')
|
||||
|
||||
expect(wrapper.emitted('navigateDown')).toHaveLength(1)
|
||||
expect(onNavigateDown).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it('should emit navigateUp on ArrowUp', async () => {
|
||||
const wrapper = createWrapper()
|
||||
const { user, onNavigateUp } = createRender()
|
||||
|
||||
await wrapper.find('input').trigger('keydown', { key: 'ArrowUp' })
|
||||
await user.click(screen.getByRole('combobox'))
|
||||
await user.keyboard('{ArrowUp}')
|
||||
|
||||
expect(wrapper.emitted('navigateUp')).toHaveLength(1)
|
||||
expect(onNavigateUp).toHaveBeenCalledOnce()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
/* eslint-disable vue/one-component-per-file */
|
||||
import { render, fireEvent } from '@testing-library/vue'
|
||||
import { defineComponent } from 'vue'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
|
||||
@@ -31,6 +32,32 @@ const VirtualGridStub = defineComponent({
|
||||
'<div><slot v-for="item in items" :key="item.key" name="item" :item="item" /></div>'
|
||||
})
|
||||
|
||||
const AssetsListItemStub = defineComponent({
|
||||
name: 'AssetsListItem',
|
||||
props: {
|
||||
previewUrl: { type: String, default: '' },
|
||||
isVideoPreview: { type: Boolean, default: false },
|
||||
previewAlt: { type: String, default: '' },
|
||||
iconName: { type: String, default: '' },
|
||||
iconAriaLabel: { type: String, default: '' },
|
||||
iconClass: { type: String, default: '' },
|
||||
iconWrapperClass: { type: String, default: '' },
|
||||
primaryText: { type: String, default: '' },
|
||||
secondaryText: { type: String, default: '' },
|
||||
stackCount: { type: Number, default: 0 },
|
||||
stackIndicatorLabel: { type: String, default: '' },
|
||||
stackExpanded: { type: Boolean, default: false },
|
||||
progressTotalPercent: { type: Number, default: undefined },
|
||||
progressCurrentPercent: { type: Number, default: undefined }
|
||||
},
|
||||
template: `<div
|
||||
class="assets-list-item-stub"
|
||||
:data-preview-url="previewUrl"
|
||||
:data-is-video-preview="isVideoPreview"
|
||||
data-testid="assets-list-item"
|
||||
><button data-testid="preview-click-trigger" @click="$emit('preview-click')" /><slot /></div>`
|
||||
})
|
||||
|
||||
const buildAsset = (id: string, name: string): AssetItem =>
|
||||
({
|
||||
id,
|
||||
@@ -43,21 +70,27 @@ const buildOutputItem = (asset: AssetItem): OutputStackListItem => ({
|
||||
asset
|
||||
})
|
||||
|
||||
const mountListView = (assetItems: OutputStackListItem[] = []) =>
|
||||
mount(AssetsSidebarListView, {
|
||||
function renderListView(
|
||||
assetItems: OutputStackListItem[] = [],
|
||||
props: Record<string, unknown> = {}
|
||||
) {
|
||||
return render(AssetsSidebarListView, {
|
||||
props: {
|
||||
assetItems,
|
||||
selectableAssets: [],
|
||||
isSelected: () => false,
|
||||
isStackExpanded: () => false,
|
||||
toggleStack: async () => {}
|
||||
toggleStack: async () => {},
|
||||
...props
|
||||
},
|
||||
global: {
|
||||
stubs: {
|
||||
VirtualGrid: VirtualGridStub
|
||||
VirtualGrid: VirtualGridStub,
|
||||
AssetsListItem: AssetsListItemStub
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
describe('AssetsSidebarListView', () => {
|
||||
it('marks mp4 assets as video previews', () => {
|
||||
@@ -67,14 +100,17 @@ describe('AssetsSidebarListView', () => {
|
||||
user_metadata: {}
|
||||
} satisfies AssetItem
|
||||
|
||||
const wrapper = mountListView([buildOutputItem(videoAsset)])
|
||||
const { container } = renderListView([buildOutputItem(videoAsset)])
|
||||
|
||||
const listItems = wrapper.findAllComponents({ name: 'AssetsListItem' })
|
||||
const assetListItem = listItems.at(-1)
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
const stubs = container.querySelectorAll('[data-testid="assets-list-item"]')
|
||||
const assetListItem = stubs[stubs.length - 1]
|
||||
|
||||
expect(assetListItem).toBeDefined()
|
||||
expect(assetListItem?.props('previewUrl')).toBe('/api/view/clip.mp4')
|
||||
expect(assetListItem?.props('isVideoPreview')).toBe(true)
|
||||
expect(assetListItem?.getAttribute('data-preview-url')).toBe(
|
||||
'/api/view/clip.mp4'
|
||||
)
|
||||
expect(assetListItem?.getAttribute('data-is-video-preview')).toBe('true')
|
||||
})
|
||||
|
||||
it('uses icon fallback for text assets even when preview_url exists', () => {
|
||||
@@ -84,14 +120,15 @@ describe('AssetsSidebarListView', () => {
|
||||
user_metadata: {}
|
||||
} satisfies AssetItem
|
||||
|
||||
const wrapper = mountListView([buildOutputItem(textAsset)])
|
||||
const { container } = renderListView([buildOutputItem(textAsset)])
|
||||
|
||||
const listItems = wrapper.findAllComponents({ name: 'AssetsListItem' })
|
||||
const assetListItem = listItems.at(-1)
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
const stubs = container.querySelectorAll('[data-testid="assets-list-item"]')
|
||||
const assetListItem = stubs[stubs.length - 1]
|
||||
|
||||
expect(assetListItem).toBeDefined()
|
||||
expect(assetListItem?.props('previewUrl')).toBe('')
|
||||
expect(assetListItem?.props('isVideoPreview')).toBe(false)
|
||||
expect(assetListItem?.getAttribute('data-preview-url')).toBe('')
|
||||
expect(assetListItem?.getAttribute('data-is-video-preview')).toBe('false')
|
||||
})
|
||||
|
||||
it('emits preview-asset when item preview is clicked', async () => {
|
||||
@@ -101,16 +138,19 @@ describe('AssetsSidebarListView', () => {
|
||||
user_metadata: {}
|
||||
} satisfies AssetItem
|
||||
|
||||
const wrapper = mountListView([buildOutputItem(imageAsset)])
|
||||
const listItems = wrapper.findAllComponents({ name: 'AssetsListItem' })
|
||||
const assetListItem = listItems.at(-1)
|
||||
const onPreviewAsset = vi.fn()
|
||||
const { container } = renderListView([buildOutputItem(imageAsset)], {
|
||||
'onPreview-asset': onPreviewAsset
|
||||
})
|
||||
|
||||
expect(assetListItem).toBeDefined()
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
const trigger = container.querySelector(
|
||||
'[data-testid="preview-click-trigger"]'
|
||||
)!
|
||||
// eslint-disable-next-line testing-library/prefer-user-event
|
||||
await fireEvent.click(trigger)
|
||||
|
||||
assetListItem!.vm.$emit('preview-click')
|
||||
await wrapper.vm.$nextTick()
|
||||
|
||||
expect(wrapper.emitted('preview-asset')).toEqual([[imageAsset]])
|
||||
expect(onPreviewAsset).toHaveBeenCalledWith(imageAsset)
|
||||
})
|
||||
|
||||
it('emits preview-asset when item is double-clicked', async () => {
|
||||
@@ -120,15 +160,16 @@ describe('AssetsSidebarListView', () => {
|
||||
user_metadata: {}
|
||||
} satisfies AssetItem
|
||||
|
||||
const wrapper = mountListView([buildOutputItem(imageAsset)])
|
||||
const listItems = wrapper.findAllComponents({ name: 'AssetsListItem' })
|
||||
const assetListItem = listItems.at(-1)
|
||||
const onPreviewAsset = vi.fn()
|
||||
const { container } = renderListView([buildOutputItem(imageAsset)], {
|
||||
'onPreview-asset': onPreviewAsset
|
||||
})
|
||||
|
||||
expect(assetListItem).toBeDefined()
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
const stub = container.querySelector('[data-testid="assets-list-item"]')!
|
||||
// eslint-disable-next-line testing-library/prefer-user-event
|
||||
await fireEvent.dblClick(stub)
|
||||
|
||||
await assetListItem!.trigger('dblclick')
|
||||
await wrapper.vm.$nextTick()
|
||||
|
||||
expect(wrapper.emitted('preview-asset')).toEqual([[imageAsset]])
|
||||
expect(onPreviewAsset).toHaveBeenCalledWith(imageAsset)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { createTestingPinia } from '@pinia/testing'
|
||||
import { ref } from 'vue'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
|
||||
import NodeLibrarySidebarTabV2 from './NodeLibrarySidebarTabV2.vue'
|
||||
|
||||
vi.mock('@vueuse/core', async () => {
|
||||
@@ -91,8 +92,8 @@ describe('NodeLibrarySidebarTabV2', () => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
function mountComponent() {
|
||||
return mount(NodeLibrarySidebarTabV2, {
|
||||
function renderComponent() {
|
||||
return render(NodeLibrarySidebarTabV2, {
|
||||
global: {
|
||||
plugins: [createTestingPinia({ stubActions: false }), i18n],
|
||||
stubs: {
|
||||
@@ -103,25 +104,23 @@ describe('NodeLibrarySidebarTabV2', () => {
|
||||
}
|
||||
|
||||
it('should render with tabs', () => {
|
||||
const wrapper = mountComponent()
|
||||
renderComponent()
|
||||
|
||||
const triggers = wrapper.findAll('[role="tab"]')
|
||||
const triggers = screen.getAllByRole('tab')
|
||||
expect(triggers).toHaveLength(3)
|
||||
})
|
||||
|
||||
it('should render search box', () => {
|
||||
const wrapper = mountComponent()
|
||||
renderComponent()
|
||||
|
||||
expect(wrapper.find('[data-testid="search-box"]').exists()).toBe(true)
|
||||
expect(screen.getByTestId('search-box')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should render only the selected panel', () => {
|
||||
const wrapper = mountComponent()
|
||||
renderComponent()
|
||||
|
||||
expect(wrapper.find('[data-testid="essential-panel"]').exists()).toBe(true)
|
||||
expect(wrapper.find('[data-testid="all-panel"]').exists()).toBe(false)
|
||||
expect(wrapper.find('[data-testid="blueprints-panel"]').exists()).toBe(
|
||||
false
|
||||
)
|
||||
expect(screen.getByTestId('essential-panel')).toBeInTheDocument()
|
||||
expect(screen.queryByTestId('all-panel')).not.toBeInTheDocument()
|
||||
expect(screen.queryByTestId('blueprints-panel')).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { fireEvent, render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import type { ComfyNodeDefImpl } from '@/stores/nodeDefStore'
|
||||
@@ -25,7 +26,9 @@ vi.mock('@/composables/node/useNodeDragToCanvas', () => ({
|
||||
}))
|
||||
|
||||
vi.mock('@/components/node/NodePreviewCard.vue', () => ({
|
||||
default: { template: '<div class="mock-preview" />' }
|
||||
default: {
|
||||
template: '<div class="mock-preview" data-testid="node-preview" />'
|
||||
}
|
||||
}))
|
||||
|
||||
describe('EssentialNodeCard', () => {
|
||||
@@ -52,69 +55,93 @@ describe('EssentialNodeCard', () => {
|
||||
}
|
||||
}
|
||||
|
||||
function mountComponent(
|
||||
function renderComponent(
|
||||
node: RenderedTreeExplorerNode<ComfyNodeDefImpl> = createMockNode()
|
||||
) {
|
||||
return mount(EssentialNodeCard, {
|
||||
props: { node },
|
||||
const onClick = vi.fn()
|
||||
const user = userEvent.setup()
|
||||
const { container } = render(EssentialNodeCard, {
|
||||
props: { node, onClick },
|
||||
global: {
|
||||
stubs: {
|
||||
Teleport: true
|
||||
}
|
||||
}
|
||||
})
|
||||
return { user, onClick, container }
|
||||
}
|
||||
|
||||
function getCard(container: Element) {
|
||||
/* eslint-disable testing-library/no-container, testing-library/no-node-access */
|
||||
const card = container.querySelector('[data-node-name]') as HTMLElement
|
||||
/* eslint-enable testing-library/no-container, testing-library/no-node-access */
|
||||
return card
|
||||
}
|
||||
|
||||
describe('rendering', () => {
|
||||
it('should display the node display_name', () => {
|
||||
const wrapper = mountComponent(
|
||||
createMockNode({ display_name: 'Load Image' })
|
||||
)
|
||||
expect(wrapper.text()).toContain('Load Image')
|
||||
renderComponent(createMockNode({ display_name: 'Load Image' }))
|
||||
expect(screen.getAllByText('Load Image').length).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
it('should set data-node-name attribute', () => {
|
||||
const wrapper = mountComponent(
|
||||
const { container } = renderComponent(
|
||||
createMockNode({ display_name: 'Save Image' })
|
||||
)
|
||||
const card = wrapper.find('[data-node-name]')
|
||||
expect(card.attributes('data-node-name')).toBe('Save Image')
|
||||
/* eslint-disable testing-library/no-container, testing-library/no-node-access */
|
||||
const card = container.querySelector('[data-node-name]')
|
||||
/* eslint-enable testing-library/no-container, testing-library/no-node-access */
|
||||
expect(card).toHaveAttribute('data-node-name', 'Save Image')
|
||||
})
|
||||
|
||||
it('should be draggable', () => {
|
||||
const wrapper = mountComponent()
|
||||
const card = wrapper.find('[draggable]')
|
||||
expect(card.attributes('draggable')).toBe('true')
|
||||
const { container } = renderComponent()
|
||||
/* eslint-disable testing-library/no-container, testing-library/no-node-access */
|
||||
const card = container.querySelector('[draggable]')
|
||||
/* eslint-enable testing-library/no-container, testing-library/no-node-access */
|
||||
expect(card).toHaveAttribute('draggable', 'true')
|
||||
})
|
||||
})
|
||||
|
||||
describe('icon generation', () => {
|
||||
it('should use override icon for LoadImage', () => {
|
||||
const wrapper = mountComponent(createMockNode({ name: 'LoadImage' }))
|
||||
const icon = wrapper.find('i')
|
||||
expect(icon.classes()).toContain('icon-s1.3-[lucide--image-up]')
|
||||
const { container } = renderComponent(
|
||||
createMockNode({ name: 'LoadImage' })
|
||||
)
|
||||
/* eslint-disable testing-library/no-container, testing-library/no-node-access */
|
||||
const icon = container.querySelector('i')
|
||||
/* eslint-enable testing-library/no-container, testing-library/no-node-access */
|
||||
expect(icon).toHaveClass('icon-s1.3-[lucide--image-up]')
|
||||
})
|
||||
|
||||
it('should use override icon for SaveImage', () => {
|
||||
const wrapper = mountComponent(createMockNode({ name: 'SaveImage' }))
|
||||
const icon = wrapper.find('i')
|
||||
expect(icon.classes()).toContain('icon-s1.3-[lucide--image-down]')
|
||||
const { container } = renderComponent(
|
||||
createMockNode({ name: 'SaveImage' })
|
||||
)
|
||||
/* eslint-disable testing-library/no-container, testing-library/no-node-access */
|
||||
const icon = container.querySelector('i')
|
||||
/* eslint-enable testing-library/no-container, testing-library/no-node-access */
|
||||
expect(icon).toHaveClass('icon-s1.3-[lucide--image-down]')
|
||||
})
|
||||
|
||||
it('should use override icon for ImageCrop', () => {
|
||||
const wrapper = mountComponent(createMockNode({ name: 'ImageCrop' }))
|
||||
const icon = wrapper.find('i')
|
||||
expect(icon.classes()).toContain('icon-s1.3-[lucide--crop]')
|
||||
const { container } = renderComponent(
|
||||
createMockNode({ name: 'ImageCrop' })
|
||||
)
|
||||
/* eslint-disable testing-library/no-container, testing-library/no-node-access */
|
||||
const icon = container.querySelector('i')
|
||||
/* eslint-enable testing-library/no-container, testing-library/no-node-access */
|
||||
expect(icon).toHaveClass('icon-s1.3-[lucide--crop]')
|
||||
})
|
||||
|
||||
it('should use kebab-case for complex node names', () => {
|
||||
const wrapper = mountComponent(
|
||||
const { container } = renderComponent(
|
||||
createMockNode({ name: 'RecraftRemoveBackgroundNode' })
|
||||
)
|
||||
const icon = wrapper.find('i')
|
||||
expect(icon.classes()).toContain(
|
||||
'icon-[comfy--recraft-remove-background-node]'
|
||||
)
|
||||
/* eslint-disable testing-library/no-container, testing-library/no-node-access */
|
||||
const icon = container.querySelector('i')
|
||||
/* eslint-enable testing-library/no-container, testing-library/no-node-access */
|
||||
expect(icon).toHaveClass('icon-[comfy--recraft-remove-background-node]')
|
||||
})
|
||||
|
||||
it('should use default node icon when nodeDef has no name', () => {
|
||||
@@ -126,21 +153,22 @@ describe('EssentialNodeCard', () => {
|
||||
totalLeaves: 1,
|
||||
data: undefined
|
||||
}
|
||||
const wrapper = mountComponent(node)
|
||||
const icon = wrapper.find('i')
|
||||
expect(icon.classes()).toContain('icon-[comfy--node]')
|
||||
const { container } = renderComponent(node)
|
||||
/* eslint-disable testing-library/no-container, testing-library/no-node-access */
|
||||
const icon = container.querySelector('i')
|
||||
/* eslint-enable testing-library/no-container, testing-library/no-node-access */
|
||||
expect(icon).toHaveClass('icon-[comfy--node]')
|
||||
})
|
||||
})
|
||||
|
||||
describe('events', () => {
|
||||
it('should emit click event when clicked', async () => {
|
||||
const node = createMockNode()
|
||||
const wrapper = mountComponent(node)
|
||||
const { user, onClick, container } = renderComponent(node)
|
||||
|
||||
await wrapper.find('div').trigger('click')
|
||||
await user.click(getCard(container))
|
||||
|
||||
expect(wrapper.emitted('click')).toBeTruthy()
|
||||
expect(wrapper.emitted('click')?.[0]).toEqual([node])
|
||||
expect(onClick).toHaveBeenCalledWith(node)
|
||||
})
|
||||
|
||||
it('should not emit click when nodeDef is undefined', async () => {
|
||||
@@ -152,29 +180,27 @@ describe('EssentialNodeCard', () => {
|
||||
totalLeaves: 1,
|
||||
data: undefined
|
||||
}
|
||||
const wrapper = mountComponent(node)
|
||||
const { user, onClick, container } = renderComponent(node)
|
||||
|
||||
await wrapper.find('div').trigger('click')
|
||||
await user.click(getCard(container))
|
||||
|
||||
expect(wrapper.emitted('click')).toBeFalsy()
|
||||
expect(onClick).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('drag and drop', () => {
|
||||
it('should call startDrag on dragstart', async () => {
|
||||
const wrapper = mountComponent()
|
||||
const card = wrapper.find('div')
|
||||
const { container } = renderComponent()
|
||||
|
||||
await card.trigger('dragstart')
|
||||
await fireEvent.dragStart(getCard(container))
|
||||
|
||||
expect(mockStartDrag).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should call handleNativeDrop on dragend', async () => {
|
||||
const wrapper = mountComponent()
|
||||
const card = wrapper.find('div')
|
||||
const { container } = renderComponent()
|
||||
|
||||
await card.trigger('dragend')
|
||||
await fireEvent.dragEnd(getCard(container))
|
||||
|
||||
expect(mockHandleNativeDrop).toHaveBeenCalled()
|
||||
})
|
||||
@@ -182,23 +208,21 @@ describe('EssentialNodeCard', () => {
|
||||
|
||||
describe('hover preview', () => {
|
||||
it('should show preview on mouseenter', async () => {
|
||||
const wrapper = mountComponent()
|
||||
const card = wrapper.find('div')
|
||||
const { user, container } = renderComponent()
|
||||
|
||||
await card.trigger('mouseenter')
|
||||
await user.hover(getCard(container))
|
||||
|
||||
expect(wrapper.find('teleport-stub').exists()).toBe(true)
|
||||
expect(screen.getByTestId('node-preview')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should hide preview after mouseleave', async () => {
|
||||
const wrapper = mountComponent()
|
||||
const card = wrapper.find('div')
|
||||
const { user, container } = renderComponent()
|
||||
|
||||
await card.trigger('mouseenter')
|
||||
expect(wrapper.find('teleport-stub').exists()).toBe(true)
|
||||
await user.hover(getCard(container))
|
||||
expect(screen.getByTestId('node-preview')).toBeInTheDocument()
|
||||
|
||||
await card.trigger('mouseleave')
|
||||
expect(wrapper.find('teleport-stub').exists()).toBe(false)
|
||||
await user.unhover(getCard(container))
|
||||
expect(screen.queryByTestId('node-preview')).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { nextTick, ref } from 'vue'
|
||||
import { render, waitFor } from '@testing-library/vue'
|
||||
import { ref } from 'vue'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import type { ComfyNodeDefImpl } from '@/stores/nodeDefStore'
|
||||
@@ -80,7 +80,7 @@ describe('EssentialNodesPanel', () => {
|
||||
}
|
||||
}
|
||||
|
||||
function mountComponent(
|
||||
function renderComponent(
|
||||
root = createMockRoot(),
|
||||
expandedKeys: string[] = [],
|
||||
flatNodes: RenderedTreeExplorerNode<ComfyNodeDefImpl>[] = []
|
||||
@@ -93,7 +93,7 @@ describe('EssentialNodesPanel', () => {
|
||||
return { root, flatNodes, keys }
|
||||
}
|
||||
}
|
||||
return mount(WrapperComponent, {
|
||||
return render(WrapperComponent, {
|
||||
global: {
|
||||
stubs: {
|
||||
Teleport: true,
|
||||
@@ -112,6 +112,9 @@ describe('EssentialNodesPanel', () => {
|
||||
},
|
||||
CollapsibleContent: {
|
||||
template: '<div class="collapsible-content"><slot /></div>'
|
||||
},
|
||||
EssentialNodeCard: {
|
||||
template: '<div data-testid="essential-node-card" />'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,54 +123,61 @@ describe('EssentialNodesPanel', () => {
|
||||
|
||||
describe('folder rendering', () => {
|
||||
it('should render all top-level folders', () => {
|
||||
const wrapper = mountComponent()
|
||||
const triggers = wrapper.findAll('.collapsible-trigger')
|
||||
expect(triggers).toHaveLength(3)
|
||||
const { container } = renderComponent()
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
expect(container.querySelectorAll('.collapsible-trigger')).toHaveLength(3)
|
||||
})
|
||||
|
||||
it('should display folder labels', () => {
|
||||
const wrapper = mountComponent()
|
||||
expect(wrapper.text()).toContain('images')
|
||||
expect(wrapper.text()).toContain('video')
|
||||
expect(wrapper.text()).toContain('audio')
|
||||
const { container } = renderComponent()
|
||||
expect(container.textContent).toContain('images')
|
||||
expect(container.textContent).toContain('video')
|
||||
expect(container.textContent).toContain('audio')
|
||||
})
|
||||
})
|
||||
|
||||
describe('default expansion', () => {
|
||||
it('should expand all folders by default when expandedKeys is empty', async () => {
|
||||
const wrapper = mountComponent(createMockRoot(), [])
|
||||
await nextTick()
|
||||
await flushPromises()
|
||||
await nextTick()
|
||||
const { container } = renderComponent(createMockRoot(), [])
|
||||
|
||||
const roots = wrapper.findAll('.collapsible-root')
|
||||
expect(roots[0].attributes('data-state')).toBe('open')
|
||||
expect(roots[1].attributes('data-state')).toBe('open')
|
||||
expect(roots[2].attributes('data-state')).toBe('open')
|
||||
await waitFor(() => {
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
const roots = container.querySelectorAll('.collapsible-root')
|
||||
expect(roots).toHaveLength(3)
|
||||
expect(roots[0].getAttribute('data-state')).toBe('open')
|
||||
expect(roots[1].getAttribute('data-state')).toBe('open')
|
||||
expect(roots[2].getAttribute('data-state')).toBe('open')
|
||||
})
|
||||
})
|
||||
|
||||
it('should respect provided expandedKeys', async () => {
|
||||
const wrapper = mountComponent(createMockRoot(), ['folder-audio'])
|
||||
await nextTick()
|
||||
const { container } = renderComponent(createMockRoot(), ['folder-audio'])
|
||||
|
||||
const roots = wrapper.findAll('.collapsible-root')
|
||||
expect(roots[0].attributes('data-state')).toBe('closed')
|
||||
expect(roots[1].attributes('data-state')).toBe('closed')
|
||||
expect(roots[2].attributes('data-state')).toBe('open')
|
||||
await waitFor(() => {
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
const roots = container.querySelectorAll('.collapsible-root')
|
||||
expect(roots).toHaveLength(3)
|
||||
expect(roots[0].getAttribute('data-state')).toBe('closed')
|
||||
expect(roots[1].getAttribute('data-state')).toBe('closed')
|
||||
expect(roots[2].getAttribute('data-state')).toBe('open')
|
||||
})
|
||||
})
|
||||
|
||||
it('should expand all provided keys', async () => {
|
||||
const wrapper = mountComponent(createMockRoot(), [
|
||||
const { container } = renderComponent(createMockRoot(), [
|
||||
'folder-images',
|
||||
'folder-video',
|
||||
'folder-audio'
|
||||
])
|
||||
await nextTick()
|
||||
|
||||
const roots = wrapper.findAll('.collapsible-root')
|
||||
expect(roots[0].attributes('data-state')).toBe('open')
|
||||
expect(roots[1].attributes('data-state')).toBe('open')
|
||||
expect(roots[2].attributes('data-state')).toBe('open')
|
||||
await waitFor(() => {
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
const roots = container.querySelectorAll('.collapsible-root')
|
||||
expect(roots).toHaveLength(3)
|
||||
expect(roots[0].getAttribute('data-state')).toBe('open')
|
||||
expect(roots[1].getAttribute('data-state')).toBe('open')
|
||||
expect(roots[2].getAttribute('data-state')).toBe('open')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -187,21 +197,24 @@ describe('EssentialNodesPanel', () => {
|
||||
]
|
||||
}
|
||||
|
||||
const wrapper = mountComponent(root, [])
|
||||
await nextTick()
|
||||
await flushPromises()
|
||||
await nextTick()
|
||||
const { container } = renderComponent(root, [])
|
||||
|
||||
const roots = wrapper.findAll('.collapsible-root')
|
||||
expect(roots).toHaveLength(1)
|
||||
expect(roots[0].attributes('data-state')).toBe('open')
|
||||
await waitFor(() => {
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
const roots = container.querySelectorAll('.collapsible-root')
|
||||
expect(roots).toHaveLength(1)
|
||||
expect(roots[0].getAttribute('data-state')).toBe('open')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('node cards', () => {
|
||||
it('should render node cards for each node in expanded folders', () => {
|
||||
const wrapper = mountComponent(createMockRoot(), ['folder-images'])
|
||||
const cards = wrapper.findAllComponents({ name: 'EssentialNodeCard' })
|
||||
const { container } = renderComponent(createMockRoot(), ['folder-images'])
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
const cards = container.querySelectorAll(
|
||||
'[data-testid="essential-node-card"]'
|
||||
)
|
||||
expect(cards.length).toBeGreaterThanOrEqual(2)
|
||||
})
|
||||
})
|
||||
@@ -213,11 +226,15 @@ describe('EssentialNodesPanel', () => {
|
||||
createMockNode('LoadImage'),
|
||||
createMockNode('SaveImage')
|
||||
]
|
||||
const wrapper = mountComponent(createMockRoot(), [], flatNodes)
|
||||
const { container } = renderComponent(createMockRoot(), [], flatNodes)
|
||||
|
||||
expect(wrapper.findAll('.collapsible-root')).toHaveLength(0)
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
expect(container.querySelectorAll('.collapsible-root')).toHaveLength(0)
|
||||
|
||||
const cards = wrapper.findAllComponents({ name: 'EssentialNodeCard' })
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
const cards = container.querySelectorAll(
|
||||
'[data-testid="essential-node-card"]'
|
||||
)
|
||||
expect(cards).toHaveLength(3)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { enableAutoUnmount, mount } from '@vue/test-utils'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { fireEvent, render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { nextTick } from 'vue'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
enableAutoUnmount(afterEach)
|
||||
|
||||
import type { NodeId } from '@/platform/workflow/validation/schemas/workflowSchema'
|
||||
import type { ResultItemImpl } from '@/stores/queueStore'
|
||||
|
||||
@@ -99,16 +98,13 @@ describe('MediaLightbox', () => {
|
||||
]
|
||||
|
||||
beforeEach(() => {
|
||||
document.body.innerHTML = '<div id="app"></div>'
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
document.body.innerHTML = ''
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
const mountGallery = (props = {}) => {
|
||||
return mount(MediaLightbox, {
|
||||
const renderGallery = (props = {}) => {
|
||||
const onUpdateActiveIndex = vi.fn()
|
||||
const user = userEvent.setup()
|
||||
const { rerender, container } = render(MediaLightbox, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
components: {
|
||||
@@ -123,107 +119,118 @@ describe('MediaLightbox', () => {
|
||||
props: {
|
||||
allGalleryItems: mockGalleryItems as ResultItemImpl[],
|
||||
activeIndex: 0,
|
||||
'onUpdate:activeIndex': onUpdateActiveIndex,
|
||||
...props
|
||||
},
|
||||
attachTo: document.getElementById('app') || undefined
|
||||
container: document.body.appendChild(document.createElement('div'))
|
||||
})
|
||||
return { user, onUpdateActiveIndex, rerender, container }
|
||||
}
|
||||
|
||||
it('renders overlay with role="dialog" and aria-modal', async () => {
|
||||
const wrapper = mountGallery()
|
||||
renderGallery()
|
||||
await nextTick()
|
||||
|
||||
const dialog = wrapper.find('[role="dialog"]')
|
||||
expect(dialog.exists()).toBe(true)
|
||||
expect(dialog.attributes('aria-modal')).toBe('true')
|
||||
const dialog = screen.getByRole('dialog')
|
||||
expect(dialog).toBeInTheDocument()
|
||||
expect(dialog).toHaveAttribute('aria-modal', 'true')
|
||||
})
|
||||
|
||||
it('shows navigation buttons when multiple items', async () => {
|
||||
const wrapper = mountGallery()
|
||||
renderGallery()
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.find('[aria-label="Previous"]').exists()).toBe(true)
|
||||
expect(wrapper.find('[aria-label="Next"]').exists()).toBe(true)
|
||||
expect(screen.getByLabelText('Previous')).toBeInTheDocument()
|
||||
expect(screen.getByLabelText('Next')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('hides navigation buttons for single item', async () => {
|
||||
const wrapper = mountGallery({
|
||||
renderGallery({
|
||||
allGalleryItems: [mockGalleryItems[0]] as ResultItemImpl[]
|
||||
})
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.find('[aria-label="Previous"]').exists()).toBe(false)
|
||||
expect(wrapper.find('[aria-label="Next"]').exists()).toBe(false)
|
||||
expect(screen.queryByLabelText('Previous')).not.toBeInTheDocument()
|
||||
expect(screen.queryByLabelText('Next')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows gallery when activeIndex changes from -1', async () => {
|
||||
const wrapper = mountGallery({ activeIndex: -1 })
|
||||
const { rerender, container } = renderGallery({ activeIndex: -1 })
|
||||
|
||||
expect(wrapper.find('[data-mask]').exists()).toBe(false)
|
||||
/* eslint-disable testing-library/no-container, testing-library/no-node-access */
|
||||
expect(container.querySelector('[data-mask]')).not.toBeInTheDocument()
|
||||
/* eslint-enable testing-library/no-container, testing-library/no-node-access */
|
||||
|
||||
await wrapper.setProps({ activeIndex: 0 })
|
||||
await rerender({
|
||||
allGalleryItems: mockGalleryItems as ResultItemImpl[],
|
||||
activeIndex: 0
|
||||
})
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.find('[data-mask]').exists()).toBe(true)
|
||||
/* eslint-disable testing-library/no-container, testing-library/no-node-access */
|
||||
expect(container.querySelector('[data-mask]')).toBeInTheDocument()
|
||||
/* eslint-enable testing-library/no-container, testing-library/no-node-access */
|
||||
})
|
||||
|
||||
it('emits update:activeIndex with -1 when close button clicked', async () => {
|
||||
const wrapper = mountGallery()
|
||||
const { user, onUpdateActiveIndex } = renderGallery()
|
||||
await nextTick()
|
||||
|
||||
await wrapper.find('[aria-label="Close"]').trigger('click')
|
||||
await user.click(screen.getByLabelText('Close'))
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.emitted('update:activeIndex')?.[0]).toEqual([-1])
|
||||
expect(onUpdateActiveIndex).toHaveBeenCalledWith(-1)
|
||||
})
|
||||
|
||||
/* eslint-disable testing-library/prefer-user-event -- keyDown on dialog element for navigation, not text input */
|
||||
describe('keyboard navigation', () => {
|
||||
it('navigates to next item on ArrowRight', async () => {
|
||||
const wrapper = mountGallery({ activeIndex: 0 })
|
||||
const { onUpdateActiveIndex } = renderGallery({ activeIndex: 0 })
|
||||
await nextTick()
|
||||
|
||||
await wrapper
|
||||
.find('[role="dialog"]')
|
||||
.trigger('keydown', { key: 'ArrowRight' })
|
||||
await fireEvent.keyDown(screen.getByRole('dialog'), {
|
||||
key: 'ArrowRight'
|
||||
})
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.emitted('update:activeIndex')?.[0]).toEqual([1])
|
||||
expect(onUpdateActiveIndex).toHaveBeenCalledWith(1)
|
||||
})
|
||||
|
||||
it('navigates to previous item on ArrowLeft', async () => {
|
||||
const wrapper = mountGallery({ activeIndex: 1 })
|
||||
const { onUpdateActiveIndex } = renderGallery({ activeIndex: 1 })
|
||||
await nextTick()
|
||||
|
||||
await wrapper
|
||||
.find('[role="dialog"]')
|
||||
.trigger('keydown', { key: 'ArrowLeft' })
|
||||
await fireEvent.keyDown(screen.getByRole('dialog'), {
|
||||
key: 'ArrowLeft'
|
||||
})
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.emitted('update:activeIndex')?.[0]).toEqual([0])
|
||||
expect(onUpdateActiveIndex).toHaveBeenCalledWith(0)
|
||||
})
|
||||
|
||||
it('wraps to last item on ArrowLeft from first', async () => {
|
||||
const wrapper = mountGallery({ activeIndex: 0 })
|
||||
const { onUpdateActiveIndex } = renderGallery({ activeIndex: 0 })
|
||||
await nextTick()
|
||||
|
||||
await wrapper
|
||||
.find('[role="dialog"]')
|
||||
.trigger('keydown', { key: 'ArrowLeft' })
|
||||
await fireEvent.keyDown(screen.getByRole('dialog'), {
|
||||
key: 'ArrowLeft'
|
||||
})
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.emitted('update:activeIndex')?.[0]).toEqual([2])
|
||||
expect(onUpdateActiveIndex).toHaveBeenCalledWith(2)
|
||||
})
|
||||
|
||||
it('closes gallery on Escape', async () => {
|
||||
const wrapper = mountGallery({ activeIndex: 0 })
|
||||
const { onUpdateActiveIndex } = renderGallery({ activeIndex: 0 })
|
||||
await nextTick()
|
||||
|
||||
await wrapper
|
||||
.find('[role="dialog"]')
|
||||
.trigger('keydown', { key: 'Escape' })
|
||||
await fireEvent.keyDown(screen.getByRole('dialog'), {
|
||||
key: 'Escape'
|
||||
})
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.emitted('update:activeIndex')?.[0]).toEqual([-1])
|
||||
expect(onUpdateActiveIndex).toHaveBeenCalledWith(-1)
|
||||
})
|
||||
})
|
||||
/* eslint-enable testing-library/prefer-user-event */
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { ref } from 'vue'
|
||||
|
||||
@@ -30,8 +30,8 @@ vi.mock('@vueuse/core', () => ({
|
||||
}))
|
||||
|
||||
describe('CompareSliderThumbnail', () => {
|
||||
const mountThumbnail = (props = {}) => {
|
||||
return mount(CompareSliderThumbnail, {
|
||||
const renderThumbnail = (props = {}) => {
|
||||
return render(CompareSliderThumbnail, {
|
||||
props: {
|
||||
baseImageSrc: '/base-image.jpg',
|
||||
overlayImageSrc: '/overlay-image.jpg',
|
||||
@@ -43,42 +43,35 @@ describe('CompareSliderThumbnail', () => {
|
||||
}
|
||||
|
||||
it('renders both base and overlay images', () => {
|
||||
const wrapper = mountThumbnail()
|
||||
const lazyImages = wrapper.findAllComponents({ name: 'LazyImage' })
|
||||
expect(lazyImages.length).toBe(2)
|
||||
expect(lazyImages[0].props('src')).toBe('/base-image.jpg')
|
||||
expect(lazyImages[1].props('src')).toBe('/overlay-image.jpg')
|
||||
renderThumbnail()
|
||||
const images = screen.getAllByRole('img')
|
||||
expect(images).toHaveLength(2)
|
||||
expect(images[0]).toHaveAttribute('src', '/base-image.jpg')
|
||||
expect(images[1]).toHaveAttribute('src', '/overlay-image.jpg')
|
||||
})
|
||||
|
||||
it('applies correct alt text to both images', () => {
|
||||
const wrapper = mountThumbnail({ alt: 'Custom Alt Text' })
|
||||
const lazyImages = wrapper.findAllComponents({ name: 'LazyImage' })
|
||||
expect(lazyImages[0].props('alt')).toBe('Custom Alt Text')
|
||||
expect(lazyImages[1].props('alt')).toBe('Custom Alt Text')
|
||||
renderThumbnail({ alt: 'Custom Alt Text' })
|
||||
const images = screen.getAllByRole('img')
|
||||
expect(images[0]).toHaveAttribute('alt', 'Custom Alt Text')
|
||||
expect(images[1]).toHaveAttribute('alt', 'Custom Alt Text')
|
||||
})
|
||||
|
||||
it('applies clip-path style to overlay image', () => {
|
||||
const wrapper = mountThumbnail()
|
||||
const overlayLazyImage = wrapper.findAllComponents({ name: 'LazyImage' })[1]
|
||||
const imageStyle = overlayLazyImage.props('imageStyle')
|
||||
expect(imageStyle.clipPath).toContain('inset')
|
||||
renderThumbnail()
|
||||
const images = screen.getAllByRole('img')
|
||||
expect(images[1].style.clipPath).toContain('inset')
|
||||
})
|
||||
|
||||
it('renders slider divider', () => {
|
||||
const wrapper = mountThumbnail()
|
||||
const divider = wrapper.find('.bg-white\\/30')
|
||||
expect(divider.exists()).toBe(true)
|
||||
renderThumbnail()
|
||||
const divider = screen.getByTestId('compare-slider-divider')
|
||||
expect(divider).toBeDefined()
|
||||
})
|
||||
|
||||
it('positions slider based on default value', () => {
|
||||
const wrapper = mountThumbnail()
|
||||
const divider = wrapper.find('.bg-white\\/30')
|
||||
expect(divider.attributes('style')).toContain('left: 50%')
|
||||
})
|
||||
|
||||
it('passes isHovered prop to BaseThumbnail', () => {
|
||||
const wrapper = mountThumbnail({ isHovered: true })
|
||||
const baseThumbnail = wrapper.findComponent({ name: 'BaseThumbnail' })
|
||||
expect(baseThumbnail.props('isHovered')).toBe(true)
|
||||
renderThumbnail()
|
||||
const divider = screen.getByTestId('compare-slider-divider')
|
||||
expect(divider.style.left).toBe('50%')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
}"
|
||||
/>
|
||||
<div
|
||||
data-testid="compare-slider-divider"
|
||||
class="pointer-events-none absolute inset-y-0 z-10 w-0.5 bg-white/30 backdrop-blur-sm"
|
||||
:style="{
|
||||
left: `${sliderPosition}%`
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import HoverDissolveThumbnail from '@/components/templates/thumbnails/HoverDissolveThumbnail.vue'
|
||||
@@ -21,8 +21,8 @@ vi.mock('@/components/common/LazyImage.vue', () => ({
|
||||
}))
|
||||
|
||||
describe('HoverDissolveThumbnail', () => {
|
||||
const mountThumbnail = (props = {}) => {
|
||||
return mount(HoverDissolveThumbnail, {
|
||||
const renderThumbnail = (props = {}) => {
|
||||
return render(HoverDissolveThumbnail, {
|
||||
props: {
|
||||
baseImageSrc: '/base-image.jpg',
|
||||
overlayImageSrc: '/overlay-image.jpg',
|
||||
@@ -35,75 +35,31 @@ describe('HoverDissolveThumbnail', () => {
|
||||
}
|
||||
|
||||
it('renders both base and overlay images', () => {
|
||||
const wrapper = mountThumbnail()
|
||||
const lazyImages = wrapper.findAllComponents({ name: 'LazyImage' })
|
||||
expect(lazyImages.length).toBe(2)
|
||||
expect(lazyImages[0].props('src')).toBe('/base-image.jpg')
|
||||
expect(lazyImages[1].props('src')).toBe('/overlay-image.jpg')
|
||||
renderThumbnail()
|
||||
const images = screen.getAllByRole('img')
|
||||
expect(images).toHaveLength(2)
|
||||
expect(images[0]).toHaveAttribute('src', '/base-image.jpg')
|
||||
expect(images[1]).toHaveAttribute('src', '/overlay-image.jpg')
|
||||
})
|
||||
|
||||
it('applies correct alt text to both images', () => {
|
||||
const wrapper = mountThumbnail({ alt: 'Custom Alt Text' })
|
||||
const lazyImages = wrapper.findAllComponents({ name: 'LazyImage' })
|
||||
expect(lazyImages[0].props('alt')).toBe('Custom Alt Text')
|
||||
expect(lazyImages[1].props('alt')).toBe('Custom Alt Text')
|
||||
renderThumbnail({ alt: 'Custom Alt Text' })
|
||||
const images = screen.getAllByRole('img')
|
||||
expect(images[0]).toHaveAttribute('alt', 'Custom Alt Text')
|
||||
expect(images[1]).toHaveAttribute('alt', 'Custom Alt Text')
|
||||
})
|
||||
|
||||
it('makes overlay image visible when hovered', () => {
|
||||
const wrapper = mountThumbnail({ isHovered: true })
|
||||
const overlayLazyImage = wrapper.findAllComponents({ name: 'LazyImage' })[1]
|
||||
const imageClass = overlayLazyImage.props('imageClass')
|
||||
const classString = Array.isArray(imageClass)
|
||||
? imageClass.join(' ')
|
||||
: imageClass
|
||||
expect(classString).toContain('opacity-100')
|
||||
expect(classString).not.toContain('opacity-0')
|
||||
renderThumbnail({ isHovered: true })
|
||||
const images = screen.getAllByRole('img')
|
||||
expect(images[1]).toHaveClass('opacity-100')
|
||||
expect(images[1]).not.toHaveClass('opacity-0')
|
||||
})
|
||||
|
||||
it('makes overlay image hidden when not hovered', () => {
|
||||
const wrapper = mountThumbnail({ isHovered: false })
|
||||
const overlayLazyImage = wrapper.findAllComponents({ name: 'LazyImage' })[1]
|
||||
const imageClass = overlayLazyImage.props('imageClass')
|
||||
const classString = Array.isArray(imageClass)
|
||||
? imageClass.join(' ')
|
||||
: imageClass
|
||||
expect(classString).toContain('opacity-0')
|
||||
expect(classString).not.toContain('opacity-100')
|
||||
})
|
||||
|
||||
it('passes isHovered prop to BaseThumbnail', () => {
|
||||
const wrapper = mountThumbnail({ isHovered: true })
|
||||
const baseThumbnail = wrapper.findComponent({ name: 'BaseThumbnail' })
|
||||
expect(baseThumbnail.props('isHovered')).toBe(true)
|
||||
})
|
||||
|
||||
it('applies transition classes to overlay image', () => {
|
||||
const wrapper = mountThumbnail()
|
||||
const overlayLazyImage = wrapper.findAllComponents({ name: 'LazyImage' })[1]
|
||||
const imageClass = overlayLazyImage.props('imageClass')
|
||||
const classString = Array.isArray(imageClass)
|
||||
? imageClass.join(' ')
|
||||
: imageClass
|
||||
expect(classString).toContain('transition-opacity')
|
||||
expect(classString).toContain('duration-300')
|
||||
})
|
||||
|
||||
it('applies correct positioning to both images', () => {
|
||||
const wrapper = mountThumbnail()
|
||||
const lazyImages = wrapper.findAllComponents({ name: 'LazyImage' })
|
||||
|
||||
// Check base image
|
||||
const baseImageClass = lazyImages[0].props('imageClass')
|
||||
const baseClassList = Array.isArray(baseImageClass)
|
||||
? baseImageClass
|
||||
: baseImageClass.split(' ')
|
||||
expect(baseClassList).toContain('size-full')
|
||||
|
||||
// Check overlay image
|
||||
const overlayImageClass = lazyImages[1].props('imageClass')
|
||||
const overlayClassList = Array.isArray(overlayImageClass)
|
||||
? overlayImageClass
|
||||
: overlayImageClass.split(' ')
|
||||
expect(overlayClassList).toContain('size-full')
|
||||
renderThumbnail({ isHovered: false })
|
||||
const images = screen.getAllByRole('img')
|
||||
expect(images[1]).toHaveClass('opacity-0')
|
||||
expect(images[1]).not.toHaveClass('opacity-100')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { VueWrapper } from '@vue/test-utils'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { h } from 'vue'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
@@ -196,32 +196,39 @@ describe('CurrentUserPopoverLegacy', () => {
|
||||
mockAuthStoreState.isFetchingBalance = false
|
||||
})
|
||||
|
||||
const mountComponent = (): VueWrapper => {
|
||||
function renderComponent() {
|
||||
const i18n = createI18n({
|
||||
legacy: false,
|
||||
locale: 'en',
|
||||
messages: { en: enMessages }
|
||||
})
|
||||
const onClose = vi.fn()
|
||||
const user = userEvent.setup()
|
||||
|
||||
return mount(CurrentUserPopoverLegacy, {
|
||||
render(CurrentUserPopoverLegacy, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
stubs: {
|
||||
Divider: true
|
||||
}
|
||||
},
|
||||
props: {
|
||||
onClose
|
||||
}
|
||||
})
|
||||
|
||||
return { user, onClose }
|
||||
}
|
||||
|
||||
it('renders user information correctly', () => {
|
||||
const wrapper = mountComponent()
|
||||
renderComponent()
|
||||
|
||||
expect(wrapper.text()).toContain('Test User')
|
||||
expect(wrapper.text()).toContain('test@example.com')
|
||||
expect(screen.getByText('Test User')).toBeInTheDocument()
|
||||
expect(screen.getByText('test@example.com')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('calls formatCreditsFromCents with correct parameters and displays formatted credits', () => {
|
||||
const wrapper = mountComponent()
|
||||
renderComponent()
|
||||
|
||||
expect(formatCreditsFromCents).toHaveBeenCalledWith({
|
||||
cents: 100_000,
|
||||
@@ -232,103 +239,72 @@ describe('CurrentUserPopoverLegacy', () => {
|
||||
}
|
||||
})
|
||||
|
||||
// Verify the formatted credit string (1000) is rendered in the DOM
|
||||
expect(wrapper.text()).toContain('1000')
|
||||
expect(screen.getByText('1000')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders logout menu item with correct text', () => {
|
||||
const wrapper = mountComponent()
|
||||
renderComponent()
|
||||
|
||||
const logoutItem = wrapper.find('[data-testid="logout-menu-item"]')
|
||||
expect(logoutItem.exists()).toBe(true)
|
||||
expect(wrapper.text()).toContain('Log Out')
|
||||
expect(screen.getByTestId('logout-menu-item')).toBeInTheDocument()
|
||||
expect(screen.getByText('Log Out')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('opens user settings and emits close event when settings item is clicked', async () => {
|
||||
const wrapper = mountComponent()
|
||||
const { user, onClose } = renderComponent()
|
||||
|
||||
const settingsItem = wrapper.find('[data-testid="user-settings-menu-item"]')
|
||||
expect(settingsItem.exists()).toBe(true)
|
||||
expect(screen.getByTestId('user-settings-menu-item')).toBeInTheDocument()
|
||||
|
||||
await settingsItem.trigger('click')
|
||||
await user.click(screen.getByTestId('user-settings-menu-item'))
|
||||
|
||||
// Verify showSettingsDialog was called with 'user'
|
||||
expect(mockShowSettingsDialog).toHaveBeenCalledWith('user')
|
||||
|
||||
// Verify close event was emitted
|
||||
expect(wrapper.emitted('close')).toBeTruthy()
|
||||
expect(wrapper.emitted('close')!.length).toBe(1)
|
||||
expect(onClose).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('calls logout function and emits close event when logout item is clicked', async () => {
|
||||
const wrapper = mountComponent()
|
||||
const { user, onClose } = renderComponent()
|
||||
|
||||
const logoutItem = wrapper.find('[data-testid="logout-menu-item"]')
|
||||
expect(logoutItem.exists()).toBe(true)
|
||||
expect(screen.getByTestId('logout-menu-item')).toBeInTheDocument()
|
||||
|
||||
await logoutItem.trigger('click')
|
||||
await user.click(screen.getByTestId('logout-menu-item'))
|
||||
|
||||
// Verify handleSignOut was called
|
||||
expect(mockHandleSignOut).toHaveBeenCalled()
|
||||
|
||||
// Verify close event was emitted
|
||||
expect(wrapper.emitted('close')).toBeTruthy()
|
||||
expect(wrapper.emitted('close')!.length).toBe(1)
|
||||
expect(onClose).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('opens API pricing docs and emits close event when partner nodes item is clicked', async () => {
|
||||
const wrapper = mountComponent()
|
||||
const { user, onClose } = renderComponent()
|
||||
|
||||
const partnerNodesItem = wrapper.find(
|
||||
'[data-testid="partner-nodes-menu-item"]'
|
||||
)
|
||||
expect(partnerNodesItem.exists()).toBe(true)
|
||||
expect(screen.getByTestId('partner-nodes-menu-item')).toBeInTheDocument()
|
||||
|
||||
await partnerNodesItem.trigger('click')
|
||||
await user.click(screen.getByTestId('partner-nodes-menu-item'))
|
||||
|
||||
// Verify window.open was called with the correct URL
|
||||
expect(window.open).toHaveBeenCalledWith(
|
||||
'https://docs.comfy.org/tutorials/partner-nodes/pricing',
|
||||
'_blank'
|
||||
)
|
||||
|
||||
// Verify close event was emitted
|
||||
expect(wrapper.emitted('close')).toBeTruthy()
|
||||
expect(wrapper.emitted('close')!.length).toBe(1)
|
||||
expect(onClose).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('opens top-up dialog and emits close event when top-up button is clicked', async () => {
|
||||
const wrapper = mountComponent()
|
||||
const { user, onClose } = renderComponent()
|
||||
|
||||
const topUpButton = wrapper.find('[data-testid="add-credits-button"]')
|
||||
expect(topUpButton.exists()).toBe(true)
|
||||
expect(screen.getByTestId('add-credits-button')).toBeInTheDocument()
|
||||
|
||||
await topUpButton.trigger('click')
|
||||
await user.click(screen.getByTestId('add-credits-button'))
|
||||
|
||||
// Verify showTopUpCreditsDialog was called
|
||||
expect(mockShowTopUpCreditsDialog).toHaveBeenCalled()
|
||||
|
||||
// Verify close event was emitted
|
||||
expect(wrapper.emitted('close')).toBeTruthy()
|
||||
expect(wrapper.emitted('close')!.length).toBe(1)
|
||||
expect(onClose).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('opens subscription dialog and emits close event when plans & pricing item is clicked', async () => {
|
||||
const wrapper = mountComponent()
|
||||
const { user, onClose } = renderComponent()
|
||||
|
||||
const plansPricingItem = wrapper.find(
|
||||
'[data-testid="plans-pricing-menu-item"]'
|
||||
)
|
||||
expect(plansPricingItem.exists()).toBe(true)
|
||||
expect(screen.getByTestId('plans-pricing-menu-item')).toBeInTheDocument()
|
||||
|
||||
await plansPricingItem.trigger('click')
|
||||
await user.click(screen.getByTestId('plans-pricing-menu-item'))
|
||||
|
||||
// Verify showPricingTable was called
|
||||
expect(mockShowPricingTable).toHaveBeenCalled()
|
||||
|
||||
// Verify close event was emitted
|
||||
expect(wrapper.emitted('close')).toBeTruthy()
|
||||
expect(wrapper.emitted('close')!.length).toBe(1)
|
||||
expect(onClose).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
describe('effective_balance_micros handling', () => {
|
||||
@@ -339,7 +315,7 @@ describe('CurrentUserPopoverLegacy', () => {
|
||||
currency: 'usd'
|
||||
}
|
||||
|
||||
const wrapper = mountComponent()
|
||||
renderComponent()
|
||||
|
||||
expect(formatCreditsFromCents).toHaveBeenCalledWith({
|
||||
cents: 150_000,
|
||||
@@ -349,7 +325,7 @@ describe('CurrentUserPopoverLegacy', () => {
|
||||
maximumFractionDigits: 2
|
||||
}
|
||||
})
|
||||
expect(wrapper.text()).toContain('1500')
|
||||
expect(screen.getByText('1500')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('uses effective_balance_micros when zero', () => {
|
||||
@@ -359,7 +335,7 @@ describe('CurrentUserPopoverLegacy', () => {
|
||||
currency: 'usd'
|
||||
}
|
||||
|
||||
const wrapper = mountComponent()
|
||||
renderComponent()
|
||||
|
||||
expect(formatCreditsFromCents).toHaveBeenCalledWith({
|
||||
cents: 0,
|
||||
@@ -369,7 +345,7 @@ describe('CurrentUserPopoverLegacy', () => {
|
||||
maximumFractionDigits: 2
|
||||
}
|
||||
})
|
||||
expect(wrapper.text()).toContain('0')
|
||||
expect(screen.getByText('0')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('uses effective_balance_micros when negative', () => {
|
||||
@@ -379,7 +355,7 @@ describe('CurrentUserPopoverLegacy', () => {
|
||||
currency: 'usd'
|
||||
}
|
||||
|
||||
const wrapper = mountComponent()
|
||||
renderComponent()
|
||||
|
||||
expect(formatCreditsFromCents).toHaveBeenCalledWith({
|
||||
cents: -50_000,
|
||||
@@ -389,7 +365,7 @@ describe('CurrentUserPopoverLegacy', () => {
|
||||
maximumFractionDigits: 2
|
||||
}
|
||||
})
|
||||
expect(wrapper.text()).toContain('-500')
|
||||
expect(screen.getByText('-500')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('falls back to amount_micros when effective_balance_micros is missing', () => {
|
||||
@@ -398,7 +374,7 @@ describe('CurrentUserPopoverLegacy', () => {
|
||||
currency: 'usd'
|
||||
}
|
||||
|
||||
const wrapper = mountComponent()
|
||||
renderComponent()
|
||||
|
||||
expect(formatCreditsFromCents).toHaveBeenCalledWith({
|
||||
cents: 100_000,
|
||||
@@ -408,7 +384,7 @@ describe('CurrentUserPopoverLegacy', () => {
|
||||
maximumFractionDigits: 2
|
||||
}
|
||||
})
|
||||
expect(wrapper.text()).toContain('1000')
|
||||
expect(screen.getByText('1000')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('falls back to 0 when both effective_balance_micros and amount_micros are missing', () => {
|
||||
@@ -416,7 +392,7 @@ describe('CurrentUserPopoverLegacy', () => {
|
||||
currency: 'usd'
|
||||
}
|
||||
|
||||
const wrapper = mountComponent()
|
||||
renderComponent()
|
||||
|
||||
expect(formatCreditsFromCents).toHaveBeenCalledWith({
|
||||
cents: 0,
|
||||
@@ -426,7 +402,7 @@ describe('CurrentUserPopoverLegacy', () => {
|
||||
maximumFractionDigits: 2
|
||||
}
|
||||
})
|
||||
expect(wrapper.text()).toContain('0')
|
||||
expect(screen.getByText('0')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -436,53 +412,47 @@ describe('CurrentUserPopoverLegacy', () => {
|
||||
})
|
||||
|
||||
it('hides credits section', () => {
|
||||
const wrapper = mountComponent()
|
||||
expect(wrapper.find('[data-testid="add-credits-button"]').exists()).toBe(
|
||||
false
|
||||
)
|
||||
renderComponent()
|
||||
expect(screen.queryByTestId('add-credits-button')).not.toBeInTheDocument()
|
||||
expect(
|
||||
wrapper.find('[data-testid="upgrade-to-add-credits-button"]').exists()
|
||||
).toBe(false)
|
||||
screen.queryByTestId('upgrade-to-add-credits-button')
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('hides subscribe button', () => {
|
||||
const wrapper = mountComponent()
|
||||
expect(wrapper.text()).not.toContain('Subscribe Button')
|
||||
renderComponent()
|
||||
expect(screen.queryByText('Subscribe Button')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('hides partner nodes menu item', () => {
|
||||
const wrapper = mountComponent()
|
||||
renderComponent()
|
||||
expect(
|
||||
wrapper.find('[data-testid="partner-nodes-menu-item"]').exists()
|
||||
).toBe(false)
|
||||
screen.queryByTestId('partner-nodes-menu-item')
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('hides plans & pricing menu item', () => {
|
||||
const wrapper = mountComponent()
|
||||
renderComponent()
|
||||
expect(
|
||||
wrapper.find('[data-testid="plans-pricing-menu-item"]').exists()
|
||||
).toBe(false)
|
||||
screen.queryByTestId('plans-pricing-menu-item')
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('hides manage plan menu item', () => {
|
||||
const wrapper = mountComponent()
|
||||
renderComponent()
|
||||
expect(
|
||||
wrapper.find('[data-testid="manage-plan-menu-item"]').exists()
|
||||
).toBe(false)
|
||||
screen.queryByTestId('manage-plan-menu-item')
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('still shows user settings menu item', () => {
|
||||
const wrapper = mountComponent()
|
||||
expect(
|
||||
wrapper.find('[data-testid="user-settings-menu-item"]').exists()
|
||||
).toBe(true)
|
||||
renderComponent()
|
||||
expect(screen.getByTestId('user-settings-menu-item')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('still shows logout menu item', () => {
|
||||
const wrapper = mountComponent()
|
||||
expect(wrapper.find('[data-testid="logout-menu-item"]').exists()).toBe(
|
||||
true
|
||||
)
|
||||
renderComponent()
|
||||
expect(screen.getByTestId('logout-menu-item')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
|
||||
import enMessages from '@/locales/en/main.json' with { type: 'json' }
|
||||
|
||||
import TopbarSubscribeButton from './TopbarSubscribeButton.vue'
|
||||
@@ -46,14 +47,14 @@ vi.mock('firebase/auth', () => ({
|
||||
signOut: vi.fn()
|
||||
}))
|
||||
|
||||
function mountComponent() {
|
||||
function renderComponent() {
|
||||
const i18n = createI18n({
|
||||
legacy: false,
|
||||
locale: 'en',
|
||||
messages: { en: enMessages }
|
||||
})
|
||||
|
||||
return mount(TopbarSubscribeButton, {
|
||||
return render(TopbarSubscribeButton, {
|
||||
global: {
|
||||
plugins: [i18n]
|
||||
}
|
||||
@@ -63,17 +64,15 @@ function mountComponent() {
|
||||
describe('TopbarSubscribeButton', () => {
|
||||
it('renders on cloud when isFreeTier is true', () => {
|
||||
mockIsCloud.value = true
|
||||
const wrapper = mountComponent()
|
||||
expect(
|
||||
wrapper.find('[data-testid="topbar-subscribe-button"]').exists()
|
||||
).toBe(true)
|
||||
renderComponent()
|
||||
expect(screen.getByTestId('topbar-subscribe-button')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('hides on non-cloud distribution', () => {
|
||||
mockIsCloud.value = false
|
||||
const wrapper = mountComponent()
|
||||
renderComponent()
|
||||
expect(
|
||||
wrapper.find('[data-testid="topbar-subscribe-button"]').exists()
|
||||
).toBe(false)
|
||||
screen.queryByTestId('topbar-subscribe-button')
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render } from '@testing-library/vue'
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
||||
import { nextTick, reactive, ref } from 'vue'
|
||||
import type { Ref } from 'vue'
|
||||
@@ -184,14 +184,14 @@ const createTask = (
|
||||
|
||||
const mountUseJobList = () => {
|
||||
let composable: ReturnType<typeof useJobList>
|
||||
const wrapper = mount({
|
||||
const result = render({
|
||||
template: '<div />',
|
||||
setup() {
|
||||
composable = useJobList()
|
||||
return {}
|
||||
}
|
||||
})
|
||||
return { wrapper, composable: composable! }
|
||||
return { ...result, composable: composable! }
|
||||
}
|
||||
|
||||
const resetStores = () => {
|
||||
@@ -230,27 +230,27 @@ const flush = async () => {
|
||||
}
|
||||
|
||||
describe('useJobList', () => {
|
||||
let wrapper: ReturnType<typeof mount> | null = null
|
||||
let unmount: (() => void) | null = null
|
||||
let api: ReturnType<typeof useJobList> | null = null
|
||||
|
||||
beforeEach(() => {
|
||||
vi.resetAllMocks()
|
||||
resetStores()
|
||||
wrapper?.unmount()
|
||||
wrapper = null
|
||||
unmount?.()
|
||||
unmount = null
|
||||
api = null
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
wrapper?.unmount()
|
||||
wrapper = null
|
||||
unmount?.()
|
||||
unmount = null
|
||||
api = null
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
const initComposable = () => {
|
||||
const mounted = mountUseJobList()
|
||||
wrapper = mounted.wrapper
|
||||
unmount = mounted.unmount
|
||||
api = mounted.composable
|
||||
return api!
|
||||
}
|
||||
@@ -321,8 +321,8 @@ describe('useJobList', () => {
|
||||
await flush()
|
||||
expect(vi.getTimerCount()).toBeGreaterThan(0)
|
||||
|
||||
wrapper?.unmount()
|
||||
wrapper = null
|
||||
unmount?.()
|
||||
unmount = null
|
||||
await flush()
|
||||
expect(vi.getTimerCount()).toBe(0)
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render } from '@testing-library/vue'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { nextTick, reactive } from 'vue'
|
||||
|
||||
@@ -45,14 +45,14 @@ vi.mock('@/stores/executionStore', () => {
|
||||
|
||||
const mountComposable = () => {
|
||||
let composable: ReturnType<typeof useQueueNotificationBanners>
|
||||
const wrapper = mount({
|
||||
const result = render({
|
||||
template: '<div />',
|
||||
setup() {
|
||||
composable = useQueueNotificationBanners()
|
||||
return {}
|
||||
}
|
||||
})
|
||||
return { wrapper, composable: composable! }
|
||||
return { ...result, composable: composable! }
|
||||
}
|
||||
|
||||
describe(useQueueNotificationBanners, () => {
|
||||
@@ -131,7 +131,7 @@ describe(useQueueNotificationBanners, () => {
|
||||
})
|
||||
|
||||
it('shows queued notifications from promptQueued events', async () => {
|
||||
const { wrapper, composable } = mountComposable()
|
||||
const { unmount, composable } = mountComposable()
|
||||
|
||||
try {
|
||||
mockApi.dispatchEvent(
|
||||
@@ -148,12 +148,12 @@ describe(useQueueNotificationBanners, () => {
|
||||
await nextTick()
|
||||
expect(composable.currentNotification.value).toBeNull()
|
||||
} finally {
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
}
|
||||
})
|
||||
|
||||
it('shows queued pending then queued confirmation', async () => {
|
||||
const { wrapper, composable } = mountComposable()
|
||||
const { unmount, composable } = mountComposable()
|
||||
|
||||
try {
|
||||
mockApi.dispatchEvent(
|
||||
@@ -182,12 +182,12 @@ describe(useQueueNotificationBanners, () => {
|
||||
requestId: 1
|
||||
})
|
||||
} finally {
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
}
|
||||
})
|
||||
|
||||
it('falls back to 1 when queued batch count is invalid', async () => {
|
||||
const { wrapper, composable } = mountComposable()
|
||||
const { unmount, composable } = mountComposable()
|
||||
|
||||
try {
|
||||
mockApi.dispatchEvent(
|
||||
@@ -200,12 +200,12 @@ describe(useQueueNotificationBanners, () => {
|
||||
count: 1
|
||||
})
|
||||
} finally {
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
}
|
||||
})
|
||||
|
||||
it('shows a completed notification from a finished batch', async () => {
|
||||
const { wrapper, composable } = mountComposable()
|
||||
const { unmount, composable } = mountComposable()
|
||||
|
||||
try {
|
||||
await runBatch({
|
||||
@@ -225,12 +225,12 @@ describe(useQueueNotificationBanners, () => {
|
||||
thumbnailUrls: ['https://example.com/preview.png']
|
||||
})
|
||||
} finally {
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
}
|
||||
})
|
||||
|
||||
it('shows one completion notification when history updates after queue becomes idle', async () => {
|
||||
const { wrapper, composable } = mountComposable()
|
||||
const { unmount, composable } = mountComposable()
|
||||
|
||||
try {
|
||||
vi.setSystemTime(4_000)
|
||||
@@ -266,12 +266,12 @@ describe(useQueueNotificationBanners, () => {
|
||||
await nextTick()
|
||||
expect(composable.currentNotification.value).toBeNull()
|
||||
} finally {
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
}
|
||||
})
|
||||
|
||||
it('queues both completed and failed notifications for mixed batches', async () => {
|
||||
const { wrapper, composable } = mountComposable()
|
||||
const { unmount, composable } = mountComposable()
|
||||
|
||||
try {
|
||||
await runBatch({
|
||||
@@ -302,12 +302,12 @@ describe(useQueueNotificationBanners, () => {
|
||||
count: 1
|
||||
})
|
||||
} finally {
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
}
|
||||
})
|
||||
|
||||
it('uses up to two completion thumbnails for notification icon previews', async () => {
|
||||
const { wrapper, composable } = mountComposable()
|
||||
const { unmount, composable } = mountComposable()
|
||||
|
||||
try {
|
||||
await runBatch({
|
||||
@@ -342,7 +342,7 @@ describe(useQueueNotificationBanners, () => {
|
||||
]
|
||||
})
|
||||
} finally {
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import type { VueWrapper } from '@vue/test-utils'
|
||||
import { render } from '@testing-library/vue'
|
||||
import { nextTick, ref } from 'vue'
|
||||
import type { Ref } from 'vue'
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest'
|
||||
|
||||
import { useQueueProgress } from '@/composables/queue/useQueueProgress'
|
||||
import { formatPercent0 } from '@/utils/numberUtil'
|
||||
@@ -32,19 +31,16 @@ vi.mock('@/stores/executionStore', () => ({
|
||||
useExecutionStore: () => createExecutionStoreMock()
|
||||
}))
|
||||
|
||||
const mountedWrappers: VueWrapper[] = []
|
||||
|
||||
const mountUseQueueProgress = () => {
|
||||
let composable: ReturnType<typeof useQueueProgress>
|
||||
const wrapper = mount({
|
||||
render({
|
||||
template: '<div />',
|
||||
setup() {
|
||||
composable = useQueueProgress()
|
||||
return {}
|
||||
}
|
||||
})
|
||||
mountedWrappers.push(wrapper)
|
||||
return { wrapper, composable: composable! }
|
||||
return { composable: composable! }
|
||||
}
|
||||
|
||||
const setExecutionProgress = (value?: number | null) => {
|
||||
@@ -62,10 +58,6 @@ describe('useQueueProgress', () => {
|
||||
setExecutingNodeProgress(null)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
mountedWrappers.splice(0).forEach((wrapper) => wrapper.unmount())
|
||||
})
|
||||
|
||||
it.each([
|
||||
{
|
||||
description: 'defaults to 0% when execution store values are missing',
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { flushPromises } from '@vue/test-utils'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { nextTick, ref } from 'vue'
|
||||
|
||||
import { useNodeHelpContent } from '@/composables/useNodeHelpContent'
|
||||
import type { ComfyNodeDefImpl } from '@/stores/nodeDefStore'
|
||||
|
||||
async function flushPromises() {
|
||||
await new Promise((r) => setTimeout(r, 0))
|
||||
}
|
||||
|
||||
function createMockNode(
|
||||
overrides: Partial<ComfyNodeDefImpl>
|
||||
): ComfyNodeDefImpl {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { ref } from 'vue'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
@@ -61,13 +62,16 @@ const createJob = (overrides: Partial<JobListItem> = {}): JobListItem => ({
|
||||
...overrides
|
||||
})
|
||||
|
||||
const mountComponent = (job: JobListItem) =>
|
||||
mount(ActiveJobCard, {
|
||||
function renderComponent(job: JobListItem) {
|
||||
const user = userEvent.setup()
|
||||
const { container } = render(ActiveJobCard, {
|
||||
props: { job },
|
||||
global: {
|
||||
plugins: [i18n]
|
||||
}
|
||||
})
|
||||
return { container, user }
|
||||
}
|
||||
|
||||
describe('ActiveJobCard', () => {
|
||||
beforeEach(() => {
|
||||
@@ -78,18 +82,19 @@ describe('ActiveJobCard', () => {
|
||||
})
|
||||
|
||||
it('displays percentage and progress bar when job is running', () => {
|
||||
const wrapper = mountComponent(
|
||||
const { container } = renderComponent(
|
||||
createJob({ state: 'running', progressTotalPercent: 65 })
|
||||
)
|
||||
|
||||
expect(wrapper.text()).toContain('65%')
|
||||
const progressBar = wrapper.find('.bg-blue-500')
|
||||
expect(progressBar.exists()).toBe(true)
|
||||
expect(progressBar.attributes('style')).toContain('width: 65%')
|
||||
expect(container.textContent).toContain('65%')
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access -- progress bar has no ARIA role in happy-dom
|
||||
const progressBar = container.querySelector('.bg-blue-500')
|
||||
expect(progressBar).not.toBeNull()
|
||||
expect(progressBar).toHaveStyle({ width: '65%' })
|
||||
})
|
||||
|
||||
it('displays status text when job is pending', () => {
|
||||
const wrapper = mountComponent(
|
||||
const { container } = renderComponent(
|
||||
createJob({
|
||||
state: 'pending',
|
||||
title: 'In queue...',
|
||||
@@ -97,116 +102,114 @@ describe('ActiveJobCard', () => {
|
||||
})
|
||||
)
|
||||
|
||||
expect(wrapper.text()).toContain('In queue...')
|
||||
const progressBar = wrapper.find('.bg-blue-500')
|
||||
expect(progressBar.exists()).toBe(false)
|
||||
expect(container.textContent).toContain('In queue...')
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access -- progress bar has no ARIA role in happy-dom
|
||||
expect(container.querySelector('.bg-blue-500')).toBeNull()
|
||||
})
|
||||
|
||||
it('shows spinner for pending state', () => {
|
||||
const wrapper = mountComponent(createJob({ state: 'pending' }))
|
||||
const { container } = renderComponent(createJob({ state: 'pending' }))
|
||||
|
||||
const spinner = wrapper.find('.icon-\\[lucide--loader-circle\\]')
|
||||
expect(spinner.exists()).toBe(true)
|
||||
expect(spinner.classes()).toContain('animate-spin')
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access -- spinner icon has no ARIA role in happy-dom
|
||||
const spinner = container.querySelector('[class*="lucide--loader-circle"]')
|
||||
expect(spinner).not.toBeNull()
|
||||
expect(spinner).toHaveClass('animate-spin')
|
||||
})
|
||||
|
||||
it('shows error icon for failed state', () => {
|
||||
const wrapper = mountComponent(
|
||||
const { container } = renderComponent(
|
||||
createJob({ state: 'failed', title: 'Failed' })
|
||||
)
|
||||
|
||||
const errorIcon = wrapper.find('.icon-\\[lucide--circle-alert\\]')
|
||||
expect(errorIcon.exists()).toBe(true)
|
||||
expect(wrapper.text()).toContain('Failed')
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access -- error icon has no ARIA role in happy-dom
|
||||
const errorIcon = container.querySelector('[class*="lucide--circle-alert"]')
|
||||
expect(errorIcon).not.toBeNull()
|
||||
expect(container.textContent).toContain('Failed')
|
||||
})
|
||||
|
||||
it('shows preview image when running with iconImageUrl', () => {
|
||||
const wrapper = mountComponent(
|
||||
renderComponent(
|
||||
createJob({
|
||||
state: 'running',
|
||||
iconImageUrl: 'https://example.com/preview.jpg'
|
||||
})
|
||||
)
|
||||
|
||||
const img = wrapper.find('img')
|
||||
expect(img.exists()).toBe(true)
|
||||
expect(img.attributes('src')).toBe('https://example.com/preview.jpg')
|
||||
const img = screen.getByRole('img')
|
||||
expect(img).toHaveAttribute('src', 'https://example.com/preview.jpg')
|
||||
})
|
||||
|
||||
it('has proper accessibility attributes', () => {
|
||||
const wrapper = mountComponent(createJob({ title: 'Generating...' }))
|
||||
renderComponent(createJob({ title: 'Generating...' }))
|
||||
|
||||
const container = wrapper.find('[role="status"]')
|
||||
expect(container.exists()).toBe(true)
|
||||
expect(container.attributes('aria-label')).toBe('Active job: Generating...')
|
||||
const status = screen.getByRole('status', {
|
||||
name: 'Active job: Generating...'
|
||||
})
|
||||
expect(status).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows delete button on hover for failed jobs', async () => {
|
||||
mockCanDeleteJob.value = true
|
||||
|
||||
const wrapper = mountComponent(
|
||||
const { user } = renderComponent(
|
||||
createJob({ state: 'failed', title: 'Failed' })
|
||||
)
|
||||
|
||||
expect(wrapper.findComponent({ name: 'Button' }).exists()).toBe(false)
|
||||
expect(
|
||||
screen.queryByRole('button', { name: 'Remove job' })
|
||||
).not.toBeInTheDocument()
|
||||
|
||||
await wrapper.find('[role="status"]').trigger('mouseenter')
|
||||
await user.hover(screen.getByRole('status'))
|
||||
|
||||
const button = wrapper.findComponent({ name: 'Button' })
|
||||
expect(button.exists()).toBe(true)
|
||||
expect(button.attributes('aria-label')).toBe('Remove job')
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Remove job' })
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('calls runDeleteJob when delete button is clicked on a failed job', async () => {
|
||||
mockCanDeleteJob.value = true
|
||||
|
||||
const wrapper = mountComponent(
|
||||
const { user } = renderComponent(
|
||||
createJob({ state: 'failed', title: 'Failed' })
|
||||
)
|
||||
|
||||
await wrapper.find('[role="status"]').trigger('mouseenter')
|
||||
|
||||
const button = wrapper.findComponent({ name: 'Button' })
|
||||
await button.trigger('click')
|
||||
await user.hover(screen.getByRole('status'))
|
||||
await user.click(screen.getByRole('button', { name: 'Remove job' }))
|
||||
|
||||
expect(mockRunDeleteJob).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it('does not show action button when job cannot be cancelled or deleted', async () => {
|
||||
const wrapper = mountComponent(
|
||||
const { user } = renderComponent(
|
||||
createJob({ state: 'running', progressTotalPercent: 50 })
|
||||
)
|
||||
|
||||
await wrapper.find('[role="status"]').trigger('mouseenter')
|
||||
await user.hover(screen.getByRole('status', { name: /Active job/ }))
|
||||
|
||||
expect(wrapper.findComponent({ name: 'Button' }).exists()).toBe(false)
|
||||
expect(screen.queryByRole('button')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows cancel button on hover for cancellable jobs', async () => {
|
||||
mockCanCancelJob.value = true
|
||||
|
||||
const wrapper = mountComponent(
|
||||
const { user } = renderComponent(
|
||||
createJob({ state: 'running', progressTotalPercent: 50 })
|
||||
)
|
||||
|
||||
await wrapper.find('[role="status"]').trigger('mouseenter')
|
||||
await user.hover(screen.getByRole('status', { name: /Active job/ }))
|
||||
|
||||
const button = wrapper.findComponent({ name: 'Button' })
|
||||
expect(button.exists()).toBe(true)
|
||||
expect(button.attributes('aria-label')).toBe('Cancel')
|
||||
expect(screen.getByRole('button', { name: 'Cancel' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('calls runCancelJob when cancel button is clicked', async () => {
|
||||
mockCanCancelJob.value = true
|
||||
|
||||
const wrapper = mountComponent(
|
||||
const { user } = renderComponent(
|
||||
createJob({ state: 'running', progressTotalPercent: 50 })
|
||||
)
|
||||
|
||||
await wrapper.find('[role="status"]').trigger('mouseenter')
|
||||
|
||||
const button = wrapper.findComponent({ name: 'Button' })
|
||||
await button.trigger('click')
|
||||
await user.hover(screen.getByRole('status', { name: /Active job/ }))
|
||||
await user.click(screen.getByRole('button', { name: 'Cancel' }))
|
||||
|
||||
expect(mockRunCancelJob).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { render, screen, waitFor } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { createPinia, setActivePinia } from 'pinia'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
@@ -60,6 +61,7 @@ vi.mock('@/components/widget/layout/BaseModalLayout.vue', () => ({
|
||||
emits: ['close'],
|
||||
template: `
|
||||
<div data-testid="base-modal-layout">
|
||||
<span data-testid="modal-title">{{ contentTitle }}</span>
|
||||
<div v-if="$slots.leftPanel" data-testid="left-panel">
|
||||
<slot name="leftPanel" />
|
||||
</div>
|
||||
@@ -87,15 +89,27 @@ vi.mock('@/components/widget/panel/LeftSidePanel.vue', () => ({
|
||||
<div v-if="$slots['header-title']" data-testid="header-title">
|
||||
<slot name="header-title" />
|
||||
</div>
|
||||
<button
|
||||
v-for="item in navItems"
|
||||
:key="item.id"
|
||||
@click="$emit('update:modelValue', item.id)"
|
||||
:data-testid="'nav-item-' + item.id"
|
||||
:class="{ active: modelValue === item.id }"
|
||||
>
|
||||
{{ item.label }}
|
||||
</button>
|
||||
<template v-for="item in navItems" :key="item.id || item.title">
|
||||
<button
|
||||
v-if="item.id"
|
||||
@click="$emit('update:modelValue', item.id)"
|
||||
:data-testid="'nav-item-' + item.id"
|
||||
:class="{ active: modelValue === item.id }"
|
||||
>
|
||||
{{ item.label }}
|
||||
</button>
|
||||
<template v-else-if="item.items">
|
||||
<button
|
||||
v-for="child in item.items"
|
||||
:key="child.id"
|
||||
@click="$emit('update:modelValue', child.id)"
|
||||
:data-testid="'nav-item-' + child.id"
|
||||
:class="{ active: modelValue === child.id }"
|
||||
>
|
||||
{{ child.label }}
|
||||
</button>
|
||||
</template>
|
||||
</template>
|
||||
</div>
|
||||
`
|
||||
}
|
||||
@@ -151,6 +165,9 @@ vi.mock('vue-i18n', () => ({
|
||||
})
|
||||
}))
|
||||
|
||||
const flushPromises = () =>
|
||||
new Promise<void>((resolve) => setTimeout(resolve, 0))
|
||||
|
||||
describe('AssetBrowserModal', () => {
|
||||
const createTestAsset = (
|
||||
id: string,
|
||||
@@ -173,11 +190,11 @@ describe('AssetBrowserModal', () => {
|
||||
}
|
||||
})
|
||||
|
||||
const createWrapper = (props: Record<string, unknown>) => {
|
||||
function renderModal(props: Record<string, unknown>) {
|
||||
const pinia = createPinia()
|
||||
setActivePinia(pinia)
|
||||
|
||||
return mount(AssetBrowserModal, {
|
||||
return render(AssetBrowserModal, {
|
||||
props,
|
||||
global: {
|
||||
plugins: [pinia],
|
||||
@@ -207,14 +224,16 @@ describe('AssetBrowserModal', () => {
|
||||
]
|
||||
mockAssetsByKey.set('CheckpointLoaderSimple', assets)
|
||||
|
||||
const wrapper = createWrapper({ nodeType: 'CheckpointLoaderSimple' })
|
||||
renderModal({ nodeType: 'CheckpointLoaderSimple' })
|
||||
await flushPromises()
|
||||
|
||||
const assetGrid = wrapper.findComponent({ name: 'AssetGrid' })
|
||||
const gridAssets = assetGrid.props('assets') as AssetItem[]
|
||||
|
||||
expect(gridAssets).toHaveLength(2)
|
||||
expect(gridAssets[0].id).toBe('asset1')
|
||||
expect(screen.getByTestId('asset-asset1')).toBeDefined()
|
||||
expect(screen.getByTestId('asset-asset2')).toBeDefined()
|
||||
/* eslint-disable testing-library/no-node-access */
|
||||
expect(
|
||||
screen.getByTestId('asset-grid').querySelectorAll('.asset-card')
|
||||
).toHaveLength(2)
|
||||
/* eslint-enable testing-library/no-node-access */
|
||||
})
|
||||
|
||||
it('passes category-filtered assets to AssetFilterBar', async () => {
|
||||
@@ -224,23 +243,22 @@ describe('AssetBrowserModal', () => {
|
||||
]
|
||||
mockAssetsByKey.set('CheckpointLoaderSimple', assets)
|
||||
|
||||
const wrapper = createWrapper({
|
||||
renderModal({
|
||||
nodeType: 'CheckpointLoaderSimple',
|
||||
showLeftPanel: true
|
||||
})
|
||||
await flushPromises()
|
||||
|
||||
const filterBar = wrapper.findComponent({ name: 'AssetFilterBar' })
|
||||
const filterBarAssets = filterBar.props('assets') as AssetItem[]
|
||||
|
||||
expect(filterBarAssets).toHaveLength(2)
|
||||
expect(screen.getByTestId('asset-filter-bar').textContent).toContain(
|
||||
'2 assets'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Data fetching', () => {
|
||||
it('triggers store refresh for node type on mount', async () => {
|
||||
const store = useAssetsStore()
|
||||
createWrapper({ nodeType: 'CheckpointLoaderSimple' })
|
||||
renderModal({ nodeType: 'CheckpointLoaderSimple' })
|
||||
await flushPromises()
|
||||
|
||||
expect(store.updateModelsForNodeType).toHaveBeenCalledWith(
|
||||
@@ -252,18 +270,17 @@ describe('AssetBrowserModal', () => {
|
||||
const assets = [createTestAsset('asset1', 'Cached Model', 'checkpoints')]
|
||||
mockAssetsByKey.set('CheckpointLoaderSimple', assets)
|
||||
|
||||
const wrapper = createWrapper({ nodeType: 'CheckpointLoaderSimple' })
|
||||
renderModal({ nodeType: 'CheckpointLoaderSimple' })
|
||||
|
||||
const assetGrid = wrapper.findComponent({ name: 'AssetGrid' })
|
||||
const gridAssets = assetGrid.props('assets') as AssetItem[]
|
||||
|
||||
expect(gridAssets).toHaveLength(1)
|
||||
expect(gridAssets[0].name).toBe('Cached Model')
|
||||
expect(screen.getByTestId('asset-asset1')).toBeDefined()
|
||||
expect(screen.getByTestId('asset-asset1').textContent).toContain(
|
||||
'Cached Model'
|
||||
)
|
||||
})
|
||||
|
||||
it('triggers store refresh for asset type (tag) on mount', async () => {
|
||||
const store = useAssetsStore()
|
||||
createWrapper({ assetType: 'models' })
|
||||
renderModal({ assetType: 'models' })
|
||||
await flushPromises()
|
||||
|
||||
expect(store.updateModelsForTag).toHaveBeenCalledWith('models')
|
||||
@@ -273,116 +290,133 @@ describe('AssetBrowserModal', () => {
|
||||
const assets = [createTestAsset('asset1', 'Tagged Model', 'models')]
|
||||
mockAssetsByKey.set('tag:models', assets)
|
||||
|
||||
const wrapper = createWrapper({ assetType: 'models' })
|
||||
renderModal({ assetType: 'models' })
|
||||
await flushPromises()
|
||||
|
||||
const assetGrid = wrapper.findComponent({ name: 'AssetGrid' })
|
||||
const gridAssets = assetGrid.props('assets') as AssetItem[]
|
||||
|
||||
expect(gridAssets).toHaveLength(1)
|
||||
expect(gridAssets[0].name).toBe('Tagged Model')
|
||||
expect(screen.getByTestId('asset-asset1')).toBeDefined()
|
||||
expect(screen.getByTestId('asset-asset1').textContent).toContain(
|
||||
'Tagged Model'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Asset Selection', () => {
|
||||
it('emits asset-select event when asset is selected', async () => {
|
||||
const user = userEvent.setup()
|
||||
const assets = [createTestAsset('asset1', 'Model A', 'checkpoints')]
|
||||
mockAssetsByKey.set('CheckpointLoaderSimple', assets)
|
||||
|
||||
const wrapper = createWrapper({ nodeType: 'CheckpointLoaderSimple' })
|
||||
const onAssetSelect = vi.fn()
|
||||
renderModal({
|
||||
nodeType: 'CheckpointLoaderSimple',
|
||||
'onAsset-select': onAssetSelect
|
||||
})
|
||||
await flushPromises()
|
||||
|
||||
const assetGrid = wrapper.findComponent({ name: 'AssetGrid' })
|
||||
await assetGrid.vm.$emit('asset-select', assets[0])
|
||||
await user.click(screen.getByTestId('asset-asset1'))
|
||||
|
||||
expect(wrapper.emitted('asset-select')).toEqual([[assets[0]]])
|
||||
expect(onAssetSelect).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ id: assets[0].id, name: assets[0].name })
|
||||
)
|
||||
})
|
||||
|
||||
it('executes onSelect callback when provided', async () => {
|
||||
const user = userEvent.setup()
|
||||
const assets = [createTestAsset('asset1', 'Model A', 'checkpoints')]
|
||||
mockAssetsByKey.set('CheckpointLoaderSimple', assets)
|
||||
|
||||
const onSelect = vi.fn()
|
||||
const wrapper = createWrapper({
|
||||
renderModal({
|
||||
nodeType: 'CheckpointLoaderSimple',
|
||||
onSelect
|
||||
})
|
||||
await flushPromises()
|
||||
|
||||
const assetGrid = wrapper.findComponent({ name: 'AssetGrid' })
|
||||
await assetGrid.vm.$emit('asset-select', assets[0])
|
||||
await user.click(screen.getByTestId('asset-asset1'))
|
||||
|
||||
expect(onSelect).toHaveBeenCalledWith(assets[0])
|
||||
expect(onSelect).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ id: assets[0].id, name: assets[0].name })
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Left Panel Conditional Logic', () => {
|
||||
it('hides left panel by default when showLeftPanel is undefined', async () => {
|
||||
const wrapper = createWrapper({ nodeType: 'CheckpointLoaderSimple' })
|
||||
renderModal({ nodeType: 'CheckpointLoaderSimple' })
|
||||
await flushPromises()
|
||||
|
||||
const leftPanel = wrapper.find('[data-testid="left-panel"]')
|
||||
expect(leftPanel.exists()).toBe(false)
|
||||
expect(screen.queryByTestId('left-panel')).toBeNull()
|
||||
})
|
||||
|
||||
it('shows left panel when showLeftPanel prop is explicitly true', async () => {
|
||||
const wrapper = createWrapper({
|
||||
renderModal({
|
||||
nodeType: 'CheckpointLoaderSimple',
|
||||
showLeftPanel: true
|
||||
})
|
||||
await flushPromises()
|
||||
|
||||
const leftPanel = wrapper.find('[data-testid="left-panel"]')
|
||||
expect(leftPanel.exists()).toBe(true)
|
||||
expect(screen.getByTestId('left-panel')).toBeDefined()
|
||||
})
|
||||
|
||||
it('hides left panel when showLeftPanel is false', async () => {
|
||||
renderModal({
|
||||
nodeType: 'CheckpointLoaderSimple',
|
||||
showLeftPanel: false
|
||||
})
|
||||
await flushPromises()
|
||||
|
||||
expect(screen.queryByTestId('left-panel')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Filter Options Reactivity', () => {
|
||||
it('updates filter options when category changes', async () => {
|
||||
const user = userEvent.setup()
|
||||
const assets = [
|
||||
createTestAsset('asset1', 'Model A', 'checkpoints'),
|
||||
createTestAsset('asset2', 'Model B', 'loras')
|
||||
]
|
||||
mockAssetsByKey.set('CheckpointLoaderSimple', assets)
|
||||
|
||||
const wrapper = createWrapper({
|
||||
renderModal({
|
||||
nodeType: 'CheckpointLoaderSimple',
|
||||
showLeftPanel: true
|
||||
})
|
||||
await flushPromises()
|
||||
|
||||
const filterBar = wrapper.findComponent({ name: 'AssetFilterBar' })
|
||||
expect(filterBar.props('assets')).toHaveLength(2)
|
||||
expect(screen.getByTestId('asset-filter-bar').textContent).toContain(
|
||||
'2 assets'
|
||||
)
|
||||
|
||||
const leftPanel = wrapper.findComponent({ name: 'LeftSidePanel' })
|
||||
await leftPanel.vm.$emit('update:modelValue', 'loras')
|
||||
await wrapper.vm.$nextTick()
|
||||
await user.click(screen.getByTestId('nav-item-loras'))
|
||||
|
||||
expect(filterBar.props('assets')).toHaveLength(1)
|
||||
await waitFor(() => {
|
||||
expect(screen.getByTestId('asset-filter-bar').textContent).toContain(
|
||||
'1 assets'
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('Title Management', () => {
|
||||
it('passes custom title to BaseModalLayout when title prop provided', async () => {
|
||||
const wrapper = createWrapper({
|
||||
renderModal({
|
||||
nodeType: 'CheckpointLoaderSimple',
|
||||
title: 'Custom Title'
|
||||
})
|
||||
await flushPromises()
|
||||
|
||||
const layout = wrapper.findComponent({ name: 'BaseModalLayout' })
|
||||
expect(layout.props('contentTitle')).toBe('Custom Title')
|
||||
expect(screen.getByTestId('modal-title').textContent).toBe('Custom Title')
|
||||
})
|
||||
|
||||
it('passes computed contentTitle to BaseModalLayout when no title prop', async () => {
|
||||
const assets = [createTestAsset('asset1', 'Model A', 'checkpoints')]
|
||||
mockAssetsByKey.set('CheckpointLoaderSimple', assets)
|
||||
|
||||
const wrapper = createWrapper({ nodeType: 'CheckpointLoaderSimple' })
|
||||
renderModal({ nodeType: 'CheckpointLoaderSimple' })
|
||||
await flushPromises()
|
||||
|
||||
const layout = wrapper.findComponent({ name: 'BaseModalLayout' })
|
||||
expect(layout.props('contentTitle')).toBe(
|
||||
expect(screen.getByTestId('modal-title').textContent).toBe(
|
||||
'assetBrowser.allCategory:{"category":"Checkpoints"}'
|
||||
)
|
||||
})
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
/* eslint-disable testing-library/no-container */
|
||||
/* eslint-disable testing-library/no-node-access */
|
||||
/* eslint-disable testing-library/prefer-user-event */
|
||||
import { fireEvent, render } from '@testing-library/vue'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { nextTick } from 'vue'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
import AssetFilterBar from '@/platform/assets/components/AssetFilterBar.vue'
|
||||
import type { AssetFilterState } from '@/platform/assets/types/filterTypes'
|
||||
import {
|
||||
createAssetWithSpecificBaseModel,
|
||||
createAssetWithSpecificExtension,
|
||||
createAssetWithoutBaseModel
|
||||
} from '@/platform/assets/fixtures/ui-mock-assets'
|
||||
import type { AssetItem } from '@/platform/assets/schemas/assetSchema'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
import type { AssetFilterState } from '@/platform/assets/types/filterTypes'
|
||||
|
||||
const i18n = createI18n({
|
||||
legacy: false,
|
||||
@@ -67,29 +70,31 @@ vi.mock('@/components/input/SingleSelect.vue', () => ({
|
||||
|
||||
// Test factory functions
|
||||
function mountAssetFilterBar(props = {}) {
|
||||
return mount(AssetFilterBar, {
|
||||
props,
|
||||
const onFilterChange = vi.fn()
|
||||
const { container } = render(AssetFilterBar, {
|
||||
props: { ...props, onFilterChange },
|
||||
global: {
|
||||
plugins: [i18n]
|
||||
}
|
||||
})
|
||||
return { container, onFilterChange }
|
||||
}
|
||||
|
||||
// Helper functions to find filters by user-facing attributes
|
||||
function findFileFormatsFilter(
|
||||
wrapper: ReturnType<typeof mountAssetFilterBar>
|
||||
) {
|
||||
return wrapper.findComponent(
|
||||
function findFileFormatsFilter(container: Element) {
|
||||
return container.querySelector(
|
||||
'[data-component-id="asset-filter-file-formats"]'
|
||||
)
|
||||
}
|
||||
|
||||
function findBaseModelsFilter(wrapper: ReturnType<typeof mountAssetFilterBar>) {
|
||||
return wrapper.findComponent('[data-component-id="asset-filter-base-models"]')
|
||||
function findBaseModelsFilter(container: Element) {
|
||||
return container.querySelector(
|
||||
'[data-component-id="asset-filter-base-models"]'
|
||||
)
|
||||
}
|
||||
|
||||
function findSortFilter(wrapper: ReturnType<typeof mountAssetFilterBar>) {
|
||||
return wrapper.findComponent('[data-component-id="asset-filter-sort"]')
|
||||
function findSortFilter(container: Element) {
|
||||
return container.querySelector('[data-component-id="asset-filter-sort"]')
|
||||
}
|
||||
|
||||
describe('AssetFilterBar', () => {
|
||||
@@ -102,49 +107,55 @@ describe('AssetFilterBar', () => {
|
||||
createAssetWithSpecificBaseModel('sd15'),
|
||||
createAssetWithSpecificBaseModel('sdxl')
|
||||
]
|
||||
const wrapper = mountAssetFilterBar({ assets })
|
||||
const { container, onFilterChange } = mountAssetFilterBar({ assets })
|
||||
|
||||
// Update file formats
|
||||
const fileFormatSelect = findFileFormatsFilter(wrapper)
|
||||
const fileFormatSelectElement = fileFormatSelect.find('select')
|
||||
const options = fileFormatSelectElement.findAll('option')
|
||||
const ckptOption = options.find((o) => o.element.value === 'ckpt')!
|
||||
const safetensorsOption = options.find(
|
||||
(o) => o.element.value === 'safetensors'
|
||||
)!
|
||||
ckptOption.element.selected = true
|
||||
safetensorsOption.element.selected = true
|
||||
await fileFormatSelectElement.trigger('change')
|
||||
const fileFormatEl = findFileFormatsFilter(container)!
|
||||
const fileFormatSelectEl = fileFormatEl.querySelector(
|
||||
'select'
|
||||
) as HTMLSelectElement
|
||||
const fileFormatOptions = fileFormatEl.querySelectorAll('option')
|
||||
const ckptOption = Array.from(fileFormatOptions).find(
|
||||
(o) => (o as HTMLOptionElement).value === 'ckpt'
|
||||
) as HTMLOptionElement
|
||||
const safetensorsOption = Array.from(fileFormatOptions).find(
|
||||
(o) => (o as HTMLOptionElement).value === 'safetensors'
|
||||
) as HTMLOptionElement
|
||||
ckptOption.selected = true
|
||||
safetensorsOption.selected = true
|
||||
await fireEvent.change(fileFormatSelectEl)
|
||||
|
||||
await nextTick()
|
||||
|
||||
// Update base models
|
||||
const baseModelSelect = findBaseModelsFilter(wrapper)
|
||||
const baseModelSelectElement = baseModelSelect.find('select')
|
||||
const sdxlOption = baseModelSelectElement
|
||||
.findAll('option')
|
||||
.find((o) => o.element.value === 'sdxl')
|
||||
sdxlOption!.element.selected = true
|
||||
await baseModelSelectElement.trigger('change')
|
||||
const baseModelEl = findBaseModelsFilter(container)!
|
||||
const baseModelSelectEl = baseModelEl.querySelector(
|
||||
'select'
|
||||
) as HTMLSelectElement
|
||||
const baseModelOptions = baseModelEl.querySelectorAll('option')
|
||||
const sdxlOption = Array.from(baseModelOptions).find(
|
||||
(o) => (o as HTMLOptionElement).value === 'sdxl'
|
||||
) as HTMLOptionElement
|
||||
sdxlOption.selected = true
|
||||
await fireEvent.change(baseModelSelectEl)
|
||||
|
||||
await nextTick()
|
||||
|
||||
// Update sort
|
||||
const sortSelect = findSortFilter(wrapper)
|
||||
const sortSelectElement = sortSelect.find('select')
|
||||
sortSelectElement.element.value = 'name-desc'
|
||||
await sortSelectElement.trigger('change')
|
||||
const sortEl = findSortFilter(container)!
|
||||
const sortSelectEl = sortEl.querySelector('select') as HTMLSelectElement
|
||||
sortSelectEl.value = 'name-desc'
|
||||
await fireEvent.change(sortSelectEl)
|
||||
|
||||
await nextTick()
|
||||
|
||||
const emitted = wrapper.emitted('filterChange')
|
||||
expect(emitted).toBeTruthy()
|
||||
expect(emitted!.length).toBeGreaterThanOrEqual(3)
|
||||
expect(onFilterChange).toHaveBeenCalled()
|
||||
expect(onFilterChange.mock.calls.length).toBeGreaterThanOrEqual(3)
|
||||
|
||||
// Check final state
|
||||
const finalState: AssetFilterState = emitted![
|
||||
emitted!.length - 1
|
||||
][0] as AssetFilterState
|
||||
const lastCall =
|
||||
onFilterChange.mock.calls[onFilterChange.mock.calls.length - 1]
|
||||
const finalState: AssetFilterState = lastCall[0]
|
||||
expect(finalState.fileFormats).toEqual(['ckpt', 'safetensors'])
|
||||
expect(finalState.baseModels).toEqual(['sdxl'])
|
||||
expect(finalState.sortBy).toBe('name-desc')
|
||||
@@ -157,18 +168,22 @@ describe('AssetFilterBar', () => {
|
||||
createAssetWithSpecificExtension('safetensors'),
|
||||
createAssetWithSpecificBaseModel('sd15')
|
||||
]
|
||||
const wrapper = mountAssetFilterBar({ assets })
|
||||
const { container, onFilterChange } = mountAssetFilterBar({ assets })
|
||||
|
||||
const fileFormatSelect = findFileFormatsFilter(wrapper)
|
||||
const fileFormatSelectElement = fileFormatSelect.find('select')
|
||||
const ckptOption = fileFormatSelectElement.findAll('option')[0]
|
||||
ckptOption.element.selected = true
|
||||
await fileFormatSelectElement.trigger('change')
|
||||
const fileFormatEl = findFileFormatsFilter(container)!
|
||||
const fileFormatSelectEl = fileFormatEl.querySelector(
|
||||
'select'
|
||||
) as HTMLSelectElement
|
||||
const firstOption = fileFormatEl.querySelector(
|
||||
'option'
|
||||
) as HTMLOptionElement
|
||||
firstOption.selected = true
|
||||
await fireEvent.change(fileFormatSelectEl)
|
||||
|
||||
await nextTick()
|
||||
|
||||
const emitted = wrapper.emitted('filterChange')
|
||||
const filterState = emitted![0][0] as AssetFilterState
|
||||
expect(onFilterChange).toHaveBeenCalled()
|
||||
const filterState: AssetFilterState = onFilterChange.mock.calls[0][0]
|
||||
|
||||
// Type and structure assertions
|
||||
expect(Array.isArray(filterState.fileFormats)).toBe(true)
|
||||
@@ -193,12 +208,15 @@ describe('AssetFilterBar', () => {
|
||||
createAssetWithSpecificExtension('pt')
|
||||
]
|
||||
|
||||
const wrapper = mountAssetFilterBar({ assets })
|
||||
const { container } = mountAssetFilterBar({ assets })
|
||||
|
||||
const fileFormatSelect = findFileFormatsFilter(wrapper)
|
||||
const options = fileFormatSelect.findAll('option')
|
||||
const fileFormatEl = findFileFormatsFilter(container)!
|
||||
const options = fileFormatEl.querySelectorAll('option')
|
||||
expect(
|
||||
options.map((o) => ({ name: o.text(), value: o.element.value }))
|
||||
Array.from(options).map((o) => ({
|
||||
name: o.textContent?.trim(),
|
||||
value: (o as HTMLOptionElement).value
|
||||
}))
|
||||
).toEqual([
|
||||
{ name: '.ckpt', value: 'ckpt' },
|
||||
{ name: '.pt', value: 'pt' },
|
||||
@@ -213,12 +231,15 @@ describe('AssetFilterBar', () => {
|
||||
createAssetWithSpecificBaseModel('sd35')
|
||||
]
|
||||
|
||||
const wrapper = mountAssetFilterBar({ assets })
|
||||
const { container } = mountAssetFilterBar({ assets })
|
||||
|
||||
const baseModelSelect = findBaseModelsFilter(wrapper)
|
||||
const options = baseModelSelect.findAll('option')
|
||||
const baseModelEl = findBaseModelsFilter(container)!
|
||||
const options = baseModelEl.querySelectorAll('option')
|
||||
expect(
|
||||
options.map((o) => ({ name: o.text(), value: o.element.value }))
|
||||
Array.from(options).map((o) => ({
|
||||
name: o.textContent?.trim(),
|
||||
value: (o as HTMLOptionElement).value
|
||||
}))
|
||||
).toEqual([
|
||||
{ name: 'sd15', value: 'sd15' },
|
||||
{ name: 'sd35', value: 'sd35' },
|
||||
@@ -230,18 +251,16 @@ describe('AssetFilterBar', () => {
|
||||
describe('Conditional Filter Visibility', () => {
|
||||
it('hides file format filter when no options available', () => {
|
||||
const assets: AssetItem[] = [] // No assets = no file format options
|
||||
const wrapper = mountAssetFilterBar({ assets })
|
||||
const { container } = mountAssetFilterBar({ assets })
|
||||
|
||||
const fileFormatSelect = findFileFormatsFilter(wrapper)
|
||||
expect(fileFormatSelect.exists()).toBe(false)
|
||||
expect(findFileFormatsFilter(container)).toBeNull()
|
||||
})
|
||||
|
||||
it('hides base model filter when no options available', () => {
|
||||
const assets = [createAssetWithoutBaseModel()] // Asset without base model = no base model options
|
||||
const wrapper = mountAssetFilterBar({ assets })
|
||||
const { container } = mountAssetFilterBar({ assets })
|
||||
|
||||
const baseModelSelect = findBaseModelsFilter(wrapper)
|
||||
expect(baseModelSelect.exists()).toBe(false)
|
||||
expect(findBaseModelsFilter(container)).toBeNull()
|
||||
})
|
||||
|
||||
it('shows both filters when options are available', () => {
|
||||
@@ -249,23 +268,17 @@ describe('AssetFilterBar', () => {
|
||||
createAssetWithSpecificExtension('safetensors'),
|
||||
createAssetWithSpecificBaseModel('sd15')
|
||||
]
|
||||
const wrapper = mountAssetFilterBar({ assets })
|
||||
const { container } = mountAssetFilterBar({ assets })
|
||||
|
||||
const fileFormatSelect = findFileFormatsFilter(wrapper)
|
||||
const baseModelSelect = findBaseModelsFilter(wrapper)
|
||||
|
||||
expect(fileFormatSelect.exists()).toBe(true)
|
||||
expect(baseModelSelect.exists()).toBe(true)
|
||||
expect(findFileFormatsFilter(container)).not.toBeNull()
|
||||
expect(findBaseModelsFilter(container)).not.toBeNull()
|
||||
})
|
||||
|
||||
it('hides both filters when no assets provided', () => {
|
||||
const wrapper = mountAssetFilterBar()
|
||||
const { container } = mountAssetFilterBar()
|
||||
|
||||
const fileFormatSelect = findFileFormatsFilter(wrapper)
|
||||
const baseModelSelect = findBaseModelsFilter(wrapper)
|
||||
|
||||
expect(fileFormatSelect.exists()).toBe(false)
|
||||
expect(baseModelSelect.exists()).toBe(false)
|
||||
expect(findFileFormatsFilter(container)).toBeNull()
|
||||
expect(findBaseModelsFilter(container)).toBeNull()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
|
||||
import AssetsListItem from './AssetsListItem.vue'
|
||||
|
||||
describe('AssetsListItem', () => {
|
||||
it('renders video element with play overlay for video previews', () => {
|
||||
const wrapper = mount(AssetsListItem, {
|
||||
const { container } = render(AssetsListItem, {
|
||||
props: {
|
||||
previewUrl: 'https://example.com/preview.mp4',
|
||||
previewAlt: 'clip.mp4',
|
||||
@@ -13,17 +15,22 @@ describe('AssetsListItem', () => {
|
||||
}
|
||||
})
|
||||
|
||||
const video = wrapper.find('video')
|
||||
expect(video.exists()).toBe(true)
|
||||
expect(video.attributes('src')).toBe('https://example.com/preview.mp4')
|
||||
expect(video.attributes('preload')).toBe('metadata')
|
||||
expect(wrapper.find('img').exists()).toBe(false)
|
||||
expect(wrapper.find('.bg-black\\/15').exists()).toBe(true)
|
||||
expect(wrapper.find('.icon-\\[lucide--play\\]').exists()).toBe(true)
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access -- no ARIA role for <video> in happy-dom
|
||||
const video = container.querySelector('video')
|
||||
expect(video).toBeInTheDocument()
|
||||
expect(video).toHaveAttribute('src', 'https://example.com/preview.mp4')
|
||||
expect(video).toHaveAttribute('preload', 'metadata')
|
||||
expect(screen.queryByRole('img')).not.toBeInTheDocument()
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access -- CSS class query for play overlay styling
|
||||
expect(container.querySelector('.bg-black\\/15')).toBeInTheDocument()
|
||||
expect(
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access -- CSS class query for play icon styling
|
||||
container.querySelector('.icon-\\[lucide--play\\]')
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('does not show play overlay for non-video previews', () => {
|
||||
const wrapper = mount(AssetsListItem, {
|
||||
const { container } = render(AssetsListItem, {
|
||||
props: {
|
||||
previewUrl: 'https://example.com/preview.jpg',
|
||||
previewAlt: 'image.png',
|
||||
@@ -31,33 +38,41 @@ describe('AssetsListItem', () => {
|
||||
}
|
||||
})
|
||||
|
||||
expect(wrapper.find('img').exists()).toBe(true)
|
||||
expect(wrapper.find('video').exists()).toBe(false)
|
||||
expect(wrapper.find('.icon-\\[lucide--play\\]').exists()).toBe(false)
|
||||
expect(screen.getByRole('img')).toBeInTheDocument()
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access -- no ARIA role for <video> in happy-dom
|
||||
expect(container.querySelector('video')).not.toBeInTheDocument()
|
||||
expect(
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access -- CSS class query for play icon styling
|
||||
container.querySelector('.icon-\\[lucide--play\\]')
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('emits preview-click when preview is clicked', async () => {
|
||||
const wrapper = mount(AssetsListItem, {
|
||||
const user = userEvent.setup()
|
||||
const { emitted } = render(AssetsListItem, {
|
||||
props: {
|
||||
previewUrl: 'https://example.com/preview.jpg',
|
||||
previewAlt: 'image.png'
|
||||
}
|
||||
})
|
||||
|
||||
await wrapper.find('img').trigger('click')
|
||||
await user.click(screen.getByRole('img'))
|
||||
|
||||
expect(wrapper.emitted('preview-click')).toHaveLength(1)
|
||||
expect(emitted()['preview-click']).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('emits preview-click when fallback icon is clicked', async () => {
|
||||
const wrapper = mount(AssetsListItem, {
|
||||
const user = userEvent.setup()
|
||||
const { container, emitted } = render(AssetsListItem, {
|
||||
props: {
|
||||
iconName: 'icon-[lucide--box]'
|
||||
}
|
||||
})
|
||||
|
||||
await wrapper.find('i').trigger('click')
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access -- aria-hidden icon, no semantic query available
|
||||
const icon = container.querySelector('i')!
|
||||
await user.click(icon)
|
||||
|
||||
expect(wrapper.emitted('preview-click')).toHaveLength(1)
|
||||
expect(emitted()['preview-click']).toHaveLength(1)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
/* eslint-disable vue/one-component-per-file */
|
||||
import { render } from '@testing-library/vue'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { defineComponent, nextTick } from 'vue'
|
||||
import type { ComponentPublicInstance } from 'vue'
|
||||
import { defineComponent, nextTick, onMounted, ref } from 'vue'
|
||||
|
||||
import MediaAssetContextMenu from '@/platform/assets/components/MediaAssetContextMenu.vue'
|
||||
import type { AssetItem } from '@/platform/assets/schemas/assetSchema'
|
||||
@@ -84,60 +84,73 @@ const buttonStub = {
|
||||
template: '<div class="button-stub"><slot /></div>'
|
||||
}
|
||||
|
||||
type MediaAssetContextMenuExposed = ComponentPublicInstance & {
|
||||
interface MediaAssetContextMenuExposed {
|
||||
show: (event: MouseEvent) => void
|
||||
}
|
||||
|
||||
const mountComponent = () =>
|
||||
mount(MediaAssetContextMenu, {
|
||||
attachTo: document.body,
|
||||
props: {
|
||||
asset,
|
||||
assetType: 'output',
|
||||
fileKind: 'image'
|
||||
},
|
||||
global: {
|
||||
stubs: {
|
||||
ContextMenu: contextMenuStub,
|
||||
Button: buttonStub
|
||||
let capturedRef: MediaAssetContextMenuExposed | null = null
|
||||
|
||||
function mountComponent() {
|
||||
const onHide = vi.fn()
|
||||
const { container, unmount } = render(
|
||||
defineComponent({
|
||||
components: { MediaAssetContextMenu },
|
||||
setup() {
|
||||
const menuRef = ref<MediaAssetContextMenuExposed | null>(null)
|
||||
onMounted(() => {
|
||||
capturedRef = menuRef.value
|
||||
})
|
||||
return { menuRef, asset, onHide }
|
||||
},
|
||||
template:
|
||||
'<MediaAssetContextMenu ref="menuRef" :asset="asset" asset-type="output" file-kind="image" @hide="onHide" />'
|
||||
}),
|
||||
{
|
||||
global: {
|
||||
stubs: {
|
||||
ContextMenu: contextMenuStub,
|
||||
Button: buttonStub
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
return { container, unmount, onHide }
|
||||
}
|
||||
|
||||
async function showMenu(
|
||||
wrapper: ReturnType<typeof mountComponent>
|
||||
): Promise<HTMLElement> {
|
||||
const exposed = wrapper.vm as MediaAssetContextMenuExposed
|
||||
async function showMenu(container: Element): Promise<HTMLElement> {
|
||||
const event = new MouseEvent('contextmenu', { bubbles: true })
|
||||
exposed.show(event)
|
||||
capturedRef!.show(event)
|
||||
await nextTick()
|
||||
|
||||
return wrapper.get('.context-menu-stub').element as HTMLElement
|
||||
// eslint-disable-next-line testing-library/no-container
|
||||
return container.querySelector('.context-menu-stub') as HTMLElement
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks()
|
||||
capturedRef = null
|
||||
document.body.innerHTML = ''
|
||||
})
|
||||
|
||||
describe('MediaAssetContextMenu', () => {
|
||||
it('dismisses outside pointerdown using the rendered root id', async () => {
|
||||
const wrapper = mountComponent()
|
||||
const { container, unmount, onHide } = mountComponent()
|
||||
const outside = document.createElement('div')
|
||||
document.body.append(outside)
|
||||
|
||||
const menu = await showMenu(wrapper)
|
||||
const menu = await showMenu(container)
|
||||
const menuId = menu.id
|
||||
|
||||
expect(menuId).not.toBe('')
|
||||
// eslint-disable-next-line testing-library/no-node-access
|
||||
expect(document.getElementById(menuId)).toBe(menu)
|
||||
|
||||
outside.dispatchEvent(new Event('pointerdown', { bubbles: true }))
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.find('.context-menu-stub').exists()).toBe(false)
|
||||
expect(wrapper.emitted('hide')).toEqual([[]])
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
expect(container.querySelector('.context-menu-stub')).toBeNull()
|
||||
expect(onHide).toHaveBeenCalledOnce()
|
||||
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { fireEvent, render } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
|
||||
import type { AssetMeta } from '../schemas/mediaAssetSchema'
|
||||
import MediaVideoTop from './MediaVideoTop.vue'
|
||||
|
||||
@@ -21,80 +23,83 @@ function createVideoAsset(
|
||||
|
||||
describe('MediaVideoTop', () => {
|
||||
it('renders playable video with darkened paused overlay and play icon', () => {
|
||||
const wrapper = mount(MediaVideoTop, {
|
||||
const { container } = render(MediaVideoTop, {
|
||||
props: {
|
||||
asset: createVideoAsset('https://example.com/thumb.jpg')
|
||||
}
|
||||
})
|
||||
|
||||
const video = wrapper.find('video')
|
||||
const videoElement = video.element as HTMLVideoElement
|
||||
expect(video.exists()).toBe(true)
|
||||
expect(videoElement.controls).toBe(false)
|
||||
expect(wrapper.find('source').attributes('src')).toBe(
|
||||
'https://example.com/thumb.jpg'
|
||||
)
|
||||
expect(wrapper.find('source').attributes('type')).toBe('video/mp4')
|
||||
expect(wrapper.find('.bg-black\\/15').exists()).toBe(true)
|
||||
expect(wrapper.find('.icon-\\[lucide--play\\]').exists()).toBe(true)
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access -- <video> has no ARIA role in happy-dom
|
||||
const video = container.querySelector('video')!
|
||||
expect(video).toBeInTheDocument()
|
||||
expect(video.controls).toBe(false)
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access -- <source> has no ARIA role in happy-dom
|
||||
const source = container.querySelector('source')!
|
||||
expect(source).toHaveAttribute('src', 'https://example.com/thumb.jpg')
|
||||
expect(source).toHaveAttribute('type', 'video/mp4')
|
||||
})
|
||||
|
||||
it('does not render source element when src is empty', () => {
|
||||
const wrapper = mount(MediaVideoTop, {
|
||||
const { container } = render(MediaVideoTop, {
|
||||
props: {
|
||||
asset: createVideoAsset('')
|
||||
}
|
||||
})
|
||||
|
||||
expect(wrapper.find('video').exists()).toBe(true)
|
||||
expect(wrapper.find('source').exists()).toBe(false)
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access -- <video> has no ARIA role in happy-dom
|
||||
expect(container.querySelector('video')).toBeInTheDocument()
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access -- <source> has no ARIA role in happy-dom
|
||||
expect(container.querySelector('source')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('emits playback events and hides paused overlay while playing', async () => {
|
||||
const wrapper = mount(MediaVideoTop, {
|
||||
const user = userEvent.setup()
|
||||
const { container, emitted } = render(MediaVideoTop, {
|
||||
props: {
|
||||
asset: createVideoAsset('https://example.com/thumb.jpg')
|
||||
}
|
||||
})
|
||||
|
||||
const video = wrapper.find('video')
|
||||
const videoElement = video.element as HTMLVideoElement
|
||||
expect(video.exists()).toBe(true)
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access -- <video> has no ARIA role in happy-dom
|
||||
const video = container.querySelector('video')!
|
||||
expect(video).toBeInTheDocument()
|
||||
|
||||
await video.trigger('play')
|
||||
expect(wrapper.emitted('videoPlayingStateChanged')?.at(-1)).toEqual([true])
|
||||
expect(wrapper.find('.bg-black\\/15').exists()).toBe(false)
|
||||
await fireEvent.play(video)
|
||||
expect(emitted()['videoPlayingStateChanged']?.at(-1)).toEqual([true])
|
||||
|
||||
await wrapper.trigger('mouseenter')
|
||||
expect(videoElement.controls).toBe(true)
|
||||
// eslint-disable-next-line testing-library/no-node-access -- root wrapper has no role
|
||||
await user.hover(container.firstElementChild!)
|
||||
expect(video.controls).toBe(true)
|
||||
|
||||
await wrapper.trigger('mouseleave')
|
||||
expect(videoElement.controls).toBe(false)
|
||||
// eslint-disable-next-line testing-library/no-node-access -- root wrapper has no role
|
||||
await user.unhover(container.firstElementChild!)
|
||||
expect(video.controls).toBe(false)
|
||||
|
||||
await video.trigger('pause')
|
||||
expect(wrapper.emitted('videoPlayingStateChanged')?.at(-1)).toEqual([false])
|
||||
expect(wrapper.find('.bg-black\\/15').exists()).toBe(true)
|
||||
expect(videoElement.controls).toBe(false)
|
||||
await fireEvent.pause(video)
|
||||
expect(emitted()['videoPlayingStateChanged']?.at(-1)).toEqual([false])
|
||||
expect(video.controls).toBe(false)
|
||||
})
|
||||
|
||||
it('starts playback from click when controls are hidden', async () => {
|
||||
const wrapper = mount(MediaVideoTop, {
|
||||
const user = userEvent.setup()
|
||||
const { container } = render(MediaVideoTop, {
|
||||
props: {
|
||||
asset: createVideoAsset('https://example.com/thumb.jpg')
|
||||
}
|
||||
})
|
||||
|
||||
const video = wrapper.find('video')
|
||||
const videoElement = video.element as HTMLVideoElement
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access -- <video> has no ARIA role in happy-dom
|
||||
const video = container.querySelector('video')!
|
||||
const playSpy = vi
|
||||
.spyOn(videoElement, 'play')
|
||||
.spyOn(video, 'play')
|
||||
.mockImplementation(() => Promise.resolve())
|
||||
|
||||
Object.defineProperty(videoElement, 'paused', {
|
||||
Object.defineProperty(video, 'paused', {
|
||||
value: true,
|
||||
configurable: true
|
||||
})
|
||||
|
||||
await video.trigger('click')
|
||||
await user.click(video)
|
||||
|
||||
expect(playSpy).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { createTestingPinia } from '@pinia/testing'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
|
||||
import type { AssetDisplayItem } from '@/platform/assets/composables/useAssetBrowser'
|
||||
|
||||
import ModelInfoPanel from './ModelInfoPanel.vue'
|
||||
@@ -40,8 +41,8 @@ describe('ModelInfoPanel', () => {
|
||||
...overrides
|
||||
})
|
||||
|
||||
const mountPanel = (asset: AssetDisplayItem) => {
|
||||
return mount(ModelInfoPanel, {
|
||||
function renderPanel(asset: AssetDisplayItem) {
|
||||
return render(ModelInfoPanel, {
|
||||
props: { asset },
|
||||
global: {
|
||||
plugins: [createTestingPinia({ stubActions: false }), i18n]
|
||||
@@ -51,14 +52,18 @@ describe('ModelInfoPanel', () => {
|
||||
|
||||
describe('Basic Info Section', () => {
|
||||
it('renders basic info section', () => {
|
||||
const wrapper = mountPanel(createMockAsset())
|
||||
expect(wrapper.text()).toContain('assetBrowser.modelInfo.basicInfo')
|
||||
renderPanel(createMockAsset())
|
||||
expect(
|
||||
screen.getByText('assetBrowser.modelInfo.basicInfo')
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('displays asset filename', () => {
|
||||
const asset = createMockAsset({ name: 'my-model.safetensors' })
|
||||
const wrapper = mountPanel(asset)
|
||||
expect(wrapper.text()).toContain('my-model.safetensors')
|
||||
renderPanel(asset)
|
||||
expect(
|
||||
screen.getAllByText('my-model.safetensors').length
|
||||
).toBeGreaterThanOrEqual(1)
|
||||
})
|
||||
|
||||
it('prefers user_metadata.filename over asset.name for filename field', () => {
|
||||
@@ -66,78 +71,88 @@ describe('ModelInfoPanel', () => {
|
||||
name: 'registry-display-name',
|
||||
user_metadata: { filename: 'checkpoints/real-file.safetensors' }
|
||||
})
|
||||
const wrapper = mountPanel(asset)
|
||||
expect(wrapper.text()).toContain('checkpoints/real-file.safetensors')
|
||||
renderPanel(asset)
|
||||
expect(
|
||||
screen.getByText('checkpoints/real-file.safetensors')
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('displays name from user_metadata when present', () => {
|
||||
const asset = createMockAsset({
|
||||
user_metadata: { name: 'My Custom Model' }
|
||||
})
|
||||
const wrapper = mountPanel(asset)
|
||||
expect(wrapper.text()).toContain('My Custom Model')
|
||||
renderPanel(asset)
|
||||
expect(screen.getByText('My Custom Model')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('falls back to asset name when user_metadata.name not present', () => {
|
||||
const asset = createMockAsset({ name: 'fallback-model.safetensors' })
|
||||
const wrapper = mountPanel(asset)
|
||||
expect(wrapper.text()).toContain('fallback-model.safetensors')
|
||||
renderPanel(asset)
|
||||
expect(
|
||||
screen.getAllByText('fallback-model.safetensors').length
|
||||
).toBeGreaterThanOrEqual(1)
|
||||
})
|
||||
|
||||
it('renders source link when source_arn is present', () => {
|
||||
const asset = createMockAsset({
|
||||
user_metadata: { source_arn: 'civitai:model:123:version:456' }
|
||||
})
|
||||
const wrapper = mountPanel(asset)
|
||||
const link = wrapper.find(
|
||||
'a[href="https://civitai.com/models/123?modelVersionId=456"]'
|
||||
renderPanel(asset)
|
||||
const link = screen.getByRole('link')
|
||||
expect(link).toHaveAttribute(
|
||||
'href',
|
||||
'https://civitai.com/models/123?modelVersionId=456'
|
||||
)
|
||||
expect(link.exists()).toBe(true)
|
||||
expect(link.attributes('target')).toBe('_blank')
|
||||
expect(link).toHaveAttribute('target', '_blank')
|
||||
})
|
||||
|
||||
it('displays Civitai icon for Civitai source', () => {
|
||||
const asset = createMockAsset({
|
||||
user_metadata: { source_arn: 'civitai:model:123:version:456' }
|
||||
})
|
||||
const wrapper = mountPanel(asset)
|
||||
expect(
|
||||
wrapper.find('img[src="/assets/images/civitai.svg"]').exists()
|
||||
).toBe(true)
|
||||
renderPanel(asset)
|
||||
expect(screen.getByRole('img')).toHaveAttribute(
|
||||
'src',
|
||||
'/assets/images/civitai.svg'
|
||||
)
|
||||
})
|
||||
|
||||
it('does not render source field when source_arn is absent', () => {
|
||||
const asset = createMockAsset()
|
||||
const wrapper = mountPanel(asset)
|
||||
const links = wrapper.findAll('a')
|
||||
expect(links).toHaveLength(0)
|
||||
renderPanel(createMockAsset())
|
||||
expect(screen.queryAllByRole('link')).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Model Tagging Section', () => {
|
||||
it('renders model tagging section', () => {
|
||||
const wrapper = mountPanel(createMockAsset())
|
||||
expect(wrapper.text()).toContain('assetBrowser.modelInfo.modelTagging')
|
||||
renderPanel(createMockAsset())
|
||||
expect(
|
||||
screen.getByText('assetBrowser.modelInfo.modelTagging')
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders model type field', () => {
|
||||
const wrapper = mountPanel(createMockAsset())
|
||||
expect(wrapper.text()).toContain('assetBrowser.modelInfo.modelType')
|
||||
renderPanel(createMockAsset())
|
||||
expect(
|
||||
screen.getByText('assetBrowser.modelInfo.modelType')
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders base models field', () => {
|
||||
const asset = createMockAsset({
|
||||
user_metadata: { base_model: ['SDXL'] }
|
||||
})
|
||||
const wrapper = mountPanel(asset)
|
||||
expect(wrapper.text()).toContain(
|
||||
'assetBrowser.modelInfo.compatibleBaseModels'
|
||||
)
|
||||
renderPanel(asset)
|
||||
expect(
|
||||
screen.getByText('assetBrowser.modelInfo.compatibleBaseModels')
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders additional tags field', () => {
|
||||
const wrapper = mountPanel(createMockAsset())
|
||||
expect(wrapper.text()).toContain('assetBrowser.modelInfo.additionalTags')
|
||||
renderPanel(createMockAsset())
|
||||
expect(
|
||||
screen.getByText('assetBrowser.modelInfo.additionalTags')
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -146,35 +161,38 @@ describe('ModelInfoPanel', () => {
|
||||
const asset = createMockAsset({
|
||||
user_metadata: { trained_words: ['trigger1', 'trigger2'] }
|
||||
})
|
||||
const wrapper = mountPanel(asset)
|
||||
expect(wrapper.text()).toContain('trigger1')
|
||||
expect(wrapper.text()).toContain('trigger2')
|
||||
renderPanel(asset)
|
||||
expect(screen.getByText('trigger1')).toBeInTheDocument()
|
||||
expect(screen.getByText('trigger2')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders description section', () => {
|
||||
const wrapper = mountPanel(createMockAsset())
|
||||
expect(wrapper.text()).toContain(
|
||||
'assetBrowser.modelInfo.modelDescription'
|
||||
)
|
||||
renderPanel(createMockAsset())
|
||||
expect(
|
||||
screen.getByText('assetBrowser.modelInfo.modelDescription')
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('does not render trigger phrases field when empty', () => {
|
||||
const asset = createMockAsset()
|
||||
const wrapper = mountPanel(asset)
|
||||
expect(wrapper.text()).not.toContain(
|
||||
'assetBrowser.modelInfo.triggerPhrases'
|
||||
)
|
||||
renderPanel(createMockAsset())
|
||||
expect(
|
||||
screen.queryByText('assetBrowser.modelInfo.triggerPhrases')
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Accordion Structure', () => {
|
||||
it('renders all three section labels', () => {
|
||||
const wrapper = mountPanel(createMockAsset())
|
||||
expect(wrapper.text()).toContain('assetBrowser.modelInfo.basicInfo')
|
||||
expect(wrapper.text()).toContain('assetBrowser.modelInfo.modelTagging')
|
||||
expect(wrapper.text()).toContain(
|
||||
'assetBrowser.modelInfo.modelDescription'
|
||||
)
|
||||
renderPanel(createMockAsset())
|
||||
expect(
|
||||
screen.getByText('assetBrowser.modelInfo.basicInfo')
|
||||
).toBeInTheDocument()
|
||||
expect(
|
||||
screen.getByText('assetBrowser.modelInfo.modelTagging')
|
||||
).toBeInTheDocument()
|
||||
expect(
|
||||
screen.getByText('assetBrowser.modelInfo.modelDescription')
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { render } from '@testing-library/vue'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { nextTick } from 'vue'
|
||||
|
||||
@@ -77,31 +77,31 @@ describe('DesktopCloudNotificationController', () => {
|
||||
const loadSettings = createDeferred()
|
||||
settingStore.load.mockImplementation(() => loadSettings.promise)
|
||||
|
||||
const wrapper = mount(DesktopCloudNotificationController)
|
||||
const { unmount } = render(DesktopCloudNotificationController)
|
||||
await nextTick()
|
||||
|
||||
settingState.shown = true
|
||||
loadSettings.resolve()
|
||||
|
||||
await flushPromises()
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
await vi.advanceTimersByTimeAsync(2000)
|
||||
|
||||
expect(dialogService.showCloudNotification).not.toHaveBeenCalled()
|
||||
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
})
|
||||
|
||||
it('does not schedule or show the notification after unmounting before settings load resolves', async () => {
|
||||
const loadSettings = createDeferred()
|
||||
settingStore.load.mockImplementation(() => loadSettings.promise)
|
||||
|
||||
const wrapper = mount(DesktopCloudNotificationController)
|
||||
const { unmount } = render(DesktopCloudNotificationController)
|
||||
await nextTick()
|
||||
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
loadSettings.resolve()
|
||||
|
||||
await flushPromises()
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
await vi.advanceTimersByTimeAsync(2000)
|
||||
|
||||
expect(settingStore.set).not.toHaveBeenCalled()
|
||||
@@ -114,9 +114,9 @@ describe('DesktopCloudNotificationController', () => {
|
||||
() => dialogOpen.promise
|
||||
)
|
||||
|
||||
const wrapper = mount(DesktopCloudNotificationController)
|
||||
const { unmount } = render(DesktopCloudNotificationController)
|
||||
|
||||
await flushPromises()
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
await vi.advanceTimersByTimeAsync(2000)
|
||||
|
||||
expect(settingStore.set).toHaveBeenCalledWith(
|
||||
@@ -128,8 +128,8 @@ describe('DesktopCloudNotificationController', () => {
|
||||
)
|
||||
|
||||
dialogOpen.resolve()
|
||||
await flushPromises()
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import { beforeEach, describe, expect, test, vi } from 'vitest'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
@@ -86,7 +86,7 @@ const createI18nInstance = () =>
|
||||
const mountView = async (query: Record<string, unknown>) => {
|
||||
mockQuery = query
|
||||
|
||||
const wrapper = mount(CloudSubscriptionRedirectView, {
|
||||
const { container } = render(CloudSubscriptionRedirectView, {
|
||||
global: {
|
||||
plugins: [createI18nInstance()]
|
||||
}
|
||||
@@ -94,7 +94,7 @@ const mountView = async (query: Record<string, unknown>) => {
|
||||
|
||||
await flushPromises()
|
||||
|
||||
return { wrapper }
|
||||
return { container }
|
||||
}
|
||||
|
||||
describe('CloudSubscriptionRedirectView', () => {
|
||||
@@ -118,13 +118,13 @@ describe('CloudSubscriptionRedirectView', () => {
|
||||
})
|
||||
|
||||
test('shows subscription copy when subscriptionType is valid', async () => {
|
||||
const { wrapper } = await mountView({ tier: 'creator' })
|
||||
await mountView({ tier: 'creator' })
|
||||
|
||||
// Should not redirect to home
|
||||
expect(mockRouterPush).not.toHaveBeenCalledWith('/')
|
||||
|
||||
// Shows copy under logo
|
||||
expect(wrapper.text()).toContain('Subscribe to Creator')
|
||||
expect(screen.getByText('Subscribe to Creator')).toBeInTheDocument()
|
||||
|
||||
// Triggers checkout flow
|
||||
expect(mockPerformSubscriptionCheckout).toHaveBeenCalledWith(
|
||||
@@ -134,11 +134,9 @@ describe('CloudSubscriptionRedirectView', () => {
|
||||
)
|
||||
|
||||
// Shows loading affordances
|
||||
expect(wrapper.findComponent({ name: 'ProgressSpinner' }).exists()).toBe(
|
||||
true
|
||||
)
|
||||
const skipLink = wrapper.get('a[href="/"]')
|
||||
expect(skipLink.text()).toContain('Skip to the cloud app')
|
||||
expect(
|
||||
screen.getByRole('link', { name: /skip to the cloud app/i })
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('opens billing portal when subscription is already active', async () => {
|
||||
@@ -152,12 +150,12 @@ describe('CloudSubscriptionRedirectView', () => {
|
||||
})
|
||||
|
||||
test('uses first value when subscriptionType is an array', async () => {
|
||||
const { wrapper } = await mountView({
|
||||
await mountView({
|
||||
tier: ['creator', 'pro']
|
||||
})
|
||||
|
||||
expect(mockRouterPush).not.toHaveBeenCalledWith('/')
|
||||
expect(wrapper.text()).toContain('Subscribe to Creator')
|
||||
expect(screen.getByText('Subscribe to Creator')).toBeInTheDocument()
|
||||
expect(mockPerformSubscriptionCheckout).toHaveBeenCalledWith(
|
||||
'creator',
|
||||
'monthly',
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { createTestingPinia } from '@pinia/testing'
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { computed, reactive, ref } from 'vue'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
@@ -7,6 +8,10 @@ import { createI18n } from 'vue-i18n'
|
||||
import PricingTable from '@/platform/cloud/subscription/components/PricingTable.vue'
|
||||
import Button from '@/components/ui/button/Button.vue'
|
||||
|
||||
async function flushPromises() {
|
||||
await new Promise((r) => setTimeout(r, 0))
|
||||
}
|
||||
|
||||
const mockIsActiveSubscription = ref(false)
|
||||
const mockSubscriptionTier = ref<
|
||||
'STANDARD' | 'CREATOR' | 'PRO' | 'FOUNDERS_EDITION' | null
|
||||
@@ -131,8 +136,11 @@ const i18n = createI18n({
|
||||
}
|
||||
})
|
||||
|
||||
function createWrapper() {
|
||||
return mount(PricingTable, {
|
||||
function renderComponent() {
|
||||
return render(PricingTable, {
|
||||
props: {
|
||||
onChooseTeamWorkspace: onChooseTeamWorkspace
|
||||
},
|
||||
global: {
|
||||
plugins: [createTestingPinia({ createSpy: vi.fn }), i18n],
|
||||
components: {
|
||||
@@ -150,6 +158,8 @@ function createWrapper() {
|
||||
})
|
||||
}
|
||||
|
||||
const onChooseTeamWorkspace = vi.fn()
|
||||
|
||||
describe('PricingTable', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
@@ -169,15 +179,15 @@ describe('PricingTable', () => {
|
||||
mockIsActiveSubscription.value = true
|
||||
mockSubscriptionTier.value = 'STANDARD'
|
||||
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
const creatorButton = wrapper
|
||||
.findAll('button')
|
||||
.find((btn) => btn.text().includes('Creator'))
|
||||
const creatorButton = screen
|
||||
.getAllByRole('button')
|
||||
.find((b) => b.textContent?.includes('Creator'))
|
||||
|
||||
expect(creatorButton).toBeDefined()
|
||||
await creatorButton?.trigger('click')
|
||||
await userEvent.click(creatorButton!)
|
||||
await flushPromises()
|
||||
|
||||
expect(mockTrackBeginCheckout).toHaveBeenCalledWith({
|
||||
@@ -194,14 +204,14 @@ describe('PricingTable', () => {
|
||||
mockIsActiveSubscription.value = true
|
||||
mockSubscriptionTier.value = 'STANDARD'
|
||||
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
const proButton = wrapper
|
||||
.findAll('button')
|
||||
.find((btn) => btn.text().includes('Pro'))
|
||||
const proButton = screen
|
||||
.getAllByRole('button')
|
||||
.find((b) => b.textContent?.includes('Pro'))
|
||||
|
||||
await proButton?.trigger('click')
|
||||
await userEvent.click(proButton!)
|
||||
await flushPromises()
|
||||
|
||||
expect(mockAccessBillingPortal).toHaveBeenCalledWith('pro-yearly')
|
||||
@@ -212,16 +222,16 @@ describe('PricingTable', () => {
|
||||
mockSubscriptionTier.value = 'STANDARD'
|
||||
mockUserId.value = 'user-early'
|
||||
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
mockUserId.value = 'user-late'
|
||||
|
||||
const creatorButton = wrapper
|
||||
.findAll('button')
|
||||
.find((btn) => btn.text().includes('Creator'))
|
||||
const creatorButton = screen
|
||||
.getAllByRole('button')
|
||||
.find((b) => b.textContent?.includes('Creator'))
|
||||
|
||||
await creatorButton?.trigger('click')
|
||||
await userEvent.click(creatorButton!)
|
||||
await flushPromises()
|
||||
|
||||
expect(mockTrackBeginCheckout).toHaveBeenCalledTimes(1)
|
||||
@@ -238,14 +248,14 @@ describe('PricingTable', () => {
|
||||
mockIsActiveSubscription.value = true
|
||||
mockSubscriptionTier.value = 'CREATOR'
|
||||
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
const currentPlanButton = wrapper
|
||||
.findAll('button')
|
||||
.find((btn) => btn.text().includes('Current Plan'))
|
||||
const currentPlanButton = screen
|
||||
.getAllByRole('button')
|
||||
.find((b) => b.textContent?.includes('Current Plan'))
|
||||
|
||||
await currentPlanButton?.trigger('click')
|
||||
await userEvent.click(currentPlanButton!)
|
||||
await flushPromises()
|
||||
|
||||
expect(mockAccessBillingPortal).not.toHaveBeenCalled()
|
||||
@@ -258,14 +268,14 @@ describe('PricingTable', () => {
|
||||
.spyOn(window, 'open')
|
||||
.mockImplementation(() => null)
|
||||
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
const subscribeButton = wrapper
|
||||
.findAll('button')
|
||||
.find((btn) => btn.text().includes('Subscribe'))
|
||||
const subscribeButton = screen
|
||||
.getAllByRole('button')
|
||||
.find((b) => b.textContent?.includes('Subscribe'))
|
||||
|
||||
await subscribeButton?.trigger('click')
|
||||
await userEvent.click(subscribeButton!)
|
||||
await flushPromises()
|
||||
|
||||
expect(mockAccessBillingPortal).not.toHaveBeenCalled()
|
||||
@@ -285,14 +295,14 @@ describe('PricingTable', () => {
|
||||
mockIsActiveSubscription.value = true
|
||||
mockSubscriptionTier.value = 'PRO'
|
||||
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
const standardButton = wrapper
|
||||
.findAll('button')
|
||||
.find((btn) => btn.text().includes('Standard'))
|
||||
const standardButton = screen
|
||||
.getAllByRole('button')
|
||||
.find((b) => b.textContent?.includes('Standard'))
|
||||
|
||||
await standardButton?.trigger('click')
|
||||
await userEvent.click(standardButton!)
|
||||
await flushPromises()
|
||||
|
||||
expect(mockAccessBillingPortal).toHaveBeenCalledWith('standard-yearly')
|
||||
@@ -301,17 +311,17 @@ describe('PricingTable', () => {
|
||||
|
||||
describe('team workspace link', () => {
|
||||
it('should emit chooseTeamWorkspace when clicking "Need team workspace?" link', async () => {
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
const teamLink = wrapper
|
||||
.findAll('button')
|
||||
.find((btn) => btn.text().includes('Need team workspace?'))
|
||||
const teamLink = screen
|
||||
.getAllByRole('button')
|
||||
.find((b) => b.textContent?.includes('Need team workspace?'))
|
||||
|
||||
expect(teamLink).toBeDefined()
|
||||
await teamLink?.trigger('click')
|
||||
await userEvent.click(teamLink!)
|
||||
|
||||
expect(wrapper.emitted('chooseTeamWorkspace')).toHaveLength(1)
|
||||
expect(onChooseTeamWorkspace).toHaveBeenCalledOnce()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { createTestingPinia } from '@pinia/testing'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { computed, ref } from 'vue'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
@@ -190,8 +191,8 @@ const i18n = createI18n({
|
||||
}
|
||||
})
|
||||
|
||||
function createWrapper(overrides = {}) {
|
||||
return mount(SubscriptionPanel, {
|
||||
function createComponent(overrides = {}) {
|
||||
return render(SubscriptionPanel, {
|
||||
global: {
|
||||
plugins: [createTestingPinia({ createSpy: vi.fn }), i18n],
|
||||
|
||||
@@ -206,7 +207,7 @@ function createWrapper(overrides = {}) {
|
||||
emits: ['click']
|
||||
},
|
||||
Skeleton: {
|
||||
template: '<div class="skeleton"></div>'
|
||||
template: '<div role="status" aria-label="Loading"></div>'
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -214,13 +215,10 @@ function createWrapper(overrides = {}) {
|
||||
})
|
||||
}
|
||||
|
||||
function findButtonByText(
|
||||
wrapper: ReturnType<typeof createWrapper>,
|
||||
text: string
|
||||
) {
|
||||
const button = wrapper
|
||||
.findAll('button')
|
||||
.find((button) => button.text().includes(text))
|
||||
function findButtonByText(text: string) {
|
||||
const button = screen
|
||||
.getAllByRole('button')
|
||||
.find((b) => b.textContent?.includes(text))
|
||||
if (!button) throw new Error(`Button with text "${text}" not found`)
|
||||
return button
|
||||
}
|
||||
@@ -240,102 +238,110 @@ describe('SubscriptionPanel', () => {
|
||||
describe('subscription state functionality', () => {
|
||||
it('shows correct UI for active subscription', () => {
|
||||
mockIsActiveSubscription.value = true
|
||||
const wrapper = createWrapper()
|
||||
expect(wrapper.text()).toContain('Manage Subscription')
|
||||
expect(wrapper.text()).toContain('Add Credits')
|
||||
const { container } = createComponent()
|
||||
expect(container.textContent).toContain('Manage Subscription')
|
||||
expect(container.textContent).toContain('Add Credits')
|
||||
})
|
||||
|
||||
it('shows correct UI for inactive subscription', () => {
|
||||
mockIsActiveSubscription.value = false
|
||||
const wrapper = createWrapper()
|
||||
expect(wrapper.findComponent({ name: 'SubscribeButton' }).exists()).toBe(
|
||||
true
|
||||
)
|
||||
expect(wrapper.text()).not.toContain('Manage Subscription')
|
||||
expect(wrapper.text()).not.toContain('Add Credits')
|
||||
const { container } = createComponent()
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
expect(container.querySelector('subscribe-button-stub')).not.toBeNull()
|
||||
expect(container.textContent).not.toContain('Manage Subscription')
|
||||
expect(container.textContent).not.toContain('Add Credits')
|
||||
})
|
||||
|
||||
it('shows renewal date for active non-cancelled subscription', () => {
|
||||
mockIsActiveSubscription.value = true
|
||||
mockIsCancelled.value = false
|
||||
const wrapper = createWrapper()
|
||||
expect(wrapper.text()).toContain('Renews 2024-12-31')
|
||||
const { container } = createComponent()
|
||||
expect(container.textContent).toContain('Renews 2024-12-31')
|
||||
})
|
||||
|
||||
it('shows expiry date for cancelled subscription', () => {
|
||||
mockIsActiveSubscription.value = true
|
||||
mockIsCancelled.value = true
|
||||
const wrapper = createWrapper()
|
||||
expect(wrapper.text()).toContain('Expires 2024-12-31')
|
||||
const { container } = createComponent()
|
||||
expect(container.textContent).toContain('Expires 2024-12-31')
|
||||
})
|
||||
|
||||
it('displays FOUNDERS_EDITION tier correctly', () => {
|
||||
mockSubscriptionTier.value = 'FOUNDERS_EDITION'
|
||||
const wrapper = createWrapper()
|
||||
expect(wrapper.text()).toContain("Founder's Edition")
|
||||
expect(wrapper.text()).toContain('5,460')
|
||||
const { container } = createComponent()
|
||||
expect(container.textContent).toContain("Founder's Edition")
|
||||
expect(container.textContent).toContain('5,460')
|
||||
})
|
||||
|
||||
it('displays CREATOR tier correctly', () => {
|
||||
mockSubscriptionTier.value = 'CREATOR'
|
||||
const wrapper = createWrapper()
|
||||
expect(wrapper.text()).toContain('Creator')
|
||||
expect(wrapper.text()).toContain('7,400')
|
||||
const { container } = createComponent()
|
||||
expect(container.textContent).toContain('Creator')
|
||||
expect(container.textContent).toContain('7,400')
|
||||
})
|
||||
})
|
||||
|
||||
describe('credit display functionality', () => {
|
||||
it('displays dynamic credit values correctly', () => {
|
||||
const wrapper = createWrapper()
|
||||
expect(wrapper.text()).toContain('10.00 Credits')
|
||||
expect(wrapper.text()).toContain('5.00 Credits')
|
||||
const { container } = createComponent()
|
||||
expect(container.textContent).toContain('10.00 Credits')
|
||||
expect(container.textContent).toContain('5.00 Credits')
|
||||
})
|
||||
|
||||
it('shows loading skeleton when fetching balance', () => {
|
||||
mockCreditsData.isLoadingBalance = true
|
||||
const wrapper = createWrapper()
|
||||
expect(wrapper.findAll('.skeleton').length).toBeGreaterThan(0)
|
||||
createComponent()
|
||||
expect(
|
||||
screen.getAllByRole('status', { name: 'Loading' }).length
|
||||
).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
it('hides skeleton when balance loaded', () => {
|
||||
mockCreditsData.isLoadingBalance = false
|
||||
const wrapper = createWrapper()
|
||||
expect(wrapper.findAll('.skeleton').length).toBe(0)
|
||||
createComponent()
|
||||
expect(screen.queryAllByRole('status', { name: 'Loading' })).toHaveLength(
|
||||
0
|
||||
)
|
||||
})
|
||||
|
||||
it('renders refill date with literal slashes', () => {
|
||||
vi.useFakeTimers()
|
||||
vi.stubEnv('TZ', 'UTC')
|
||||
|
||||
mockIsActiveSubscription.value = true
|
||||
const wrapper = createWrapper()
|
||||
expect(wrapper.text()).toMatch(/Included \(Refills \d{2}\/\d{2}\/\d{2}\)/)
|
||||
expect(wrapper.text()).not.toContain('/')
|
||||
|
||||
vi.useRealTimers()
|
||||
vi.unstubAllEnvs()
|
||||
try {
|
||||
mockIsActiveSubscription.value = true
|
||||
const { container } = createComponent()
|
||||
expect(container.textContent).toMatch(
|
||||
/Included \(Refills \d{2}\/\d{2}\/\d{2}\)/
|
||||
)
|
||||
expect(container.textContent).not.toContain('/')
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
vi.unstubAllEnvs()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('action buttons', () => {
|
||||
it('should call handleLearnMoreClick when learn more is clicked', async () => {
|
||||
const wrapper = createWrapper()
|
||||
const learnMoreButton = findButtonByText(wrapper, 'Learn More')
|
||||
await learnMoreButton.trigger('click')
|
||||
createComponent()
|
||||
const learnMoreButton = findButtonByText('Learn More')
|
||||
await userEvent.click(learnMoreButton)
|
||||
expect(mockActionsData.handleLearnMoreClick).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it('should call handleMessageSupport when message support is clicked', async () => {
|
||||
const wrapper = createWrapper()
|
||||
const supportButton = findButtonByText(wrapper, 'Message Support')
|
||||
await supportButton.trigger('click')
|
||||
createComponent()
|
||||
const supportButton = findButtonByText('Message Support')
|
||||
await userEvent.click(supportButton)
|
||||
expect(mockActionsData.handleMessageSupport).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it('should call handleRefresh when refresh button is clicked', async () => {
|
||||
const wrapper = createWrapper()
|
||||
const refreshButton = wrapper.find('button[aria-label="Refresh credits"]')
|
||||
await refreshButton.trigger('click')
|
||||
createComponent()
|
||||
const refreshButton = screen.getByRole('button', {
|
||||
name: 'Refresh credits'
|
||||
})
|
||||
await userEvent.click(refreshButton)
|
||||
expect(mockActionsData.handleRefresh).toHaveBeenCalledOnce()
|
||||
})
|
||||
})
|
||||
@@ -343,16 +349,18 @@ describe('SubscriptionPanel', () => {
|
||||
describe('loading states', () => {
|
||||
it('should show loading state on support button when loading', () => {
|
||||
mockActionsData.isLoadingSupport = true
|
||||
const wrapper = createWrapper()
|
||||
const supportButton = findButtonByText(wrapper, 'Message Support')
|
||||
expect(supportButton.attributes('disabled')).toBeDefined()
|
||||
createComponent()
|
||||
const supportButton = findButtonByText('Message Support')
|
||||
expect(supportButton).toBeDisabled()
|
||||
})
|
||||
|
||||
it('should show loading state on refresh button when loading balance', () => {
|
||||
mockCreditsData.isLoadingBalance = true
|
||||
const wrapper = createWrapper()
|
||||
const refreshButton = wrapper.find('button[aria-label="Refresh credits"]')
|
||||
expect(refreshButton.attributes('disabled')).toBeDefined()
|
||||
createComponent()
|
||||
const refreshButton = screen.getByRole('button', {
|
||||
name: 'Refresh credits'
|
||||
})
|
||||
expect(refreshButton).toBeDisabled()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import PrimeVue from 'primevue/config'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
@@ -12,7 +13,8 @@ import type {
|
||||
vi.mock('./MissingModelRow.vue', () => ({
|
||||
default: {
|
||||
name: 'MissingModelRow',
|
||||
template: '<div class="model-row" />',
|
||||
template:
|
||||
'<div class="model-row" :data-show-node-id-badge="showNodeIdBadge" :data-is-asset-supported="isAssetSupported" :data-directory="directory"><button class="locate-trigger" @click="$emit(\'locate-model\', model?.representative?.nodeId)">Locate</button></div>',
|
||||
props: ['model', 'directory', 'showNodeIdBadge', 'isAssetSupported'],
|
||||
emits: ['locate-model']
|
||||
}
|
||||
@@ -83,13 +85,15 @@ function mountCard(
|
||||
props: Partial<{
|
||||
missingModelGroups: MissingModelGroup[]
|
||||
showNodeIdBadge: boolean
|
||||
}> = {}
|
||||
}> = {},
|
||||
onLocateModel?: (nodeId: string) => void
|
||||
) {
|
||||
return mount(MissingModelCard, {
|
||||
return render(MissingModelCard, {
|
||||
props: {
|
||||
missingModelGroups: [makeGroup()],
|
||||
showNodeIdBadge: false,
|
||||
...props
|
||||
...props,
|
||||
...(onLocateModel ? { onLocateModel } : {})
|
||||
},
|
||||
global: {
|
||||
plugins: [PrimeVue, i18n]
|
||||
@@ -104,90 +108,90 @@ describe('MissingModelCard', () => {
|
||||
|
||||
describe('Rendering & Props', () => {
|
||||
it('renders directory name in category header', () => {
|
||||
const wrapper = mountCard({
|
||||
const { container } = mountCard({
|
||||
missingModelGroups: [makeGroup({ directory: 'loras' })]
|
||||
})
|
||||
expect(wrapper.text()).toContain('loras')
|
||||
expect(container.textContent).toContain('loras')
|
||||
})
|
||||
|
||||
it('renders translated unknown category when directory is null', () => {
|
||||
const wrapper = mountCard({
|
||||
const { container } = mountCard({
|
||||
missingModelGroups: [makeGroup({ directory: null })]
|
||||
})
|
||||
expect(wrapper.text()).toContain('Unknown Category')
|
||||
expect(container.textContent).toContain('Unknown Category')
|
||||
})
|
||||
|
||||
it('renders model count in category header', () => {
|
||||
const wrapper = mountCard({
|
||||
const { container } = mountCard({
|
||||
missingModelGroups: [
|
||||
makeGroup({ modelNames: ['a.safetensors', 'b.safetensors'] })
|
||||
]
|
||||
})
|
||||
expect(wrapper.text()).toContain('(2)')
|
||||
expect(container.textContent).toContain('(2)')
|
||||
})
|
||||
|
||||
it('renders correct number of MissingModelRow components', () => {
|
||||
const wrapper = mountCard({
|
||||
const { container } = mountCard({
|
||||
missingModelGroups: [
|
||||
makeGroup({
|
||||
modelNames: ['a.safetensors', 'b.safetensors', 'c.safetensors']
|
||||
})
|
||||
]
|
||||
})
|
||||
expect(
|
||||
wrapper.findAllComponents({ name: 'MissingModelRow' })
|
||||
).toHaveLength(3)
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
expect(container.querySelectorAll('.model-row')).toHaveLength(3)
|
||||
})
|
||||
|
||||
it('renders multiple groups', () => {
|
||||
const wrapper = mountCard({
|
||||
const { container } = mountCard({
|
||||
missingModelGroups: [
|
||||
makeGroup({ directory: 'checkpoints' }),
|
||||
makeGroup({ directory: 'loras' })
|
||||
]
|
||||
})
|
||||
expect(wrapper.text()).toContain('checkpoints')
|
||||
expect(wrapper.text()).toContain('loras')
|
||||
expect(container.textContent).toContain('checkpoints')
|
||||
expect(container.textContent).toContain('loras')
|
||||
})
|
||||
|
||||
it('renders zero rows when missingModelGroups is empty', () => {
|
||||
const wrapper = mountCard({ missingModelGroups: [] })
|
||||
expect(
|
||||
wrapper.findAllComponents({ name: 'MissingModelRow' })
|
||||
).toHaveLength(0)
|
||||
const { container } = mountCard({ missingModelGroups: [] })
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
expect(container.querySelectorAll('.model-row')).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('passes props correctly to MissingModelRow children', () => {
|
||||
const wrapper = mountCard({ showNodeIdBadge: true })
|
||||
const row = wrapper.findComponent({ name: 'MissingModelRow' })
|
||||
expect(row.props('showNodeIdBadge')).toBe(true)
|
||||
expect(row.props('isAssetSupported')).toBe(true)
|
||||
expect(row.props('directory')).toBe('checkpoints')
|
||||
const { container } = mountCard({ showNodeIdBadge: true })
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
const row = container.querySelector('.model-row')
|
||||
expect(row).not.toBeNull()
|
||||
expect(row!.getAttribute('data-show-node-id-badge')).toBe('true')
|
||||
expect(row!.getAttribute('data-is-asset-supported')).toBe('true')
|
||||
expect(row!.getAttribute('data-directory')).toBe('checkpoints')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Asset Unsupported Group', () => {
|
||||
it('shows "Import Not Supported" header for unsupported groups', () => {
|
||||
const wrapper = mountCard({
|
||||
const { container } = mountCard({
|
||||
missingModelGroups: [makeGroup({ isAssetSupported: false })]
|
||||
})
|
||||
expect(wrapper.text()).toContain('Import Not Supported')
|
||||
expect(container.textContent).toContain('Import Not Supported')
|
||||
})
|
||||
|
||||
it('shows info notice for unsupported groups', () => {
|
||||
const wrapper = mountCard({
|
||||
const { container } = mountCard({
|
||||
missingModelGroups: [makeGroup({ isAssetSupported: false })]
|
||||
})
|
||||
expect(wrapper.text()).toContain(
|
||||
expect(container.textContent).toContain(
|
||||
'Cloud environment does not support model imports'
|
||||
)
|
||||
})
|
||||
|
||||
it('hides info notice for supported groups', () => {
|
||||
const wrapper = mountCard({
|
||||
const { container } = mountCard({
|
||||
missingModelGroups: [makeGroup({ isAssetSupported: true })]
|
||||
})
|
||||
expect(wrapper.text()).not.toContain(
|
||||
expect(container.textContent).not.toContain(
|
||||
'Cloud environment does not support model imports'
|
||||
)
|
||||
})
|
||||
@@ -195,11 +199,11 @@ describe('MissingModelCard', () => {
|
||||
|
||||
describe('Event Handling', () => {
|
||||
it('emits locateModel when child emits locate-model', async () => {
|
||||
const wrapper = mountCard()
|
||||
const row = wrapper.findComponent({ name: 'MissingModelRow' })
|
||||
await row.vm.$emit('locate-model', '42')
|
||||
expect(wrapper.emitted('locateModel')).toBeTruthy()
|
||||
expect(wrapper.emitted('locateModel')?.[0]).toEqual(['42'])
|
||||
const onLocateModel = vi.fn()
|
||||
mountCard({}, onLocateModel)
|
||||
const locateButton = screen.getByRole('button', { name: 'Locate' })
|
||||
await userEvent.click(locateButton)
|
||||
expect(onLocateModel).toHaveBeenCalledWith('1')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -214,31 +218,31 @@ describe('MissingModelCard (OSS)', () => {
|
||||
})
|
||||
|
||||
it('shows directory name instead of "Import Not Supported" for unsupported groups', () => {
|
||||
const wrapper = mountCard({
|
||||
const { container } = mountCard({
|
||||
missingModelGroups: [
|
||||
makeGroup({ directory: 'checkpoints', isAssetSupported: false })
|
||||
]
|
||||
})
|
||||
expect(wrapper.text()).toContain('checkpoints')
|
||||
expect(wrapper.text()).not.toContain('Import Not Supported')
|
||||
expect(container.textContent).toContain('checkpoints')
|
||||
expect(container.textContent).not.toContain('Import Not Supported')
|
||||
})
|
||||
|
||||
it('hides info notice for unsupported groups', () => {
|
||||
const wrapper = mountCard({
|
||||
const { container } = mountCard({
|
||||
missingModelGroups: [makeGroup({ isAssetSupported: false })]
|
||||
})
|
||||
expect(wrapper.text()).not.toContain(
|
||||
expect(container.textContent).not.toContain(
|
||||
'Cloud environment does not support model imports'
|
||||
)
|
||||
})
|
||||
|
||||
it('renders unknown category for null directory in OSS', () => {
|
||||
const wrapper = mountCard({
|
||||
const { container } = mountCard({
|
||||
missingModelGroups: [
|
||||
makeGroup({ directory: null, isAssetSupported: false })
|
||||
]
|
||||
})
|
||||
expect(wrapper.text()).toContain('Unknown Category')
|
||||
expect(wrapper.text()).not.toContain('Import Not Supported')
|
||||
expect(container.textContent).toContain('Unknown Category')
|
||||
expect(container.textContent).not.toContain('Import Not Supported')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen, fireEvent } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { createPinia, setActivePinia } from 'pinia'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
@@ -72,14 +73,14 @@ const i18n = createI18n({
|
||||
|
||||
const MODEL_KEY = 'supported::checkpoints::model.safetensors'
|
||||
|
||||
function mountComponent(
|
||||
function renderComponent(
|
||||
props: Partial<{
|
||||
modelKey: string
|
||||
directory: string | null
|
||||
typeMismatch: string | null
|
||||
}> = {}
|
||||
) {
|
||||
return mount(MissingModelUrlInput, {
|
||||
return render(MissingModelUrlInput, {
|
||||
props: {
|
||||
modelKey: MODEL_KEY,
|
||||
directory: 'checkpoints',
|
||||
@@ -104,24 +105,25 @@ describe('MissingModelUrlInput', () => {
|
||||
describe('URL input is always editable', () => {
|
||||
it('input is editable when privateModelsEnabled is true', () => {
|
||||
mockPrivateModelsEnabled.value = true
|
||||
const wrapper = mountComponent()
|
||||
const input = wrapper.find('input')
|
||||
expect(input.attributes('readonly')).toBeUndefined()
|
||||
renderComponent()
|
||||
const input = screen.getByRole('textbox')
|
||||
expect(input).not.toHaveAttribute('readonly')
|
||||
})
|
||||
|
||||
it('input is editable when privateModelsEnabled is false (free tier)', () => {
|
||||
mockPrivateModelsEnabled.value = false
|
||||
const wrapper = mountComponent()
|
||||
const input = wrapper.find('input')
|
||||
expect(input.attributes('readonly')).toBeUndefined()
|
||||
renderComponent()
|
||||
const input = screen.getByRole('textbox')
|
||||
expect(input).not.toHaveAttribute('readonly')
|
||||
})
|
||||
|
||||
it('input accepts user typing when privateModelsEnabled is false', async () => {
|
||||
mockPrivateModelsEnabled.value = false
|
||||
const wrapper = mountComponent()
|
||||
const input = wrapper.find('input')
|
||||
input.element.value = 'https://example.com/model.safetensors'
|
||||
await input.trigger('input')
|
||||
renderComponent()
|
||||
const input = screen.getByRole('textbox') as HTMLInputElement
|
||||
input.value = 'https://example.com/model.safetensors'
|
||||
// eslint-disable-next-line testing-library/prefer-user-event
|
||||
await fireEvent.input(input)
|
||||
expect(mockHandleUrlInput).toHaveBeenCalledWith(
|
||||
MODEL_KEY,
|
||||
'https://example.com/model.safetensors'
|
||||
@@ -132,6 +134,7 @@ describe('MissingModelUrlInput', () => {
|
||||
describe('Import button gates on subscription', () => {
|
||||
it('calls handleImport when privateModelsEnabled is true', async () => {
|
||||
mockPrivateModelsEnabled.value = true
|
||||
const user = userEvent.setup()
|
||||
const store = useMissingModelStore()
|
||||
store.urlMetadata[MODEL_KEY] = {
|
||||
filename: 'model.safetensors',
|
||||
@@ -139,12 +142,10 @@ describe('MissingModelUrlInput', () => {
|
||||
final_url: 'https://example.com/model.safetensors'
|
||||
}
|
||||
|
||||
const wrapper = mountComponent()
|
||||
const importBtn = wrapper
|
||||
.findAll('button')
|
||||
.find((b) => b.text().includes('Import'))
|
||||
expect(importBtn).toBeTruthy()
|
||||
await importBtn!.trigger('click')
|
||||
renderComponent()
|
||||
const importBtn = screen.getByRole('button', { name: /Import/ })
|
||||
expect(importBtn).toBeInTheDocument()
|
||||
await user.click(importBtn)
|
||||
|
||||
expect(mockHandleImport).toHaveBeenCalledWith(MODEL_KEY, 'checkpoints')
|
||||
expect(mockShowUploadDialog).not.toHaveBeenCalled()
|
||||
@@ -152,6 +153,7 @@ describe('MissingModelUrlInput', () => {
|
||||
|
||||
it('calls showUploadDialog when privateModelsEnabled is false (free tier)', async () => {
|
||||
mockPrivateModelsEnabled.value = false
|
||||
const user = userEvent.setup()
|
||||
const store = useMissingModelStore()
|
||||
store.urlMetadata[MODEL_KEY] = {
|
||||
filename: 'model.safetensors',
|
||||
@@ -159,12 +161,10 @@ describe('MissingModelUrlInput', () => {
|
||||
final_url: 'https://example.com/model.safetensors'
|
||||
}
|
||||
|
||||
const wrapper = mountComponent()
|
||||
const importBtn = wrapper
|
||||
.findAll('button')
|
||||
.find((b) => b.text().includes('Import'))
|
||||
expect(importBtn).toBeTruthy()
|
||||
await importBtn!.trigger('click')
|
||||
renderComponent()
|
||||
const importBtn = screen.getByRole('button', { name: /Import/ })
|
||||
expect(importBtn).toBeInTheDocument()
|
||||
await user.click(importBtn)
|
||||
|
||||
expect(mockShowUploadDialog).toHaveBeenCalled()
|
||||
expect(mockHandleImport).not.toHaveBeenCalled()
|
||||
@@ -172,11 +172,12 @@ describe('MissingModelUrlInput', () => {
|
||||
|
||||
it('clear button works for free-tier users', async () => {
|
||||
mockPrivateModelsEnabled.value = false
|
||||
const user = userEvent.setup()
|
||||
const store = useMissingModelStore()
|
||||
store.urlInputs[MODEL_KEY] = 'https://example.com/model.safetensors'
|
||||
const wrapper = mountComponent()
|
||||
const clearBtn = wrapper.find('button[aria-label="Clear URL"]')
|
||||
await clearBtn.trigger('click')
|
||||
renderComponent()
|
||||
const clearBtn = screen.getByRole('button', { name: 'Clear URL' })
|
||||
await user.click(clearBtn)
|
||||
expect(mockHandleUrlInput).toHaveBeenCalledWith(MODEL_KEY, '')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { createTestingPinia } from '@pinia/testing'
|
||||
import { fromAny } from '@total-typescript/shoehorn'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import PrimeVue from 'primevue/config'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
@@ -44,13 +45,15 @@ function makeGroup(overrides: Partial<SwapNodeGroup> = {}): SwapNodeGroup {
|
||||
}
|
||||
}
|
||||
|
||||
function mountRow(
|
||||
function renderRow(
|
||||
props: Partial<{
|
||||
group: SwapNodeGroup
|
||||
showNodeIdBadge: boolean
|
||||
'onLocate-node': (nodeId: string) => void
|
||||
onReplace: (group: SwapNodeGroup) => void
|
||||
}> = {}
|
||||
) {
|
||||
return mount(SwapNodeGroupRow, {
|
||||
return render(SwapNodeGroupRow, {
|
||||
props: {
|
||||
group: makeGroup(),
|
||||
showNodeIdBadge: false,
|
||||
@@ -68,17 +71,17 @@ function mountRow(
|
||||
describe('SwapNodeGroupRow', () => {
|
||||
describe('Basic Rendering', () => {
|
||||
it('renders the group type name', () => {
|
||||
const wrapper = mountRow()
|
||||
expect(wrapper.text()).toContain('OldNodeType')
|
||||
const { container } = renderRow()
|
||||
expect(container.textContent).toContain('OldNodeType')
|
||||
})
|
||||
|
||||
it('renders node count in parentheses', () => {
|
||||
const wrapper = mountRow()
|
||||
expect(wrapper.text()).toContain('(2)')
|
||||
const { container } = renderRow()
|
||||
expect(container.textContent).toContain('(2)')
|
||||
})
|
||||
|
||||
it('renders node count of 5 for 5 nodeTypes', () => {
|
||||
const wrapper = mountRow({
|
||||
const { container } = renderRow({
|
||||
group: makeGroup({
|
||||
nodeTypes: Array.from({ length: 5 }, (_, i) => ({
|
||||
type: 'OldNodeType',
|
||||
@@ -87,63 +90,71 @@ describe('SwapNodeGroupRow', () => {
|
||||
}))
|
||||
})
|
||||
})
|
||||
expect(wrapper.text()).toContain('(5)')
|
||||
expect(container.textContent).toContain('(5)')
|
||||
})
|
||||
|
||||
it('renders the replacement target name', () => {
|
||||
const wrapper = mountRow()
|
||||
expect(wrapper.text()).toContain('NewNodeType')
|
||||
const { container } = renderRow()
|
||||
expect(container.textContent).toContain('NewNodeType')
|
||||
})
|
||||
|
||||
it('shows "Unknown" when newNodeId is undefined', () => {
|
||||
const wrapper = mountRow({
|
||||
const { container } = renderRow({
|
||||
group: makeGroup({ newNodeId: undefined })
|
||||
})
|
||||
expect(wrapper.text()).toContain('Unknown')
|
||||
expect(container.textContent).toContain('Unknown')
|
||||
})
|
||||
|
||||
it('renders "Replace Node" button', () => {
|
||||
const wrapper = mountRow()
|
||||
expect(wrapper.text()).toContain('Replace Node')
|
||||
renderRow()
|
||||
expect(
|
||||
screen.getByRole('button', { name: /Replace Node/ })
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Expand / Collapse', () => {
|
||||
it('starts collapsed — node list not visible', () => {
|
||||
const wrapper = mountRow({ showNodeIdBadge: true })
|
||||
expect(wrapper.text()).not.toContain('#1')
|
||||
const { container } = renderRow({ showNodeIdBadge: true })
|
||||
expect(container.textContent).not.toContain('#1')
|
||||
})
|
||||
|
||||
it('expands when chevron is clicked', async () => {
|
||||
const wrapper = mountRow({ showNodeIdBadge: true })
|
||||
await wrapper.get('button[aria-label="Expand"]').trigger('click')
|
||||
expect(wrapper.text()).toContain('#1')
|
||||
expect(wrapper.text()).toContain('#2')
|
||||
const user = userEvent.setup()
|
||||
const { container } = renderRow({ showNodeIdBadge: true })
|
||||
await user.click(screen.getByRole('button', { name: 'Expand' }))
|
||||
expect(container.textContent).toContain('#1')
|
||||
expect(container.textContent).toContain('#2')
|
||||
})
|
||||
|
||||
it('collapses when chevron is clicked again', async () => {
|
||||
const wrapper = mountRow({ showNodeIdBadge: true })
|
||||
await wrapper.get('button[aria-label="Expand"]').trigger('click')
|
||||
expect(wrapper.text()).toContain('#1')
|
||||
await wrapper.get('button[aria-label="Collapse"]').trigger('click')
|
||||
expect(wrapper.text()).not.toContain('#1')
|
||||
const user = userEvent.setup()
|
||||
const { container } = renderRow({ showNodeIdBadge: true })
|
||||
await user.click(screen.getByRole('button', { name: 'Expand' }))
|
||||
expect(container.textContent).toContain('#1')
|
||||
await user.click(screen.getByRole('button', { name: 'Collapse' }))
|
||||
expect(container.textContent).not.toContain('#1')
|
||||
})
|
||||
|
||||
it('updates the toggle control state when expanded', async () => {
|
||||
const wrapper = mountRow()
|
||||
expect(wrapper.find('button[aria-label="Expand"]').exists()).toBe(true)
|
||||
await wrapper.get('button[aria-label="Expand"]').trigger('click')
|
||||
expect(wrapper.find('button[aria-label="Collapse"]').exists()).toBe(true)
|
||||
const user = userEvent.setup()
|
||||
renderRow()
|
||||
expect(screen.getByRole('button', { name: 'Expand' })).toBeInTheDocument()
|
||||
await user.click(screen.getByRole('button', { name: 'Expand' }))
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Collapse' })
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Node Type List (Expanded)', () => {
|
||||
async function expand(wrapper: ReturnType<typeof mountRow>) {
|
||||
await wrapper.get('button[aria-label="Expand"]').trigger('click')
|
||||
async function expand() {
|
||||
const user = userEvent.setup()
|
||||
await user.click(screen.getByRole('button', { name: 'Expand' }))
|
||||
}
|
||||
|
||||
it('renders all nodeTypes when expanded', async () => {
|
||||
const wrapper = mountRow({
|
||||
const { container } = renderRow({
|
||||
group: makeGroup({
|
||||
nodeTypes: [
|
||||
{ type: 'OldNodeType', nodeId: '10', isReplaceable: true },
|
||||
@@ -153,36 +164,36 @@ describe('SwapNodeGroupRow', () => {
|
||||
}),
|
||||
showNodeIdBadge: true
|
||||
})
|
||||
await expand(wrapper)
|
||||
expect(wrapper.text()).toContain('#10')
|
||||
expect(wrapper.text()).toContain('#20')
|
||||
expect(wrapper.text()).toContain('#30')
|
||||
await expand()
|
||||
expect(container.textContent).toContain('#10')
|
||||
expect(container.textContent).toContain('#20')
|
||||
expect(container.textContent).toContain('#30')
|
||||
})
|
||||
|
||||
it('shows nodeId badge when showNodeIdBadge is true', async () => {
|
||||
const wrapper = mountRow({ showNodeIdBadge: true })
|
||||
await expand(wrapper)
|
||||
expect(wrapper.text()).toContain('#1')
|
||||
expect(wrapper.text()).toContain('#2')
|
||||
const { container } = renderRow({ showNodeIdBadge: true })
|
||||
await expand()
|
||||
expect(container.textContent).toContain('#1')
|
||||
expect(container.textContent).toContain('#2')
|
||||
})
|
||||
|
||||
it('hides nodeId badge when showNodeIdBadge is false', async () => {
|
||||
const wrapper = mountRow({ showNodeIdBadge: false })
|
||||
await expand(wrapper)
|
||||
expect(wrapper.text()).not.toContain('#1')
|
||||
expect(wrapper.text()).not.toContain('#2')
|
||||
const { container } = renderRow({ showNodeIdBadge: false })
|
||||
await expand()
|
||||
expect(container.textContent).not.toContain('#1')
|
||||
expect(container.textContent).not.toContain('#2')
|
||||
})
|
||||
|
||||
it('renders Locate button for each nodeType with nodeId', async () => {
|
||||
const wrapper = mountRow({ showNodeIdBadge: true })
|
||||
await expand(wrapper)
|
||||
expect(wrapper.findAll('button[aria-label="Locate Node"]')).toHaveLength(
|
||||
2
|
||||
)
|
||||
renderRow({ showNodeIdBadge: true })
|
||||
await expand()
|
||||
expect(
|
||||
screen.getAllByRole('button', { name: 'Locate Node' })
|
||||
).toHaveLength(2)
|
||||
})
|
||||
|
||||
it('does not render Locate button for nodeTypes without nodeId', async () => {
|
||||
const wrapper = mountRow({
|
||||
renderRow({
|
||||
group: makeGroup({
|
||||
// Intentionally omits nodeId to test graceful handling of incomplete node data
|
||||
nodeTypes: fromAny<MissingNodeType[], unknown>([
|
||||
@@ -190,56 +201,56 @@ describe('SwapNodeGroupRow', () => {
|
||||
])
|
||||
})
|
||||
})
|
||||
await expand(wrapper)
|
||||
expect(wrapper.find('button[aria-label="Locate Node"]').exists()).toBe(
|
||||
false
|
||||
)
|
||||
await expand()
|
||||
expect(
|
||||
screen.queryByRole('button', { name: 'Locate Node' })
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Events', () => {
|
||||
it('emits locate-node with correct nodeId', async () => {
|
||||
const wrapper = mountRow({ showNodeIdBadge: true })
|
||||
await wrapper.get('button[aria-label="Expand"]').trigger('click')
|
||||
const locateBtns = wrapper.findAll('button[aria-label="Locate Node"]')
|
||||
await locateBtns[0].trigger('click')
|
||||
expect(wrapper.emitted('locate-node')).toBeTruthy()
|
||||
expect(wrapper.emitted('locate-node')?.[0]).toEqual(['1'])
|
||||
const onLocateNode = vi.fn()
|
||||
const user = userEvent.setup()
|
||||
renderRow({ showNodeIdBadge: true, 'onLocate-node': onLocateNode })
|
||||
await user.click(screen.getByRole('button', { name: 'Expand' }))
|
||||
const locateBtns = screen.getAllByRole('button', { name: 'Locate Node' })
|
||||
await user.click(locateBtns[0])
|
||||
expect(onLocateNode).toHaveBeenCalledWith('1')
|
||||
|
||||
await locateBtns[1].trigger('click')
|
||||
expect(wrapper.emitted('locate-node')?.[1]).toEqual(['2'])
|
||||
await user.click(locateBtns[1])
|
||||
expect(onLocateNode).toHaveBeenCalledWith('2')
|
||||
})
|
||||
|
||||
it('emits replace with group when Replace button is clicked', async () => {
|
||||
const group = makeGroup()
|
||||
const wrapper = mountRow({ group })
|
||||
const replaceBtn = wrapper
|
||||
.findAll('button')
|
||||
.find((b) => b.text().includes('Replace Node'))
|
||||
if (!replaceBtn) throw new Error('Replace button not found')
|
||||
await replaceBtn.trigger('click')
|
||||
expect(wrapper.emitted('replace')).toBeTruthy()
|
||||
expect(wrapper.emitted('replace')?.[0][0]).toEqual(group)
|
||||
const onReplace = vi.fn()
|
||||
const user = userEvent.setup()
|
||||
renderRow({ group, onReplace })
|
||||
const replaceBtn = screen.getByRole('button', { name: /Replace Node/ })
|
||||
await user.click(replaceBtn)
|
||||
expect(onReplace).toHaveBeenCalledWith(group)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Edge Cases', () => {
|
||||
it('handles empty nodeTypes array', () => {
|
||||
const wrapper = mountRow({
|
||||
const { container } = renderRow({
|
||||
group: makeGroup({ nodeTypes: [] })
|
||||
})
|
||||
expect(wrapper.text()).toContain('(0)')
|
||||
expect(container.textContent).toContain('(0)')
|
||||
})
|
||||
|
||||
it('handles string nodeType entries', async () => {
|
||||
const wrapper = mountRow({
|
||||
const user = userEvent.setup()
|
||||
const { container } = renderRow({
|
||||
group: makeGroup({
|
||||
// Intentionally uses a plain string entry to test legacy node type handling
|
||||
nodeTypes: fromAny<MissingNodeType[], unknown>(['StringType'])
|
||||
})
|
||||
})
|
||||
await wrapper.get('button[aria-label="Expand"]').trigger('click')
|
||||
expect(wrapper.text()).toContain('StringType')
|
||||
await user.click(screen.getByRole('button', { name: 'Expand' }))
|
||||
expect(container.textContent).toContain('StringType')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { createTestingPinia } from '@pinia/testing'
|
||||
import PrimeVue from 'primevue/config'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
@@ -9,7 +10,8 @@ import type { SwapNodeGroup } from '@/components/rightSidePanel/errors/useErrorG
|
||||
vi.mock('./SwapNodeGroupRow.vue', () => ({
|
||||
default: {
|
||||
name: 'SwapNodeGroupRow',
|
||||
template: '<div class="swap-row" />',
|
||||
template:
|
||||
'<div class="swap-row" :data-show-node-id-badge="showNodeIdBadge" :data-group-type="group?.type"><button class="locate-trigger" @click="$emit(\'locate-node\', group?.nodeTypes?.[0]?.nodeId)">Locate</button><button class="replace-trigger" @click="$emit(\'replace\', group)">Replace</button></div>',
|
||||
props: ['group', 'showNodeIdBadge'],
|
||||
emits: ['locate-node', 'replace']
|
||||
}
|
||||
@@ -37,13 +39,21 @@ function mountCard(
|
||||
props: Partial<{
|
||||
swapNodeGroups: SwapNodeGroup[]
|
||||
showNodeIdBadge: boolean
|
||||
}> = {}
|
||||
}> = {},
|
||||
callbacks?: {
|
||||
onLocateNode?: (nodeId: string) => void
|
||||
onReplace?: (group: SwapNodeGroup) => void
|
||||
}
|
||||
) {
|
||||
return mount(SwapNodesCard, {
|
||||
return render(SwapNodesCard, {
|
||||
props: {
|
||||
swapNodeGroups: makeGroups(),
|
||||
showNodeIdBadge: false,
|
||||
...props
|
||||
...props,
|
||||
...(callbacks?.onLocateNode
|
||||
? { 'onLocate-node': callbacks.onLocateNode }
|
||||
: {}),
|
||||
...(callbacks?.onReplace ? { onReplace: callbacks.onReplace } : {})
|
||||
},
|
||||
global: {
|
||||
plugins: [createTestingPinia({ createSpy: vi.fn }), PrimeVue, i18n]
|
||||
@@ -54,76 +64,81 @@ function mountCard(
|
||||
describe('SwapNodesCard', () => {
|
||||
describe('Rendering', () => {
|
||||
it('renders guidance message', () => {
|
||||
const wrapper = mountCard()
|
||||
expect(wrapper.find('p').exists()).toBe(true)
|
||||
const { container } = mountCard()
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
expect(container.querySelector('p')).not.toBeNull()
|
||||
})
|
||||
|
||||
it('renders correct number of SwapNodeGroupRow components', () => {
|
||||
const wrapper = mountCard({ swapNodeGroups: makeGroups(3) })
|
||||
expect(
|
||||
wrapper.findAllComponents({ name: 'SwapNodeGroupRow' })
|
||||
).toHaveLength(3)
|
||||
const { container } = mountCard({ swapNodeGroups: makeGroups(3) })
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
expect(container.querySelectorAll('.swap-row')).toHaveLength(3)
|
||||
})
|
||||
|
||||
it('renders zero rows when swapNodeGroups is empty', () => {
|
||||
const wrapper = mountCard({ swapNodeGroups: [] })
|
||||
expect(
|
||||
wrapper.findAllComponents({ name: 'SwapNodeGroupRow' })
|
||||
).toHaveLength(0)
|
||||
const { container } = mountCard({ swapNodeGroups: [] })
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
expect(container.querySelectorAll('.swap-row')).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('renders one row when swapNodeGroups has one entry', () => {
|
||||
const wrapper = mountCard({ swapNodeGroups: makeGroups(1) })
|
||||
expect(
|
||||
wrapper.findAllComponents({ name: 'SwapNodeGroupRow' })
|
||||
).toHaveLength(1)
|
||||
const { container } = mountCard({ swapNodeGroups: makeGroups(1) })
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
expect(container.querySelectorAll('.swap-row')).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('passes showNodeIdBadge to children', () => {
|
||||
const wrapper = mountCard({
|
||||
const { container } = mountCard({
|
||||
swapNodeGroups: makeGroups(1),
|
||||
showNodeIdBadge: true
|
||||
})
|
||||
const row = wrapper.findComponent({ name: 'SwapNodeGroupRow' })
|
||||
expect(row.props('showNodeIdBadge')).toBe(true)
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
const row = container.querySelector('.swap-row')
|
||||
expect(row!.getAttribute('data-show-node-id-badge')).toBe('true')
|
||||
})
|
||||
|
||||
it('passes group prop to children', () => {
|
||||
const groups = makeGroups(1)
|
||||
const wrapper = mountCard({ swapNodeGroups: groups })
|
||||
const row = wrapper.findComponent({ name: 'SwapNodeGroupRow' })
|
||||
expect(row.props('group')).toEqual(groups[0])
|
||||
const { container } = mountCard({ swapNodeGroups: groups })
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
const row = container.querySelector('.swap-row')
|
||||
expect(row!.getAttribute('data-group-type')).toBe(groups[0].type)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Events', () => {
|
||||
it('bubbles locate-node event from child', async () => {
|
||||
const wrapper = mountCard()
|
||||
const row = wrapper.findComponent({ name: 'SwapNodeGroupRow' })
|
||||
await row.vm.$emit('locate-node', '42')
|
||||
expect(wrapper.emitted('locate-node')).toBeTruthy()
|
||||
expect(wrapper.emitted('locate-node')?.[0]).toEqual(['42'])
|
||||
const onLocateNode = vi.fn()
|
||||
mountCard({}, { onLocateNode })
|
||||
const locateButtons = screen.getAllByRole('button', { name: 'Locate' })
|
||||
await userEvent.click(locateButtons[0])
|
||||
expect(onLocateNode).toHaveBeenCalledWith('0')
|
||||
})
|
||||
|
||||
it('bubbles replace event from child', async () => {
|
||||
const groups = makeGroups(1)
|
||||
const wrapper = mountCard({ swapNodeGroups: groups })
|
||||
const row = wrapper.findComponent({ name: 'SwapNodeGroupRow' })
|
||||
await row.vm.$emit('replace', groups[0])
|
||||
expect(wrapper.emitted('replace')).toBeTruthy()
|
||||
expect(wrapper.emitted('replace')?.[0][0]).toEqual(groups[0])
|
||||
const onReplace = vi.fn()
|
||||
mountCard({ swapNodeGroups: groups }, { onReplace })
|
||||
const replaceButton = screen.getByRole('button', { name: 'Replace' })
|
||||
await userEvent.click(replaceButton)
|
||||
expect(onReplace).toHaveBeenCalledWith(groups[0])
|
||||
})
|
||||
|
||||
it('bubbles events from correct child when multiple rows', async () => {
|
||||
const groups = makeGroups(3)
|
||||
const wrapper = mountCard({ swapNodeGroups: groups })
|
||||
const rows = wrapper.findAllComponents({ name: 'SwapNodeGroupRow' })
|
||||
const onLocateNode = vi.fn()
|
||||
const onReplace = vi.fn()
|
||||
mountCard({ swapNodeGroups: groups }, { onLocateNode, onReplace })
|
||||
|
||||
await rows[2].vm.$emit('locate-node', '99')
|
||||
expect(wrapper.emitted('locate-node')?.[0]).toEqual(['99'])
|
||||
const locateButtons = screen.getAllByRole('button', { name: 'Locate' })
|
||||
await userEvent.click(locateButtons[2])
|
||||
expect(onLocateNode).toHaveBeenCalledWith('2')
|
||||
|
||||
await rows[1].vm.$emit('replace', groups[1])
|
||||
expect(wrapper.emitted('replace')?.[0][0]).toEqual(groups[1])
|
||||
const replaceButtons = screen.getAllByRole('button', {
|
||||
name: 'Replace'
|
||||
})
|
||||
await userEvent.click(replaceButtons[1])
|
||||
expect(onReplace).toHaveBeenCalledWith(groups[1])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import type { VueWrapper } from '@vue/test-utils'
|
||||
import { render } from '@testing-library/vue'
|
||||
import { nextTick, reactive } from 'vue'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
@@ -21,7 +20,7 @@ vi.mock('@/stores/queueStore', () => {
|
||||
import { useQueueStore } from '@/stores/queueStore'
|
||||
|
||||
function mountUseQueuePolling() {
|
||||
return mount({
|
||||
render({
|
||||
template: '<div />',
|
||||
setup() {
|
||||
useQueuePolling()
|
||||
@@ -31,7 +30,6 @@ function mountUseQueuePolling() {
|
||||
}
|
||||
|
||||
describe('useQueuePolling', () => {
|
||||
let wrapper: VueWrapper
|
||||
const store = useQueueStore() as Partial<
|
||||
ReturnType<typeof useQueueStore>
|
||||
> as {
|
||||
@@ -48,17 +46,16 @@ describe('useQueuePolling', () => {
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
wrapper?.unmount()
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
it('does not call update on creation', () => {
|
||||
wrapper = mountUseQueuePolling()
|
||||
mountUseQueuePolling()
|
||||
expect(store.update).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('polls when activeJobsCount is exactly 1', async () => {
|
||||
wrapper = mountUseQueuePolling()
|
||||
mountUseQueuePolling()
|
||||
|
||||
store.activeJobsCount = 1
|
||||
await vi.advanceTimersByTimeAsync(8_000)
|
||||
@@ -67,7 +64,7 @@ describe('useQueuePolling', () => {
|
||||
})
|
||||
|
||||
it('does not poll when activeJobsCount > 1', async () => {
|
||||
wrapper = mountUseQueuePolling()
|
||||
mountUseQueuePolling()
|
||||
|
||||
store.activeJobsCount = 2
|
||||
await vi.advanceTimersByTimeAsync(16_000)
|
||||
@@ -77,7 +74,7 @@ describe('useQueuePolling', () => {
|
||||
|
||||
it('stops polling when activeJobsCount drops to 0', async () => {
|
||||
store.activeJobsCount = 1
|
||||
wrapper = mountUseQueuePolling()
|
||||
mountUseQueuePolling()
|
||||
|
||||
store.activeJobsCount = 0
|
||||
await vi.advanceTimersByTimeAsync(16_000)
|
||||
@@ -87,7 +84,7 @@ describe('useQueuePolling', () => {
|
||||
|
||||
it('resets timer when loading completes', async () => {
|
||||
store.activeJobsCount = 1
|
||||
wrapper = mountUseQueuePolling()
|
||||
mountUseQueuePolling()
|
||||
|
||||
// Advance 5s toward the 8s timeout
|
||||
await vi.advanceTimersByTimeAsync(5_000)
|
||||
@@ -110,7 +107,7 @@ describe('useQueuePolling', () => {
|
||||
|
||||
it('applies exponential backoff on successive polls', async () => {
|
||||
store.activeJobsCount = 1
|
||||
wrapper = mountUseQueuePolling()
|
||||
mountUseQueuePolling()
|
||||
|
||||
// First poll at 8s
|
||||
await vi.advanceTimersByTimeAsync(8_000)
|
||||
@@ -131,7 +128,7 @@ describe('useQueuePolling', () => {
|
||||
|
||||
it('skips poll when an update is already in-flight', async () => {
|
||||
store.activeJobsCount = 1
|
||||
wrapper = mountUseQueuePolling()
|
||||
mountUseQueuePolling()
|
||||
|
||||
// Simulate an external update starting before the timer fires
|
||||
store.isLoading = true
|
||||
@@ -148,7 +145,7 @@ describe('useQueuePolling', () => {
|
||||
|
||||
it('resets backoff when activeJobsCount changes', async () => {
|
||||
store.activeJobsCount = 1
|
||||
wrapper = mountUseQueuePolling()
|
||||
mountUseQueuePolling()
|
||||
|
||||
// First poll at 8s (backs off delay to 12s)
|
||||
await vi.advanceTimersByTimeAsync(8_000)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
|
||||
import type { SecretMetadata } from '../types'
|
||||
import SecretListItem from './SecretListItem.vue'
|
||||
|
||||
@@ -26,12 +28,12 @@ function createMockSecret(
|
||||
}
|
||||
}
|
||||
|
||||
function mountComponent(props: {
|
||||
function renderComponent(props: {
|
||||
secret: SecretMetadata
|
||||
loading?: boolean
|
||||
disabled?: boolean
|
||||
}) {
|
||||
return mount(SecretListItem, {
|
||||
return render(SecretListItem, {
|
||||
props,
|
||||
global: {
|
||||
stubs: {
|
||||
@@ -56,123 +58,134 @@ describe('SecretListItem', () => {
|
||||
describe('rendering', () => {
|
||||
it('displays secret name', () => {
|
||||
const secret = createMockSecret({ name: 'My API Key' })
|
||||
const wrapper = mountComponent({ secret })
|
||||
renderComponent({ secret })
|
||||
|
||||
expect(wrapper.text()).toContain('My API Key')
|
||||
expect(screen.getByText('My API Key')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('displays provider label when provider exists', () => {
|
||||
const secret = createMockSecret({ provider: 'huggingface' })
|
||||
const wrapper = mountComponent({ secret })
|
||||
renderComponent({ secret })
|
||||
|
||||
expect(wrapper.text()).toContain('HuggingFace')
|
||||
expect(screen.getByText('HuggingFace')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('displays Civitai provider label', () => {
|
||||
const secret = createMockSecret({ provider: 'civitai' })
|
||||
const wrapper = mountComponent({ secret })
|
||||
renderComponent({ secret })
|
||||
|
||||
expect(wrapper.text()).toContain('Civitai')
|
||||
expect(screen.getByText('Civitai')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('hides provider badge when no provider', () => {
|
||||
const secret = createMockSecret({ provider: undefined })
|
||||
const wrapper = mountComponent({ secret })
|
||||
renderComponent({ secret })
|
||||
|
||||
expect(wrapper.text()).not.toContain('HuggingFace')
|
||||
expect(wrapper.text()).not.toContain('Civitai')
|
||||
expect(screen.queryByText('HuggingFace')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('Civitai')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('displays created date', () => {
|
||||
const secret = createMockSecret({ created_at: '2024-01-15T10:00:00Z' })
|
||||
const wrapper = mountComponent({ secret })
|
||||
renderComponent({ secret })
|
||||
|
||||
expect(wrapper.text()).toContain('secrets.createdAt')
|
||||
expect(screen.getByText(/secrets\.createdAt/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('displays last used date when available', () => {
|
||||
const secret = createMockSecret({ last_used_at: '2024-01-20T10:00:00Z' })
|
||||
const wrapper = mountComponent({ secret })
|
||||
renderComponent({ secret })
|
||||
|
||||
expect(wrapper.text()).toContain('secrets.lastUsed')
|
||||
expect(screen.getByText(/secrets\.lastUsed/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('hides last used when not available', () => {
|
||||
const secret = createMockSecret({ last_used_at: undefined })
|
||||
const wrapper = mountComponent({ secret })
|
||||
renderComponent({ secret })
|
||||
|
||||
expect(wrapper.text()).not.toContain('secrets.lastUsed')
|
||||
expect(screen.queryByText(/secrets\.lastUsed/)).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('loading state', () => {
|
||||
it('shows spinner when loading', () => {
|
||||
const secret = createMockSecret()
|
||||
const wrapper = mountComponent({ secret, loading: true })
|
||||
const { container } = renderComponent({ secret, loading: true })
|
||||
|
||||
expect(wrapper.find('.pi-spinner').exists()).toBe(true)
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access -- PrimeIcon has no ARIA role
|
||||
expect(container.querySelector('.pi-spinner')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('hides action buttons when loading', () => {
|
||||
const secret = createMockSecret()
|
||||
const wrapper = mountComponent({ secret, loading: true })
|
||||
const { container } = renderComponent({ secret, loading: true })
|
||||
|
||||
expect(wrapper.find('.pi-pen-to-square').exists()).toBe(false)
|
||||
expect(wrapper.find('.pi-trash').exists()).toBe(false)
|
||||
expect(
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access -- PrimeIcon has no ARIA role
|
||||
container.querySelector('.pi-pen-to-square')
|
||||
).not.toBeInTheDocument()
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access -- PrimeIcon has no ARIA role
|
||||
expect(container.querySelector('.pi-trash')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows action buttons when not loading', () => {
|
||||
const secret = createMockSecret()
|
||||
const wrapper = mountComponent({ secret, loading: false })
|
||||
const { container } = renderComponent({ secret, loading: false })
|
||||
|
||||
expect(wrapper.find('.pi-pen-to-square').exists()).toBe(true)
|
||||
expect(wrapper.find('.pi-trash').exists()).toBe(true)
|
||||
expect(
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access -- PrimeIcon has no ARIA role
|
||||
container.querySelector('.pi-pen-to-square')
|
||||
).toBeInTheDocument()
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access -- PrimeIcon has no ARIA role
|
||||
expect(container.querySelector('.pi-trash')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('disabled state', () => {
|
||||
it('disables buttons when disabled prop is true', () => {
|
||||
const secret = createMockSecret()
|
||||
const wrapper = mountComponent({ secret, disabled: true })
|
||||
renderComponent({ secret, disabled: true })
|
||||
|
||||
const buttons = wrapper.findAll('button')
|
||||
const buttons = screen.getAllByRole('button')
|
||||
buttons.forEach((button) => {
|
||||
expect(button.attributes('disabled')).toBeDefined()
|
||||
expect(button).toBeDisabled()
|
||||
})
|
||||
})
|
||||
|
||||
it('enables buttons when disabled prop is false', () => {
|
||||
const secret = createMockSecret()
|
||||
const wrapper = mountComponent({ secret, disabled: false })
|
||||
renderComponent({ secret, disabled: false })
|
||||
|
||||
const buttons = wrapper.findAll('button')
|
||||
const buttons = screen.getAllByRole('button')
|
||||
buttons.forEach((button) => {
|
||||
expect(button.attributes('disabled')).toBeUndefined()
|
||||
expect(button).toBeEnabled()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('events', () => {
|
||||
it('emits edit event when edit button clicked', async () => {
|
||||
const user = userEvent.setup()
|
||||
const secret = createMockSecret()
|
||||
const wrapper = mountComponent({ secret })
|
||||
const { emitted } = renderComponent({ secret })
|
||||
|
||||
const editButton = wrapper.findAll('button')[0]
|
||||
await editButton.trigger('click')
|
||||
const buttons = screen.getAllByRole('button')
|
||||
await user.click(buttons[0])
|
||||
|
||||
expect(wrapper.emitted('edit')).toBeDefined()
|
||||
expect(wrapper.emitted('edit')!.length).toBeGreaterThanOrEqual(1)
|
||||
expect(emitted()['edit']).toBeDefined()
|
||||
expect(emitted()['edit']!.length).toBeGreaterThanOrEqual(1)
|
||||
})
|
||||
|
||||
it('emits delete event when delete button clicked', async () => {
|
||||
const user = userEvent.setup()
|
||||
const secret = createMockSecret()
|
||||
const wrapper = mountComponent({ secret })
|
||||
const { emitted } = renderComponent({ secret })
|
||||
|
||||
const deleteButton = wrapper.findAll('button')[1]
|
||||
await deleteButton.trigger('click')
|
||||
const buttons = screen.getAllByRole('button')
|
||||
await user.click(buttons[1])
|
||||
|
||||
expect(wrapper.emitted('delete')).toBeDefined()
|
||||
expect(wrapper.emitted('delete')!.length).toBeGreaterThanOrEqual(1)
|
||||
expect(emitted()['delete']).toBeDefined()
|
||||
expect(emitted()['delete']!.length).toBeGreaterThanOrEqual(1)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { flushPromises, shallowMount } from '@vue/test-utils'
|
||||
import { describe, expect, it, vi, beforeEach } from 'vitest'
|
||||
import { render } from '@testing-library/vue'
|
||||
import { defineComponent } from 'vue'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import SettingItem from '@/platform/settings/components/SettingItem.vue'
|
||||
import type { SettingParams } from '@/platform/settings/types'
|
||||
import { i18n } from '@/i18n'
|
||||
|
||||
/**
|
||||
* Verifies that SettingItem emits telemetry when its value changes
|
||||
* and suppresses telemetry when the value remains the same.
|
||||
*/
|
||||
const flushPromises = () =>
|
||||
new Promise<void>((resolve) => setTimeout(resolve, 0))
|
||||
|
||||
const trackSettingChanged = vi.fn()
|
||||
vi.mock('@/platform/telemetry', () => ({
|
||||
useTelemetry: vi.fn(() => ({
|
||||
@@ -25,22 +25,29 @@ vi.mock('@/platform/settings/settingStore', () => ({
|
||||
})
|
||||
}))
|
||||
|
||||
/**
|
||||
* Minimal stub for FormItem that allows emitting `update:form-value`.
|
||||
*/
|
||||
const FormItemUpdateStub = {
|
||||
template: '<div />',
|
||||
emits: ['update:form-value'],
|
||||
props: ['id', 'item', 'formValue']
|
||||
}
|
||||
let emitFormValue: ((value: unknown) => void) | null = null
|
||||
|
||||
const FormItemUpdateStub = defineComponent({
|
||||
props: {
|
||||
id: { type: String, default: '' },
|
||||
item: { type: Object, default: undefined },
|
||||
formValue: { type: [String, Number, Boolean, Object], default: undefined }
|
||||
},
|
||||
setup(_, { emit }) {
|
||||
emitFormValue = (value: unknown) => emit('update:form-value', value)
|
||||
return {}
|
||||
},
|
||||
template: '<div data-testid="form-item-stub" />'
|
||||
})
|
||||
|
||||
describe('SettingItem (telemetry UI tracking)', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
emitFormValue = null
|
||||
})
|
||||
|
||||
const mountComponent = (setting: SettingParams) => {
|
||||
return shallowMount(SettingItem, {
|
||||
function renderComponent(setting: SettingParams) {
|
||||
return render(SettingItem, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
stubs: {
|
||||
@@ -65,11 +72,9 @@ describe('SettingItem (telemetry UI tracking)', () => {
|
||||
mockGet.mockReturnValueOnce('default').mockReturnValueOnce('normalized')
|
||||
mockSet.mockResolvedValue(undefined)
|
||||
|
||||
const wrapper = mountComponent(settingParams)
|
||||
renderComponent(settingParams)
|
||||
|
||||
const newValue = 'newvalue'
|
||||
const formItem = wrapper.findComponent(FormItemUpdateStub)
|
||||
formItem.vm.$emit('update:form-value', newValue)
|
||||
emitFormValue!('newvalue')
|
||||
|
||||
await flushPromises()
|
||||
|
||||
@@ -94,11 +99,9 @@ describe('SettingItem (telemetry UI tracking)', () => {
|
||||
mockGet.mockReturnValueOnce('same').mockReturnValueOnce('same')
|
||||
mockSet.mockResolvedValue(undefined)
|
||||
|
||||
const wrapper = mountComponent(settingParams)
|
||||
renderComponent(settingParams)
|
||||
|
||||
const unchangedValue = 'same'
|
||||
const formItem = wrapper.findComponent(FormItemUpdateStub)
|
||||
formItem.vm.$emit('update:form-value', unchangedValue)
|
||||
emitFormValue!('same')
|
||||
|
||||
await flushPromises()
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { nextTick } from 'vue'
|
||||
|
||||
const FEATURE_USAGE_KEY = 'Comfy.FeatureUsage'
|
||||
const POPOVER_SELECTOR = '[data-testid="nightly-survey-popover"]'
|
||||
|
||||
const mockIsNightly = vi.hoisted(() => ({ value: true }))
|
||||
const mockIsCloud = vi.hoisted(() => ({ value: false }))
|
||||
@@ -60,20 +60,24 @@ describe('NightlySurveyPopover', () => {
|
||||
afterEach(() => {
|
||||
localStorage.clear()
|
||||
vi.useRealTimers()
|
||||
document.body.innerHTML = ''
|
||||
})
|
||||
|
||||
async function mountComponent(config = defaultConfig) {
|
||||
async function renderComponent(
|
||||
config = defaultConfig,
|
||||
eventHandlers: Record<string, ReturnType<typeof vi.fn>> = {}
|
||||
) {
|
||||
const { default: NightlySurveyPopover } =
|
||||
await import('./NightlySurveyPopover.vue')
|
||||
return mount(NightlySurveyPopover, {
|
||||
props: { config },
|
||||
return render(NightlySurveyPopover, {
|
||||
props: {
|
||||
config,
|
||||
...eventHandlers
|
||||
},
|
||||
global: {
|
||||
stubs: {
|
||||
Teleport: true
|
||||
}
|
||||
},
|
||||
attachTo: document.body
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -81,80 +85,89 @@ describe('NightlySurveyPopover', () => {
|
||||
it('shows popover after delay when eligible', async () => {
|
||||
setFeatureUsage('test-feature', 5)
|
||||
|
||||
const wrapper = await mountComponent()
|
||||
await renderComponent()
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.find(POPOVER_SELECTOR).exists()).toBe(false)
|
||||
expect(
|
||||
screen.queryByTestId('nightly-survey-popover')
|
||||
).not.toBeInTheDocument()
|
||||
|
||||
await vi.advanceTimersByTimeAsync(100)
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.find(POPOVER_SELECTOR).exists()).toBe(true)
|
||||
expect(screen.getByTestId('nightly-survey-popover')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('does not show when not eligible', async () => {
|
||||
setFeatureUsage('test-feature', 1)
|
||||
|
||||
const wrapper = await mountComponent()
|
||||
await renderComponent()
|
||||
await nextTick()
|
||||
await vi.advanceTimersByTimeAsync(1000)
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.find(POPOVER_SELECTOR).exists()).toBe(false)
|
||||
expect(
|
||||
screen.queryByTestId('nightly-survey-popover')
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('does not show on cloud', async () => {
|
||||
mockIsCloud.value = true
|
||||
setFeatureUsage('test-feature', 5)
|
||||
|
||||
const wrapper = await mountComponent()
|
||||
await renderComponent()
|
||||
await nextTick()
|
||||
await vi.advanceTimersByTimeAsync(1000)
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.find(POPOVER_SELECTOR).exists()).toBe(false)
|
||||
expect(
|
||||
screen.queryByTestId('nightly-survey-popover')
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('user actions', () => {
|
||||
it('emits shown event when displayed', async () => {
|
||||
setFeatureUsage('test-feature', 5)
|
||||
const onShown = vi.fn()
|
||||
|
||||
const wrapper = await mountComponent()
|
||||
await renderComponent(defaultConfig, { onShown })
|
||||
await vi.advanceTimersByTimeAsync(100)
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.emitted('shown')).toHaveLength(1)
|
||||
expect(onShown).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('emits dismissed when close button clicked', async () => {
|
||||
setFeatureUsage('test-feature', 5)
|
||||
const onDismissed = vi.fn()
|
||||
const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime })
|
||||
|
||||
const wrapper = await mountComponent()
|
||||
await renderComponent(defaultConfig, { onDismissed })
|
||||
await vi.advanceTimersByTimeAsync(100)
|
||||
await nextTick()
|
||||
|
||||
const closeButton = wrapper.find('[aria-label="g.close"]')
|
||||
await closeButton.trigger('click')
|
||||
const closeButton = screen.getByRole('button', { name: 'g.close' })
|
||||
await user.click(closeButton)
|
||||
|
||||
expect(wrapper.emitted('dismissed')).toHaveLength(1)
|
||||
expect(onDismissed).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('emits optedOut when opt out button clicked', async () => {
|
||||
setFeatureUsage('test-feature', 5)
|
||||
const onOptedOut = vi.fn()
|
||||
const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime })
|
||||
|
||||
const wrapper = await mountComponent()
|
||||
await renderComponent(defaultConfig, { onOptedOut })
|
||||
await vi.advanceTimersByTimeAsync(100)
|
||||
await nextTick()
|
||||
|
||||
const buttons = wrapper.findAll('button')
|
||||
const optOutButton = buttons.find((b) =>
|
||||
b.text().includes('nightlySurvey.dontAskAgain')
|
||||
)
|
||||
expect(optOutButton).toBeDefined()
|
||||
await optOutButton!.trigger('click')
|
||||
const optOutButton = screen.getByRole('button', {
|
||||
name: /nightlySurvey.dontAskAgain/
|
||||
})
|
||||
await user.click(optOutButton)
|
||||
|
||||
expect(wrapper.emitted('optedOut')).toHaveLength(1)
|
||||
expect(onOptedOut).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -162,7 +175,7 @@ describe('NightlySurveyPopover', () => {
|
||||
it('uses custom delay from config', async () => {
|
||||
setFeatureUsage('test-feature', 5)
|
||||
|
||||
const wrapper = await mountComponent({
|
||||
await renderComponent({
|
||||
...defaultConfig,
|
||||
delayMs: 500
|
||||
})
|
||||
@@ -170,17 +183,19 @@ describe('NightlySurveyPopover', () => {
|
||||
|
||||
await vi.advanceTimersByTimeAsync(400)
|
||||
await nextTick()
|
||||
expect(wrapper.find(POPOVER_SELECTOR).exists()).toBe(false)
|
||||
expect(
|
||||
screen.queryByTestId('nightly-survey-popover')
|
||||
).not.toBeInTheDocument()
|
||||
|
||||
await vi.advanceTimersByTimeAsync(100)
|
||||
await nextTick()
|
||||
expect(wrapper.find(POPOVER_SELECTOR).exists()).toBe(true)
|
||||
expect(screen.getByTestId('nightly-survey-popover')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('does not show when config is disabled', async () => {
|
||||
setFeatureUsage('test-feature', 5)
|
||||
|
||||
const wrapper = await mountComponent({
|
||||
await renderComponent({
|
||||
...defaultConfig,
|
||||
enabled: false
|
||||
})
|
||||
@@ -188,7 +203,9 @@ describe('NightlySurveyPopover', () => {
|
||||
await vi.advanceTimersByTimeAsync(1000)
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.find(POPOVER_SELECTOR).exists()).toBe(false)
|
||||
expect(
|
||||
screen.queryByTestId('nightly-survey-popover')
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { VueWrapper } from '@vue/test-utils'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { nextTick } from 'vue'
|
||||
|
||||
import type { ReleaseNote } from '../common/releaseService'
|
||||
import ReleaseNotificationToast from './ReleaseNotificationToast.vue'
|
||||
@@ -66,6 +67,14 @@ vi.mock('@/stores/commandStore', () => ({
|
||||
}))
|
||||
}))
|
||||
|
||||
vi.mock('@/composables/useExternalLink', () => ({
|
||||
useExternalLink: vi.fn(() => ({
|
||||
buildDocsUrl: vi.fn((path: string) => `https://docs.comfy.org${path}`),
|
||||
staticUrls: {},
|
||||
docsPaths: {}
|
||||
}))
|
||||
}))
|
||||
|
||||
// Mock release store
|
||||
const mockReleaseStore = {
|
||||
recentRelease: null as ReleaseNote | null,
|
||||
@@ -81,10 +90,8 @@ vi.mock('../common/releaseStore', () => ({
|
||||
}))
|
||||
|
||||
describe('ReleaseNotificationToast', () => {
|
||||
let wrapper: VueWrapper<InstanceType<typeof ReleaseNotificationToast>>
|
||||
|
||||
const mountComponent = (props = {}) => {
|
||||
return mount(ReleaseNotificationToast, {
|
||||
const renderComponent = (props = {}) => {
|
||||
return render(ReleaseNotificationToast, {
|
||||
global: {
|
||||
mocks: {
|
||||
$t: (key: string) => {
|
||||
@@ -100,7 +107,6 @@ describe('ReleaseNotificationToast', () => {
|
||||
}
|
||||
},
|
||||
stubs: {
|
||||
// Stub Lucide icons
|
||||
'i-lucide-rocket': true,
|
||||
'i-lucide-external-link': true
|
||||
}
|
||||
@@ -112,9 +118,8 @@ describe('ReleaseNotificationToast', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
mockData.isDesktop = false
|
||||
// Reset store state
|
||||
mockReleaseStore.recentRelease = null
|
||||
mockReleaseStore.shouldShowToast = true // Force show for testing
|
||||
mockReleaseStore.shouldShowToast = true
|
||||
})
|
||||
|
||||
it('renders correctly when shouldShow is true', () => {
|
||||
@@ -123,8 +128,8 @@ describe('ReleaseNotificationToast', () => {
|
||||
content: '# Test Release\n\nSome content'
|
||||
} as ReleaseNote
|
||||
|
||||
wrapper = mountComponent()
|
||||
expect(wrapper.find('.release-toast-popup').exists()).toBe(true)
|
||||
renderComponent()
|
||||
expect(screen.getByText('New update is out!')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('displays rocket icon', () => {
|
||||
@@ -133,8 +138,12 @@ describe('ReleaseNotificationToast', () => {
|
||||
content: '# Test Release'
|
||||
} as ReleaseNote
|
||||
|
||||
wrapper = mountComponent()
|
||||
expect(wrapper.find('.release-toast-popup').exists()).toBe(true)
|
||||
const { container } = renderComponent()
|
||||
/* eslint-disable testing-library/no-container, testing-library/no-node-access */
|
||||
expect(
|
||||
container.querySelector('.icon-\\[lucide--rocket\\]')
|
||||
).toBeInTheDocument()
|
||||
/* eslint-enable testing-library/no-container, testing-library/no-node-access */
|
||||
})
|
||||
|
||||
it('displays release version', () => {
|
||||
@@ -143,8 +152,8 @@ describe('ReleaseNotificationToast', () => {
|
||||
content: '# Test Release'
|
||||
} as ReleaseNote
|
||||
|
||||
wrapper = mountComponent()
|
||||
expect(wrapper.text()).toContain('1.2.3')
|
||||
renderComponent()
|
||||
expect(screen.getByText('1.2.3')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('calls handleSkipRelease when skip button is clicked', async () => {
|
||||
@@ -153,15 +162,10 @@ describe('ReleaseNotificationToast', () => {
|
||||
content: '# Test Release'
|
||||
} as ReleaseNote
|
||||
|
||||
wrapper = mountComponent()
|
||||
renderComponent()
|
||||
const user = userEvent.setup()
|
||||
|
||||
const buttons = wrapper.findAll('button')
|
||||
const skipButton = buttons.find(
|
||||
(btn) =>
|
||||
btn.text().includes('Skip') || btn.element.innerHTML.includes('skip')
|
||||
)
|
||||
expect(skipButton).toBeDefined()
|
||||
await skipButton!.trigger('click')
|
||||
await user.click(screen.getByRole('button', { name: /skip/i }))
|
||||
|
||||
expect(mockReleaseStore.handleSkipRelease).toHaveBeenCalledWith('1.2.3')
|
||||
})
|
||||
@@ -172,17 +176,16 @@ describe('ReleaseNotificationToast', () => {
|
||||
content: '# Test Release'
|
||||
} as ReleaseNote
|
||||
|
||||
// Mock window.open
|
||||
const mockWindowOpen = vi.fn()
|
||||
Object.defineProperty(window, 'open', {
|
||||
value: mockWindowOpen,
|
||||
writable: true
|
||||
})
|
||||
|
||||
wrapper = mountComponent()
|
||||
renderComponent()
|
||||
const user = userEvent.setup()
|
||||
|
||||
// Call the handler directly instead of triggering DOM event
|
||||
await wrapper.vm.handleUpdate()
|
||||
await user.click(screen.getByRole('button', { name: /update/i }))
|
||||
|
||||
expect(mockWindowOpen).toHaveBeenCalledWith(
|
||||
'https://docs.comfy.org/installation/update_comfyui',
|
||||
@@ -205,8 +208,10 @@ describe('ReleaseNotificationToast', () => {
|
||||
writable: true
|
||||
})
|
||||
|
||||
wrapper = mountComponent()
|
||||
await wrapper.vm.handleUpdate()
|
||||
renderComponent()
|
||||
const user = userEvent.setup()
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /update/i }))
|
||||
|
||||
expect(commandExecuteMock).toHaveBeenCalledWith(
|
||||
'Comfy-Desktop.CheckForUpdates'
|
||||
@@ -231,8 +236,10 @@ describe('ReleaseNotificationToast', () => {
|
||||
writable: true
|
||||
})
|
||||
|
||||
wrapper = mountComponent()
|
||||
await wrapper.vm.handleUpdate()
|
||||
renderComponent()
|
||||
const user = userEvent.setup()
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /update/i }))
|
||||
|
||||
expect(toastErrorHandlerMock).toHaveBeenCalledWith(error)
|
||||
expect(mockWindowOpen).not.toHaveBeenCalled()
|
||||
@@ -244,10 +251,10 @@ describe('ReleaseNotificationToast', () => {
|
||||
content: '# Test Release'
|
||||
} as ReleaseNote
|
||||
|
||||
wrapper = mountComponent()
|
||||
renderComponent()
|
||||
const user = userEvent.setup()
|
||||
|
||||
// Call the handler directly instead of triggering DOM event
|
||||
await wrapper.vm.handleLearnMore()
|
||||
await user.click(screen.getByRole('link', { name: /what's new/i }))
|
||||
|
||||
expect(mockReleaseStore.handleShowChangelog).toHaveBeenCalledWith('1.2.3')
|
||||
})
|
||||
@@ -258,12 +265,12 @@ describe('ReleaseNotificationToast', () => {
|
||||
content: '# Test Release'
|
||||
} as ReleaseNote
|
||||
|
||||
wrapper = mountComponent()
|
||||
renderComponent()
|
||||
|
||||
const learnMoreLink = wrapper.find('a[target="_blank"]')
|
||||
expect(learnMoreLink.exists()).toBe(true)
|
||||
expect(learnMoreLink.attributes('href')).toContain(
|
||||
'docs.comfy.org/changelog'
|
||||
const learnMoreLink = screen.getByRole('link', { name: /what's new/i })
|
||||
expect(learnMoreLink).toHaveAttribute(
|
||||
'href',
|
||||
expect.stringContaining('docs.comfy.org/changelog')
|
||||
)
|
||||
})
|
||||
|
||||
@@ -281,16 +288,15 @@ describe('ReleaseNotificationToast', () => {
|
||||
content: '# Test Release Title\n\nSome content'
|
||||
} as ReleaseNote
|
||||
|
||||
wrapper = mountComponent()
|
||||
renderComponent()
|
||||
|
||||
// Should call markdown renderer with title removed
|
||||
expect(mockMarkdownRenderer).toHaveBeenCalledWith('\n\nSome content')
|
||||
})
|
||||
|
||||
it('fetches releases on mount when not already loaded', async () => {
|
||||
mockReleaseStore.releases = [] // Empty releases array
|
||||
it('fetches releases on mount when not already loaded', () => {
|
||||
mockReleaseStore.releases = []
|
||||
|
||||
wrapper = mountComponent()
|
||||
renderComponent()
|
||||
|
||||
expect(mockReleaseStore.fetchReleases).toHaveBeenCalled()
|
||||
})
|
||||
@@ -302,61 +308,52 @@ describe('ReleaseNotificationToast', () => {
|
||||
content: ''
|
||||
} as ReleaseNote
|
||||
|
||||
wrapper = mountComponent()
|
||||
renderComponent()
|
||||
|
||||
// Should render fallback content
|
||||
const descriptionElement = wrapper.find('.pl-14')
|
||||
expect(descriptionElement.exists()).toBe(true)
|
||||
expect(descriptionElement.text()).toContain('Check out the latest')
|
||||
expect(screen.getByText(/Check out the latest/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('auto-hides after timeout', async () => {
|
||||
vi.useFakeTimers()
|
||||
try {
|
||||
mockReleaseStore.recentRelease = {
|
||||
version: '1.2.3',
|
||||
content: '# Test Release'
|
||||
} as ReleaseNote
|
||||
|
||||
mockReleaseStore.recentRelease = {
|
||||
version: '1.2.3',
|
||||
content: '# Test Release'
|
||||
} as ReleaseNote
|
||||
renderComponent()
|
||||
|
||||
wrapper = mountComponent()
|
||||
expect(screen.getByText('New update is out!')).toBeInTheDocument()
|
||||
|
||||
// Initially visible
|
||||
expect(wrapper.find('.release-toast-popup').exists()).toBe(true)
|
||||
vi.advanceTimersByTime(8000)
|
||||
await nextTick()
|
||||
|
||||
// Fast-forward time to trigger auto-hide
|
||||
vi.advanceTimersByTime(8000)
|
||||
await wrapper.vm.$nextTick()
|
||||
|
||||
// Component should call dismissToast internally which hides it
|
||||
// We can't test DOM visibility change because the component uses local state
|
||||
// But we can verify the timer was set and would have triggered
|
||||
expect(vi.getTimerCount()).toBe(0) // Timer should be cleared after auto-hide
|
||||
|
||||
vi.useRealTimers()
|
||||
expect(vi.getTimerCount()).toBe(0)
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
|
||||
it('clears auto-hide timer when manually dismissed', async () => {
|
||||
vi.useFakeTimers()
|
||||
try {
|
||||
mockReleaseStore.recentRelease = {
|
||||
version: '1.2.3',
|
||||
content: '# Test Release'
|
||||
} as ReleaseNote
|
||||
|
||||
mockReleaseStore.recentRelease = {
|
||||
version: '1.2.3',
|
||||
content: '# Test Release'
|
||||
} as ReleaseNote
|
||||
const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime })
|
||||
|
||||
wrapper = mountComponent()
|
||||
renderComponent()
|
||||
|
||||
// Start the timer
|
||||
vi.advanceTimersByTime(1000)
|
||||
vi.advanceTimersByTime(1000)
|
||||
|
||||
// Manually dismiss by calling handler directly
|
||||
await wrapper.vm.handleSkip()
|
||||
await user.click(screen.getByRole('button', { name: /skip/i }))
|
||||
|
||||
// Timer should be cleared
|
||||
expect(vi.getTimerCount()).toBe(0)
|
||||
|
||||
// Verify the store method was called (manual dismissal)
|
||||
expect(mockReleaseStore.handleSkipRelease).toHaveBeenCalled()
|
||||
|
||||
vi.useRealTimers()
|
||||
expect(vi.getTimerCount()).toBe(0)
|
||||
expect(mockReleaseStore.handleSkipRelease).toHaveBeenCalled()
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { VueWrapper } from '@vue/test-utils'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import Button from '@/components/ui/button/Button.vue'
|
||||
import PrimeVue from 'primevue/config'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
@@ -62,10 +62,8 @@ vi.mock('../common/releaseStore', () => ({
|
||||
}))
|
||||
|
||||
describe('WhatsNewPopup', () => {
|
||||
let wrapper: VueWrapper
|
||||
|
||||
const mountComponent = (props = {}) => {
|
||||
return mount(WhatsNewPopup, {
|
||||
const renderComponent = (props = {}) => {
|
||||
return render(WhatsNewPopup, {
|
||||
global: {
|
||||
plugins: [PrimeVue],
|
||||
components: { Button },
|
||||
@@ -75,7 +73,6 @@ describe('WhatsNewPopup', () => {
|
||||
}
|
||||
},
|
||||
stubs: {
|
||||
// Stub Lucide icons
|
||||
'i-lucide-x': true,
|
||||
'i-lucide-external-link': true
|
||||
}
|
||||
@@ -86,7 +83,6 @@ describe('WhatsNewPopup', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
// Reset store state
|
||||
mockReleaseStore.recentRelease = null
|
||||
mockReleaseStore.shouldShowPopup = false
|
||||
mockReleaseStore.releases = []
|
||||
@@ -101,14 +97,16 @@ describe('WhatsNewPopup', () => {
|
||||
content: '# Test Release\n\nSome content'
|
||||
} as ReleaseNote
|
||||
|
||||
wrapper = mountComponent()
|
||||
expect(wrapper.find('.whats-new-popup').exists()).toBe(true)
|
||||
const { container } = renderComponent()
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
expect(container.querySelector('.whats-new-popup')).not.toBeNull()
|
||||
})
|
||||
|
||||
it('does not render when shouldShow is false', () => {
|
||||
mockReleaseStore.shouldShowPopup = false
|
||||
wrapper = mountComponent()
|
||||
expect(wrapper.find('.whats-new-popup').exists()).toBe(false)
|
||||
const { container } = renderComponent()
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
expect(container.querySelector('.whats-new-popup')).toBeNull()
|
||||
})
|
||||
|
||||
it('calls handleWhatsNewSeen when close button is clicked', async () => {
|
||||
@@ -118,10 +116,10 @@ describe('WhatsNewPopup', () => {
|
||||
content: '# Test Release'
|
||||
} as ReleaseNote
|
||||
|
||||
wrapper = mountComponent()
|
||||
const user = userEvent.setup()
|
||||
renderComponent()
|
||||
|
||||
const closeButton = wrapper.findComponent(Button)
|
||||
await closeButton.trigger('click')
|
||||
await user.click(screen.getByRole('button', { name: /close/i }))
|
||||
|
||||
expect(mockReleaseStore.handleWhatsNewSeen).toHaveBeenCalledWith('1.2.3')
|
||||
})
|
||||
@@ -133,10 +131,10 @@ describe('WhatsNewPopup', () => {
|
||||
content: '# Test Release'
|
||||
} as ReleaseNote
|
||||
|
||||
wrapper = mountComponent()
|
||||
renderComponent()
|
||||
|
||||
const learnMoreLink = wrapper.find('.learn-more-link')
|
||||
expect(learnMoreLink.attributes('href')).toContain(
|
||||
const learnMoreLink = screen.getByRole('link')
|
||||
expect(learnMoreLink.getAttribute('href')).toContain(
|
||||
'docs.comfy.org/changelog'
|
||||
)
|
||||
})
|
||||
@@ -148,11 +146,10 @@ describe('WhatsNewPopup', () => {
|
||||
content: ''
|
||||
} as ReleaseNote
|
||||
|
||||
wrapper = mountComponent()
|
||||
const { container } = renderComponent()
|
||||
|
||||
// Should render fallback content
|
||||
const contentElement = wrapper.find('.content-text')
|
||||
expect(contentElement.exists()).toBe(true)
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
expect(container.querySelector('.content-text')).not.toBeNull()
|
||||
})
|
||||
|
||||
it('emits whats-new-dismissed event when popup is closed', async () => {
|
||||
@@ -162,30 +159,29 @@ describe('WhatsNewPopup', () => {
|
||||
content: '# Test Release'
|
||||
} as ReleaseNote
|
||||
|
||||
wrapper = mountComponent()
|
||||
const onDismissed = vi.fn()
|
||||
const user = userEvent.setup()
|
||||
renderComponent({ 'onWhats-new-dismissed': onDismissed })
|
||||
|
||||
// Call the close method directly instead of triggering DOM event
|
||||
await (
|
||||
wrapper.vm as typeof wrapper.vm & { closePopup: () => Promise<void> }
|
||||
).closePopup()
|
||||
await user.click(screen.getByRole('button', { name: /close/i }))
|
||||
|
||||
expect(wrapper.emitted('whats-new-dismissed')).toBeTruthy()
|
||||
expect(onDismissed).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('fetches releases on mount when not already loaded', async () => {
|
||||
mockReleaseStore.shouldShowPopup = true
|
||||
mockReleaseStore.releases = [] // Empty releases array
|
||||
mockReleaseStore.releases = []
|
||||
|
||||
wrapper = mountComponent()
|
||||
renderComponent()
|
||||
|
||||
expect(mockReleaseStore.fetchReleases).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not fetch releases when already loaded', async () => {
|
||||
mockReleaseStore.shouldShowPopup = true
|
||||
mockReleaseStore.releases = [{ version: '1.0.0' } as ReleaseNote] // Non-empty releases array
|
||||
mockReleaseStore.releases = [{ version: '1.0.0' } as ReleaseNote]
|
||||
|
||||
wrapper = mountComponent()
|
||||
renderComponent()
|
||||
|
||||
expect(mockReleaseStore.fetchReleases).not.toHaveBeenCalled()
|
||||
})
|
||||
@@ -205,9 +201,8 @@ describe('WhatsNewPopup', () => {
|
||||
content: '# Original Title\n\nContent'
|
||||
} as ReleaseNote
|
||||
|
||||
wrapper = mountComponent()
|
||||
renderComponent()
|
||||
|
||||
// Should call markdown renderer with original content (no modification)
|
||||
expect(mockMarkdownRenderer).toHaveBeenCalledWith(
|
||||
'# Original Title\n\nContent'
|
||||
)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render } from '@testing-library/vue'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { useWorkflowService } from '@/platform/workflow/core/services/workflowService'
|
||||
@@ -54,7 +54,7 @@ describe('useWorkflowAutoSave', () => {
|
||||
mockAutoSaveDelay = 1000
|
||||
mockActiveWorkflow = { isModified: true, isPersisted: true }
|
||||
|
||||
mount({
|
||||
render({
|
||||
template: `<div></div>`,
|
||||
setup() {
|
||||
useWorkflowAutoSave()
|
||||
@@ -75,7 +75,7 @@ describe('useWorkflowAutoSave', () => {
|
||||
mockAutoSaveDelay = 1000
|
||||
mockActiveWorkflow = { isModified: false, isPersisted: true }
|
||||
|
||||
mount({
|
||||
render({
|
||||
template: `<div></div>`,
|
||||
setup() {
|
||||
useWorkflowAutoSave()
|
||||
@@ -96,7 +96,7 @@ describe('useWorkflowAutoSave', () => {
|
||||
mockAutoSaveDelay = 1000
|
||||
mockActiveWorkflow = { isModified: true, isPersisted: true }
|
||||
|
||||
mount({
|
||||
render({
|
||||
template: `<div></div>`,
|
||||
setup() {
|
||||
useWorkflowAutoSave()
|
||||
@@ -115,7 +115,7 @@ describe('useWorkflowAutoSave', () => {
|
||||
mockAutoSaveDelay = 2000
|
||||
mockActiveWorkflow = { isModified: true, isPersisted: true }
|
||||
|
||||
mount({
|
||||
render({
|
||||
template: `<div></div>`,
|
||||
setup() {
|
||||
useWorkflowAutoSave()
|
||||
@@ -138,7 +138,7 @@ describe('useWorkflowAutoSave', () => {
|
||||
mockAutoSaveDelay = 2000
|
||||
mockActiveWorkflow = { isModified: true, isPersisted: true }
|
||||
|
||||
mount({
|
||||
render({
|
||||
template: `<div></div>`,
|
||||
setup() {
|
||||
useWorkflowAutoSave()
|
||||
@@ -173,7 +173,7 @@ describe('useWorkflowAutoSave', () => {
|
||||
.mockImplementation(() => {})
|
||||
|
||||
try {
|
||||
mount({
|
||||
render({
|
||||
template: `<div></div>`,
|
||||
setup() {
|
||||
useWorkflowAutoSave()
|
||||
@@ -202,7 +202,7 @@ describe('useWorkflowAutoSave', () => {
|
||||
mockAutoSaveDelay = 1000
|
||||
mockActiveWorkflow = { isModified: true, isPersisted: true }
|
||||
|
||||
mount({
|
||||
render({
|
||||
template: `<div></div>`,
|
||||
setup() {
|
||||
useWorkflowAutoSave()
|
||||
@@ -234,7 +234,7 @@ describe('useWorkflowAutoSave', () => {
|
||||
it('should clean up event listeners on component unmount', async () => {
|
||||
mockAutoSaveSetting = 'after delay'
|
||||
|
||||
const wrapper = mount({
|
||||
const { unmount } = render({
|
||||
template: `<div></div>`,
|
||||
setup() {
|
||||
useWorkflowAutoSave()
|
||||
@@ -242,7 +242,7 @@ describe('useWorkflowAutoSave', () => {
|
||||
}
|
||||
})
|
||||
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
|
||||
expect(api.removeEventListener).toHaveBeenCalled()
|
||||
})
|
||||
@@ -252,7 +252,7 @@ describe('useWorkflowAutoSave', () => {
|
||||
mockAutoSaveDelay = 0
|
||||
mockActiveWorkflow = { isModified: true, isPersisted: true }
|
||||
|
||||
mount({
|
||||
render({
|
||||
template: `<div></div>`,
|
||||
setup() {
|
||||
useWorkflowAutoSave()
|
||||
@@ -282,7 +282,7 @@ describe('useWorkflowAutoSave', () => {
|
||||
mockAutoSaveDelay = 1000
|
||||
mockActiveWorkflow = { isModified: true, isPersisted: false }
|
||||
|
||||
mount({
|
||||
render({
|
||||
template: `<div></div>`,
|
||||
setup() {
|
||||
useWorkflowAutoSave()
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
/* eslint-disable testing-library/no-container, testing-library/no-node-access */
|
||||
import { fromPartial } from '@total-typescript/shoehorn'
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
@@ -60,8 +62,12 @@ function makePayload(
|
||||
}
|
||||
}
|
||||
|
||||
function mountComponent(props: Record<string, unknown> = {}) {
|
||||
return mount(OpenSharedWorkflowDialogContent, {
|
||||
async function flushPromises() {
|
||||
await new Promise((r) => setTimeout(r, 0))
|
||||
}
|
||||
|
||||
function renderComponent(props: Record<string, unknown> = {}) {
|
||||
return render(OpenSharedWorkflowDialogContent, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
stubs: {
|
||||
@@ -87,52 +93,50 @@ describe('OpenSharedWorkflowDialogContent', () => {
|
||||
describe('loading state', () => {
|
||||
it('shows skeleton placeholders while loading', () => {
|
||||
mockGetSharedWorkflow.mockReturnValue(new Promise(() => {}))
|
||||
const wrapper = mountComponent()
|
||||
renderComponent()
|
||||
|
||||
expect(
|
||||
wrapper.findAllComponents({ name: 'Skeleton' }).length
|
||||
).toBeGreaterThan(0)
|
||||
expect(screen.getByRole('status')).toBeDefined()
|
||||
})
|
||||
|
||||
it('shows dialog title in header while loading', () => {
|
||||
mockGetSharedWorkflow.mockReturnValue(new Promise(() => {}))
|
||||
const wrapper = mountComponent()
|
||||
const header = wrapper.find('header h2')
|
||||
expect(header.text()).toBe('Open shared workflow')
|
||||
const { container } = renderComponent()
|
||||
const header = container.querySelector('header h2') as HTMLElement
|
||||
expect(header.textContent).toBe('Open shared workflow')
|
||||
})
|
||||
})
|
||||
|
||||
describe('error state', () => {
|
||||
it('shows error message when fetch fails', async () => {
|
||||
mockGetSharedWorkflow.mockRejectedValue(new Error('Network error'))
|
||||
const wrapper = mountComponent()
|
||||
const { container } = renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.text()).toContain(
|
||||
expect(container.textContent).toContain(
|
||||
'Could not load this shared workflow. Please try again later.'
|
||||
)
|
||||
})
|
||||
|
||||
it('shows close button in error state', async () => {
|
||||
mockGetSharedWorkflow.mockRejectedValue(new Error('Network error'))
|
||||
const wrapper = mountComponent()
|
||||
const { container } = renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
const footerButtons = wrapper.findAll('footer button')
|
||||
const footerButtons = container.querySelectorAll('footer button')
|
||||
expect(footerButtons).toHaveLength(1)
|
||||
expect(footerButtons[0].text()).toBe('Close')
|
||||
expect(footerButtons[0].textContent).toBe('Close')
|
||||
})
|
||||
|
||||
it('calls onCancel when close is clicked in error state', async () => {
|
||||
mockGetSharedWorkflow.mockRejectedValue(new Error('Network error'))
|
||||
const onCancel = vi.fn()
|
||||
const wrapper = mountComponent({ onCancel })
|
||||
const { container } = renderComponent({ onCancel })
|
||||
await flushPromises()
|
||||
|
||||
const closeButton = wrapper
|
||||
.findAll('footer button')
|
||||
.find((b) => b.text() === 'Close')
|
||||
await closeButton!.trigger('click')
|
||||
const closeButton = Array.from(
|
||||
container.querySelectorAll('footer button')
|
||||
).find((b) => b.textContent === 'Close') as HTMLElement
|
||||
await userEvent.click(closeButton)
|
||||
expect(onCancel).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -142,60 +146,62 @@ describe('OpenSharedWorkflowDialogContent', () => {
|
||||
mockGetSharedWorkflow.mockResolvedValue(
|
||||
makePayload({ name: 'My Workflow' })
|
||||
)
|
||||
const wrapper = mountComponent()
|
||||
const { container } = renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.find('main h2').text()).toBe('My Workflow')
|
||||
expect(
|
||||
(container.querySelector('main h2') as HTMLElement).textContent
|
||||
).toBe('My Workflow')
|
||||
})
|
||||
|
||||
it('shows "Open workflow" as primary CTA', async () => {
|
||||
mockGetSharedWorkflow.mockResolvedValue(makePayload())
|
||||
const wrapper = mountComponent()
|
||||
const { container } = renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
const buttons = wrapper.findAll('footer button')
|
||||
const buttons = container.querySelectorAll('footer button')
|
||||
const primaryButton = buttons[buttons.length - 1]
|
||||
expect(primaryButton.text()).toBe('Open workflow')
|
||||
expect(primaryButton.textContent).toBe('Open workflow')
|
||||
})
|
||||
|
||||
it('does not show "Open without importing" button', async () => {
|
||||
mockGetSharedWorkflow.mockResolvedValue(makePayload())
|
||||
const wrapper = mountComponent()
|
||||
const { container } = renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.text()).not.toContain('Open without importing')
|
||||
expect(container.textContent).not.toContain('Open without importing')
|
||||
})
|
||||
|
||||
it('does not show warning or asset sections', async () => {
|
||||
mockGetSharedWorkflow.mockResolvedValue(makePayload())
|
||||
const wrapper = mountComponent()
|
||||
const { container } = renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.text()).not.toContain('non-public assets')
|
||||
expect(container.textContent).not.toContain('non-public assets')
|
||||
})
|
||||
|
||||
it('calls onConfirm with payload when primary button is clicked', async () => {
|
||||
const payload = makePayload()
|
||||
mockGetSharedWorkflow.mockResolvedValue(payload)
|
||||
const onConfirm = vi.fn()
|
||||
const wrapper = mountComponent({ onConfirm })
|
||||
const { container } = renderComponent({ onConfirm })
|
||||
await flushPromises()
|
||||
|
||||
const buttons = wrapper.findAll('footer button')
|
||||
await buttons[buttons.length - 1].trigger('click')
|
||||
const buttons = container.querySelectorAll('footer button')
|
||||
await userEvent.click(buttons[buttons.length - 1] as HTMLElement)
|
||||
expect(onConfirm).toHaveBeenCalledWith(payload)
|
||||
})
|
||||
|
||||
it('calls onCancel when cancel button is clicked', async () => {
|
||||
mockGetSharedWorkflow.mockResolvedValue(makePayload())
|
||||
const onCancel = vi.fn()
|
||||
const wrapper = mountComponent({ onCancel })
|
||||
const { container } = renderComponent({ onCancel })
|
||||
await flushPromises()
|
||||
|
||||
const cancelButton = wrapper
|
||||
.findAll('footer button')
|
||||
.find((b) => b.text() === 'Cancel')
|
||||
await cancelButton!.trigger('click')
|
||||
const cancelButton = Array.from(
|
||||
container.querySelectorAll('footer button')
|
||||
).find((b) => b.textContent === 'Cancel') as HTMLElement
|
||||
await userEvent.click(cancelButton)
|
||||
expect(onCancel).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -235,54 +241,54 @@ describe('OpenSharedWorkflowDialogContent', () => {
|
||||
|
||||
it('shows "Copy assets & open workflow" as primary CTA', async () => {
|
||||
mockGetSharedWorkflow.mockResolvedValue(assetsPayload)
|
||||
const wrapper = mountComponent()
|
||||
const { container } = renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
const buttons = wrapper.findAll('footer button')
|
||||
const buttons = container.querySelectorAll('footer button')
|
||||
const primaryButton = buttons[buttons.length - 1]
|
||||
expect(primaryButton.text()).toBe('Copy assets & open workflow')
|
||||
expect(primaryButton.textContent).toBe('Copy assets & open workflow')
|
||||
})
|
||||
|
||||
it('shows non-public assets warning', async () => {
|
||||
mockGetSharedWorkflow.mockResolvedValue(assetsPayload)
|
||||
const wrapper = mountComponent()
|
||||
const { container } = renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.text()).toContain('non-public assets')
|
||||
expect(container.textContent).toContain('non-public assets')
|
||||
})
|
||||
|
||||
it('shows "Open without importing" button', async () => {
|
||||
mockGetSharedWorkflow.mockResolvedValue(assetsPayload)
|
||||
const wrapper = mountComponent()
|
||||
renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
const openWithoutImporting = wrapper
|
||||
.findAll('button')
|
||||
.find((b) => b.text() === 'Open without importing')
|
||||
const openWithoutImporting = screen
|
||||
.getAllByRole('button')
|
||||
.find((b) => b.textContent === 'Open without importing')
|
||||
expect(openWithoutImporting).toBeDefined()
|
||||
})
|
||||
|
||||
it('calls onOpenWithoutImporting with payload', async () => {
|
||||
mockGetSharedWorkflow.mockResolvedValue(assetsPayload)
|
||||
const onOpenWithoutImporting = vi.fn()
|
||||
const wrapper = mountComponent({ onOpenWithoutImporting })
|
||||
renderComponent({ onOpenWithoutImporting })
|
||||
await flushPromises()
|
||||
|
||||
const button = wrapper
|
||||
.findAll('button')
|
||||
.find((b) => b.text() === 'Open without importing')
|
||||
await button!.trigger('click')
|
||||
const button = screen
|
||||
.getAllByRole('button')
|
||||
.find((b) => b.textContent === 'Open without importing')
|
||||
await userEvent.click(button!)
|
||||
expect(onOpenWithoutImporting).toHaveBeenCalledWith(assetsPayload)
|
||||
})
|
||||
|
||||
it('calls onConfirm with payload when primary button is clicked', async () => {
|
||||
mockGetSharedWorkflow.mockResolvedValue(assetsPayload)
|
||||
const onConfirm = vi.fn()
|
||||
const wrapper = mountComponent({ onConfirm })
|
||||
const { container } = renderComponent({ onConfirm })
|
||||
await flushPromises()
|
||||
|
||||
const buttons = wrapper.findAll('footer button')
|
||||
await buttons[buttons.length - 1].trigger('click')
|
||||
const buttons = container.querySelectorAll('footer button')
|
||||
await userEvent.click(buttons[buttons.length - 1] as HTMLElement)
|
||||
expect(onConfirm).toHaveBeenCalledWith(assetsPayload)
|
||||
})
|
||||
|
||||
@@ -310,18 +316,17 @@ describe('OpenSharedWorkflowDialogContent', () => {
|
||||
]
|
||||
})
|
||||
mockGetSharedWorkflow.mockResolvedValue(mixedPayload)
|
||||
const wrapper = mountComponent()
|
||||
const { container } = renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
// Should still show assets panel (has 1 non-owned)
|
||||
expect(wrapper.text()).toContain('non-public assets')
|
||||
expect(container.textContent).toContain('non-public assets')
|
||||
})
|
||||
})
|
||||
|
||||
describe('fetches with correct shareId', () => {
|
||||
it('passes shareId to getSharedWorkflow', async () => {
|
||||
mockGetSharedWorkflow.mockResolvedValue(makePayload())
|
||||
mountComponent({ shareId: 'my-share-123' })
|
||||
renderComponent({ shareId: 'my-share-123' })
|
||||
await flushPromises()
|
||||
|
||||
expect(mockGetSharedWorkflow).toHaveBeenCalledWith('my-share-123')
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
<template v-if="isLoading">
|
||||
<main class="flex gap-8 px-8 pt-4 pb-6">
|
||||
<div class="flex min-w-0 flex-1 flex-col gap-12 py-4">
|
||||
<div role="status" class="flex min-w-0 flex-1 flex-col gap-12 py-4">
|
||||
<Skeleton class="h-8 w-3/5" />
|
||||
<Skeleton class="h-4 w-4/5" />
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { nextTick } from 'vue'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
import type { ComponentProps } from 'vue-component-type-helpers'
|
||||
@@ -24,10 +24,10 @@ const i18n = createI18n({
|
||||
})
|
||||
|
||||
describe(ShareAssetWarningBox, () => {
|
||||
function createWrapper(
|
||||
function renderComponent(
|
||||
props: Partial<ComponentProps<typeof ShareAssetWarningBox>> = {}
|
||||
) {
|
||||
return mount(ShareAssetWarningBox, {
|
||||
return render(ShareAssetWarningBox, {
|
||||
props: {
|
||||
items: [
|
||||
{
|
||||
@@ -50,6 +50,7 @@ describe(ShareAssetWarningBox, () => {
|
||||
}
|
||||
],
|
||||
acknowledged: false,
|
||||
'onUpdate:acknowledged': props['onUpdate:acknowledged'],
|
||||
...props
|
||||
},
|
||||
global: {
|
||||
@@ -59,73 +60,65 @@ describe(ShareAssetWarningBox, () => {
|
||||
}
|
||||
|
||||
it('renders warning text', () => {
|
||||
const wrapper = createWrapper()
|
||||
expect(wrapper.text()).toContain(
|
||||
const { container } = renderComponent()
|
||||
expect(container.textContent).toContain(
|
||||
'Your workflow contains private models and/or media files'
|
||||
)
|
||||
})
|
||||
|
||||
it('renders media and model collapsible sections', () => {
|
||||
const wrapper = createWrapper()
|
||||
const { container } = renderComponent()
|
||||
|
||||
expect(wrapper.text()).toContain('1 Media File')
|
||||
expect(wrapper.text()).toContain('1 Model')
|
||||
expect(container.textContent).toContain('1 Media File')
|
||||
expect(container.textContent).toContain('1 Model')
|
||||
})
|
||||
|
||||
it('keeps at most one accordion section open at a time', async () => {
|
||||
const wrapper = createWrapper()
|
||||
const user = userEvent.setup()
|
||||
renderComponent()
|
||||
|
||||
const mediaHeader = wrapper.get('[data-testid="section-header-media"]')
|
||||
const modelsHeader = wrapper.get('[data-testid="section-header-models"]')
|
||||
const mediaChevron = mediaHeader.get('i')
|
||||
const modelsChevron = modelsHeader.get('i')
|
||||
const mediaHeader = screen.getByTestId('section-header-media')
|
||||
const modelsHeader = screen.getByTestId('section-header-models')
|
||||
|
||||
expect(mediaHeader.attributes('aria-expanded')).toBe('true')
|
||||
expect(modelsHeader.attributes('aria-expanded')).toBe('false')
|
||||
expect(mediaHeader.attributes('aria-controls')).toBe(
|
||||
expect(mediaHeader).toHaveAttribute('aria-expanded', 'true')
|
||||
expect(modelsHeader).toHaveAttribute('aria-expanded', 'false')
|
||||
expect(mediaHeader).toHaveAttribute(
|
||||
'aria-controls',
|
||||
'section-content-media'
|
||||
)
|
||||
expect(modelsHeader.attributes('aria-controls')).toBe(
|
||||
expect(modelsHeader).toHaveAttribute(
|
||||
'aria-controls',
|
||||
'section-content-models'
|
||||
)
|
||||
expect(mediaChevron.classes()).toContain('rotate-90')
|
||||
expect(modelsChevron.classes()).not.toContain('rotate-90')
|
||||
|
||||
await modelsHeader.trigger('click')
|
||||
await nextTick()
|
||||
await user.click(modelsHeader)
|
||||
|
||||
expect(mediaHeader.attributes('aria-expanded')).toBe('false')
|
||||
expect(modelsHeader.attributes('aria-expanded')).toBe('true')
|
||||
expect(mediaChevron.classes()).not.toContain('rotate-90')
|
||||
expect(modelsChevron.classes()).toContain('rotate-90')
|
||||
expect(mediaHeader).toHaveAttribute('aria-expanded', 'false')
|
||||
expect(modelsHeader).toHaveAttribute('aria-expanded', 'true')
|
||||
|
||||
await mediaHeader.trigger('click')
|
||||
await nextTick()
|
||||
await user.click(mediaHeader)
|
||||
|
||||
expect(mediaHeader.attributes('aria-expanded')).toBe('true')
|
||||
expect(modelsHeader.attributes('aria-expanded')).toBe('false')
|
||||
expect(mediaChevron.classes()).toContain('rotate-90')
|
||||
expect(modelsChevron.classes()).not.toContain('rotate-90')
|
||||
expect(mediaHeader).toHaveAttribute('aria-expanded', 'true')
|
||||
expect(modelsHeader).toHaveAttribute('aria-expanded', 'false')
|
||||
|
||||
await mediaHeader.trigger('click')
|
||||
await nextTick()
|
||||
await user.click(mediaHeader)
|
||||
|
||||
expect(mediaHeader.attributes('aria-expanded')).toBe('false')
|
||||
expect(modelsHeader.attributes('aria-expanded')).toBe('false')
|
||||
expect(mediaHeader).toHaveAttribute('aria-expanded', 'false')
|
||||
expect(modelsHeader).toHaveAttribute('aria-expanded', 'false')
|
||||
})
|
||||
|
||||
it('defaults to media section when both sections are available', () => {
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
|
||||
const mediaHeader = wrapper.get('[data-testid="section-header-media"]')
|
||||
const modelsHeader = wrapper.get('[data-testid="section-header-models"]')
|
||||
const mediaHeader = screen.getByTestId('section-header-media')
|
||||
const modelsHeader = screen.getByTestId('section-header-models')
|
||||
|
||||
expect(mediaHeader.attributes('aria-expanded')).toBe('true')
|
||||
expect(modelsHeader.attributes('aria-expanded')).toBe('false')
|
||||
expect(mediaHeader).toHaveAttribute('aria-expanded', 'true')
|
||||
expect(modelsHeader).toHaveAttribute('aria-expanded', 'false')
|
||||
})
|
||||
|
||||
it('defaults to models section when media is unavailable', () => {
|
||||
const wrapper = createWrapper({
|
||||
const { container } = renderComponent({
|
||||
items: [
|
||||
{
|
||||
id: 'model-default',
|
||||
@@ -139,14 +132,15 @@ describe(ShareAssetWarningBox, () => {
|
||||
]
|
||||
})
|
||||
|
||||
expect(wrapper.text()).toContain('1 Model')
|
||||
const modelsHeader = wrapper.get('[data-testid="section-header-models"]')
|
||||
expect(container.textContent).toContain('1 Model')
|
||||
const modelsHeader = screen.getByTestId('section-header-models')
|
||||
|
||||
expect(modelsHeader.attributes('aria-expanded')).toBe('true')
|
||||
expect(modelsHeader).toHaveAttribute('aria-expanded', 'true')
|
||||
})
|
||||
|
||||
it('allows collapsing the only expanded section when models are unavailable', async () => {
|
||||
const wrapper = createWrapper({
|
||||
const user = userEvent.setup()
|
||||
renderComponent({
|
||||
items: [
|
||||
{
|
||||
id: 'asset-image',
|
||||
@@ -160,47 +154,43 @@ describe(ShareAssetWarningBox, () => {
|
||||
]
|
||||
})
|
||||
|
||||
const mediaHeader = wrapper.get('[data-testid="section-header-media"]')
|
||||
const mediaChevron = mediaHeader.get('i')
|
||||
const mediaHeader = screen.getByTestId('section-header-media')
|
||||
|
||||
expect(mediaHeader.attributes('aria-expanded')).toBe('true')
|
||||
expect(mediaChevron.classes()).toContain('rotate-90')
|
||||
expect(mediaHeader).toHaveAttribute('aria-expanded', 'true')
|
||||
|
||||
await mediaHeader.trigger('click')
|
||||
await nextTick()
|
||||
await user.click(mediaHeader)
|
||||
|
||||
expect(mediaHeader.attributes('aria-expanded')).toBe('false')
|
||||
expect(mediaChevron.classes()).not.toContain('rotate-90')
|
||||
expect(mediaHeader).toHaveAttribute('aria-expanded', 'false')
|
||||
})
|
||||
|
||||
it('emits acknowledged update when checkbox is toggled', async () => {
|
||||
const wrapper = createWrapper()
|
||||
const onUpdateAcknowledged = vi.fn()
|
||||
const user = userEvent.setup()
|
||||
renderComponent({ 'onUpdate:acknowledged': onUpdateAcknowledged })
|
||||
|
||||
const checkbox = wrapper.find('input[type="checkbox"]')
|
||||
await checkbox.setValue(true)
|
||||
await nextTick()
|
||||
const checkbox = screen.getByRole('checkbox')
|
||||
await user.click(checkbox)
|
||||
|
||||
expect(wrapper.emitted('update:acknowledged')).toBeTruthy()
|
||||
expect(wrapper.emitted('update:acknowledged')![0]).toEqual([true])
|
||||
expect(onUpdateAcknowledged).toHaveBeenCalledWith(true)
|
||||
})
|
||||
|
||||
it('displays asset names in the assets section', () => {
|
||||
const wrapper = createWrapper()
|
||||
const { container } = renderComponent()
|
||||
|
||||
expect(wrapper.text()).toContain('image.png')
|
||||
expect(container.textContent).toContain('image.png')
|
||||
})
|
||||
|
||||
it('renders thumbnail previews for assets when URLs are available', () => {
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
|
||||
const images = wrapper.findAll('img')
|
||||
const images = screen.getAllByRole('img')
|
||||
expect(images).toHaveLength(1)
|
||||
expect(images[0].attributes('src')).toBe('https://example.com/a.jpg')
|
||||
expect(images[0].attributes('alt')).toBe('image.png')
|
||||
expect(images[0]).toHaveAttribute('src', 'https://example.com/a.jpg')
|
||||
expect(images[0]).toHaveAttribute('alt', 'image.png')
|
||||
})
|
||||
|
||||
it('renders fallback icon when thumbnail is missing', () => {
|
||||
const wrapper = createWrapper({
|
||||
const { container } = renderComponent({
|
||||
items: [
|
||||
{
|
||||
id: 'asset-image',
|
||||
@@ -223,15 +213,16 @@ describe(ShareAssetWarningBox, () => {
|
||||
]
|
||||
})
|
||||
|
||||
const fallbackIcons = wrapper
|
||||
.findAll('i')
|
||||
.filter((icon) => icon.classes().includes('icon-[lucide--image]'))
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
const fallbackIcons = Array.from(container.querySelectorAll('i')).filter(
|
||||
(i) => i.classList.contains('icon-[lucide--image]')
|
||||
)
|
||||
|
||||
expect(fallbackIcons).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('hides assets section when no assets provided', () => {
|
||||
const wrapper = createWrapper({
|
||||
const { container } = renderComponent({
|
||||
items: [
|
||||
{
|
||||
id: 'model-default',
|
||||
@@ -245,11 +236,11 @@ describe(ShareAssetWarningBox, () => {
|
||||
]
|
||||
})
|
||||
|
||||
expect(wrapper.text()).not.toContain('Media File')
|
||||
expect(container.textContent).not.toContain('Media File')
|
||||
})
|
||||
|
||||
it('hides models section when no models provided', () => {
|
||||
const wrapper = createWrapper({
|
||||
const { container } = renderComponent({
|
||||
items: [
|
||||
{
|
||||
id: 'asset-image',
|
||||
@@ -263,6 +254,6 @@ describe(ShareAssetWarningBox, () => {
|
||||
]
|
||||
})
|
||||
|
||||
expect(wrapper.text()).not.toContain('Model')
|
||||
expect(container.textContent).not.toContain('Model')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { nextTick, reactive } from 'vue'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
@@ -131,6 +132,10 @@ const i18n = createI18n({
|
||||
}
|
||||
})
|
||||
|
||||
async function flushPromises() {
|
||||
await new Promise((r) => setTimeout(r, 0))
|
||||
}
|
||||
|
||||
describe('ShareWorkflowDialogContent', () => {
|
||||
const onClose = vi.fn()
|
||||
|
||||
@@ -181,8 +186,8 @@ describe('ShareWorkflowDialogContent', () => {
|
||||
mockGetShareableAssets.mockResolvedValue(mockShareServiceData.items)
|
||||
})
|
||||
|
||||
function createWrapper() {
|
||||
return mount(ShareWorkflowDialogContent, {
|
||||
function renderComponent() {
|
||||
return render(ShareWorkflowDialogContent, {
|
||||
props: { onClose },
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
@@ -215,84 +220,74 @@ describe('ShareWorkflowDialogContent', () => {
|
||||
isModified: true,
|
||||
lastModified: 1000
|
||||
}
|
||||
const wrapper = createWrapper()
|
||||
const { container } = renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.text()).toContain(
|
||||
expect(container.textContent).toContain(
|
||||
'You must save your workflow before sharing.'
|
||||
)
|
||||
expect(wrapper.text()).toContain('Save workflow')
|
||||
expect(container.textContent).toContain('Save workflow')
|
||||
})
|
||||
|
||||
it('renders share-link and publish tabs when comfy hub upload is enabled', async () => {
|
||||
mockFlags.comfyHubUploadEnabled = true
|
||||
const wrapper = createWrapper()
|
||||
const { container } = renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.text()).toContain('Share')
|
||||
expect(wrapper.text()).toContain('Publish')
|
||||
const publishTabPanel = wrapper.find('[data-testid="publish-tab-panel"]')
|
||||
expect(publishTabPanel.exists()).toBe(true)
|
||||
expect(publishTabPanel.attributes('style')).toContain('display: none')
|
||||
expect(container.textContent).toContain('Share')
|
||||
expect(container.textContent).toContain('Publish')
|
||||
const publishTabPanel = screen.getByTestId('publish-tab-panel')
|
||||
expect(publishTabPanel).not.toBeVisible()
|
||||
})
|
||||
|
||||
it('hides the publish tab when comfy hub upload is disabled', async () => {
|
||||
const wrapper = createWrapper()
|
||||
const { container } = renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.text()).toContain('Share')
|
||||
expect(wrapper.text()).not.toContain('Publish')
|
||||
expect(wrapper.find('[data-testid="publish-intro"]').exists()).toBe(false)
|
||||
expect(container.textContent).toContain('Share')
|
||||
expect(container.textContent).not.toContain('Publish')
|
||||
expect(screen.queryByTestId('publish-intro')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows publish intro panel in the share dialog', async () => {
|
||||
mockFlags.comfyHubUploadEnabled = true
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
const publishTab = wrapper
|
||||
.findAll('button')
|
||||
.find((button) => button.text().includes('Publish'))
|
||||
const publishTab = screen.getByRole('tab', { name: /Publish/ })
|
||||
|
||||
expect(publishTab).toBeDefined()
|
||||
await publishTab!.trigger('click')
|
||||
await userEvent.click(publishTab)
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.find('[data-testid="publish-intro"]').exists()).toBe(true)
|
||||
expect(screen.getByTestId('publish-intro')).toBeTruthy()
|
||||
})
|
||||
|
||||
it('shows start publishing CTA in the publish intro panel', async () => {
|
||||
mockFlags.comfyHubUploadEnabled = true
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
const publishTab = wrapper
|
||||
.findAll('button')
|
||||
.find((button) => button.text().includes('Publish'))
|
||||
expect(publishTab).toBeDefined()
|
||||
const publishTab = screen.getByRole('tab', { name: /Publish/ })
|
||||
|
||||
await publishTab!.trigger('click')
|
||||
await userEvent.click(publishTab)
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.find('[data-testid="publish-intro-cta"]').text()).toBe(
|
||||
expect(screen.getByTestId('publish-intro-cta').textContent).toBe(
|
||||
'Start publishing'
|
||||
)
|
||||
})
|
||||
|
||||
it('opens publish dialog from intro cta and closes share dialog', async () => {
|
||||
mockFlags.comfyHubUploadEnabled = true
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
const publishTab = wrapper
|
||||
.findAll('button')
|
||||
.find((button) => button.text().includes('Publish'))
|
||||
const publishTab = screen.getByRole('tab', { name: /Publish/ })
|
||||
|
||||
expect(publishTab).toBeDefined()
|
||||
await publishTab!.trigger('click')
|
||||
await userEvent.click(publishTab)
|
||||
await flushPromises()
|
||||
|
||||
await wrapper.find('[data-testid="publish-intro-cta"]').trigger('click')
|
||||
await userEvent.click(screen.getByTestId('publish-intro-cta'))
|
||||
await nextTick()
|
||||
|
||||
expect(onClose).toHaveBeenCalledOnce()
|
||||
@@ -300,37 +295,37 @@ describe('ShareWorkflowDialogContent', () => {
|
||||
})
|
||||
|
||||
it('disables publish button when acknowledgment is unchecked', async () => {
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
const publishButton = wrapper
|
||||
.findAll('button')
|
||||
.find((button) => button.text().includes('Create link'))
|
||||
const publishButton = screen.getByRole('button', {
|
||||
name: /Create link/i
|
||||
})
|
||||
|
||||
expect(publishButton?.attributes('disabled')).toBeDefined()
|
||||
expect(publishButton).toBeDisabled()
|
||||
})
|
||||
|
||||
it('enables publish button when acknowledgment is checked', async () => {
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
const checkbox = wrapper.find('input[type="checkbox"]')
|
||||
await checkbox.setValue(true)
|
||||
const checkbox = screen.getByRole('checkbox')
|
||||
await userEvent.click(checkbox)
|
||||
await nextTick()
|
||||
|
||||
const publishButton = wrapper
|
||||
.findAll('button')
|
||||
.find((button) => button.text().includes('Create link'))
|
||||
const publishButton = screen.getByRole('button', {
|
||||
name: /Create link/i
|
||||
})
|
||||
|
||||
expect(publishButton?.attributes('disabled')).toBeUndefined()
|
||||
expect(publishButton).toBeEnabled()
|
||||
})
|
||||
|
||||
it('calls onClose when close button is clicked', async () => {
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
const closeButton = wrapper.find('[aria-label="Close"]')
|
||||
await closeButton.trigger('click')
|
||||
const closeButton = screen.getByRole('button', { name: 'Close' })
|
||||
await userEvent.click(closeButton)
|
||||
|
||||
expect(onClose).toHaveBeenCalled()
|
||||
})
|
||||
@@ -359,19 +354,18 @@ describe('ShareWorkflowDialogContent', () => {
|
||||
|
||||
mockGetShareableAssets.mockResolvedValueOnce(initialShareableAssets)
|
||||
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
const checkbox = wrapper.find('input[type="checkbox"]')
|
||||
await checkbox.setValue(true)
|
||||
const checkbox = screen.getByRole('checkbox')
|
||||
await userEvent.click(checkbox)
|
||||
await nextTick()
|
||||
|
||||
const publishButton = wrapper
|
||||
.findAll('button')
|
||||
.find((button) => button.text().includes('Create link'))
|
||||
expect(publishButton).toBeDefined()
|
||||
const publishButton = screen.getByRole('button', {
|
||||
name: /Create link/i
|
||||
})
|
||||
|
||||
await publishButton!.trigger('click')
|
||||
await userEvent.click(publishButton)
|
||||
await flushPromises()
|
||||
|
||||
expect(mockGetShareableAssets).toHaveBeenCalledTimes(1)
|
||||
@@ -400,11 +394,11 @@ describe('ShareWorkflowDialogContent', () => {
|
||||
publishedAt
|
||||
})
|
||||
|
||||
const wrapper = createWrapper()
|
||||
const { container } = renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.text()).toContain('You have made changes...')
|
||||
expect(wrapper.text()).toContain('Update link')
|
||||
expect(container.textContent).toContain('You have made changes...')
|
||||
expect(container.textContent).toContain('Update link')
|
||||
})
|
||||
|
||||
it('shows copy URL when workflow has not changed since publish', async () => {
|
||||
@@ -426,11 +420,11 @@ describe('ShareWorkflowDialogContent', () => {
|
||||
publishedAt
|
||||
})
|
||||
|
||||
const wrapper = createWrapper()
|
||||
const { container } = renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.text()).toContain('Anyone with this link...')
|
||||
expect(wrapper.text()).not.toContain('Update link')
|
||||
expect(container.textContent).toContain('Anyone with this link...')
|
||||
expect(container.textContent).not.toContain('Update link')
|
||||
})
|
||||
|
||||
describe('error and edge cases', () => {
|
||||
@@ -443,22 +437,22 @@ describe('ShareWorkflowDialogContent', () => {
|
||||
isModified: false,
|
||||
lastModified: 1000
|
||||
}
|
||||
const wrapper = createWrapper()
|
||||
const { container } = renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.text()).toContain(
|
||||
expect(container.textContent).toContain(
|
||||
'You must save your workflow before sharing.'
|
||||
)
|
||||
expect(wrapper.text()).toContain('Workflow name')
|
||||
expect(container.textContent).toContain('Workflow name')
|
||||
})
|
||||
|
||||
it('shows error toast when getPublishStatus rejects', async () => {
|
||||
mockGetPublishStatus.mockRejectedValue(new Error('Server down'))
|
||||
|
||||
const wrapper = createWrapper()
|
||||
const { container } = renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.text()).toContain('Create link')
|
||||
expect(container.textContent).toContain('Create link')
|
||||
expect(mockToast.add).toHaveBeenCalledWith({
|
||||
severity: 'error',
|
||||
summary: 'Failed to load publish status'
|
||||
@@ -468,19 +462,18 @@ describe('ShareWorkflowDialogContent', () => {
|
||||
it('shows error toast when publishWorkflow rejects', async () => {
|
||||
mockGetShareableAssets.mockResolvedValue([])
|
||||
|
||||
const wrapper = createWrapper()
|
||||
const { container } = renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
mockPublishWorkflow.mockRejectedValue(new Error('Publish failed'))
|
||||
|
||||
const publishButton = wrapper
|
||||
.findAll('button')
|
||||
.find((btn) => btn.text().includes('Create link'))
|
||||
expect(publishButton).toBeDefined()
|
||||
await publishButton!.trigger('click')
|
||||
const publishButton = screen.getByRole('button', {
|
||||
name: /Create link/i
|
||||
})
|
||||
await userEvent.click(publishButton)
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.text()).not.toContain('Anyone with this link...')
|
||||
expect(container.textContent).not.toContain('Anyone with this link...')
|
||||
expect(mockToast.add).toHaveBeenCalledWith({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
@@ -490,10 +483,10 @@ describe('ShareWorkflowDialogContent', () => {
|
||||
|
||||
it('renders unsaved state when no active workflow exists', async () => {
|
||||
mockWorkflowStore.activeWorkflow = null
|
||||
const wrapper = createWrapper()
|
||||
const { container } = renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.text()).toContain(
|
||||
expect(container.textContent).toContain(
|
||||
'You must save your workflow before sharing.'
|
||||
)
|
||||
})
|
||||
@@ -501,31 +494,27 @@ describe('ShareWorkflowDialogContent', () => {
|
||||
it('does not call publishWorkflow when workflow is null during publish', async () => {
|
||||
mockGetShareableAssets.mockResolvedValue([])
|
||||
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
mockWorkflowStore.activeWorkflow = null
|
||||
|
||||
const publishButton = wrapper
|
||||
.findAll('button')
|
||||
.find((btn) => btn.text().includes('Create link'))
|
||||
if (publishButton) {
|
||||
await publishButton.trigger('click')
|
||||
await flushPromises()
|
||||
}
|
||||
const publishButton = screen.getByRole('button', {
|
||||
name: /Create link/i
|
||||
})
|
||||
await userEvent.click(publishButton)
|
||||
await flushPromises()
|
||||
|
||||
expect(mockPublishWorkflow).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not switch to publishToHub mode when flag is disabled', async () => {
|
||||
mockFlags.comfyHubUploadEnabled = false
|
||||
const wrapper = createWrapper()
|
||||
const { container } = renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.find('[data-testid="publish-tab-panel"]').exists()).toBe(
|
||||
false
|
||||
)
|
||||
expect(wrapper.text()).not.toContain('Publish')
|
||||
expect(screen.queryByTestId('publish-tab-panel')).not.toBeInTheDocument()
|
||||
expect(container.textContent).not.toContain('Publish')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { nextTick } from 'vue'
|
||||
|
||||
import { COMFY_HUB_TAG_OPTIONS } from '@/platform/workflow/sharing/constants/comfyHubTags'
|
||||
|
||||
@@ -13,15 +15,21 @@ vi.mock('@/platform/workflow/sharing/services/comfyHubService', () => ({
|
||||
|
||||
import ComfyHubDescribeStep from './ComfyHubDescribeStep.vue'
|
||||
|
||||
function mountStep(
|
||||
props: Partial<InstanceType<typeof ComfyHubDescribeStep>['$props']> = {}
|
||||
async function flushPromises() {
|
||||
await new Promise((r) => setTimeout(r, 0))
|
||||
}
|
||||
|
||||
function renderStep(
|
||||
props: Partial<InstanceType<typeof ComfyHubDescribeStep>['$props']> = {},
|
||||
callbacks: Record<string, ReturnType<typeof vi.fn>> = {}
|
||||
) {
|
||||
return mount(ComfyHubDescribeStep, {
|
||||
return render(ComfyHubDescribeStep, {
|
||||
props: {
|
||||
name: 'Workflow Name',
|
||||
description: 'Workflow description',
|
||||
tags: [],
|
||||
...props
|
||||
...props,
|
||||
...callbacks
|
||||
},
|
||||
global: {
|
||||
mocks: {
|
||||
@@ -75,43 +83,56 @@ function mountStep(
|
||||
describe('ComfyHubDescribeStep', () => {
|
||||
it('emits name and description updates', async () => {
|
||||
mockFetchTagLabels.mockRejectedValue(new Error('offline'))
|
||||
const wrapper = mountStep()
|
||||
const onUpdateName = vi.fn()
|
||||
const onUpdateDescription = vi.fn()
|
||||
renderStep(
|
||||
{},
|
||||
{
|
||||
'onUpdate:name': onUpdateName,
|
||||
'onUpdate:description': onUpdateDescription
|
||||
}
|
||||
)
|
||||
await flushPromises()
|
||||
|
||||
await wrapper.find('[data-testid="name-input"]').setValue('New workflow')
|
||||
await wrapper
|
||||
.find('[data-testid="description-input"]')
|
||||
.setValue('New description')
|
||||
const nameInput = screen.getByTestId('name-input')
|
||||
const descInput = screen.getByTestId('description-input')
|
||||
|
||||
expect(wrapper.emitted('update:name')).toEqual([['New workflow']])
|
||||
expect(wrapper.emitted('update:description')).toEqual([['New description']])
|
||||
await userEvent.clear(nameInput)
|
||||
await userEvent.type(nameInput, 'New workflow')
|
||||
await userEvent.clear(descInput)
|
||||
await userEvent.type(descInput, 'New description')
|
||||
|
||||
expect(onUpdateName).toHaveBeenLastCalledWith('New workflow')
|
||||
expect(onUpdateDescription).toHaveBeenLastCalledWith('New description')
|
||||
})
|
||||
|
||||
it('uses fetched tags from API', async () => {
|
||||
const apiTags = ['Alpha', 'Beta', 'Gamma']
|
||||
mockFetchTagLabels.mockResolvedValue(apiTags)
|
||||
const wrapper = mountStep()
|
||||
const { container } = renderStep()
|
||||
await flushPromises()
|
||||
|
||||
const suggestionValues = wrapper
|
||||
.findAll(
|
||||
const suggestionValues = Array.from(
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
container.querySelectorAll(
|
||||
'[data-testid="tags-input"][data-disabled="true"] [data-testid="tag-item"]'
|
||||
)
|
||||
.map((button) => button.attributes('data-value'))
|
||||
).map((el) => el.getAttribute('data-value'))
|
||||
|
||||
expect(suggestionValues).toEqual(apiTags)
|
||||
})
|
||||
|
||||
it('falls back to hardcoded tags when API fails', async () => {
|
||||
mockFetchTagLabels.mockRejectedValue(new Error('network error'))
|
||||
const wrapper = mountStep()
|
||||
const { container } = renderStep()
|
||||
await flushPromises()
|
||||
|
||||
const suggestionValues = wrapper
|
||||
.findAll(
|
||||
const suggestionValues = Array.from(
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
container.querySelectorAll(
|
||||
'[data-testid="tags-input"][data-disabled="true"] [data-testid="tag-item"]'
|
||||
)
|
||||
.map((button) => button.attributes('data-value'))
|
||||
).map((el) => el.getAttribute('data-value'))
|
||||
|
||||
expect(suggestionValues).toHaveLength(10)
|
||||
expect(suggestionValues[0]).toBe(COMFY_HUB_TAG_OPTIONS[0])
|
||||
@@ -120,30 +141,32 @@ describe('ComfyHubDescribeStep', () => {
|
||||
it('adds a suggested tag when clicked', async () => {
|
||||
const apiTags = ['Alpha', 'Beta']
|
||||
mockFetchTagLabels.mockResolvedValue(apiTags)
|
||||
const wrapper = mountStep()
|
||||
const onUpdateTags = vi.fn()
|
||||
const { container } = renderStep({}, { 'onUpdate:tags': onUpdateTags })
|
||||
await flushPromises()
|
||||
|
||||
const suggestionButtons = wrapper.findAll(
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
const suggestionButtons = container.querySelectorAll(
|
||||
'[data-testid="tags-input"][data-disabled="true"] [data-testid="tag-item"]'
|
||||
)
|
||||
|
||||
await suggestionButtons[0].trigger('click')
|
||||
await userEvent.click(suggestionButtons[0] as HTMLElement)
|
||||
|
||||
const tagUpdates = wrapper.emitted('update:tags')
|
||||
expect(tagUpdates?.at(-1)).toEqual([['Alpha']])
|
||||
expect(onUpdateTags).toHaveBeenLastCalledWith(['Alpha'])
|
||||
})
|
||||
|
||||
it('hides already-selected tags from suggestions', async () => {
|
||||
const apiTags = ['Alpha', 'Beta', 'Gamma']
|
||||
mockFetchTagLabels.mockResolvedValue(apiTags)
|
||||
const wrapper = mountStep({ tags: ['Alpha'] })
|
||||
const { container } = renderStep({ tags: ['Alpha'] })
|
||||
await flushPromises()
|
||||
|
||||
const suggestionValues = wrapper
|
||||
.findAll(
|
||||
const suggestionValues = Array.from(
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
container.querySelectorAll(
|
||||
'[data-testid="tags-input"][data-disabled="true"] [data-testid="tag-item"]'
|
||||
)
|
||||
.map((button) => button.attributes('data-value'))
|
||||
).map((el) => el.getAttribute('data-value'))
|
||||
|
||||
expect(suggestionValues).not.toContain('Alpha')
|
||||
expect(suggestionValues).toEqual(['Beta', 'Gamma'])
|
||||
@@ -151,22 +174,24 @@ describe('ComfyHubDescribeStep', () => {
|
||||
|
||||
it('toggles between default and full suggestion lists', async () => {
|
||||
mockFetchTagLabels.mockRejectedValue(new Error('offline'))
|
||||
const wrapper = mountStep()
|
||||
const { container } = renderStep()
|
||||
await flushPromises()
|
||||
|
||||
const defaultSuggestions = wrapper.findAll(
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
const defaultSuggestions = container.querySelectorAll(
|
||||
'[data-testid="tags-input"][data-disabled="true"] [data-testid="tag-item"]'
|
||||
)
|
||||
expect(defaultSuggestions).toHaveLength(10)
|
||||
expect(wrapper.text()).toContain('comfyHubPublish.showMoreTags')
|
||||
expect(container.textContent).toContain('comfyHubPublish.showMoreTags')
|
||||
|
||||
await wrapper.find('[data-testid="toggle-suggestions"]').trigger('click')
|
||||
await wrapper.vm.$nextTick()
|
||||
await userEvent.click(screen.getByTestId('toggle-suggestions'))
|
||||
await nextTick()
|
||||
|
||||
const allSuggestions = wrapper.findAll(
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
const allSuggestions = container.querySelectorAll(
|
||||
'[data-testid="tags-input"][data-disabled="true"] [data-testid="tag-item"]'
|
||||
)
|
||||
expect(allSuggestions).toHaveLength(COMFY_HUB_TAG_OPTIONS.length)
|
||||
expect(wrapper.text()).toContain('comfyHubPublish.showLessTags')
|
||||
expect(container.textContent).toContain('comfyHubPublish.showLessTags')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { fireEvent, render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import type { ExampleImage } from '@/platform/workflow/sharing/types/comfyHubTypes'
|
||||
@@ -18,9 +19,12 @@ function createImages(count: number): ExampleImage[] {
|
||||
}))
|
||||
}
|
||||
|
||||
function mountStep(images: ExampleImage[]) {
|
||||
return mount(ComfyHubExamplesStep, {
|
||||
props: { exampleImages: images },
|
||||
function renderStep(
|
||||
images: ExampleImage[],
|
||||
callbacks: Record<string, ReturnType<typeof vi.fn>> = {}
|
||||
) {
|
||||
return render(ComfyHubExamplesStep, {
|
||||
props: { exampleImages: images, ...callbacks },
|
||||
global: {
|
||||
mocks: { $t: (key: string) => key }
|
||||
}
|
||||
@@ -33,63 +37,78 @@ describe('ComfyHubExamplesStep', () => {
|
||||
})
|
||||
|
||||
it('renders all example images', () => {
|
||||
const wrapper = mountStep(createImages(3))
|
||||
expect(wrapper.findAll('[role="listitem"]')).toHaveLength(3)
|
||||
renderStep(createImages(3))
|
||||
expect(screen.getAllByRole('listitem')).toHaveLength(3)
|
||||
})
|
||||
|
||||
it('emits reordered array when moving image left via keyboard', async () => {
|
||||
const wrapper = mountStep(createImages(3))
|
||||
const onUpdateExampleImages = vi.fn()
|
||||
renderStep(createImages(3), {
|
||||
'onUpdate:exampleImages': onUpdateExampleImages
|
||||
})
|
||||
|
||||
const tiles = wrapper.findAll('[role="listitem"]')
|
||||
await tiles[1].trigger('keydown', { key: 'ArrowLeft', shiftKey: true })
|
||||
const tiles = screen.getAllByRole('listitem')
|
||||
// eslint-disable-next-line testing-library/prefer-user-event
|
||||
await fireEvent.keyDown(tiles[1], { key: 'ArrowLeft', shiftKey: true })
|
||||
|
||||
const emitted = wrapper.emitted('update:exampleImages')
|
||||
expect(emitted).toBeTruthy()
|
||||
const reordered = emitted![0][0] as ExampleImage[]
|
||||
expect(onUpdateExampleImages).toHaveBeenCalled()
|
||||
const reordered = onUpdateExampleImages.mock.calls[0][0] as ExampleImage[]
|
||||
expect(reordered.map((img) => img.id)).toEqual(['img-1', 'img-0', 'img-2'])
|
||||
})
|
||||
|
||||
it('emits reordered array when moving image right via keyboard', async () => {
|
||||
const wrapper = mountStep(createImages(3))
|
||||
const onUpdateExampleImages = vi.fn()
|
||||
renderStep(createImages(3), {
|
||||
'onUpdate:exampleImages': onUpdateExampleImages
|
||||
})
|
||||
|
||||
const tiles = wrapper.findAll('[role="listitem"]')
|
||||
await tiles[1].trigger('keydown', { key: 'ArrowRight', shiftKey: true })
|
||||
const tiles = screen.getAllByRole('listitem')
|
||||
// eslint-disable-next-line testing-library/prefer-user-event
|
||||
await fireEvent.keyDown(tiles[1], { key: 'ArrowRight', shiftKey: true })
|
||||
|
||||
const emitted = wrapper.emitted('update:exampleImages')
|
||||
expect(emitted).toBeTruthy()
|
||||
const reordered = emitted![0][0] as ExampleImage[]
|
||||
expect(onUpdateExampleImages).toHaveBeenCalled()
|
||||
const reordered = onUpdateExampleImages.mock.calls[0][0] as ExampleImage[]
|
||||
expect(reordered.map((img) => img.id)).toEqual(['img-0', 'img-2', 'img-1'])
|
||||
})
|
||||
|
||||
it('does not emit when moving first image left (boundary)', async () => {
|
||||
const wrapper = mountStep(createImages(3))
|
||||
const onUpdateExampleImages = vi.fn()
|
||||
renderStep(createImages(3), {
|
||||
'onUpdate:exampleImages': onUpdateExampleImages
|
||||
})
|
||||
|
||||
const tiles = wrapper.findAll('[role="listitem"]')
|
||||
await tiles[0].trigger('keydown', { key: 'ArrowLeft', shiftKey: true })
|
||||
const tiles = screen.getAllByRole('listitem')
|
||||
// eslint-disable-next-line testing-library/prefer-user-event
|
||||
await fireEvent.keyDown(tiles[0], { key: 'ArrowLeft', shiftKey: true })
|
||||
|
||||
expect(wrapper.emitted('update:exampleImages')).toBeFalsy()
|
||||
expect(onUpdateExampleImages).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not emit when moving last image right (boundary)', async () => {
|
||||
const wrapper = mountStep(createImages(3))
|
||||
const onUpdateExampleImages = vi.fn()
|
||||
renderStep(createImages(3), {
|
||||
'onUpdate:exampleImages': onUpdateExampleImages
|
||||
})
|
||||
|
||||
const tiles = wrapper.findAll('[role="listitem"]')
|
||||
await tiles[2].trigger('keydown', { key: 'ArrowRight', shiftKey: true })
|
||||
const tiles = screen.getAllByRole('listitem')
|
||||
// eslint-disable-next-line testing-library/prefer-user-event
|
||||
await fireEvent.keyDown(tiles[2], { key: 'ArrowRight', shiftKey: true })
|
||||
|
||||
expect(wrapper.emitted('update:exampleImages')).toBeFalsy()
|
||||
expect(onUpdateExampleImages).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('emits filtered array when removing an image', async () => {
|
||||
const wrapper = mountStep(createImages(2))
|
||||
const onUpdateExampleImages = vi.fn()
|
||||
renderStep(createImages(2), {
|
||||
'onUpdate:exampleImages': onUpdateExampleImages
|
||||
})
|
||||
|
||||
const removeBtn = wrapper.find(
|
||||
'button[aria-label="comfyHubPublish.removeExampleImage"]'
|
||||
)
|
||||
expect(removeBtn.exists()).toBe(true)
|
||||
await removeBtn.trigger('click')
|
||||
const removeBtn = screen.getAllByRole('button', {
|
||||
name: 'comfyHubPublish.removeExampleImage'
|
||||
})[0]
|
||||
await userEvent.click(removeBtn)
|
||||
|
||||
const emitted = wrapper.emitted('update:exampleImages')
|
||||
expect(emitted).toBeTruthy()
|
||||
expect(emitted![0][0]).toHaveLength(1)
|
||||
expect(onUpdateExampleImages).toHaveBeenCalled()
|
||||
expect(onUpdateExampleImages.mock.calls[0][0]).toHaveLength(1)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { ref } from 'vue'
|
||||
|
||||
@@ -105,6 +106,10 @@ vi.mock('@/platform/workflow/management/stores/workflowStore', () => ({
|
||||
})
|
||||
}))
|
||||
|
||||
async function flushPromises() {
|
||||
await new Promise((r) => setTimeout(r, 0))
|
||||
}
|
||||
|
||||
describe('ComfyHubPublishDialog', () => {
|
||||
const onClose = vi.fn()
|
||||
|
||||
@@ -122,8 +127,8 @@ describe('ComfyHubPublishDialog', () => {
|
||||
})
|
||||
})
|
||||
|
||||
function createWrapper() {
|
||||
return mount(ComfyHubPublishDialog, {
|
||||
function renderComponent() {
|
||||
return render(ComfyHubPublishDialog, {
|
||||
props: { onClose },
|
||||
global: {
|
||||
mocks: {
|
||||
@@ -165,27 +170,27 @@ describe('ComfyHubPublishDialog', () => {
|
||||
}
|
||||
|
||||
it('starts in publish wizard mode and prefetches profile asynchronously', async () => {
|
||||
createWrapper()
|
||||
renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
expect(mockFetchProfile).toHaveBeenCalledWith()
|
||||
})
|
||||
|
||||
it('switches to profile creation step when final-step publish requires profile', async () => {
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
await wrapper.find('[data-testid="require-profile"]').trigger('click')
|
||||
await userEvent.click(screen.getByTestId('require-profile'))
|
||||
|
||||
expect(mockOpenProfileCreationStep).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it('returns to finish state after gate complete and does not auto-close', async () => {
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
await wrapper.find('[data-testid="require-profile"]').trigger('click')
|
||||
await wrapper.find('[data-testid="gate-complete"]').trigger('click')
|
||||
await userEvent.click(screen.getByTestId('require-profile'))
|
||||
await userEvent.click(screen.getByTestId('gate-complete'))
|
||||
|
||||
expect(mockOpenProfileCreationStep).toHaveBeenCalledOnce()
|
||||
expect(mockCloseProfileCreationStep).toHaveBeenCalledOnce()
|
||||
@@ -194,11 +199,11 @@ describe('ComfyHubPublishDialog', () => {
|
||||
})
|
||||
|
||||
it('returns to finish state when profile gate is closed', async () => {
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
await wrapper.find('[data-testid="require-profile"]').trigger('click')
|
||||
await wrapper.find('[data-testid="gate-close"]').trigger('click')
|
||||
await userEvent.click(screen.getByTestId('require-profile'))
|
||||
await userEvent.click(screen.getByTestId('gate-close'))
|
||||
|
||||
expect(mockOpenProfileCreationStep).toHaveBeenCalledOnce()
|
||||
expect(mockCloseProfileCreationStep).toHaveBeenCalledOnce()
|
||||
@@ -206,10 +211,10 @@ describe('ComfyHubPublishDialog', () => {
|
||||
})
|
||||
|
||||
it('closes dialog after successful publish', async () => {
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
await wrapper.find('[data-testid="publish"]').trigger('click')
|
||||
await userEvent.click(screen.getByTestId('publish'))
|
||||
await flushPromises()
|
||||
|
||||
expect(mockSubmitToComfyHub).toHaveBeenCalledOnce()
|
||||
@@ -230,7 +235,7 @@ describe('ComfyHubPublishDialog', () => {
|
||||
}
|
||||
})
|
||||
|
||||
createWrapper()
|
||||
renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
expect(mockApplyPrefill).toHaveBeenCalledWith({
|
||||
@@ -242,7 +247,7 @@ describe('ComfyHubPublishDialog', () => {
|
||||
})
|
||||
|
||||
it('does not apply prefill when workflow is not published', async () => {
|
||||
createWrapper()
|
||||
renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
expect(mockApplyPrefill).not.toHaveBeenCalled()
|
||||
@@ -257,7 +262,7 @@ describe('ComfyHubPublishDialog', () => {
|
||||
prefill: null
|
||||
})
|
||||
|
||||
createWrapper()
|
||||
renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
expect(mockApplyPrefill).not.toHaveBeenCalled()
|
||||
@@ -266,7 +271,7 @@ describe('ComfyHubPublishDialog', () => {
|
||||
it('silently ignores prefill fetch errors', async () => {
|
||||
mockGetPublishStatus.mockRejectedValue(new Error('Network error'))
|
||||
|
||||
createWrapper()
|
||||
renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
expect(mockApplyPrefill).not.toHaveBeenCalled()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { ref } from 'vue'
|
||||
|
||||
@@ -59,6 +60,10 @@ function createDefaultFormData(): ComfyHubPublishFormData {
|
||||
}
|
||||
}
|
||||
|
||||
async function flushPromises() {
|
||||
await new Promise((r) => setTimeout(r, 0))
|
||||
}
|
||||
|
||||
describe('ComfyHubPublishWizardContent', () => {
|
||||
const onPublish = vi.fn()
|
||||
const onGoNext = vi.fn()
|
||||
@@ -78,12 +83,12 @@ describe('ComfyHubPublishWizardContent', () => {
|
||||
mockFlags.comfyHubProfileGateEnabled = true
|
||||
})
|
||||
|
||||
function createWrapper(
|
||||
function renderComponent(
|
||||
overrides: Partial<
|
||||
InstanceType<typeof ComfyHubPublishWizardContent>['$props']
|
||||
> = {}
|
||||
) {
|
||||
return mount(ComfyHubPublishWizardContent, {
|
||||
return render(ComfyHubPublishWizardContent, {
|
||||
props: {
|
||||
currentStep: 'finish',
|
||||
formData: createDefaultFormData(),
|
||||
@@ -171,8 +176,8 @@ describe('ComfyHubPublishWizardContent', () => {
|
||||
it('calls onPublish when profile exists', async () => {
|
||||
mockCheckProfile.mockResolvedValue(true)
|
||||
|
||||
const wrapper = createWrapper()
|
||||
await wrapper.find('[data-testid="publish-btn"]').trigger('click')
|
||||
renderComponent()
|
||||
await userEvent.click(screen.getByTestId('publish-btn'))
|
||||
await flushPromises()
|
||||
|
||||
expect(mockCheckProfile).toHaveBeenCalledOnce()
|
||||
@@ -183,8 +188,8 @@ describe('ComfyHubPublishWizardContent', () => {
|
||||
it('calls onRequireProfile when no profile exists', async () => {
|
||||
mockCheckProfile.mockResolvedValue(false)
|
||||
|
||||
const wrapper = createWrapper()
|
||||
await wrapper.find('[data-testid="publish-btn"]').trigger('click')
|
||||
renderComponent()
|
||||
await userEvent.click(screen.getByTestId('publish-btn'))
|
||||
await flushPromises()
|
||||
|
||||
expect(onRequireProfile).toHaveBeenCalledOnce()
|
||||
@@ -195,8 +200,8 @@ describe('ComfyHubPublishWizardContent', () => {
|
||||
const error = new Error('Network error')
|
||||
mockCheckProfile.mockRejectedValue(error)
|
||||
|
||||
const wrapper = createWrapper()
|
||||
await wrapper.find('[data-testid="publish-btn"]').trigger('click')
|
||||
renderComponent()
|
||||
await userEvent.click(screen.getByTestId('publish-btn'))
|
||||
await flushPromises()
|
||||
|
||||
expect(mockToastErrorHandler).toHaveBeenCalledWith(error)
|
||||
@@ -207,8 +212,8 @@ describe('ComfyHubPublishWizardContent', () => {
|
||||
it('calls onPublish directly when profile gate is disabled', async () => {
|
||||
mockFlags.comfyHubProfileGateEnabled = false
|
||||
|
||||
const wrapper = createWrapper()
|
||||
await wrapper.find('[data-testid="publish-btn"]').trigger('click')
|
||||
renderComponent()
|
||||
await userEvent.click(screen.getByTestId('publish-btn'))
|
||||
await flushPromises()
|
||||
|
||||
expect(mockCheckProfile).not.toHaveBeenCalled()
|
||||
@@ -221,11 +226,11 @@ describe('ComfyHubPublishWizardContent', () => {
|
||||
const publishDeferred = createDeferred<void>()
|
||||
onPublish.mockReturnValue(publishDeferred.promise)
|
||||
|
||||
const wrapper = createWrapper()
|
||||
const publishBtn = wrapper.find('[data-testid="publish-btn"]')
|
||||
renderComponent()
|
||||
const publishBtn = screen.getByTestId('publish-btn')
|
||||
|
||||
await publishBtn.trigger('click')
|
||||
await publishBtn.trigger('click')
|
||||
await userEvent.click(publishBtn)
|
||||
await userEvent.click(publishBtn)
|
||||
await flushPromises()
|
||||
|
||||
expect(onPublish).toHaveBeenCalledTimes(1)
|
||||
@@ -238,8 +243,8 @@ describe('ComfyHubPublishWizardContent', () => {
|
||||
const publishError = new Error('Publish failed')
|
||||
onPublish.mockRejectedValueOnce(publishError)
|
||||
|
||||
const wrapper = createWrapper()
|
||||
await wrapper.find('[data-testid="publish-btn"]').trigger('click')
|
||||
renderComponent()
|
||||
await userEvent.click(screen.getByTestId('publish-btn'))
|
||||
await flushPromises()
|
||||
|
||||
expect(onPublish).toHaveBeenCalledOnce()
|
||||
@@ -251,33 +256,33 @@ describe('ComfyHubPublishWizardContent', () => {
|
||||
const publishDeferred = createDeferred<void>()
|
||||
onPublish.mockReturnValue(publishDeferred.promise)
|
||||
|
||||
const wrapper = createWrapper()
|
||||
const publishBtn = wrapper.find('[data-testid="publish-btn"]')
|
||||
renderComponent()
|
||||
const publishBtn = screen.getByTestId('publish-btn')
|
||||
|
||||
await publishBtn.trigger('click')
|
||||
await userEvent.click(publishBtn)
|
||||
await flushPromises()
|
||||
|
||||
const footer = wrapper.find('[data-testid="publish-footer"]')
|
||||
expect(footer.attributes('data-publish-disabled')).toBe('true')
|
||||
expect(footer.attributes('data-is-publishing')).toBe('true')
|
||||
const footer = screen.getByTestId('publish-footer')
|
||||
expect(footer.getAttribute('data-publish-disabled')).toBe('true')
|
||||
expect(footer.getAttribute('data-is-publishing')).toBe('true')
|
||||
|
||||
publishDeferred.resolve(undefined)
|
||||
await flushPromises()
|
||||
|
||||
expect(footer.attributes('data-is-publishing')).toBe('false')
|
||||
expect(footer.getAttribute('data-is-publishing')).toBe('false')
|
||||
})
|
||||
|
||||
it('resets guard after publish error so retry is possible', async () => {
|
||||
onPublish.mockRejectedValueOnce(new Error('Publish failed'))
|
||||
|
||||
const wrapper = createWrapper()
|
||||
const publishBtn = wrapper.find('[data-testid="publish-btn"]')
|
||||
renderComponent()
|
||||
const publishBtn = screen.getByTestId('publish-btn')
|
||||
|
||||
await publishBtn.trigger('click')
|
||||
await userEvent.click(publishBtn)
|
||||
await flushPromises()
|
||||
|
||||
onPublish.mockResolvedValueOnce(undefined)
|
||||
await publishBtn.trigger('click')
|
||||
await userEvent.click(publishBtn)
|
||||
await flushPromises()
|
||||
|
||||
expect(onPublish).toHaveBeenCalledTimes(2)
|
||||
@@ -287,48 +292,42 @@ describe('ComfyHubPublishWizardContent', () => {
|
||||
describe('isPublishDisabled', () => {
|
||||
it('disables publish when gate enabled and hasProfile is not true', () => {
|
||||
mockHasProfile.value = null
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
|
||||
const footer = wrapper.find('[data-testid="publish-footer"]')
|
||||
expect(footer.attributes('data-publish-disabled')).toBe('true')
|
||||
const footer = screen.getByTestId('publish-footer')
|
||||
expect(footer.getAttribute('data-publish-disabled')).toBe('true')
|
||||
})
|
||||
|
||||
it('enables publish when gate enabled and hasProfile is true', async () => {
|
||||
mockHasProfile.value = true
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
await flushPromises()
|
||||
|
||||
const footer = wrapper.find('[data-testid="publish-footer"]')
|
||||
expect(footer.attributes('data-publish-disabled')).toBe('false')
|
||||
const footer = screen.getByTestId('publish-footer')
|
||||
expect(footer.getAttribute('data-publish-disabled')).toBe('false')
|
||||
})
|
||||
|
||||
it('enables publish when gate is disabled regardless of profile', () => {
|
||||
mockFlags.comfyHubProfileGateEnabled = false
|
||||
mockHasProfile.value = null
|
||||
const wrapper = createWrapper()
|
||||
renderComponent()
|
||||
|
||||
const footer = wrapper.find('[data-testid="publish-footer"]')
|
||||
expect(footer.attributes('data-publish-disabled')).toBe('false')
|
||||
const footer = screen.getByTestId('publish-footer')
|
||||
expect(footer.getAttribute('data-publish-disabled')).toBe('false')
|
||||
})
|
||||
})
|
||||
|
||||
describe('profileCreation step rendering', () => {
|
||||
it('shows profile creation form when on profileCreation step', () => {
|
||||
const wrapper = createWrapper({ currentStep: 'profileCreation' })
|
||||
expect(wrapper.find('[data-testid="publish-gate-flow"]').exists()).toBe(
|
||||
true
|
||||
)
|
||||
expect(wrapper.find('[data-testid="publish-footer"]').exists()).toBe(
|
||||
false
|
||||
)
|
||||
renderComponent({ currentStep: 'profileCreation' })
|
||||
expect(screen.getByTestId('publish-gate-flow')).toBeTruthy()
|
||||
expect(screen.queryByTestId('publish-footer')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows wizard content when not on profileCreation step', () => {
|
||||
const wrapper = createWrapper({ currentStep: 'finish' })
|
||||
expect(wrapper.find('[data-testid="publish-gate-flow"]').exists()).toBe(
|
||||
false
|
||||
)
|
||||
expect(wrapper.find('[data-testid="publish-footer"]').exists()).toBe(true)
|
||||
renderComponent({ currentStep: 'finish' })
|
||||
expect(screen.queryByTestId('publish-gate-flow')).not.toBeInTheDocument()
|
||||
expect(screen.getByTestId('publish-footer')).toBeTruthy()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { flushPromises } from '@vue/test-utils'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { useTemplateWorkflows } from '@/platform/workflow/templates/composables/useTemplateWorkflows'
|
||||
import { useWorkflowTemplatesStore } from '@/platform/workflow/templates/repositories/workflowTemplatesStore'
|
||||
|
||||
async function flushPromises() {
|
||||
await new Promise((r) => setTimeout(r, 0))
|
||||
}
|
||||
|
||||
// Mock the store
|
||||
vi.mock(
|
||||
'@/platform/workflow/templates/repositories/workflowTemplatesStore',
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { ref } from 'vue'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
import WorkspaceAuthGate from './WorkspaceAuthGate.vue'
|
||||
|
||||
async function flushPromises() {
|
||||
await new Promise((r) => setTimeout(r, 0))
|
||||
}
|
||||
|
||||
const mockIsInitialized = ref(false)
|
||||
const mockCurrentUser = ref<object | null>(null)
|
||||
|
||||
@@ -80,7 +84,7 @@ describe('WorkspaceAuthGate', () => {
|
||||
const i18n = createI18n({ legacy: false })
|
||||
|
||||
const mountComponent = () =>
|
||||
mount(WorkspaceAuthGate, {
|
||||
render(WorkspaceAuthGate, {
|
||||
global: { plugins: [i18n] },
|
||||
slots: {
|
||||
default: '<div data-testid="slot-content">App Content</div>'
|
||||
@@ -91,10 +95,10 @@ describe('WorkspaceAuthGate', () => {
|
||||
it('renders slot immediately when isCloud is false', async () => {
|
||||
mockIsCloud.value = false
|
||||
|
||||
const wrapper = mountComponent()
|
||||
mountComponent()
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.find('[data-testid="slot-content"]').exists()).toBe(true)
|
||||
expect(screen.getByTestId('slot-content')).toBeInTheDocument()
|
||||
expect(mockRefreshRemoteConfig).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -103,22 +107,22 @@ describe('WorkspaceAuthGate', () => {
|
||||
it('hides slot while waiting for Firebase auth', () => {
|
||||
mockIsInitialized.value = false
|
||||
|
||||
const wrapper = mountComponent()
|
||||
mountComponent()
|
||||
|
||||
expect(wrapper.find('[data-testid="slot-content"]').exists()).toBe(false)
|
||||
expect(screen.queryByTestId('slot-content')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders slot when Firebase initializes with no user', async () => {
|
||||
mockIsInitialized.value = false
|
||||
|
||||
const wrapper = mountComponent()
|
||||
expect(wrapper.find('[data-testid="slot-content"]').exists()).toBe(false)
|
||||
mountComponent()
|
||||
expect(screen.queryByTestId('slot-content')).not.toBeInTheDocument()
|
||||
|
||||
mockIsInitialized.value = true
|
||||
mockCurrentUser.value = null
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.find('[data-testid="slot-content"]').exists()).toBe(true)
|
||||
expect(screen.getByTestId('slot-content')).toBeInTheDocument()
|
||||
expect(mockRefreshRemoteConfig).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -139,21 +143,21 @@ describe('WorkspaceAuthGate', () => {
|
||||
it('renders slot when teamWorkspacesEnabled is false', async () => {
|
||||
mockTeamWorkspacesEnabled.value = false
|
||||
|
||||
const wrapper = mountComponent()
|
||||
mountComponent()
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.find('[data-testid="slot-content"]').exists()).toBe(true)
|
||||
expect(screen.getByTestId('slot-content')).toBeInTheDocument()
|
||||
expect(mockWorkspaceStoreInitialize).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('initializes workspace store when teamWorkspacesEnabled is true', async () => {
|
||||
mockTeamWorkspacesEnabled.value = true
|
||||
|
||||
const wrapper = mountComponent()
|
||||
mountComponent()
|
||||
await flushPromises()
|
||||
|
||||
expect(mockWorkspaceStoreInitialize).toHaveBeenCalled()
|
||||
expect(wrapper.find('[data-testid="slot-content"]').exists()).toBe(true)
|
||||
expect(screen.getByTestId('slot-content')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('calls resumePendingPricingFlow after successful workspace init', async () => {
|
||||
@@ -170,11 +174,11 @@ describe('WorkspaceAuthGate', () => {
|
||||
mockTeamWorkspacesEnabled.value = true
|
||||
mockWorkspaceStoreInitState.value = 'ready'
|
||||
|
||||
const wrapper = mountComponent()
|
||||
mountComponent()
|
||||
await flushPromises()
|
||||
|
||||
expect(mockWorkspaceStoreInitialize).not.toHaveBeenCalled()
|
||||
expect(wrapper.find('[data-testid="slot-content"]').exists()).toBe(true)
|
||||
expect(screen.getByTestId('slot-content')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -187,30 +191,32 @@ describe('WorkspaceAuthGate', () => {
|
||||
it('renders slot when remote config refresh fails', async () => {
|
||||
mockRefreshRemoteConfig.mockRejectedValue(new Error('Network error'))
|
||||
|
||||
const wrapper = mountComponent()
|
||||
mountComponent()
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.find('[data-testid="slot-content"]').exists()).toBe(true)
|
||||
expect(screen.getByTestId('slot-content')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders slot when remote config refresh times out', async () => {
|
||||
vi.useFakeTimers()
|
||||
// Never-resolving promise simulates a hanging request
|
||||
mockRefreshRemoteConfig.mockReturnValue(new Promise(() => {}))
|
||||
try {
|
||||
// Never-resolving promise simulates a hanging request
|
||||
mockRefreshRemoteConfig.mockReturnValue(new Promise(() => {}))
|
||||
|
||||
const wrapper = mountComponent()
|
||||
await flushPromises()
|
||||
mountComponent()
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
|
||||
// Slot not yet rendered before timeout
|
||||
expect(wrapper.find('[data-testid="slot-content"]').exists()).toBe(false)
|
||||
// Slot not yet rendered before timeout
|
||||
expect(screen.queryByTestId('slot-content')).not.toBeInTheDocument()
|
||||
|
||||
// Advance past the 10 second timeout
|
||||
await vi.advanceTimersByTimeAsync(10_001)
|
||||
await flushPromises()
|
||||
// Advance past the 10 second timeout
|
||||
await vi.advanceTimersByTimeAsync(10_001)
|
||||
|
||||
// Should render slot after timeout (graceful degradation)
|
||||
expect(wrapper.find('[data-testid="slot-content"]').exists()).toBe(true)
|
||||
vi.useRealTimers()
|
||||
// Should render slot after timeout (graceful degradation)
|
||||
expect(screen.getByTestId('slot-content')).toBeInTheDocument()
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
|
||||
it('renders slot when workspace store initialization fails', async () => {
|
||||
@@ -219,10 +225,10 @@ describe('WorkspaceAuthGate', () => {
|
||||
new Error('Workspace init failed')
|
||||
)
|
||||
|
||||
const wrapper = mountComponent()
|
||||
mountComponent()
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.find('[data-testid="slot-content"]').exists()).toBe(true)
|
||||
expect(screen.getByTestId('slot-content')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
/* eslint-disable testing-library/no-container */
|
||||
/* eslint-disable testing-library/no-node-access */
|
||||
import { render } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
import { nextTick } from 'vue'
|
||||
|
||||
import TeamWorkspacesDialogContent from './TeamWorkspacesDialogContent.vue'
|
||||
|
||||
const flushPromises = () =>
|
||||
new Promise<void>((resolve) => setTimeout(resolve, 0))
|
||||
|
||||
const mockCloseDialog = vi.fn()
|
||||
const mockToastAdd = vi.fn()
|
||||
const mockSwitchWorkspace = vi.fn()
|
||||
@@ -71,14 +77,14 @@ const i18n = createI18n({
|
||||
const ButtonStub = {
|
||||
name: 'Button',
|
||||
template:
|
||||
'<button :disabled="disabled" @click="$emit(\'click\')"><slot /></button>',
|
||||
'<button :disabled="disabled" :data-loading="loading" @click="$emit(\'click\')"><slot /></button>',
|
||||
props: ['disabled', 'loading', 'variant', 'size']
|
||||
}
|
||||
|
||||
function mountComponent(props: Record<string, unknown> = {}) {
|
||||
return mount(TeamWorkspacesDialogContent, {
|
||||
const user = userEvent.setup()
|
||||
const { container } = render(TeamWorkspacesDialogContent, {
|
||||
props,
|
||||
shallow: true,
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
stubs: {
|
||||
@@ -87,10 +93,14 @@ function mountComponent(props: Record<string, unknown> = {}) {
|
||||
}
|
||||
}
|
||||
})
|
||||
return { container, user }
|
||||
}
|
||||
|
||||
function findCreateButton(wrapper: ReturnType<typeof mountComponent>) {
|
||||
return wrapper.findComponent(ButtonStub)
|
||||
function findCreateButton(container: Element): HTMLButtonElement {
|
||||
const buttons = container.querySelectorAll('button')
|
||||
return Array.from(buttons).find(
|
||||
(btn) => !btn.closest('header') && !btn.closest('li')
|
||||
) as HTMLButtonElement
|
||||
}
|
||||
|
||||
function setOwnedWorkspaces() {
|
||||
@@ -123,35 +133,37 @@ describe('TeamWorkspacesDialogContent', () => {
|
||||
describe('workspace listing', () => {
|
||||
it('displays only owned workspaces', () => {
|
||||
setOwnedWorkspaces()
|
||||
const wrapper = mountComponent()
|
||||
const items = wrapper.findAll('li')
|
||||
const { container } = mountComponent()
|
||||
const items = container.querySelectorAll('li')
|
||||
expect(items).toHaveLength(1)
|
||||
expect(wrapper.text()).toContain('Team Alpha')
|
||||
expect(wrapper.text()).not.toContain('Team Beta')
|
||||
expect(container.textContent).toContain('Team Alpha')
|
||||
expect(container.textContent).not.toContain('Team Beta')
|
||||
})
|
||||
|
||||
it('shows tier label for subscribed workspaces', () => {
|
||||
setOwnedWorkspaces()
|
||||
const wrapper = mountComponent()
|
||||
expect(wrapper.text()).toContain('Pro')
|
||||
const { container } = mountComponent()
|
||||
expect(container.textContent).toContain('Pro')
|
||||
})
|
||||
|
||||
it('hides workspace list section when no owned workspaces', () => {
|
||||
const wrapper = mountComponent()
|
||||
expect(wrapper.findAll('li')).toHaveLength(0)
|
||||
const { container } = mountComponent()
|
||||
expect(container.querySelectorAll('li')).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('shows create-only subtitle when no owned workspaces', () => {
|
||||
const wrapper = mountComponent()
|
||||
const subtitle = wrapper.find('header p')
|
||||
expect(subtitle.text()).toBe('teamWorkspacesDialog.subtitleNoWorkspaces')
|
||||
const { container } = mountComponent()
|
||||
const subtitle = container.querySelector('header p')
|
||||
expect(subtitle?.textContent).toBe(
|
||||
'teamWorkspacesDialog.subtitleNoWorkspaces'
|
||||
)
|
||||
})
|
||||
|
||||
it('shows switch-or-create subtitle when owned workspaces exist', () => {
|
||||
setOwnedWorkspaces()
|
||||
const wrapper = mountComponent()
|
||||
const subtitle = wrapper.find('header p')
|
||||
expect(subtitle.text()).toBe('teamWorkspacesDialog.subtitle')
|
||||
const { container } = mountComponent()
|
||||
const subtitle = container.querySelector('header p')
|
||||
expect(subtitle?.textContent).toBe('teamWorkspacesDialog.subtitle')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -159,10 +171,10 @@ describe('TeamWorkspacesDialogContent', () => {
|
||||
it('calls switchWorkspace with workspace id and closes dialog on success', async () => {
|
||||
mockSwitchWorkspace.mockResolvedValue(true)
|
||||
setOwnedWorkspaces()
|
||||
const wrapper = mountComponent()
|
||||
const { container, user } = mountComponent()
|
||||
|
||||
const switchButton = wrapper.find('li button')
|
||||
await switchButton.trigger('click')
|
||||
const switchButton = container.querySelector('li button')!
|
||||
await user.click(switchButton)
|
||||
await flushPromises()
|
||||
|
||||
expect(mockSwitchWorkspace).toHaveBeenCalledWith('ws-1')
|
||||
@@ -174,10 +186,10 @@ describe('TeamWorkspacesDialogContent', () => {
|
||||
it('shows error toast and keeps dialog open when switch fails', async () => {
|
||||
mockSwitchWorkspace.mockRejectedValue(new Error('Network error'))
|
||||
setOwnedWorkspaces()
|
||||
const wrapper = mountComponent()
|
||||
const { container, user } = mountComponent()
|
||||
|
||||
const switchButton = wrapper.find('li button')
|
||||
await switchButton.trigger('click')
|
||||
const switchButton = container.querySelector('li button')!
|
||||
await user.click(switchButton)
|
||||
await flushPromises()
|
||||
|
||||
expect(mockCloseDialog).not.toHaveBeenCalled()
|
||||
@@ -192,55 +204,68 @@ describe('TeamWorkspacesDialogContent', () => {
|
||||
|
||||
describe('name validation', () => {
|
||||
it('disables create button for empty name', () => {
|
||||
const wrapper = mountComponent()
|
||||
expect(findCreateButton(wrapper).props('disabled')).toBe(true)
|
||||
const { container } = mountComponent()
|
||||
expect(findCreateButton(container)).toBeDisabled()
|
||||
})
|
||||
|
||||
it('enables create button for valid name', async () => {
|
||||
const wrapper = mountComponent()
|
||||
const input = wrapper.find('#workspace-name-input')
|
||||
await input.setValue('My Team')
|
||||
const { container, user } = mountComponent()
|
||||
const input = container.querySelector(
|
||||
'#workspace-name-input'
|
||||
) as HTMLInputElement
|
||||
await user.clear(input)
|
||||
await user.type(input, 'My Team')
|
||||
await nextTick()
|
||||
|
||||
expect(findCreateButton(wrapper).props('disabled')).toBe(false)
|
||||
expect(findCreateButton(container)).not.toBeDisabled()
|
||||
})
|
||||
|
||||
it('disables create button for name with special characters', async () => {
|
||||
const wrapper = mountComponent()
|
||||
const input = wrapper.find('#workspace-name-input')
|
||||
await input.setValue('!@#$%')
|
||||
const { container, user } = mountComponent()
|
||||
const input = container.querySelector(
|
||||
'#workspace-name-input'
|
||||
) as HTMLInputElement
|
||||
await user.clear(input)
|
||||
await user.type(input, '!@#$%')
|
||||
await nextTick()
|
||||
|
||||
expect(findCreateButton(wrapper).props('disabled')).toBe(true)
|
||||
expect(findCreateButton(container)).toBeDisabled()
|
||||
})
|
||||
|
||||
it('disables create button for name exceeding 50 characters', async () => {
|
||||
const wrapper = mountComponent()
|
||||
const input = wrapper.find('#workspace-name-input')
|
||||
await input.setValue('a'.repeat(51))
|
||||
const { container, user } = mountComponent()
|
||||
const input = container.querySelector(
|
||||
'#workspace-name-input'
|
||||
) as HTMLInputElement
|
||||
await user.clear(input)
|
||||
await user.type(input, 'a'.repeat(51))
|
||||
await nextTick()
|
||||
|
||||
expect(findCreateButton(wrapper).props('disabled')).toBe(true)
|
||||
expect(findCreateButton(container)).toBeDisabled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('workspace creation', () => {
|
||||
async function typeAndCreate(
|
||||
wrapper: ReturnType<typeof mountComponent>,
|
||||
container: Element,
|
||||
user: ReturnType<typeof userEvent.setup>,
|
||||
name: string
|
||||
) {
|
||||
await wrapper.find('#workspace-name-input').setValue(name)
|
||||
await nextTick()
|
||||
findCreateButton(wrapper).vm.$emit('click')
|
||||
const input = container.querySelector(
|
||||
'#workspace-name-input'
|
||||
) as HTMLInputElement
|
||||
await user.clear(input)
|
||||
await user.type(input, name)
|
||||
await user.click(findCreateButton(container))
|
||||
await flushPromises()
|
||||
}
|
||||
|
||||
it('calls createWorkspace and onConfirm on success', async () => {
|
||||
mockCreateWorkspace.mockResolvedValue({ id: 'new-ws' })
|
||||
const onConfirm = vi.fn()
|
||||
const wrapper = mountComponent({ onConfirm })
|
||||
const { container, user } = mountComponent({ onConfirm })
|
||||
|
||||
await typeAndCreate(wrapper, 'New Team')
|
||||
await typeAndCreate(container, user, 'New Team')
|
||||
|
||||
expect(mockCreateWorkspace).toHaveBeenCalledWith('New Team')
|
||||
expect(onConfirm).toHaveBeenCalledWith('New Team')
|
||||
@@ -251,9 +276,9 @@ describe('TeamWorkspacesDialogContent', () => {
|
||||
|
||||
it('shows error toast when creation fails', async () => {
|
||||
mockCreateWorkspace.mockRejectedValue(new Error('Limit reached'))
|
||||
const wrapper = mountComponent()
|
||||
const { container, user } = mountComponent()
|
||||
|
||||
await typeAndCreate(wrapper, 'New Team')
|
||||
await typeAndCreate(container, user, 'New Team')
|
||||
|
||||
expect(mockToastAdd).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
@@ -267,9 +292,9 @@ describe('TeamWorkspacesDialogContent', () => {
|
||||
it('shows separate toast when onConfirm fails but still closes dialog', async () => {
|
||||
mockCreateWorkspace.mockResolvedValue({ id: 'new-ws' })
|
||||
const onConfirm = vi.fn().mockRejectedValue(new Error('Setup failed'))
|
||||
const wrapper = mountComponent({ onConfirm })
|
||||
const { container, user } = mountComponent({ onConfirm })
|
||||
|
||||
await typeAndCreate(wrapper, 'New Team')
|
||||
await typeAndCreate(container, user, 'New Team')
|
||||
|
||||
expect(mockCreateWorkspace).toHaveBeenCalledWith('New Team')
|
||||
expect(mockToastAdd).toHaveBeenCalledWith(
|
||||
@@ -286,16 +311,16 @@ describe('TeamWorkspacesDialogContent', () => {
|
||||
it('does not call onConfirm when createWorkspace fails', async () => {
|
||||
mockCreateWorkspace.mockRejectedValue(new Error('Limit reached'))
|
||||
const onConfirm = vi.fn()
|
||||
const wrapper = mountComponent({ onConfirm })
|
||||
const { container, user } = mountComponent({ onConfirm })
|
||||
|
||||
await typeAndCreate(wrapper, 'New Team')
|
||||
await typeAndCreate(container, user, 'New Team')
|
||||
|
||||
expect(onConfirm).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not call createWorkspace when name is invalid', async () => {
|
||||
const wrapper = mountComponent()
|
||||
findCreateButton(wrapper).vm.$emit('click')
|
||||
const { container, user } = mountComponent()
|
||||
await user.click(findCreateButton(container))
|
||||
await nextTick()
|
||||
|
||||
expect(mockCreateWorkspace).not.toHaveBeenCalled()
|
||||
@@ -303,29 +328,29 @@ describe('TeamWorkspacesDialogContent', () => {
|
||||
|
||||
it('resets loading state after createWorkspace fails', async () => {
|
||||
mockCreateWorkspace.mockRejectedValue(new Error('Limit reached'))
|
||||
const wrapper = mountComponent()
|
||||
const { container, user } = mountComponent()
|
||||
|
||||
await typeAndCreate(wrapper, 'New Team')
|
||||
await typeAndCreate(container, user, 'New Team')
|
||||
|
||||
expect(findCreateButton(wrapper).props('loading')).toBe(false)
|
||||
expect(findCreateButton(container).dataset.loading).toBe('false')
|
||||
})
|
||||
|
||||
it('resets loading state after onConfirm fails', async () => {
|
||||
mockCreateWorkspace.mockResolvedValue({ id: 'new-ws' })
|
||||
const onConfirm = vi.fn().mockRejectedValue(new Error('Setup failed'))
|
||||
const wrapper = mountComponent({ onConfirm })
|
||||
const { container, user } = mountComponent({ onConfirm })
|
||||
|
||||
await typeAndCreate(wrapper, 'New Team')
|
||||
await typeAndCreate(container, user, 'New Team')
|
||||
|
||||
expect(findCreateButton(wrapper).props('loading')).toBe(false)
|
||||
expect(findCreateButton(container).dataset.loading).toBe('false')
|
||||
})
|
||||
})
|
||||
|
||||
describe('close button', () => {
|
||||
it('closes dialog on close button click', async () => {
|
||||
const wrapper = mountComponent()
|
||||
const closeBtn = wrapper.find('header button')
|
||||
await closeBtn.trigger('click')
|
||||
const { container, user } = mountComponent()
|
||||
const closeBtn = container.querySelector('header button')!
|
||||
await user.click(closeBtn)
|
||||
|
||||
expect(mockCloseDialog).toHaveBeenCalledWith({
|
||||
key: 'team-workspaces'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { fireEvent, render, screen } from '@testing-library/vue'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { computed, nextTick } from 'vue'
|
||||
|
||||
@@ -46,21 +46,18 @@ describe('TransformPane', () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers()
|
||||
vi.resetAllMocks()
|
||||
|
||||
// Create mock canvas with LiteGraph interface
|
||||
})
|
||||
|
||||
describe('component mounting', () => {
|
||||
it('should mount successfully with minimal props', () => {
|
||||
const mockCanvas = createMockLGraphCanvas()
|
||||
const wrapper = mount(TransformPane, {
|
||||
render(TransformPane, {
|
||||
props: {
|
||||
canvas: mockCanvas
|
||||
}
|
||||
})
|
||||
|
||||
expect(wrapper.exists()).toBe(true)
|
||||
expect(wrapper.find('[data-testid="transform-pane"]').exists()).toBe(true)
|
||||
expect(screen.getByTestId('transform-pane')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should apply transform style from composable', async () => {
|
||||
@@ -70,21 +67,22 @@ describe('TransformPane', () => {
|
||||
}
|
||||
|
||||
const mockCanvas = createMockLGraphCanvas()
|
||||
const wrapper = mount(TransformPane, {
|
||||
render(TransformPane, {
|
||||
props: {
|
||||
canvas: mockCanvas
|
||||
}
|
||||
})
|
||||
await nextTick()
|
||||
|
||||
const transformPane = wrapper.find('[data-testid="transform-pane"]')
|
||||
const style = transformPane.attributes('style')
|
||||
expect(style).toContain('transform: scale(2) translate(100px, 50px)')
|
||||
const transformPane = screen.getByTestId('transform-pane')
|
||||
expect(transformPane.getAttribute('style')).toContain(
|
||||
'transform: scale(2) translate(100px, 50px)'
|
||||
)
|
||||
})
|
||||
|
||||
it('should render slot content', () => {
|
||||
const mockCanvas = createMockLGraphCanvas()
|
||||
const wrapper = mount(TransformPane, {
|
||||
render(TransformPane, {
|
||||
props: {
|
||||
canvas: mockCanvas
|
||||
},
|
||||
@@ -93,15 +91,14 @@ describe('TransformPane', () => {
|
||||
}
|
||||
})
|
||||
|
||||
expect(wrapper.find('.test-content').exists()).toBe(true)
|
||||
expect(wrapper.find('.test-content').text()).toBe('Test Node')
|
||||
expect(screen.getByText('Test Node')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('RAF synchronization', () => {
|
||||
it('should call syncWithCanvas during RAF updates', async () => {
|
||||
const mockCanvas = createMockLGraphCanvas()
|
||||
mount(TransformPane, {
|
||||
render(TransformPane, {
|
||||
props: {
|
||||
canvas: mockCanvas
|
||||
}
|
||||
@@ -109,7 +106,6 @@ describe('TransformPane', () => {
|
||||
|
||||
await nextTick()
|
||||
|
||||
// Allow RAF to execute
|
||||
vi.advanceTimersToNextFrame()
|
||||
|
||||
const transformState = useTransformState()
|
||||
@@ -120,7 +116,7 @@ describe('TransformPane', () => {
|
||||
describe('canvas event listeners', () => {
|
||||
it('should add event listeners to canvas on mount', async () => {
|
||||
const mockCanvas = createMockLGraphCanvas()
|
||||
mount(TransformPane, {
|
||||
render(TransformPane, {
|
||||
props: {
|
||||
canvas: mockCanvas
|
||||
}
|
||||
@@ -137,14 +133,14 @@ describe('TransformPane', () => {
|
||||
|
||||
it('should remove event listeners on unmount', async () => {
|
||||
const mockCanvas = createMockLGraphCanvas()
|
||||
const wrapper = mount(TransformPane, {
|
||||
const { unmount } = render(TransformPane, {
|
||||
props: {
|
||||
canvas: mockCanvas
|
||||
}
|
||||
})
|
||||
|
||||
await nextTick()
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
|
||||
expect(mockCanvas.canvas.removeEventListener).toHaveBeenCalledWith(
|
||||
'wheel',
|
||||
@@ -157,36 +153,32 @@ describe('TransformPane', () => {
|
||||
describe('interaction state management', () => {
|
||||
it('should handle pointer events for node delegation', async () => {
|
||||
const mockCanvas = createMockLGraphCanvas()
|
||||
const wrapper = mount(TransformPane, {
|
||||
render(TransformPane, {
|
||||
props: {
|
||||
canvas: mockCanvas
|
||||
}
|
||||
})
|
||||
|
||||
const transformPane = wrapper.find('[data-testid="transform-pane"]')
|
||||
const transformPane = screen.getByTestId('transform-pane')
|
||||
|
||||
// Simulate pointer down - we can't test the exact delegation logic
|
||||
// in unit tests due to vue-test-utils limitations, but we can verify
|
||||
// the event handler is set up correctly
|
||||
await transformPane.trigger('pointerdown')
|
||||
/* eslint-disable testing-library/prefer-user-event -- pointerDown for delegation, not a click */
|
||||
await fireEvent.pointerDown(transformPane)
|
||||
/* eslint-enable testing-library/prefer-user-event */
|
||||
|
||||
// The test passes if no errors are thrown during event handling
|
||||
expect(transformPane.exists()).toBe(true)
|
||||
expect(transformPane).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('transform state integration', () => {
|
||||
it('should provide transform utilities to child components', () => {
|
||||
const mockCanvas = createMockLGraphCanvas()
|
||||
mount(TransformPane, {
|
||||
render(TransformPane, {
|
||||
props: {
|
||||
canvas: mockCanvas
|
||||
}
|
||||
})
|
||||
|
||||
const transformState = useTransformState()
|
||||
// The component should provide transform state via Vue's provide/inject
|
||||
// This is tested indirectly through the composable integration
|
||||
expect(transformState.syncWithCanvas).toBeDefined()
|
||||
expect(transformState.canvasToScreen).toBeDefined()
|
||||
expect(transformState.screenToCanvas).toBeDefined()
|
||||
@@ -195,14 +187,13 @@ describe('TransformPane', () => {
|
||||
|
||||
describe('error handling', () => {
|
||||
it('should handle null canvas gracefully', () => {
|
||||
const wrapper = mount(TransformPane, {
|
||||
render(TransformPane, {
|
||||
props: {
|
||||
canvas: undefined
|
||||
}
|
||||
})
|
||||
|
||||
expect(wrapper.exists()).toBe(true)
|
||||
expect(wrapper.find('[data-testid="transform-pane"]').exists()).toBe(true)
|
||||
expect(screen.getByTestId('transform-pane')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render } from '@testing-library/vue'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { defineComponent } from 'vue'
|
||||
|
||||
@@ -41,9 +41,12 @@ vi.mock('@/renderer/core/layout/store/layoutStore', () => ({
|
||||
|
||||
import { useLayoutSync } from '@/renderer/core/layout/sync/useLayoutSync'
|
||||
|
||||
let syncApi: ReturnType<typeof useLayoutSync>
|
||||
|
||||
const LayoutSyncHarness = defineComponent({
|
||||
setup() {
|
||||
return useLayoutSync()
|
||||
syncApi = useLayoutSync()
|
||||
return syncApi
|
||||
},
|
||||
template: '<div />'
|
||||
})
|
||||
@@ -85,9 +88,9 @@ describe('useLayoutSync', () => {
|
||||
size: { width: 120, height: 70 }
|
||||
})
|
||||
|
||||
const wrapper = mount(LayoutSyncHarness)
|
||||
const { unmount } = render(LayoutSyncHarness)
|
||||
|
||||
wrapper.vm.startSync(canvas as never)
|
||||
syncApi.startSync(canvas as never)
|
||||
|
||||
testState.listener?.({ nodeIds: ['1'], source: LayoutSource.External })
|
||||
testState.listener?.({ nodeIds: ['1'], source: LayoutSource.External })
|
||||
@@ -102,7 +105,7 @@ describe('useLayoutSync', () => {
|
||||
expect(liteNode.pos).toEqual([10, 15])
|
||||
expect(liteNode.size).toEqual([120, 70])
|
||||
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
})
|
||||
|
||||
it('flushes interactive updates in a microtask without waiting for raf', () => {
|
||||
@@ -123,9 +126,9 @@ describe('useLayoutSync', () => {
|
||||
size: { width: 120, height: 70 }
|
||||
})
|
||||
|
||||
const wrapper = mount(LayoutSyncHarness)
|
||||
const { unmount } = render(LayoutSyncHarness)
|
||||
|
||||
wrapper.vm.startSync(canvas as never)
|
||||
syncApi.startSync(canvas as never)
|
||||
testState.listener?.({ nodeIds: ['1'], source: LayoutSource.Vue })
|
||||
|
||||
expect(testState.rafCallback).toBeNull()
|
||||
@@ -136,7 +139,7 @@ describe('useLayoutSync', () => {
|
||||
expect(canvas.setDirty).toHaveBeenCalledTimes(1)
|
||||
expect(liteNode.pos).toEqual([20, 30])
|
||||
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
})
|
||||
|
||||
it('promotes queued raf work to microtask when interactive changes arrive', () => {
|
||||
@@ -156,9 +159,9 @@ describe('useLayoutSync', () => {
|
||||
size: { width: 100, height: 50 }
|
||||
})
|
||||
|
||||
const wrapper = mount(LayoutSyncHarness)
|
||||
const { unmount } = render(LayoutSyncHarness)
|
||||
|
||||
wrapper.vm.startSync(canvas as never)
|
||||
syncApi.startSync(canvas as never)
|
||||
testState.listener?.({ nodeIds: ['1'], source: LayoutSource.External })
|
||||
expect(testState.rafCallback).toBeTruthy()
|
||||
|
||||
@@ -167,6 +170,6 @@ describe('useLayoutSync', () => {
|
||||
expect(testState.cancelAnimationFrame).toHaveBeenCalledWith(1)
|
||||
expect(testState.microtaskCallback).toBeTruthy()
|
||||
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render } from '@testing-library/vue'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { nextTick, ref } from 'vue'
|
||||
|
||||
@@ -169,11 +169,11 @@ describe('useTransformSettling', () => {
|
||||
template: '<div>{{ isTransforming }}</div>'
|
||||
}
|
||||
|
||||
const wrapper = mount(TestComponent)
|
||||
const { unmount } = render(TestComponent)
|
||||
await nextTick()
|
||||
|
||||
// Unmount component
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
|
||||
// Should have removed wheel event listener
|
||||
expect(removeEventListenerSpy).toHaveBeenCalledWith(
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { createTestingPinia } from '@pinia/testing'
|
||||
import { shallowMount } from '@vue/test-utils'
|
||||
import { setActivePinia } from 'pinia'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
|
||||
import OutputHistoryActiveQueueItem from './OutputHistoryActiveQueueItem.vue'
|
||||
|
||||
const i18n = createI18n({ legacy: false, locale: 'en' })
|
||||
@@ -15,8 +16,8 @@ vi.mock('@/stores/commandStore', () => ({
|
||||
})
|
||||
}))
|
||||
|
||||
function mountComponent(queueCount: number) {
|
||||
return shallowMount(OutputHistoryActiveQueueItem, {
|
||||
function renderComponent(queueCount: number) {
|
||||
return render(OutputHistoryActiveQueueItem, {
|
||||
props: { queueCount },
|
||||
global: { plugins: [i18n] }
|
||||
})
|
||||
@@ -24,21 +25,17 @@ function mountComponent(queueCount: number) {
|
||||
|
||||
describe('OutputHistoryActiveQueueItem', () => {
|
||||
it('hides badge when queueCount is 1', () => {
|
||||
const wrapper = mountComponent(1)
|
||||
const badge = wrapper.find('[aria-hidden="true"]')
|
||||
expect(badge.exists()).toBe(false)
|
||||
renderComponent(1)
|
||||
expect(screen.queryByText('1')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows badge with correct count when queueCount is 3', () => {
|
||||
const wrapper = mountComponent(3)
|
||||
const badge = wrapper.find('[aria-hidden="true"]')
|
||||
expect(badge.exists()).toBe(true)
|
||||
expect(badge.text()).toBe('3')
|
||||
renderComponent(3)
|
||||
expect(screen.getByText('3')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('hides badge when queueCount is 0', () => {
|
||||
const wrapper = mountComponent(0)
|
||||
const badge = wrapper.find('[aria-hidden="true"]')
|
||||
expect(badge.exists()).toBe(false)
|
||||
renderComponent(0)
|
||||
expect(screen.queryByText('0')).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { nextTick } from 'vue'
|
||||
|
||||
import { render } from '@testing-library/vue'
|
||||
|
||||
const initializeStandaloneViewer = vi.fn()
|
||||
const cleanup = vi.fn()
|
||||
|
||||
@@ -44,20 +45,20 @@ describe('Preview3d', () => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
async function mountPreview3d(
|
||||
async function renderPreview3d(
|
||||
modelUrl = 'http://localhost/view?filename=model.glb'
|
||||
) {
|
||||
const wrapper = mount(
|
||||
const result = render(
|
||||
(await import('@/renderer/extensions/linearMode/Preview3d.vue')).default,
|
||||
{ props: { modelUrl } }
|
||||
)
|
||||
await nextTick()
|
||||
await nextTick()
|
||||
return wrapper
|
||||
return result
|
||||
}
|
||||
|
||||
it('initializes the viewer on mount', async () => {
|
||||
const wrapper = await mountPreview3d()
|
||||
const { unmount } = await renderPreview3d()
|
||||
|
||||
expect(initializeStandaloneViewer).toHaveBeenCalledOnce()
|
||||
expect(initializeStandaloneViewer).toHaveBeenCalledWith(
|
||||
@@ -65,14 +66,14 @@ describe('Preview3d', () => {
|
||||
'http://localhost/view?filename=model.glb'
|
||||
)
|
||||
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
})
|
||||
|
||||
it('cleans up the viewer on unmount', async () => {
|
||||
const wrapper = await mountPreview3d()
|
||||
const { unmount } = await renderPreview3d()
|
||||
cleanup.mockClear()
|
||||
|
||||
wrapper.unmount()
|
||||
unmount()
|
||||
|
||||
expect(cleanup).toHaveBeenCalledOnce()
|
||||
})
|
||||
@@ -80,16 +81,16 @@ describe('Preview3d', () => {
|
||||
it('reinitializes correctly after unmount and remount', async () => {
|
||||
const url = 'http://localhost/view?filename=model.glb'
|
||||
|
||||
const wrapper1 = await mountPreview3d(url)
|
||||
const result1 = await renderPreview3d(url)
|
||||
expect(initializeStandaloneViewer).toHaveBeenCalledTimes(1)
|
||||
|
||||
cleanup.mockClear()
|
||||
wrapper1.unmount()
|
||||
result1.unmount()
|
||||
expect(cleanup).toHaveBeenCalledOnce()
|
||||
|
||||
vi.clearAllMocks()
|
||||
|
||||
const wrapper2 = await mountPreview3d(url)
|
||||
const result2 = await renderPreview3d(url)
|
||||
expect(initializeStandaloneViewer).toHaveBeenCalledTimes(1)
|
||||
expect(initializeStandaloneViewer).toHaveBeenCalledWith(
|
||||
expect.any(HTMLElement),
|
||||
@@ -97,19 +98,19 @@ describe('Preview3d', () => {
|
||||
)
|
||||
|
||||
cleanup.mockClear()
|
||||
wrapper2.unmount()
|
||||
result2.unmount()
|
||||
expect(cleanup).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it('reinitializes when modelUrl changes on existing instance', async () => {
|
||||
const wrapper = await mountPreview3d(
|
||||
const result = await renderPreview3d(
|
||||
'http://localhost/view?filename=model-a.glb'
|
||||
)
|
||||
expect(initializeStandaloneViewer).toHaveBeenCalledOnce()
|
||||
|
||||
vi.clearAllMocks()
|
||||
|
||||
await wrapper.setProps({
|
||||
await result.rerender({
|
||||
modelUrl: 'http://localhost/view?filename=model-b.glb'
|
||||
})
|
||||
await nextTick()
|
||||
@@ -122,6 +123,6 @@ describe('Preview3d', () => {
|
||||
'http://localhost/view?filename=model-b.glb'
|
||||
)
|
||||
|
||||
wrapper.unmount()
|
||||
result.unmount()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { createTestingPinia } from '@pinia/testing'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { fireEvent, render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { nextTick } from 'vue'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
@@ -44,10 +45,10 @@ describe('VideoPreview', () => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
function mountVideoPreview(
|
||||
function renderVideoPreview(
|
||||
props: Partial<ComponentProps<typeof VideoPreview>> = {}
|
||||
) {
|
||||
return mount(VideoPreview, {
|
||||
return render(VideoPreview, {
|
||||
props: { ...defaultProps, ...props } as ComponentProps<
|
||||
typeof VideoPreview
|
||||
>,
|
||||
@@ -63,44 +64,62 @@ describe('VideoPreview', () => {
|
||||
describe('batch cycling with identical URLs', () => {
|
||||
it('should not enter persistent loading state when cycling through identical videos', async () => {
|
||||
const sameUrl = '/api/view?filename=test.mp4&type=output'
|
||||
const wrapper = mountVideoPreview({
|
||||
const { container } = renderVideoPreview({
|
||||
imageUrls: [sameUrl, sameUrl, sameUrl]
|
||||
})
|
||||
const user = userEvent.setup()
|
||||
|
||||
// Simulate initial video load
|
||||
await wrapper.find('video').trigger('loadeddata')
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
const videoEl = container.querySelector('video')
|
||||
expect(videoEl).not.toBeNull()
|
||||
await fireEvent.loadedData(videoEl!)
|
||||
await nextTick()
|
||||
expect(wrapper.find('[aria-busy="true"]').exists()).toBe(false)
|
||||
expect(
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
container.querySelector('[aria-busy="true"]')
|
||||
).not.toBeInTheDocument()
|
||||
|
||||
// Click second navigation dot to cycle to identical URL
|
||||
const dots = wrapper.findAll('[aria-label^="View video"]')
|
||||
await dots[1].trigger('click')
|
||||
const dots = screen.getAllByRole('button', { name: /^View video/ })
|
||||
await user.click(dots[1])
|
||||
await nextTick()
|
||||
|
||||
// Should NOT be in loading state since URL didn't change
|
||||
expect(wrapper.find('[aria-busy="true"]').exists()).toBe(false)
|
||||
expect(
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
container.querySelector('[aria-busy="true"]')
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should show loader when cycling to a different URL', async () => {
|
||||
const wrapper = mountVideoPreview({
|
||||
const { container } = renderVideoPreview({
|
||||
imageUrls: [
|
||||
'/api/view?filename=a.mp4&type=output',
|
||||
'/api/view?filename=b.mp4&type=output'
|
||||
]
|
||||
})
|
||||
const user = userEvent.setup()
|
||||
|
||||
// Simulate initial video load
|
||||
await wrapper.find('video').trigger('loadeddata')
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
const videoEl = container.querySelector('video')
|
||||
expect(videoEl).not.toBeNull()
|
||||
await fireEvent.loadedData(videoEl!)
|
||||
await nextTick()
|
||||
expect(wrapper.find('[aria-busy="true"]').exists()).toBe(false)
|
||||
expect(
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
container.querySelector('[aria-busy="true"]')
|
||||
).not.toBeInTheDocument()
|
||||
|
||||
// Click second dot — different URL
|
||||
const dots = wrapper.findAll('[aria-label^="View video"]')
|
||||
await dots[1].trigger('click')
|
||||
const dots = screen.getAllByRole('button', { name: /^View video/ })
|
||||
await user.click(dots[1])
|
||||
await nextTick()
|
||||
|
||||
// Should be in loading state since URL changed
|
||||
expect(wrapper.find('[aria-busy="true"]').exists()).toBe(true)
|
||||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
||||
expect(container.querySelector('[aria-busy="true"]')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
/* eslint-disable testing-library/no-container, testing-library/no-node-access */
|
||||
/* eslint-disable testing-library/prefer-user-event */
|
||||
import { createTestingPinia } from '@pinia/testing'
|
||||
import type { VueWrapper } from '@vue/test-utils'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { render, screen, fireEvent } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { nextTick } from 'vue'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
@@ -46,10 +48,9 @@ describe('ImagePreview', () => {
|
||||
'/api/view?filename=test2.png&type=output'
|
||||
]
|
||||
}
|
||||
const wrapperRegistry = new Set<VueWrapper>()
|
||||
|
||||
const mountImagePreview = (props = {}) => {
|
||||
const wrapper = mount(ImagePreview, {
|
||||
function renderImagePreview(props = {}) {
|
||||
return render(ImagePreview, {
|
||||
props: { ...defaultProps, ...props },
|
||||
global: {
|
||||
plugins: [
|
||||
@@ -67,14 +68,11 @@ describe('ImagePreview', () => {
|
||||
}
|
||||
}
|
||||
})
|
||||
wrapperRegistry.add(wrapper)
|
||||
return wrapper
|
||||
}
|
||||
|
||||
/** Switch a multi-image wrapper from default grid mode to gallery mode */
|
||||
async function switchToGallery(wrapper: VueWrapper) {
|
||||
const thumbnails = wrapper.findAll('button[aria-label^="View image"]')
|
||||
await thumbnails[0].trigger('click')
|
||||
async function switchToGallery(user: ReturnType<typeof userEvent.setup>) {
|
||||
const thumbnails = screen.getAllByRole('button', { name: /^View image/ })
|
||||
await user.click(thumbnails[0])
|
||||
await nextTick()
|
||||
}
|
||||
|
||||
@@ -82,318 +80,342 @@ describe('ImagePreview', () => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
wrapperRegistry.forEach((wrapper) => {
|
||||
wrapper.unmount()
|
||||
})
|
||||
wrapperRegistry.clear()
|
||||
})
|
||||
|
||||
it('does not render when no imageUrls provided', () => {
|
||||
const wrapper = mountImagePreview({ imageUrls: [] })
|
||||
const { container } = renderImagePreview({ imageUrls: [] })
|
||||
|
||||
expect(wrapper.find('.image-preview').exists()).toBe(false)
|
||||
expect(container.querySelector('.image-preview')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('displays calculating dimensions text in gallery mode', async () => {
|
||||
const wrapper = mountImagePreview({
|
||||
renderImagePreview({
|
||||
imageUrls: [defaultProps.imageUrls[0]]
|
||||
})
|
||||
|
||||
expect(wrapper.text()).toContain('Calculating dimensions')
|
||||
screen.getByText('Calculating dimensions')
|
||||
})
|
||||
|
||||
it('shows navigation dots for multiple images in gallery mode', async () => {
|
||||
const wrapper = mountImagePreview()
|
||||
await switchToGallery(wrapper)
|
||||
renderImagePreview()
|
||||
const user = userEvent.setup()
|
||||
await switchToGallery(user)
|
||||
|
||||
const navigationDots = wrapper.findAll('[aria-label*="View image"]')
|
||||
const navigationDots = screen.getAllByRole('button', {
|
||||
name: /View image/
|
||||
})
|
||||
expect(navigationDots).toHaveLength(2)
|
||||
})
|
||||
|
||||
it('does not show navigation dots for single image', () => {
|
||||
const wrapper = mountImagePreview({
|
||||
renderImagePreview({
|
||||
imageUrls: [defaultProps.imageUrls[0]]
|
||||
})
|
||||
|
||||
const navigationDots = wrapper.findAll('[aria-label*="View image"]')
|
||||
const navigationDots = screen.queryAllByRole('button', {
|
||||
name: /View image/
|
||||
})
|
||||
expect(navigationDots).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('shows mask/edit button only for single images', async () => {
|
||||
// Multiple images in gallery mode - should not show mask button
|
||||
const multipleImagesWrapper = mountImagePreview()
|
||||
await switchToGallery(multipleImagesWrapper)
|
||||
it('does not show mask/edit button for multiple images in gallery mode', async () => {
|
||||
renderImagePreview()
|
||||
const user = userEvent.setup()
|
||||
await switchToGallery(user)
|
||||
|
||||
expect(
|
||||
multipleImagesWrapper.find('[aria-label="Edit or mask image"]').exists()
|
||||
).toBe(false)
|
||||
screen.queryByRole('button', { name: 'Edit or mask image' })
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
// Single image - should show mask button
|
||||
const singleImageWrapper = mountImagePreview({
|
||||
it('shows mask/edit button for single images', () => {
|
||||
renderImagePreview({
|
||||
imageUrls: [defaultProps.imageUrls[0]]
|
||||
})
|
||||
|
||||
expect(
|
||||
singleImageWrapper.find('[aria-label="Edit or mask image"]').exists()
|
||||
).toBe(true)
|
||||
screen.getByRole('button', { name: 'Edit or mask image' })
|
||||
})
|
||||
|
||||
it('handles download button click', async () => {
|
||||
const wrapper = mountImagePreview({
|
||||
renderImagePreview({
|
||||
imageUrls: [defaultProps.imageUrls[0]]
|
||||
})
|
||||
const user = userEvent.setup()
|
||||
|
||||
const downloadButton = wrapper.find('[aria-label="Download image"]')
|
||||
expect(downloadButton.exists()).toBe(true)
|
||||
await downloadButton.trigger('click')
|
||||
const downloadButton = screen.getByRole('button', {
|
||||
name: 'Download image'
|
||||
})
|
||||
await user.click(downloadButton)
|
||||
|
||||
expect(downloadFile).toHaveBeenCalledWith(defaultProps.imageUrls[0])
|
||||
})
|
||||
|
||||
it('switches images when navigation dots are clicked', async () => {
|
||||
const wrapper = mountImagePreview()
|
||||
await switchToGallery(wrapper)
|
||||
renderImagePreview()
|
||||
const user = userEvent.setup()
|
||||
await switchToGallery(user)
|
||||
|
||||
// Initially shows first image
|
||||
expect(wrapper.find('img').attributes('src')).toBe(
|
||||
expect(screen.getByRole('img')).toHaveAttribute(
|
||||
'src',
|
||||
defaultProps.imageUrls[0]
|
||||
)
|
||||
|
||||
// Click second navigation dot
|
||||
const navigationDots = wrapper.findAll('[aria-label*="View image"]')
|
||||
await navigationDots[1].trigger('click')
|
||||
const navigationDots = screen.getAllByRole('button', {
|
||||
name: /View image/
|
||||
})
|
||||
await user.click(navigationDots[1])
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.find('img').attributes('src')).toBe(
|
||||
expect(screen.getByRole('img')).toHaveAttribute(
|
||||
'src',
|
||||
defaultProps.imageUrls[1]
|
||||
)
|
||||
})
|
||||
|
||||
it('marks active navigation dot with aria-current', async () => {
|
||||
const wrapper = mountImagePreview()
|
||||
await switchToGallery(wrapper)
|
||||
renderImagePreview()
|
||||
const user = userEvent.setup()
|
||||
await switchToGallery(user)
|
||||
|
||||
const navigationDots = wrapper.findAll('[aria-label*="View image"]')
|
||||
const navigationDots = screen.getAllByRole('button', {
|
||||
name: /View image/
|
||||
})
|
||||
|
||||
// First dot should be active
|
||||
expect(navigationDots[0].attributes('aria-current')).toBe('true')
|
||||
expect(navigationDots[1].attributes('aria-current')).toBeUndefined()
|
||||
expect(navigationDots[0]).toHaveAttribute('aria-current', 'true')
|
||||
expect(navigationDots[1]).not.toHaveAttribute('aria-current')
|
||||
|
||||
await navigationDots[1].trigger('click')
|
||||
await user.click(navigationDots[1])
|
||||
await nextTick()
|
||||
|
||||
// Second dot should now be active
|
||||
expect(navigationDots[0].attributes('aria-current')).toBeUndefined()
|
||||
expect(navigationDots[1].attributes('aria-current')).toBe('true')
|
||||
expect(navigationDots[0]).not.toHaveAttribute('aria-current')
|
||||
expect(navigationDots[1]).toHaveAttribute('aria-current', 'true')
|
||||
})
|
||||
|
||||
it('has proper accessibility attributes', () => {
|
||||
const wrapper = mountImagePreview({
|
||||
renderImagePreview({
|
||||
imageUrls: [defaultProps.imageUrls[0]]
|
||||
})
|
||||
|
||||
const img = wrapper.find('img')
|
||||
expect(img.attributes('alt')).toBe('View image 1 of 1')
|
||||
expect(screen.getByRole('img')).toHaveAttribute('alt', 'View image 1 of 1')
|
||||
})
|
||||
|
||||
it('updates alt text when switching images', async () => {
|
||||
const wrapper = mountImagePreview()
|
||||
await switchToGallery(wrapper)
|
||||
renderImagePreview()
|
||||
const user = userEvent.setup()
|
||||
await switchToGallery(user)
|
||||
|
||||
expect(wrapper.find('img').attributes('alt')).toBe('View image 1 of 2')
|
||||
expect(screen.getByRole('img')).toHaveAttribute('alt', 'View image 1 of 2')
|
||||
|
||||
// Switch to second image
|
||||
const navigationDots = wrapper.findAll('[aria-label*="View image"]')
|
||||
await navigationDots[1].trigger('click')
|
||||
const navigationDots = screen.getAllByRole('button', {
|
||||
name: /View image/
|
||||
})
|
||||
await user.click(navigationDots[1])
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.find('img').attributes('alt')).toBe('View image 2 of 2')
|
||||
expect(screen.getByRole('img')).toHaveAttribute('alt', 'View image 2 of 2')
|
||||
})
|
||||
|
||||
describe('keyboard navigation', () => {
|
||||
it('navigates to next image with ArrowRight', async () => {
|
||||
const wrapper = mountImagePreview()
|
||||
await switchToGallery(wrapper)
|
||||
const { container } = renderImagePreview()
|
||||
const user = userEvent.setup()
|
||||
await switchToGallery(user)
|
||||
|
||||
await wrapper
|
||||
.find('.image-preview')
|
||||
.trigger('keydown', { key: 'ArrowRight' })
|
||||
const preview = container.querySelector('.image-preview') as HTMLElement
|
||||
await fireEvent.keyDown(preview, { key: 'ArrowRight' })
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.find('[data-testid="main-image"]').attributes('src')).toBe(
|
||||
expect(screen.getByTestId('main-image')).toHaveAttribute(
|
||||
'src',
|
||||
defaultProps.imageUrls[1]
|
||||
)
|
||||
})
|
||||
|
||||
it('navigates to previous image with ArrowLeft', async () => {
|
||||
const wrapper = mountImagePreview()
|
||||
await switchToGallery(wrapper)
|
||||
const { container } = renderImagePreview()
|
||||
const user = userEvent.setup()
|
||||
await switchToGallery(user)
|
||||
|
||||
await wrapper
|
||||
.find('.image-preview')
|
||||
.trigger('keydown', { key: 'ArrowRight' })
|
||||
const preview = container.querySelector('.image-preview') as HTMLElement
|
||||
await fireEvent.keyDown(preview, { key: 'ArrowRight' })
|
||||
await nextTick()
|
||||
|
||||
await wrapper
|
||||
.find('.image-preview')
|
||||
.trigger('keydown', { key: 'ArrowLeft' })
|
||||
await fireEvent.keyDown(preview, { key: 'ArrowLeft' })
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.find('[data-testid="main-image"]').attributes('src')).toBe(
|
||||
expect(screen.getByTestId('main-image')).toHaveAttribute(
|
||||
'src',
|
||||
defaultProps.imageUrls[0]
|
||||
)
|
||||
})
|
||||
|
||||
it('wraps around from last to first with ArrowRight', async () => {
|
||||
const wrapper = mountImagePreview()
|
||||
await switchToGallery(wrapper)
|
||||
const { container } = renderImagePreview()
|
||||
const user = userEvent.setup()
|
||||
await switchToGallery(user)
|
||||
|
||||
await wrapper
|
||||
.find('.image-preview')
|
||||
.trigger('keydown', { key: 'ArrowRight' })
|
||||
const preview = container.querySelector('.image-preview') as HTMLElement
|
||||
await fireEvent.keyDown(preview, { key: 'ArrowRight' })
|
||||
await nextTick()
|
||||
await wrapper
|
||||
.find('.image-preview')
|
||||
.trigger('keydown', { key: 'ArrowRight' })
|
||||
await fireEvent.keyDown(preview, { key: 'ArrowRight' })
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.find('[data-testid="main-image"]').attributes('src')).toBe(
|
||||
expect(screen.getByTestId('main-image')).toHaveAttribute(
|
||||
'src',
|
||||
defaultProps.imageUrls[0]
|
||||
)
|
||||
})
|
||||
|
||||
it('wraps around from first to last with ArrowLeft', async () => {
|
||||
const wrapper = mountImagePreview()
|
||||
await switchToGallery(wrapper)
|
||||
const { container } = renderImagePreview()
|
||||
const user = userEvent.setup()
|
||||
await switchToGallery(user)
|
||||
|
||||
await wrapper
|
||||
.find('.image-preview')
|
||||
.trigger('keydown', { key: 'ArrowLeft' })
|
||||
const preview = container.querySelector('.image-preview') as HTMLElement
|
||||
await fireEvent.keyDown(preview, { key: 'ArrowLeft' })
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.find('[data-testid="main-image"]').attributes('src')).toBe(
|
||||
expect(screen.getByTestId('main-image')).toHaveAttribute(
|
||||
'src',
|
||||
defaultProps.imageUrls[1]
|
||||
)
|
||||
})
|
||||
|
||||
it('navigates to first image with Home', async () => {
|
||||
const wrapper = mountImagePreview()
|
||||
await switchToGallery(wrapper)
|
||||
const { container } = renderImagePreview()
|
||||
const user = userEvent.setup()
|
||||
await switchToGallery(user)
|
||||
|
||||
await wrapper
|
||||
.find('.image-preview')
|
||||
.trigger('keydown', { key: 'ArrowRight' })
|
||||
const preview = container.querySelector('.image-preview') as HTMLElement
|
||||
await fireEvent.keyDown(preview, { key: 'ArrowRight' })
|
||||
await nextTick()
|
||||
|
||||
await wrapper.find('.image-preview').trigger('keydown', { key: 'Home' })
|
||||
await fireEvent.keyDown(preview, { key: 'Home' })
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.find('[data-testid="main-image"]').attributes('src')).toBe(
|
||||
expect(screen.getByTestId('main-image')).toHaveAttribute(
|
||||
'src',
|
||||
defaultProps.imageUrls[0]
|
||||
)
|
||||
})
|
||||
|
||||
it('navigates to last image with End', async () => {
|
||||
const wrapper = mountImagePreview()
|
||||
await switchToGallery(wrapper)
|
||||
const { container } = renderImagePreview()
|
||||
const user = userEvent.setup()
|
||||
await switchToGallery(user)
|
||||
|
||||
await wrapper.find('.image-preview').trigger('keydown', { key: 'End' })
|
||||
const preview = container.querySelector('.image-preview') as HTMLElement
|
||||
await fireEvent.keyDown(preview, { key: 'End' })
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.find('[data-testid="main-image"]').attributes('src')).toBe(
|
||||
expect(screen.getByTestId('main-image')).toHaveAttribute(
|
||||
'src',
|
||||
defaultProps.imageUrls[1]
|
||||
)
|
||||
})
|
||||
|
||||
it('ignores arrow keys in grid mode', async () => {
|
||||
const wrapper = mountImagePreview()
|
||||
const { container } = renderImagePreview()
|
||||
|
||||
const gridThumbnails = wrapper.findAll('button[aria-label^="View image"]')
|
||||
const gridThumbnails = screen.getAllByRole('button', {
|
||||
name: /^View image/
|
||||
})
|
||||
expect(gridThumbnails).toHaveLength(2)
|
||||
|
||||
await wrapper
|
||||
.find('.image-preview')
|
||||
.trigger('keydown', { key: 'ArrowRight' })
|
||||
const preview = container.querySelector('.image-preview') as HTMLElement
|
||||
await fireEvent.keyDown(preview, { key: 'ArrowRight' })
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.find('[role="region"]').exists()).toBe(false)
|
||||
expect(screen.queryByRole('region')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('ignores arrow keys for single image', async () => {
|
||||
const wrapper = mountImagePreview({
|
||||
const { container } = renderImagePreview({
|
||||
imageUrls: [defaultProps.imageUrls[0]]
|
||||
})
|
||||
|
||||
const initialSrc = wrapper.find('img').attributes('src')
|
||||
await wrapper
|
||||
.find('.image-preview')
|
||||
.trigger('keydown', { key: 'ArrowRight' })
|
||||
const initialSrc = screen.getByRole('img').getAttribute('src')
|
||||
const preview = container.querySelector('.image-preview') as HTMLElement
|
||||
await fireEvent.keyDown(preview, { key: 'ArrowRight' })
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.find('img').attributes('src')).toBe(initialSrc)
|
||||
expect(screen.getByRole('img')).toHaveAttribute('src', initialSrc!)
|
||||
})
|
||||
})
|
||||
|
||||
describe('grid view', () => {
|
||||
it('defaults to grid mode for multiple images', () => {
|
||||
const wrapper = mountImagePreview()
|
||||
renderImagePreview()
|
||||
|
||||
const gridThumbnails = wrapper.findAll('button[aria-label^="View image"]')
|
||||
const gridThumbnails = screen.getAllByRole('button', {
|
||||
name: /^View image/
|
||||
})
|
||||
expect(gridThumbnails).toHaveLength(2)
|
||||
})
|
||||
|
||||
it('defaults to gallery mode for single image', () => {
|
||||
const wrapper = mountImagePreview({
|
||||
renderImagePreview({
|
||||
imageUrls: [defaultProps.imageUrls[0]]
|
||||
})
|
||||
|
||||
expect(wrapper.find('[role="region"]').exists()).toBe(true)
|
||||
const gridThumbnails = wrapper.findAll('button[aria-label^="View image"]')
|
||||
screen.getByRole('region')
|
||||
const gridThumbnails = screen.queryAllByRole('button', {
|
||||
name: /^View image/
|
||||
})
|
||||
expect(gridThumbnails).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('switches to gallery mode when grid thumbnail is clicked', async () => {
|
||||
const wrapper = mountImagePreview()
|
||||
renderImagePreview()
|
||||
const user = userEvent.setup()
|
||||
|
||||
const thumbnails = wrapper.findAll('button[aria-label^="View image"]')
|
||||
await thumbnails[1].trigger('click')
|
||||
const thumbnails = screen.getAllByRole('button', {
|
||||
name: /^View image/
|
||||
})
|
||||
await user.click(thumbnails[1])
|
||||
await nextTick()
|
||||
|
||||
const mainImg = wrapper.find('[data-testid="main-image"]')
|
||||
expect(mainImg.exists()).toBe(true)
|
||||
expect(mainImg.attributes('src')).toBe(defaultProps.imageUrls[1])
|
||||
const mainImg = screen.getByTestId('main-image')
|
||||
expect(mainImg).toHaveAttribute('src', defaultProps.imageUrls[1])
|
||||
})
|
||||
|
||||
it('shows back-to-grid button next to navigation dots', async () => {
|
||||
const wrapper = mountImagePreview()
|
||||
await switchToGallery(wrapper)
|
||||
renderImagePreview()
|
||||
const user = userEvent.setup()
|
||||
await switchToGallery(user)
|
||||
|
||||
const gridButton = wrapper.find('[aria-label="Grid view"]')
|
||||
expect(gridButton.exists()).toBe(true)
|
||||
const gridButtons = screen.getAllByRole('button', { name: 'Grid view' })
|
||||
expect(gridButtons.length).toBeGreaterThanOrEqual(1)
|
||||
})
|
||||
|
||||
it('switches back to grid mode via back-to-grid button', async () => {
|
||||
const wrapper = mountImagePreview()
|
||||
await switchToGallery(wrapper)
|
||||
renderImagePreview()
|
||||
const user = userEvent.setup()
|
||||
await switchToGallery(user)
|
||||
|
||||
const gridButton = wrapper.find('[aria-label="Grid view"]')
|
||||
await gridButton.trigger('click')
|
||||
const gridButtons = screen.getAllByRole('button', { name: 'Grid view' })
|
||||
await user.click(gridButtons[0])
|
||||
await nextTick()
|
||||
|
||||
const gridThumbnails = wrapper.findAll('button[aria-label^="View image"]')
|
||||
const gridThumbnails = screen.getAllByRole('button', {
|
||||
name: /^View image/
|
||||
})
|
||||
expect(gridThumbnails).toHaveLength(2)
|
||||
})
|
||||
|
||||
it('resets to grid mode when URLs change to multiple images', async () => {
|
||||
const wrapper = mountImagePreview()
|
||||
await switchToGallery(wrapper)
|
||||
const { rerender } = renderImagePreview()
|
||||
const user = userEvent.setup()
|
||||
await switchToGallery(user)
|
||||
|
||||
// Verify we're in gallery mode
|
||||
expect(wrapper.find('[role="region"]').exists()).toBe(true)
|
||||
screen.getByRole('region')
|
||||
|
||||
// Change URLs
|
||||
await wrapper.setProps({
|
||||
await rerender({
|
||||
imageUrls: [
|
||||
'/api/view?filename=new1.png&type=output',
|
||||
'/api/view?filename=new2.png&type=output',
|
||||
@@ -403,7 +425,9 @@ describe('ImagePreview', () => {
|
||||
await nextTick()
|
||||
|
||||
// Should be back in grid mode
|
||||
const gridThumbnails = wrapper.findAll('button[aria-label^="View image"]')
|
||||
const gridThumbnails = screen.getAllByRole('button', {
|
||||
name: /^View image/
|
||||
})
|
||||
expect(gridThumbnails).toHaveLength(3)
|
||||
})
|
||||
})
|
||||
@@ -411,21 +435,26 @@ describe('ImagePreview', () => {
|
||||
describe('batch cycling with identical URLs', () => {
|
||||
it('should not enter persistent loading state when cycling through identical images', async () => {
|
||||
vi.useFakeTimers()
|
||||
const user = userEvent.setup({
|
||||
advanceTimers: vi.advanceTimersByTime
|
||||
})
|
||||
try {
|
||||
const sameUrl = '/api/view?filename=test.png&type=output'
|
||||
const wrapper = mountImagePreview({
|
||||
const { container } = renderImagePreview({
|
||||
imageUrls: [sameUrl, sameUrl, sameUrl]
|
||||
})
|
||||
await switchToGallery(wrapper)
|
||||
await switchToGallery(user)
|
||||
|
||||
// Simulate initial image load
|
||||
await wrapper.find('img').trigger('load')
|
||||
await fireEvent.load(screen.getByRole('img'))
|
||||
await nextTick()
|
||||
expect(wrapper.find('[aria-busy="true"]').exists()).toBe(false)
|
||||
expect(
|
||||
container.querySelector('[aria-busy="true"]')
|
||||
).not.toBeInTheDocument()
|
||||
|
||||
// Click second navigation dot to cycle
|
||||
const dots = wrapper.findAll('[aria-label*="View image"]')
|
||||
await dots[1].trigger('click')
|
||||
const dots = screen.getAllByRole('button', { name: /View image/ })
|
||||
await user.click(dots[1])
|
||||
await nextTick()
|
||||
|
||||
// Advance past the delayed loader timeout
|
||||
@@ -433,7 +462,9 @@ describe('ImagePreview', () => {
|
||||
await nextTick()
|
||||
|
||||
// Should NOT be in loading state since URL didn't change
|
||||
expect(wrapper.find('[aria-busy="true"]').exists()).toBe(false)
|
||||
expect(
|
||||
container.querySelector('[aria-busy="true"]')
|
||||
).not.toBeInTheDocument()
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
@@ -443,20 +474,27 @@ describe('ImagePreview', () => {
|
||||
describe('URL change detection', () => {
|
||||
it('should NOT reset loading state when imageUrls prop is reassigned with identical URLs', async () => {
|
||||
vi.useFakeTimers()
|
||||
const user = userEvent.setup({
|
||||
advanceTimers: vi.advanceTimersByTime
|
||||
})
|
||||
try {
|
||||
const urls = ['/api/view?filename=test.png&type=output']
|
||||
const wrapper = mountImagePreview({ imageUrls: urls })
|
||||
const { container, rerender } = renderImagePreview({
|
||||
imageUrls: urls
|
||||
})
|
||||
void user
|
||||
|
||||
// Simulate image load completing
|
||||
const img = wrapper.find('img')
|
||||
await img.trigger('load')
|
||||
await fireEvent.load(screen.getByRole('img'))
|
||||
await nextTick()
|
||||
|
||||
// Verify loader is hidden after load
|
||||
expect(wrapper.find('[aria-busy="true"]').exists()).toBe(false)
|
||||
expect(
|
||||
container.querySelector('[aria-busy="true"]')
|
||||
).not.toBeInTheDocument()
|
||||
|
||||
// Reassign with new array reference but same content
|
||||
await wrapper.setProps({ imageUrls: [...urls] })
|
||||
await rerender({ imageUrls: [...urls] })
|
||||
await nextTick()
|
||||
|
||||
// Advance past the 250ms delayed loader timeout
|
||||
@@ -464,7 +502,9 @@ describe('ImagePreview', () => {
|
||||
await nextTick()
|
||||
|
||||
// Loading state should NOT have been reset
|
||||
expect(wrapper.find('[aria-busy="true"]').exists()).toBe(false)
|
||||
expect(
|
||||
container.querySelector('[aria-busy="true"]')
|
||||
).not.toBeInTheDocument()
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
@@ -472,20 +512,27 @@ describe('ImagePreview', () => {
|
||||
|
||||
it('should reset loading state when imageUrls prop changes to different URLs', async () => {
|
||||
vi.useFakeTimers()
|
||||
const user = userEvent.setup({
|
||||
advanceTimers: vi.advanceTimersByTime
|
||||
})
|
||||
try {
|
||||
const urls = ['/api/view?filename=test.png&type=output']
|
||||
const wrapper = mountImagePreview({ imageUrls: urls })
|
||||
const { container, rerender } = renderImagePreview({
|
||||
imageUrls: urls
|
||||
})
|
||||
|
||||
// Simulate image load completing
|
||||
const img = wrapper.find('img')
|
||||
await img.trigger('load')
|
||||
await fireEvent.load(screen.getByRole('img'))
|
||||
await nextTick()
|
||||
|
||||
// Verify loader is hidden
|
||||
expect(wrapper.find('[aria-busy="true"]').exists()).toBe(false)
|
||||
expect(
|
||||
container.querySelector('[aria-busy="true"]')
|
||||
).not.toBeInTheDocument()
|
||||
|
||||
void user
|
||||
// Change to different URL
|
||||
await wrapper.setProps({
|
||||
await rerender({
|
||||
imageUrls: ['/api/view?filename=different.png&type=output']
|
||||
})
|
||||
await nextTick()
|
||||
@@ -494,24 +541,26 @@ describe('ImagePreview', () => {
|
||||
await vi.advanceTimersByTimeAsync(300)
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.find('[aria-busy="true"]').exists()).toBe(true)
|
||||
expect(
|
||||
container.querySelector('[aria-busy="true"]')
|
||||
).toBeInTheDocument()
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
|
||||
it('should handle empty to non-empty URL transitions correctly', async () => {
|
||||
const wrapper = mountImagePreview({ imageUrls: [] })
|
||||
const { container, rerender } = renderImagePreview({ imageUrls: [] })
|
||||
|
||||
expect(wrapper.find('.image-preview').exists()).toBe(false)
|
||||
expect(container.querySelector('.image-preview')).not.toBeInTheDocument()
|
||||
|
||||
await wrapper.setProps({
|
||||
await rerender({
|
||||
imageUrls: ['/api/view?filename=test.png&type=output']
|
||||
})
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.find('.image-preview').exists()).toBe(true)
|
||||
expect(wrapper.find('img').exists()).toBe(true)
|
||||
expect(container.querySelector('.image-preview')).toBeInTheDocument()
|
||||
screen.getByRole('img')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user