|
| 1 | +import {SETTINGS_INIT} from '@config/state'; |
| 2 | +import {getCloudThemeWallpaper} from '@config/themePresets'; |
| 3 | +import themeController from '@helpers/themeController'; |
| 4 | +import type {Theme} from '@layer'; |
| 5 | + |
| 6 | +const factory = SETTINGS_INIT.themes.find((theme) => theme.name === 'light'); |
| 7 | +const factoryWallpaper = factory.settings.find((settings) => settings.base_theme._ === 'baseThemeDay').wallpaper; |
| 8 | + |
| 9 | +const makeTheme = (wallpaper?: Theme['settings'][number]['wallpaper']) => ({ |
| 10 | + _: 'theme', |
| 11 | + id: '1', |
| 12 | + access_hash: '', |
| 13 | + slug: 'theme', |
| 14 | + title: 'Theme', |
| 15 | + pFlags: {}, |
| 16 | + settings: [{_: 'themeSettings', pFlags: {}, base_theme: {_: 'baseThemeDay'}, accent_color: 0x7e5fe5, message_colors: [0x7e5fe5, 0x2d7ed5], wallpaper}] |
| 17 | +} as Theme); |
| 18 | + |
| 19 | +describe('the plain white the server gives the Day base of a cloud theme', () => { |
| 20 | + const white = {_: 'wallPaperNoFile', id: 1, pFlags: {}, settings: {_: 'wallPaperSettings', pFlags: {}, background_color: 0xffffff}} as const; |
| 21 | + const classic = {...factoryWallpaper, slug: 'classic'}; |
| 22 | + const make = (base: 'baseThemeDay' | 'baseThemeNight', wallpaper: any) => { |
| 23 | + const entry = {_: 'themeSettings', pFlags: {}, base_theme: {_: base}, accent_color: 0, wallpaper} as any; |
| 24 | + return {...makeTheme(), settings: [entry, {...entry, base_theme: {_: 'baseThemeClassic'}, wallpaper: classic}]} as Theme; |
| 25 | + }; |
| 26 | + |
| 27 | + test('gives way to the wallpaper of the theme\'s Classic base', () => { |
| 28 | + const theme = make('baseThemeDay', white); |
| 29 | + expect(getCloudThemeWallpaper(theme, theme.settings[0])).toBe(classic); |
| 30 | + }); |
| 31 | + |
| 32 | + test('another colour, or another base, stays', () => { |
| 33 | + const colored = {...white, settings: {...white.settings, background_color: 0xff0000}}; |
| 34 | + const day = make('baseThemeDay', colored); |
| 35 | + expect(getCloudThemeWallpaper(day, day.settings[0])).toBe(colored); |
| 36 | + const night = make('baseThemeNight', white); |
| 37 | + expect(getCloudThemeWallpaper(night, night.settings[0])).toBe(white); |
| 38 | + }); |
| 39 | + |
| 40 | + test('a white picked for an AppTheme stays, a chat\'s theme gets the wallpaper', () => { |
| 41 | + vi.spyOn(themeController as any, 'getResolvedThemeName').mockReturnValue('light'); |
| 42 | + const theme = make('baseThemeDay', white); |
| 43 | + expect(themeController.getThemeWallpaper({...theme, name: 'light'} as any)).toBe(white); |
| 44 | + expect(themeController.getThemeWallpaper(theme)).toBe(classic); |
| 45 | + vi.restoreAllMocks(); |
| 46 | + }); |
| 47 | +}); |
| 48 | + |
| 49 | +describe('a theme without a wallpaper of its own', () => { |
| 50 | + beforeEach(() => { |
| 51 | + vi.spyOn(themeController as any, 'getResolvedThemeName').mockReturnValue('light'); |
| 52 | + }); |
| 53 | + |
| 54 | + afterEach(() => { |
| 55 | + vi.restoreAllMocks(); |
| 56 | + }); |
| 57 | + |
| 58 | + test('keeps the current wallpaper', () => { |
| 59 | + const current = {...makeTheme(factoryWallpaper), name: 'light'} as any; |
| 60 | + vi.spyOn(themeController, 'getTheme').mockReturnValue(current); |
| 61 | + expect(themeController.getThemeWallpaper(makeTheme())).toBe(factoryWallpaper); |
| 62 | + }); |
| 63 | + |
| 64 | + test('saved as the current theme, it gets the factory wallpaper', () => { |
| 65 | + const current = {...makeTheme(), name: 'light'} as any; |
| 66 | + vi.spyOn(themeController, 'getTheme').mockReturnValue(current); |
| 67 | + expect(themeController.getThemeWallpaper(current)).toBe(factoryWallpaper); |
| 68 | + }); |
| 69 | + |
| 70 | + test('a wallpaper of its own stays', () => { |
| 71 | + const own = {...factoryWallpaper, slug: 'own'}; |
| 72 | + vi.spyOn(themeController, 'getTheme').mockReturnValue(factory); |
| 73 | + expect(themeController.getThemeWallpaper(makeTheme(own))).toBe(own); |
| 74 | + }); |
| 75 | +}); |
0 commit comments