x
This commit is contained in:
1 parent
78b722e120
commit
75770ca122
18 files changed
+1119
-318
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import { describe, expect, test } from 'bun:test'
|
||||
import { DEFAULT_FOOTER_LAYOUT_SETTINGS } from '@homaroma/types'
|
||||
import {
|
||||
mergeFooterLayoutSettings,
|
||||
normalizeFooterLayoutSettings,
|
||||
validateFooterLayoutSettingsPatch,
|
||||
} from './footerLayoutSettings'
|
||||
|
||||
describe('footer layout settings', () => {
|
||||
test('normalizes missing and invalid persisted values to the shared default', () => {
|
||||
expect(normalizeFooterLayoutSettings(null)).toEqual(DEFAULT_FOOTER_LAYOUT_SETTINGS)
|
||||
expect(normalizeFooterLayoutSettings({ columns: ['brand'] })).toEqual(
|
||||
DEFAULT_FOOTER_LAYOUT_SETTINGS,
|
||||
)
|
||||
})
|
||||
|
||||
test('preserves a valid persisted layout', () => {
|
||||
const layout = { ...DEFAULT_FOOTER_LAYOUT_SETTINGS, mobileColumns: 2 as const }
|
||||
expect(normalizeFooterLayoutSettings(layout)).toEqual(layout)
|
||||
})
|
||||
|
||||
test('merges a partial finale patch without losing sibling settings', () => {
|
||||
expect(mergeFooterLayoutSettings(DEFAULT_FOOTER_LAYOUT_SETTINGS, {
|
||||
containerWidth: 'wide',
|
||||
finale: { enabled: false },
|
||||
})).toEqual({
|
||||
...DEFAULT_FOOTER_LAYOUT_SETTINGS,
|
||||
containerWidth: 'wide',
|
||||
finale: { ...DEFAULT_FOOTER_LAYOUT_SETTINGS.finale, enabled: false },
|
||||
})
|
||||
})
|
||||
|
||||
test('strictly rejects unknown patch fields', () => {
|
||||
const result = validateFooterLayoutSettingsPatch({ arbitraryCss: 'display:none' })
|
||||
expect(result.success).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,32 @@
|
||||
import {
|
||||
DEFAULT_FOOTER_LAYOUT_SETTINGS,
|
||||
FooterLayoutSettingsPatchSchema,
|
||||
FooterLayoutSettingsSchema,
|
||||
type FooterLayoutSettings,
|
||||
type FooterLayoutSettingsPatch,
|
||||
} from '@homaroma/types'
|
||||
|
||||
export function normalizeFooterLayoutSettings(value: unknown): FooterLayoutSettings {
|
||||
const result = FooterLayoutSettingsSchema.safeParse(value)
|
||||
if (result.success) return result.data
|
||||
|
||||
return FooterLayoutSettingsSchema.parse(DEFAULT_FOOTER_LAYOUT_SETTINGS)
|
||||
}
|
||||
|
||||
export function validateFooterLayoutSettingsPatch(value: unknown) {
|
||||
return FooterLayoutSettingsPatchSchema.safeParse(value)
|
||||
}
|
||||
|
||||
export function mergeFooterLayoutSettings(
|
||||
current: FooterLayoutSettings,
|
||||
patch: FooterLayoutSettingsPatch,
|
||||
): FooterLayoutSettings {
|
||||
return FooterLayoutSettingsSchema.parse({
|
||||
...current,
|
||||
...patch,
|
||||
finale: {
|
||||
...current.finale,
|
||||
...patch.finale,
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user