11import { mount } from '@vue/test-utils'
2- import { describe , expect , it , vi } from 'vitest'
2+ import { createTestingPinia } from '@pinia/testing'
3+ import { describe , expect , it } from 'vitest'
4+ import { createI18n } from 'vue-i18n'
35
46import type { AssetDisplayItem } from '@/platform/assets/composables/useAssetBrowser'
57
68import ModelInfoPanel from './ModelInfoPanel.vue'
79
8- vi . mock ( 'vue-i18n' , ( ) => ( {
9- useI18n : ( ) => ( {
10- t : ( key : string , params ?: Record < string , string > ) =>
11- params ? `${ key } :${ JSON . stringify ( params ) } ` : key
12- } )
13- } ) )
14-
15- vi . mock (
16- '@/components/rightSidePanel/layout/PropertiesAccordionItem.vue' ,
17- ( ) => ( {
18- default : {
19- name : 'PropertiesAccordionItem' ,
20- template : `
21- <div data-testid="accordion-item">
22- <div data-testid="accordion-label"><slot name="label" /></div>
23- <div data-testid="accordion-content"><slot /></div>
24- </div>
25- `
26- }
27- } )
28- )
29-
30- vi . mock ( './ModelInfoField.vue' , ( ) => ( {
31- default : {
32- name : 'ModelInfoField' ,
33- props : [ 'label' ] ,
34- template : `
35- <div data-testid="model-info-field" :data-label="label">
36- <span>{{ label }}</span>
37- <slot />
38- </div>
39- `
40- }
41- } ) )
10+ const i18n = createI18n ( {
11+ legacy : false ,
12+ locale : 'en' ,
13+ messages : { en : { } } ,
14+ missingWarn : false ,
15+ fallbackWarn : false
16+ } )
4217
4318describe ( 'ModelInfoPanel' , ( ) => {
4419 const createMockAsset = (
@@ -63,6 +38,7 @@ describe('ModelInfoPanel', () => {
6338 return mount ( ModelInfoPanel , {
6439 props : { asset } ,
6540 global : {
41+ plugins : [ createTestingPinia ( { stubActions : false } ) , i18n ] ,
6642 mocks : {
6743 $t : ( key : string , params ?: Record < string , string > ) =>
6844 params ? `${ key } :${ JSON . stringify ( params ) } ` : key
@@ -72,9 +48,9 @@ describe('ModelInfoPanel', () => {
7248 }
7349
7450 describe ( 'Basic Info Section' , ( ) => {
75- it ( 'renders panel title ' , ( ) => {
51+ it ( 'renders basic info section ' , ( ) => {
7652 const wrapper = mountPanel ( createMockAsset ( ) )
77- expect ( wrapper . text ( ) ) . toContain ( 'assetBrowser.modelInfo.title ' )
53+ expect ( wrapper . text ( ) ) . toContain ( 'assetBrowser.modelInfo.basicInfo ' )
7854 } )
7955
8056 it ( 'displays asset filename' , ( ) => {
@@ -83,47 +59,41 @@ describe('ModelInfoPanel', () => {
8359 expect ( wrapper . text ( ) ) . toContain ( 'my-model.safetensors' )
8460 } )
8561
86- it ( 'displays display_name from user_metadata when present' , ( ) => {
62+ it ( 'displays name from user_metadata when present' , ( ) => {
8763 const asset = createMockAsset ( {
88- user_metadata : { display_name : 'My Custom Model' }
64+ user_metadata : { name : 'My Custom Model' }
8965 } )
9066 const wrapper = mountPanel ( asset )
9167 expect ( wrapper . text ( ) ) . toContain ( 'My Custom Model' )
9268 } )
9369
94- it ( 'falls back to asset name when display_name not present' , ( ) => {
70+ it ( 'falls back to asset name when user_metadata.name not present' , ( ) => {
9571 const asset = createMockAsset ( { name : 'fallback-model.safetensors' } )
9672 const wrapper = mountPanel ( asset )
9773 expect ( wrapper . text ( ) ) . toContain ( 'fallback-model.safetensors' )
9874 } )
9975
100- it ( 'renders source link when source_url is present' , ( ) => {
76+ it ( 'renders source link when source_arn is present' , ( ) => {
10177 const asset = createMockAsset ( {
102- user_metadata : { source_url : 'https:// civitai.com/models/ 123' }
78+ user_metadata : { source_arn : 'civitai:model: 123:version:456 ' }
10379 } )
10480 const wrapper = mountPanel ( asset )
105- const link = wrapper . find ( 'a[href="https://civitai.com/models/123"]' )
81+ const link = wrapper . find (
82+ 'a[href="https://civitai.com/models/123?modelVersionId=456"]'
83+ )
10684 expect ( link . exists ( ) ) . toBe ( true )
10785 expect ( link . attributes ( 'target' ) ) . toBe ( '_blank' )
10886 } )
10987
11088 it ( 'displays correct source name for Civitai' , ( ) => {
11189 const asset = createMockAsset ( {
112- user_metadata : { source_url : 'https:// civitai.com/models/ 123' }
90+ user_metadata : { source_arn : 'civitai:model: 123:version:456 ' }
11391 } )
11492 const wrapper = mountPanel ( asset )
11593 expect ( wrapper . text ( ) ) . toContain ( 'Civitai' )
11694 } )
11795
118- it ( 'displays correct source name for Hugging Face' , ( ) => {
119- const asset = createMockAsset ( {
120- user_metadata : { source_url : 'https://huggingface.co/org/model' }
121- } )
122- const wrapper = mountPanel ( asset )
123- expect ( wrapper . text ( ) ) . toContain ( 'Hugging Face' )
124- } )
125-
126- it ( 'does not render source field when source_url is absent' , ( ) => {
96+ it ( 'does not render source field when source_arn is absent' , ( ) => {
12797 const asset = createMockAsset ( )
12898 const wrapper = mountPanel ( asset )
12999 const links = wrapper . findAll ( 'a' )
@@ -132,55 +102,47 @@ describe('ModelInfoPanel', () => {
132102 } )
133103
134104 describe ( 'Model Tagging Section' , ( ) => {
135- it ( 'displays model type from tags' , ( ) => {
136- const asset = createMockAsset ( { tags : [ 'models' , 'loras' ] } )
137- const wrapper = mountPanel ( asset )
138- expect ( wrapper . text ( ) ) . toContain ( 'loras' )
105+ it ( 'renders model tagging section' , ( ) => {
106+ const wrapper = mountPanel ( createMockAsset ( ) )
107+ expect ( wrapper . text ( ) ) . toContain ( 'assetBrowser.modelInfo.modelTagging' )
139108 } )
140109
141- it ( 'extracts last segment from nested tag path' , ( ) => {
142- const asset = createMockAsset ( {
143- tags : [ 'models' , 'checkpoints/sd15' ]
144- } )
145- const wrapper = mountPanel ( asset )
146- expect ( wrapper . text ( ) ) . toContain ( 'sd15' )
110+ it ( 'renders model type field' , ( ) => {
111+ const wrapper = mountPanel ( createMockAsset ( ) )
112+ expect ( wrapper . text ( ) ) . toContain ( 'assetBrowser.modelInfo.modelType' )
147113 } )
148114
149- it ( 'displays base_model when present ' , ( ) => {
115+ it ( 'renders base models field ' , ( ) => {
150116 const asset = createMockAsset ( {
151- user_metadata : { base_model : 'SDXL' }
117+ user_metadata : { base_models : [ 'SDXL' ] }
152118 } )
153119 const wrapper = mountPanel ( asset )
154- expect ( wrapper . text ( ) ) . toContain ( 'SDXL' )
120+ expect ( wrapper . text ( ) ) . toContain (
121+ 'assetBrowser.modelInfo.compatibleBaseModels'
122+ )
155123 } )
156124
157- it ( 'renders additional tags as badges' , ( ) => {
158- const asset = createMockAsset ( {
159- user_metadata : { tags : [ 'anime' , 'portrait' , 'detailed' ] }
160- } )
161- const wrapper = mountPanel ( asset )
162- expect ( wrapper . text ( ) ) . toContain ( 'anime' )
163- expect ( wrapper . text ( ) ) . toContain ( 'portrait' )
164- expect ( wrapper . text ( ) ) . toContain ( 'detailed' )
125+ it ( 'renders additional tags field' , ( ) => {
126+ const wrapper = mountPanel ( createMockAsset ( ) )
127+ expect ( wrapper . text ( ) ) . toContain ( 'assetBrowser.modelInfo.additionalTags' )
165128 } )
166129 } )
167130
168131 describe ( 'Model Description Section' , ( ) => {
169132 it ( 'renders trigger phrases when present' , ( ) => {
170133 const asset = createMockAsset ( {
171- user_metadata : { trigger_phrases : [ 'trigger1' , 'trigger2' ] }
134+ user_metadata : { trained_words : [ 'trigger1' , 'trigger2' ] }
172135 } )
173136 const wrapper = mountPanel ( asset )
174137 expect ( wrapper . text ( ) ) . toContain ( 'trigger1' )
175138 expect ( wrapper . text ( ) ) . toContain ( 'trigger2' )
176139 } )
177140
178- it ( 'renders description when present' , ( ) => {
179- const asset = createMockAsset ( {
180- user_metadata : { description : 'A detailed model description' }
181- } )
182- const wrapper = mountPanel ( asset )
183- expect ( wrapper . text ( ) ) . toContain ( 'A detailed model description' )
141+ it ( 'renders description section' , ( ) => {
142+ const wrapper = mountPanel ( createMockAsset ( ) )
143+ expect ( wrapper . text ( ) ) . toContain (
144+ 'assetBrowser.modelInfo.modelDescription'
145+ )
184146 } )
185147
186148 it ( 'does not render trigger phrases field when empty' , ( ) => {
@@ -193,18 +155,11 @@ describe('ModelInfoPanel', () => {
193155 } )
194156
195157 describe ( 'Accordion Structure' , ( ) => {
196- it ( 'renders three accordion sections' , ( ) => {
197- const wrapper = mountPanel ( createMockAsset ( ) )
198- const accordions = wrapper . findAll ( '[data-testid="accordion-item"]' )
199- expect ( accordions ) . toHaveLength ( 3 )
200- } )
201-
202- it ( 'renders correct section labels' , ( ) => {
158+ it ( 'renders all three section labels' , ( ) => {
203159 const wrapper = mountPanel ( createMockAsset ( ) )
204- const labels = wrapper . findAll ( '[data-testid="accordion-label"]' )
205- expect ( labels [ 0 ] . text ( ) ) . toContain ( 'assetBrowser.modelInfo.basicInfo' )
206- expect ( labels [ 1 ] . text ( ) ) . toContain ( 'assetBrowser.modelInfo.modelTagging' )
207- expect ( labels [ 2 ] . text ( ) ) . toContain (
160+ expect ( wrapper . text ( ) ) . toContain ( 'assetBrowser.modelInfo.basicInfo' )
161+ expect ( wrapper . text ( ) ) . toContain ( 'assetBrowser.modelInfo.modelTagging' )
162+ expect ( wrapper . text ( ) ) . toContain (
208163 'assetBrowser.modelInfo.modelDescription'
209164 )
210165 } )
0 commit comments