mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-07-15 11:44:10 +00:00
## Summary Address code review feedback from #10134 by renaming the component and improving implementation quality. ## Changes - Rename `ResultGallery` → `MediaLightbox` across all references - Replace `useEventListener(window, 'keydown')` with `@keydown` on dialog element - Remove change detector tests (`renders close button`, `prevents default on arrow keys`) - Remove redundant `toBeVisible()` before Playwright click (implicit wait) - Update keyboard tests to dispatch on dialog element instead of `window` - Sort button icon sizes (`icon-sm`, `icon`, `icon-lg`) - Wire zoom event to lightbox in `MediaAssetCard` story via `context.args` - Add standalone `MediaLightbox` Storybook story under `Platform/Assets/` Fixes #10134 ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-10235-refactor-Rename-ResultGallery-to-MediaLightbox-and-address-code-review-3276d73d365081299b42f682373a12f1) by [Unito](https://www.unito.io) --------- Co-authored-by: Alexander Brown <drjkl@comfy.org> Co-authored-by: Amp <amp@ampcode.com>
124 lines
3.2 KiB
TypeScript
124 lines
3.2 KiB
TypeScript
import { createTestingPinia } from '@pinia/testing'
|
|
import { mount } from '@vue/test-utils'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { defineComponent } from 'vue'
|
|
|
|
import QueueProgressOverlay from '@/components/queue/QueueProgressOverlay.vue'
|
|
import { i18n } from '@/i18n'
|
|
import type { JobStatus } from '@/platform/remote/comfyui/jobs/jobTypes'
|
|
import { TaskItemImpl, useQueueStore } from '@/stores/queueStore'
|
|
import { useSidebarTabStore } from '@/stores/workspace/sidebarTabStore'
|
|
|
|
vi.mock('@/platform/distribution/types', () => ({
|
|
isCloud: false
|
|
}))
|
|
|
|
const QueueOverlayExpandedStub = defineComponent({
|
|
name: 'QueueOverlayExpanded',
|
|
props: {
|
|
headerTitle: {
|
|
type: String,
|
|
required: true
|
|
}
|
|
},
|
|
template: `
|
|
<div>
|
|
<div data-testid="expanded-title">{{ headerTitle }}</div>
|
|
<button data-testid="show-assets-button" @click="$emit('show-assets')" />
|
|
</div>
|
|
`
|
|
})
|
|
|
|
function createTask(id: string, status: JobStatus): TaskItemImpl {
|
|
return new TaskItemImpl({
|
|
id,
|
|
status,
|
|
create_time: 0,
|
|
priority: 0
|
|
})
|
|
}
|
|
|
|
const mountComponent = (
|
|
runningTasks: TaskItemImpl[],
|
|
pendingTasks: TaskItemImpl[]
|
|
) => {
|
|
const pinia = createTestingPinia({
|
|
createSpy: vi.fn,
|
|
stubActions: false
|
|
})
|
|
const queueStore = useQueueStore(pinia)
|
|
const sidebarTabStore = useSidebarTabStore(pinia)
|
|
queueStore.runningTasks = runningTasks
|
|
queueStore.pendingTasks = pendingTasks
|
|
|
|
const wrapper = mount(QueueProgressOverlay, {
|
|
props: {
|
|
expanded: true
|
|
},
|
|
global: {
|
|
plugins: [pinia, i18n],
|
|
stubs: {
|
|
QueueOverlayExpanded: QueueOverlayExpandedStub,
|
|
QueueOverlayActive: true,
|
|
MediaLightbox: true
|
|
},
|
|
directives: {
|
|
tooltip: () => {}
|
|
}
|
|
}
|
|
})
|
|
|
|
return { wrapper, sidebarTabStore }
|
|
}
|
|
|
|
describe('QueueProgressOverlay', () => {
|
|
beforeEach(() => {
|
|
i18n.global.locale.value = 'en'
|
|
})
|
|
|
|
it('shows expanded header with running and queued labels', () => {
|
|
const { wrapper } = mountComponent(
|
|
[
|
|
createTask('running-1', 'in_progress'),
|
|
createTask('running-2', 'in_progress')
|
|
],
|
|
[createTask('pending-1', 'pending')]
|
|
)
|
|
|
|
expect(wrapper.get('[data-testid="expanded-title"]').text()).toBe(
|
|
'2 running, 1 queued'
|
|
)
|
|
})
|
|
|
|
it('shows only running label when queued count is zero', () => {
|
|
const { wrapper } = mountComponent(
|
|
[createTask('running-1', 'in_progress')],
|
|
[]
|
|
)
|
|
|
|
expect(wrapper.get('[data-testid="expanded-title"]').text()).toBe(
|
|
'1 running'
|
|
)
|
|
})
|
|
|
|
it('shows job queue title when there are no active jobs', () => {
|
|
const { wrapper } = mountComponent([], [])
|
|
|
|
expect(wrapper.get('[data-testid="expanded-title"]').text()).toBe(
|
|
'Job Queue'
|
|
)
|
|
})
|
|
|
|
it('toggles the assets sidebar tab when show-assets is clicked', async () => {
|
|
const { wrapper, sidebarTabStore } = mountComponent([], [])
|
|
|
|
expect(sidebarTabStore.activeSidebarTabId).toBe(null)
|
|
|
|
await wrapper.get('[data-testid="show-assets-button"]').trigger('click')
|
|
expect(sidebarTabStore.activeSidebarTabId).toBe('assets')
|
|
|
|
await wrapper.get('[data-testid="show-assets-button"]').trigger('click')
|
|
expect(sidebarTabStore.activeSidebarTabId).toBe(null)
|
|
})
|
|
})
|