mirror of
https://github.com/LizardByte/Sunshine.git
synced 2026-12-02 01:52:49 +00:00
fix(web): restore category filter button corners
This commit is contained in:
2 files changed
+74
-26
No files matched your search
@@ -8,24 +8,27 @@
|
||||
|
||||
<!-- Category Filter -->
|
||||
<div class="toolbar mb-4">
|
||||
<fieldset class="btn-group">
|
||||
<fieldset>
|
||||
<legend class="visually-hidden">{{ $t('featured.category_filter') }}</legend>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-outline-primary"
|
||||
:class="{ active: selectedCategory === null }"
|
||||
@click="selectedCategory = null">
|
||||
{{ $t('_common.all') }}
|
||||
</button>
|
||||
<button
|
||||
v-for="category in categories"
|
||||
:key="category.id"
|
||||
type="button"
|
||||
class="btn btn-outline-primary"
|
||||
:class="{ active: selectedCategory === category.id }"
|
||||
@click="selectedCategory = category.id">
|
||||
{{ $t(`featured.categories.${category.originalId}`) }}
|
||||
</button>
|
||||
<!-- @brief Keep the legend outside Bootstrap's button group to preserve its outer corners. -->
|
||||
<div class="btn-group">
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-outline-primary"
|
||||
:class="{ active: selectedCategory === null }"
|
||||
@click="selectedCategory = null">
|
||||
{{ $t('_common.all') }}
|
||||
</button>
|
||||
<button
|
||||
v-for="category in categories"
|
||||
:key="category.id"
|
||||
type="button"
|
||||
class="btn btn-outline-primary"
|
||||
:class="{ active: selectedCategory === category.id }"
|
||||
@click="selectedCategory = category.id">
|
||||
{{ $t(`featured.categories.${category.originalId}`) }}
|
||||
</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -50,6 +50,25 @@ function componentStyle(markup, selector) {
|
||||
return getComputedStyle(document.querySelector(selector))
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Mount the featured page with a deterministic app directory.
|
||||
*
|
||||
* @param {object} directory App and category data returned by the directory service.
|
||||
* @returns {Promise<import('@vue/test-utils').VueWrapper>} Mounted featured page.
|
||||
*/
|
||||
async function mountFeatured(directory) {
|
||||
vi.stubGlobal('fetch', vi.fn(async () => ({
|
||||
ok: true,
|
||||
json: async () => directory,
|
||||
})))
|
||||
wrapper = mount(Featured, {
|
||||
attachTo: document.body,
|
||||
global: { mocks: { $t: key => key }, stubs: { Navbar: true, SimpleIcon: true } },
|
||||
})
|
||||
await flushPromises()
|
||||
return wrapper
|
||||
}
|
||||
|
||||
const componentCases = [
|
||||
['body', '<div></div>', 'body', { backgroundColor: 'var(--color-bg-base)', color: 'var(--color-text-base)' }],
|
||||
['card', '<div class="card"></div>', '.card', { backgroundColor: 'var(--color-surface)', color: 'var(--color-text-base)' }],
|
||||
@@ -93,6 +112,40 @@ const componentCases = [
|
||||
]
|
||||
|
||||
describe.each(['light', 'dark'])('%s theme cascade', theme => {
|
||||
it.each([0, 1, 2])('rounds the outside category filter corners with %i categories', async categoryCount => {
|
||||
document.documentElement.dataset.theme = theme
|
||||
document.documentElement.dataset.bsTheme = theme
|
||||
const categories = [
|
||||
{ id: 'clients', originalId: 'clients' },
|
||||
{ id: 'tools', originalId: 'tools' },
|
||||
].slice(0, categoryCount)
|
||||
await mountFeatured({ apps: [], categories })
|
||||
|
||||
expect(wrapper.get('fieldset legend').text()).toBe('featured.category_filter')
|
||||
const buttons = wrapper.findAll('.btn-group > .btn')
|
||||
expect(buttons).toHaveLength(categoryCount + 1)
|
||||
const firstStyle = getComputedStyle(buttons[0].element)
|
||||
const lastStyle = getComputedStyle(buttons.at(-1).element)
|
||||
expect(firstStyle.borderTopLeftRadius).not.toBe('0px')
|
||||
expect(firstStyle.borderBottomLeftRadius).not.toBe('0px')
|
||||
expect(lastStyle.borderTopRightRadius).not.toBe('0px')
|
||||
expect(lastStyle.borderBottomRightRadius).not.toBe('0px')
|
||||
if (categoryCount > 0) {
|
||||
expect(firstStyle.borderTopRightRadius).toBe('0px')
|
||||
expect(firstStyle.borderBottomRightRadius).toBe('0px')
|
||||
expect(lastStyle.borderTopLeftRadius).toBe('0px')
|
||||
expect(lastStyle.borderBottomLeftRadius).toBe('0px')
|
||||
for (const button of buttons.slice(1, -1)) {
|
||||
const style = getComputedStyle(button.element)
|
||||
expect([style.borderTopLeftRadius, style.borderBottomLeftRadius, style.borderTopRightRadius, style.borderBottomRightRadius]).toEqual(['0px', '0px', '0px', '0px'])
|
||||
}
|
||||
await buttons[1].trigger('click')
|
||||
expect(buttons[1].classes()).toContain('active')
|
||||
await buttons[0].trigger('click')
|
||||
expect(buttons[0].classes()).toContain('active')
|
||||
}
|
||||
})
|
||||
|
||||
it('allows specific component rules to override theme defaults', () => {
|
||||
document.documentElement.dataset.theme = theme
|
||||
document.documentElement.dataset.bsTheme = theme
|
||||
@@ -120,15 +173,7 @@ describe.each(['light', 'dark'])('%s theme cascade', theme => {
|
||||
it('themes the rendered official and platform badges without Bootstrap background utilities', async () => {
|
||||
document.documentElement.dataset.theme = theme
|
||||
document.documentElement.dataset.bsTheme = theme
|
||||
vi.stubGlobal('fetch', vi.fn(async () => ({
|
||||
ok: true,
|
||||
json: async () => ({ apps: [{ id: 'sample', name: 'Sample App', official: true, platforms: ['linux'] }] }),
|
||||
})))
|
||||
wrapper = mount(Featured, {
|
||||
attachTo: document.body,
|
||||
global: { mocks: { $t: key => key }, stubs: { Navbar: true, SimpleIcon: true } },
|
||||
})
|
||||
await flushPromises()
|
||||
await mountFeatured({ apps: [{ id: 'sample', name: 'Sample App', official: true, platforms: ['linux'] }] })
|
||||
|
||||
const [official, platform] = wrapper.findAll('.badge')
|
||||
expect(getComputedStyle(official.element).backgroundColor).toBe('var(--color-primary)')
|
||||
|
||||
Reference in new issue
Block a user