Merge remote-tracking branch 'origin/develop' into users-statuses-pinia

This commit is contained in:
Henry Jameson 2026-08-12 15:57:42 +03:00
commit 657f405ee0
27 changed files with 167 additions and 20 deletions

View file

@ -0,0 +1,58 @@
import {
getResourcesIndex,
hasInvalidCachedThemeRules,
} from 'src/services/style_setter/style_setter.js'
describe('resource index', () => {
afterEach(() => {
vi.restoreAllMocks()
vi.unstubAllGlobals()
})
it('ignores an HTML fallback returned for a missing custom index', async () => {
vi.spyOn(console, 'warn').mockImplementation(() => undefined)
vi.stubGlobal(
'fetch',
vi
.fn()
.mockResolvedValueOnce(
new Response(JSON.stringify({ builtin: { version: 1 } }), {
headers: { 'Content-Type': 'application/json' },
}),
)
.mockResolvedValueOnce(
new Response('<!doctype html><title>Pleroma</title>', {
headers: { 'Content-Type': 'text/html' },
}),
),
)
const resources = await getResourcesIndex('/static/styles.json')
expect(Object.keys(resources)).to.deep.equal(['builtin'])
expect(resources.builtin()).to.deep.equal({ version: 1 })
})
})
describe('style setter cache', () => {
it('rejects cached rules containing serialized objects', () => {
expect(
hasInvalidCachedThemeRules([
['html { --font: [object Object]; }'],
['.post { --font: sans-serif; }'],
]),
).to.equal(true)
})
it('accepts cached rules containing valid font families', () => {
expect(
hasInvalidCachedThemeRules([
['html { --font: sans-serif; }'],
[
'.post { --font: "Atkinson Hyperlegible"; }',
'.post::after { content: "[object Object]"; }',
],
]),
).to.equal(false)
})
})

View file

@ -0,0 +1,42 @@
import {
basePaletteKeys,
convertTheme2To3,
} from 'src/services/theme_data/theme2_to_theme3.js'
describe('Theme 2 to Theme 3 conversion', () => {
it('converts font descriptors to CSS font families', () => {
const colors = Object.fromEntries(
[...basePaletteKeys].map((key) => [key, '#000000']),
)
const rules = convertTheme2To3({
colors,
fonts: {
interface: { family: 'sans-serif' },
input: { family: 'Open Sans' },
post: { family: 'Atkinson Hyperlegible' },
postCode: { family: 'monospace' },
},
})
expect(rules).to.deep.include({
source: '2to3',
component: 'Root',
directives: { '--font': 'generic | sans-serif' },
})
expect(rules).to.deep.include({
source: '2to3',
component: 'Root',
directives: { '--monoFont': 'generic | monospace' },
})
expect(rules).to.deep.include({
source: '2to3',
component: 'Input',
directives: { '--font': 'generic | Open Sans' },
})
expect(rules).to.deep.include({
source: '2to3',
component: 'RichContent',
directives: { '--font': 'generic | Atkinson Hyperlegible' },
})
})
})