Skip to content

Commit 6242dd8

Browse files
[test] Fix TemplateWorkflowCard test by properly mocking useTemplateWorkflows
1 parent ebad093 commit 6242dd8

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

src/components/templates/TemplateWorkflowCard.spec.ts

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,69 @@ vi.mock('@vueuse/core', () => ({
4646
vi.mock('@/scripts/api', () => ({
4747
api: {
4848
fileURL: (path: string) => `/fileURL${path}`,
49-
apiURL: (path: string) => `/apiURL${path}`
49+
apiURL: (path: string) => `/apiURL${path}`,
50+
addEventListener: vi.fn(),
51+
removeEventListener: vi.fn()
5052
}
5153
}))
5254

55+
vi.mock('@/scripts/app', () => ({
56+
app: {
57+
loadGraphData: vi.fn()
58+
}
59+
}))
60+
61+
vi.mock('@/stores/dialogStore', () => ({
62+
useDialogStore: () => ({
63+
closeDialog: vi.fn()
64+
})
65+
}))
66+
67+
vi.mock('@/stores/workflowTemplatesStore', () => ({
68+
useWorkflowTemplatesStore: () => ({
69+
isLoaded: true,
70+
loadWorkflowTemplates: vi.fn().mockResolvedValue(true),
71+
groupedTemplates: []
72+
})
73+
}))
74+
75+
vi.mock('vue-i18n', () => ({
76+
useI18n: () => ({
77+
t: (key: string, fallback: string) => fallback || key
78+
})
79+
}))
80+
81+
vi.mock('@/composables/useTemplateWorkflows', () => ({
82+
useTemplateWorkflows: () => ({
83+
getTemplateThumbnailUrl: (
84+
template: TemplateInfo,
85+
sourceModule: string,
86+
index = ''
87+
) => {
88+
const basePath =
89+
sourceModule === 'default'
90+
? `/fileURL/templates/${template.name}`
91+
: `/apiURL/workflow_templates/${sourceModule}/${template.name}`
92+
const indexSuffix = sourceModule === 'default' && index ? `-${index}` : ''
93+
return `${basePath}${indexSuffix}.${template.mediaSubtype}`
94+
},
95+
getTemplateTitle: (template: TemplateInfo, sourceModule: string) => {
96+
const fallback =
97+
template.title ?? template.name ?? `${sourceModule} Template`
98+
return sourceModule === 'default'
99+
? template.localizedTitle ?? fallback
100+
: fallback
101+
},
102+
getTemplateDescription: (template: TemplateInfo, sourceModule: string) => {
103+
return sourceModule === 'default'
104+
? template.localizedDescription ?? ''
105+
: template.description?.replace(/[-_]/g, ' ').trim() ?? ''
106+
},
107+
loadWorkflowTemplate: vi.fn(),
108+
fetchTemplateJson: vi.fn()
109+
})
110+
}))
111+
53112
describe('TemplateWorkflowCard', () => {
54113
const createTemplate = (overrides = {}): TemplateInfo => ({
55114
name: 'test-template',

0 commit comments

Comments
 (0)