diff --git a/browser_tests/tests/templates.spec.ts-snapshots/template-grid-desktop-chromium-linux.png b/browser_tests/tests/templates.spec.ts-snapshots/template-grid-desktop-chromium-linux.png index ecf8658c8..a378f877a 100644 Binary files a/browser_tests/tests/templates.spec.ts-snapshots/template-grid-desktop-chromium-linux.png and b/browser_tests/tests/templates.spec.ts-snapshots/template-grid-desktop-chromium-linux.png differ diff --git a/browser_tests/tests/templates.spec.ts-snapshots/template-grid-mobile-chromium-linux.png b/browser_tests/tests/templates.spec.ts-snapshots/template-grid-mobile-chromium-linux.png index 9bad33cd8..577965c23 100644 Binary files a/browser_tests/tests/templates.spec.ts-snapshots/template-grid-mobile-chromium-linux.png and b/browser_tests/tests/templates.spec.ts-snapshots/template-grid-mobile-chromium-linux.png differ diff --git a/browser_tests/tests/templates.spec.ts-snapshots/template-grid-tablet-chromium-linux.png b/browser_tests/tests/templates.spec.ts-snapshots/template-grid-tablet-chromium-linux.png index 448ae25cc..2bf7298b2 100644 Binary files a/browser_tests/tests/templates.spec.ts-snapshots/template-grid-tablet-chromium-linux.png and b/browser_tests/tests/templates.spec.ts-snapshots/template-grid-tablet-chromium-linux.png differ diff --git a/browser_tests/tests/templates.spec.ts-snapshots/template-grid-varying-content-chromium-linux.png b/browser_tests/tests/templates.spec.ts-snapshots/template-grid-varying-content-chromium-linux.png index 40452d452..03ac1fc1f 100644 Binary files a/browser_tests/tests/templates.spec.ts-snapshots/template-grid-varying-content-chromium-linux.png and b/browser_tests/tests/templates.spec.ts-snapshots/template-grid-varying-content-chromium-linux.png differ diff --git a/src/components/templates/TemplateWorkflowCard.spec.ts b/src/components/templates/TemplateWorkflowCard.spec.ts index 795bb66a7..dc3266db8 100644 --- a/src/components/templates/TemplateWorkflowCard.spec.ts +++ b/src/components/templates/TemplateWorkflowCard.spec.ts @@ -46,10 +46,68 @@ vi.mock('@vueuse/core', () => ({ vi.mock('@/scripts/api', () => ({ api: { fileURL: (path: string) => `/fileURL${path}`, - apiURL: (path: string) => `/apiURL${path}` + apiURL: (path: string) => `/apiURL${path}`, + addEventListener: vi.fn(), + removeEventListener: vi.fn() } })) +vi.mock('@/scripts/app', () => ({ + app: { + loadGraphData: vi.fn() + } +})) + +vi.mock('@/stores/dialogStore', () => ({ + useDialogStore: () => ({ + closeDialog: vi.fn() + }) +})) + +vi.mock('@/stores/workflowTemplatesStore', () => ({ + useWorkflowTemplatesStore: () => ({ + isLoaded: true, + loadWorkflowTemplates: vi.fn().mockResolvedValue(true), + groupedTemplates: [] + }) +})) + +vi.mock('vue-i18n', () => ({ + useI18n: () => ({ + t: (key: string, fallback: string) => fallback || key + }) +})) + +vi.mock('@/composables/useTemplateWorkflows', () => ({ + useTemplateWorkflows: () => ({ + getTemplateThumbnailUrl: ( + template: TemplateInfo, + sourceModule: string, + index = '' + ) => { + const basePath = + sourceModule === 'default' + ? `/fileURL/templates/${template.name}` + : `/apiURL/workflow_templates/${sourceModule}/${template.name}` + const indexSuffix = sourceModule === 'default' && index ? `-${index}` : '' + return `${basePath}${indexSuffix}.${template.mediaSubtype}` + }, + getTemplateTitle: (template: TemplateInfo, sourceModule: string) => { + const fallback = + template.title ?? template.name ?? `${sourceModule} Template` + return sourceModule === 'default' + ? template.localizedTitle ?? fallback + : fallback + }, + getTemplateDescription: (template: TemplateInfo, sourceModule: string) => { + return sourceModule === 'default' + ? template.localizedDescription ?? '' + : template.description?.replace(/[-_]/g, ' ').trim() ?? '' + }, + loadWorkflowTemplate: vi.fn() + }) +})) + describe('TemplateWorkflowCard', () => { const createTemplate = (overrides = {}): TemplateInfo => ({ name: 'test-template', diff --git a/src/components/templates/TemplateWorkflowCard.vue b/src/components/templates/TemplateWorkflowCard.vue index 8b79081ce..4860b9c77 100644 --- a/src/components/templates/TemplateWorkflowCard.vue +++ b/src/components/templates/TemplateWorkflowCard.vue @@ -86,7 +86,7 @@ import AudioThumbnail from '@/components/templates/thumbnails/AudioThumbnail.vue import CompareSliderThumbnail from '@/components/templates/thumbnails/CompareSliderThumbnail.vue' import DefaultThumbnail from '@/components/templates/thumbnails/DefaultThumbnail.vue' import HoverDissolveThumbnail from '@/components/templates/thumbnails/HoverDissolveThumbnail.vue' -import { api } from '@/scripts/api' +import { useTemplateWorkflows } from '@/composables/useTemplateWorkflows' import { TemplateInfo } from '@/types/workflowTemplateTypes' const UPSCALE_ZOOM_SCALE = 16 // for upscale templates, exaggerate the hover zoom @@ -102,36 +102,36 @@ const { sourceModule, loading, template } = defineProps<{ const cardRef = ref(null) const isHovered = useElementHover(cardRef) -const getThumbnailUrl = (index = '') => { - const basePath = - sourceModule === 'default' - ? api.fileURL(`/templates/${template.name}`) - : api.apiURL(`/workflow_templates/${sourceModule}/${template.name}`) +const { getTemplateThumbnailUrl, getTemplateTitle, getTemplateDescription } = + useTemplateWorkflows() - // For templates from custom nodes, multiple images is not yet supported - const indexSuffix = sourceModule === 'default' && index ? `-${index}` : '' - - return `${basePath}${indexSuffix}.${template.mediaSubtype}` -} +// Determine the effective source module to use (from template or prop) +const effectiveSourceModule = computed( + () => template.sourceModule || sourceModule +) const baseThumbnailSrc = computed(() => - getThumbnailUrl(sourceModule === 'default' ? '1' : '') + getTemplateThumbnailUrl( + template, + effectiveSourceModule.value, + effectiveSourceModule.value === 'default' ? '1' : '' + ) ) + const overlayThumbnailSrc = computed(() => - getThumbnailUrl(sourceModule === 'default' ? '2' : '') + getTemplateThumbnailUrl( + template, + effectiveSourceModule.value, + effectiveSourceModule.value === 'default' ? '2' : '' + ) ) -const description = computed(() => { - return sourceModule === 'default' - ? template.localizedDescription ?? '' - : template.description.replace(/[-_]/g, ' ').trim() -}) - -const title = computed(() => { - return sourceModule === 'default' - ? template.localizedTitle ?? '' - : template.name -}) +const description = computed(() => + getTemplateDescription(template, effectiveSourceModule.value) +) +const title = computed(() => + getTemplateTitle(template, effectiveSourceModule.value) +) defineEmits<{ loadWorkflow: [name: string] diff --git a/src/components/templates/TemplateWorkflowList.vue b/src/components/templates/TemplateWorkflowList.vue index 2757e50be..061dbb104 100644 --- a/src/components/templates/TemplateWorkflowList.vue +++ b/src/components/templates/TemplateWorkflowList.vue @@ -1,21 +1,19 @@