Show each LoRA dropdown label once

This commit is contained in:
Towsty
2026-09-12 20:45:19 -05:00
parent 401e6c26a2
commit fb87a50a39
2 changed files with 21 additions and 1 deletions
+2 -1
View File
@@ -97,7 +97,8 @@
v-for="name in availableNames" v-for="name in availableNames"
:key="name" :key="name"
:value="name" :value="name"
>{{ labelFor(name) }}{{ filenameSubtitle ? ' — '+name : '' }}</option> :title="name"
>{{ labelFor(name) }}</option>
</select> </select>
</div> </div>
</template> </template>
+19
View File
@@ -0,0 +1,19 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import {readFileSync} from 'node:fs'
import * as Vue from 'vue'
import {compile} from '@vue/compiler-dom'
import {renderToString} from '@vue/server-renderer'
import {loraFriendlyName,loraIdentityKey} from '../utils/loras.ts'
test('LoRA dropdown renders one clean label or alias, with filename only in tooltip',async()=>{
const source=readFileSync(new URL('../components/LoraSelect.vue',import.meta.url),'utf8')
const option=source.match(/<option\s+v-for="name in availableNames"[\s\S]*?<\/option>/)[0]
const render=new Function('Vue',compile('<select>'+option+'</select>',{mode:'function',prefixIdentifiers:true}).code)(Vue)
const names=['xaigen-minimax csot.safetensors','folder/XAIgen-klein-portrait.safetensors']
const aliases={[loraIdentityKey(names[1])]:'Portrait style'}
const html=await renderToString(Vue.createSSRApp({render,setup:()=>({availableNames:names,filenameSubtitle:true,labelFor:name=>loraFriendlyName(name,aliases)})}))
const options=[...html.matchAll(/<option[^>]*title="([^"]*)"[^>]*>([^<]*)<\/option>/g)]
assert.deepEqual(options.map(match=>match[1]),names)
assert.deepEqual(options.map(match=>match[2]),['xaigen-minimax csot','Portrait style'])
})