|
| 1 | +import { mount } from '@vue/test-utils' |
| 2 | +import { describe, expect, it, vi } from 'vitest' |
| 3 | +import { ref } from 'vue' |
| 4 | + |
| 5 | +import TemplateWorkflowCard from '@/components/templates/TemplateWorkflowCard.vue' |
| 6 | +import { TemplateInfo } from '@/types/workflowTemplateTypes' |
| 7 | + |
| 8 | +vi.mock('@/components/templates/thumbnails/AudioThumbnail.vue', () => ({ |
| 9 | + default: { |
| 10 | + name: 'AudioThumbnail', |
| 11 | + template: '<div class="mock-audio-thumbnail" :data-src="src"></div>', |
| 12 | + props: ['src'] |
| 13 | + } |
| 14 | +})) |
| 15 | + |
| 16 | +vi.mock('@/components/templates/thumbnails/CompareSliderThumbnail.vue', () => ({ |
| 17 | + default: { |
| 18 | + name: 'CompareSliderThumbnail', |
| 19 | + template: |
| 20 | + '<div class="mock-compare-slider" :data-base="baseImageSrc" :data-overlay="overlayImageSrc"></div>', |
| 21 | + props: ['baseImageSrc', 'overlayImageSrc', 'alt', 'isHovered'] |
| 22 | + } |
| 23 | +})) |
| 24 | + |
| 25 | +vi.mock('@/components/templates/thumbnails/DefaultThumbnail.vue', () => ({ |
| 26 | + default: { |
| 27 | + name: 'DefaultThumbnail', |
| 28 | + template: '<div class="mock-default-thumbnail" :data-src="src"></div>', |
| 29 | + props: ['src', 'alt', 'isHovered', 'isVideo', 'hoverZoom'] |
| 30 | + } |
| 31 | +})) |
| 32 | + |
| 33 | +vi.mock('@/components/templates/thumbnails/HoverDissolveThumbnail.vue', () => ({ |
| 34 | + default: { |
| 35 | + name: 'HoverDissolveThumbnail', |
| 36 | + template: |
| 37 | + '<div class="mock-hover-dissolve" :data-base="baseImageSrc" :data-overlay="overlayImageSrc"></div>', |
| 38 | + props: ['baseImageSrc', 'overlayImageSrc', 'alt', 'isHovered'] |
| 39 | + } |
| 40 | +})) |
| 41 | + |
| 42 | +vi.mock('@vueuse/core', () => ({ |
| 43 | + useElementHover: () => ref(false) |
| 44 | +})) |
| 45 | + |
| 46 | +vi.mock('@/scripts/api', () => ({ |
| 47 | + api: { |
| 48 | + fileURL: (path: string) => `/fileURL${path}`, |
| 49 | + apiURL: (path: string) => `/apiURL${path}` |
| 50 | + } |
| 51 | +})) |
| 52 | + |
| 53 | +describe('TemplateWorkflowCard', () => { |
| 54 | + const createTemplate = (overrides = {}): TemplateInfo => ({ |
| 55 | + name: 'test-template', |
| 56 | + mediaType: 'image', |
| 57 | + mediaSubtype: 'png', |
| 58 | + thumbnailVariant: 'default', |
| 59 | + description: 'Test description', |
| 60 | + ...overrides |
| 61 | + }) |
| 62 | + |
| 63 | + const mountCard = (props = {}) => { |
| 64 | + return mount(TemplateWorkflowCard, { |
| 65 | + props: { |
| 66 | + sourceModule: 'default', |
| 67 | + categoryTitle: 'Test Category', |
| 68 | + loading: false, |
| 69 | + template: createTemplate(), |
| 70 | + ...props |
| 71 | + }, |
| 72 | + global: { |
| 73 | + stubs: { |
| 74 | + Card: { |
| 75 | + template: |
| 76 | + '<div class="card" @click="$emit(\'click\')"><slot name="header" /><slot name="content" /></div>', |
| 77 | + props: ['dataTestid', 'pt'] |
| 78 | + }, |
| 79 | + ProgressSpinner: { |
| 80 | + template: '<div class="progress-spinner"></div>' |
| 81 | + } |
| 82 | + } |
| 83 | + } |
| 84 | + }) |
| 85 | + } |
| 86 | + |
| 87 | + it('emits loadWorkflow event when clicked', async () => { |
| 88 | + const wrapper = mountCard({ |
| 89 | + template: createTemplate({ name: 'test-workflow' }) |
| 90 | + }) |
| 91 | + await wrapper.find('.card').trigger('click') |
| 92 | + expect(wrapper.emitted('loadWorkflow')).toBeTruthy() |
| 93 | + expect(wrapper.emitted('loadWorkflow')?.[0]).toEqual(['test-workflow']) |
| 94 | + }) |
| 95 | + |
| 96 | + it('shows loading spinner when loading is true', () => { |
| 97 | + const wrapper = mountCard({ loading: true }) |
| 98 | + expect(wrapper.find('.progress-spinner').exists()).toBe(true) |
| 99 | + }) |
| 100 | + |
| 101 | + it('renders audio thumbnail for audio media type', () => { |
| 102 | + const wrapper = mountCard({ |
| 103 | + template: createTemplate({ mediaType: 'audio' }) |
| 104 | + }) |
| 105 | + expect(wrapper.find('.mock-audio-thumbnail').exists()).toBe(true) |
| 106 | + }) |
| 107 | + |
| 108 | + it('renders compare slider thumbnail for compareSlider variant', () => { |
| 109 | + const wrapper = mountCard({ |
| 110 | + template: createTemplate({ thumbnailVariant: 'compareSlider' }) |
| 111 | + }) |
| 112 | + expect(wrapper.find('.mock-compare-slider').exists()).toBe(true) |
| 113 | + }) |
| 114 | + |
| 115 | + it('renders hover dissolve thumbnail for hoverDissolve variant', () => { |
| 116 | + const wrapper = mountCard({ |
| 117 | + template: createTemplate({ thumbnailVariant: 'hoverDissolve' }) |
| 118 | + }) |
| 119 | + expect(wrapper.find('.mock-hover-dissolve').exists()).toBe(true) |
| 120 | + }) |
| 121 | + |
| 122 | + it('renders default thumbnail by default', () => { |
| 123 | + const wrapper = mountCard() |
| 124 | + expect(wrapper.find('.mock-default-thumbnail').exists()).toBe(true) |
| 125 | + }) |
| 126 | + |
| 127 | + it('passes correct props to default thumbnail for video', () => { |
| 128 | + const wrapper = mountCard({ |
| 129 | + template: createTemplate({ mediaType: 'video' }) |
| 130 | + }) |
| 131 | + const thumbnail = wrapper.find('.mock-default-thumbnail') |
| 132 | + expect(thumbnail.exists()).toBe(true) |
| 133 | + }) |
| 134 | + |
| 135 | + it('uses zoomHover scale when variant is zoomHover', () => { |
| 136 | + const wrapper = mountCard({ |
| 137 | + template: createTemplate({ thumbnailVariant: 'zoomHover' }) |
| 138 | + }) |
| 139 | + expect(wrapper.find('.mock-default-thumbnail').exists()).toBe(true) |
| 140 | + }) |
| 141 | + |
| 142 | + it('displays localized title for default source module', () => { |
| 143 | + const wrapper = mountCard({ |
| 144 | + sourceModule: 'default', |
| 145 | + template: createTemplate({ localizedTitle: 'My Localized Title' }) |
| 146 | + }) |
| 147 | + expect(wrapper.text()).toContain('My Localized Title') |
| 148 | + }) |
| 149 | + |
| 150 | + it('displays template name as title for non-default source modules', () => { |
| 151 | + const wrapper = mountCard({ |
| 152 | + sourceModule: 'custom', |
| 153 | + template: createTemplate({ name: 'custom-template' }) |
| 154 | + }) |
| 155 | + expect(wrapper.text()).toContain('custom-template') |
| 156 | + }) |
| 157 | + |
| 158 | + it('displays localized description for default source module', () => { |
| 159 | + const wrapper = mountCard({ |
| 160 | + sourceModule: 'default', |
| 161 | + template: createTemplate({ |
| 162 | + localizedDescription: 'My Localized Description' |
| 163 | + }) |
| 164 | + }) |
| 165 | + expect(wrapper.text()).toContain('My Localized Description') |
| 166 | + }) |
| 167 | + |
| 168 | + it('processes description for non-default source modules', () => { |
| 169 | + const wrapper = mountCard({ |
| 170 | + sourceModule: 'custom', |
| 171 | + template: createTemplate({ description: 'custom_module-description' }) |
| 172 | + }) |
| 173 | + expect(wrapper.text()).toContain('custom module description') |
| 174 | + }) |
| 175 | + |
| 176 | + it('generates correct thumbnail URLs for default source module', () => { |
| 177 | + const wrapper = mountCard({ |
| 178 | + sourceModule: 'default', |
| 179 | + template: createTemplate({ |
| 180 | + name: 'my-template', |
| 181 | + mediaSubtype: 'jpg' |
| 182 | + }) |
| 183 | + }) |
| 184 | + const vm = wrapper.vm as any |
| 185 | + expect(vm.baseThumbnailSrc).toBe('/fileURL/templates/my-template-1.jpg') |
| 186 | + expect(vm.overlayThumbnailSrc).toBe('/fileURL/templates/my-template-2.jpg') |
| 187 | + }) |
| 188 | + |
| 189 | + it('generates correct thumbnail URLs for custom source module', () => { |
| 190 | + const wrapper = mountCard({ |
| 191 | + sourceModule: 'custom-module', |
| 192 | + template: createTemplate({ |
| 193 | + name: 'my-template', |
| 194 | + mediaSubtype: 'png' |
| 195 | + }) |
| 196 | + }) |
| 197 | + const vm = wrapper.vm as any |
| 198 | + expect(vm.baseThumbnailSrc).toBe( |
| 199 | + '/apiURL/workflow_templates/custom-module/my-template.png' |
| 200 | + ) |
| 201 | + expect(vm.overlayThumbnailSrc).toBe( |
| 202 | + '/apiURL/workflow_templates/custom-module/my-template.png' |
| 203 | + ) |
| 204 | + }) |
| 205 | +}) |
0 commit comments