appearance.test.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { describe, expect, it } from 'vitest'
  2. import { DEFAULT_APPEARANCE, launchAppearanceKey, normalizeAppearance, wantsBlur } from './appearance'
  3. describe('normalizeAppearance', () => {
  4. it('fills defaults for a missing or partial value', () => {
  5. expect(normalizeAppearance(undefined)).toEqual(DEFAULT_APPEARANCE)
  6. expect(normalizeAppearance({ theme: 'light' })).toEqual({ ...DEFAULT_APPEARANCE, theme: 'light' })
  7. })
  8. it('clamps out of range numbers and drops unknown themes', () => {
  9. const a = normalizeAppearance({
  10. theme: 'neon' as never,
  11. accentHue: 500,
  12. accentChroma: -1,
  13. windowOpacity: 3
  14. })
  15. expect(a).toEqual({
  16. theme: 'dark',
  17. accentHue: 360,
  18. accentChroma: 0,
  19. windowOpacity: 40,
  20. blur: false,
  21. previewAnimation: 'always'
  22. })
  23. })
  24. })
  25. describe('launchAppearanceKey', () => {
  26. it('ignores what can change live', () => {
  27. const base = normalizeAppearance({ windowOpacity: 80 })
  28. expect(launchAppearanceKey({ ...base, windowOpacity: 60, accentHue: 10, theme: 'light' })).toBe(
  29. launchAppearanceKey(base)
  30. )
  31. })
  32. it('changes when the window has to become transparent or blurred', () => {
  33. const opaque = normalizeAppearance({})
  34. expect(launchAppearanceKey({ ...opaque, windowOpacity: 90 })).not.toBe(launchAppearanceKey(opaque))
  35. expect(wantsBlur({ ...opaque, blur: true })).toBe(false)
  36. expect(wantsBlur({ ...opaque, blur: true, windowOpacity: 90 })).toBe(true)
  37. })
  38. })