diff --git a/tests/test_viewer_studio.cjs b/tests/test_viewer_studio.cjs index 0fab2fb59..301f4b0a1 100644 --- a/tests/test_viewer_studio.cjs +++ b/tests/test_viewer_studio.cjs @@ -290,6 +290,46 @@ test('switching to EU relabels the stats panel, the buttons, the texture gallery assert.equal(studio.elements.get('tex-count').innerText, 'Could not load the textures'); }); +test('category chips and headers show the catNames of the chosen language and keep the server name as the filter', () => { + const studio = loadStudio(); + studio.context.models = [ + { name: 'car.glb', folder: 'veh', category: 'Транспорт (Vehicles)', size: 4, url: '/models/car.glb' }, + { name: 'odd.glb', folder: 'x', category: 'Custom', size: 4, url: '/models/odd.glb' }, + ]; + studio.run(`allModels = models; renderCategoryChips({'Транспорт (Vehicles)': 1, Custom: 1}); renderAccordionList();`); + const chips = () => studio.elements.get('category-chips').children.slice(1).map(chip => chip.innerText); + const headers = () => studio.elements.get('model-list').children.map(group => visibleText(group.children[0].innerHTML).trim()); + assert.deepEqual(chips(), ['Транспорт (1)', 'Custom (1)']); + assert.deepEqual(headers().map(text => text.split(/\s+/)[0]), ['Транспорт', 'Custom']); + + studio.run(`setLanguage('eu')`); + assert.deepEqual(chips(), ['Vehicles (1)', 'Custom (1)']); + assert.deepEqual(headers().map(text => text.split(/\s+/)[0]), ['Vehicles', 'Custom']); + // The chip still filters by the server's name. + studio.run(`selectCategory('Транспорт (Vehicles)', document.getElementById('category-chips').children[1])`); + assert.equal(studio.run('activeCategory'), 'Транспорт (Vehicles)'); + assert.deepEqual(headers().map(text => text.split(/\s+/)[0]), ['Vehicles']); +}); + +test('model search matches the category name shown in the chosen language, not only the server name', () => { + const studio = loadStudio(); + studio.context.models = [ + { name: 'tree.glb', folder: 'x', category: 'Растительность (Nature)', size: 4, url: '/models/tree.glb' }, + { name: 'car.glb', folder: 'y', category: 'Транспорт (Vehicles)', size: 4, url: '/models/car.glb' }, + ]; + studio.run(`currentLang = 'eu'; allModels = models; renderAccordionList();`); + const search = query => { + studio.context.query = query; + studio.run(`document.getElementById('model-search').value = query; onModelSearch();`); + return studio.elements.get('model-list').children.map(group => visibleText(group.children[0].innerHTML).trim().split(/\s+/)[0]); + }; + // "Vegetation" is only in the EU label "Vegetation & Nature", not in the server's name. + assert.deepEqual(search('Vegetation'), ['Vegetation']); + // The server's name still matches, in either language. + assert.deepEqual(search('Транспорт'), ['Vehicles']); + assert.deepEqual(search('Nature'), ['Vegetation']); +}); + test('each model category pages independently, including a partial last page', () => { const studio = loadStudio(); studio.context.models = ['Props', 'Vehicles'].flatMap(category => Array.from({ length: 101 }, (_, i) => ({ diff --git a/viewer/studio.html b/viewer/studio.html index 1dec6b9cf..2375f4076 100644 --- a/viewer/studio.html +++ b/viewer/studio.html @@ -590,6 +590,7 @@ function applyTranslations() { document.getElementById('tex-heading').innerText = t.texHeading; const allChip = document.getElementById('chip-all'); if (allChip) allChip.innerText = `${t.allCategories} (${allModels.length})`; + for (const { chip, cat, count } of categoryChips) chip.innerText = `${categoryLabel(cat)} (${count})`; if (texturesLoaded) document.getElementById('tex-count').innerText = `${allTextures.length} ${t.texCountSuffix}`; // Each stats label is the text node in front of its value (