|
| 1 | +import type { DevframeHubContext } from '@devframes/hub/node' |
| 2 | +import { readFileSync } from 'node:fs' |
| 3 | +import { fileURLToPath } from 'node:url' |
| 4 | +import { describe, expect, it } from 'vitest' |
| 5 | +import { createUi } from './index' |
| 6 | + |
| 7 | +function createContext(): DevframeHubContext { |
| 8 | + return { staticConfig: {} } as unknown as DevframeHubContext |
| 9 | +} |
| 10 | + |
| 11 | +describe('createUi branding background', () => { |
| 12 | + it('defines the viewer background through a static token', () => { |
| 13 | + expect.assertions(6) |
| 14 | + |
| 15 | + const html = readFileSync(fileURLToPath(new URL('../dist/client/standalone/index.html', import.meta.url)), 'utf8') |
| 16 | + |
| 17 | + expect(html).not.toContain('__hub-ui.css') |
| 18 | + expect(html).toContain('html.viewer-background-custom') |
| 19 | + expect(html).toContain('--devframes-viewer-background: #fff') |
| 20 | + expect(html).toContain('--devframes-viewer-background: #111') |
| 21 | + expect(html).toContain('background: var(--devframes-viewer-background)') |
| 22 | + expect(html).toMatch(/html\.viewer-background-custom\s*\{[^}]*color-scheme:\s*normal/) |
| 23 | + }) |
| 24 | + |
| 25 | + it('preserves the default viewer background', () => { |
| 26 | + expect.assertions(2) |
| 27 | + |
| 28 | + const context = createContext() |
| 29 | + const ui = createUi() |
| 30 | + ui.setup?.(context) |
| 31 | + |
| 32 | + expect(context.staticConfig.ui).toEqual({ branding: {} }) |
| 33 | + expect(ui.assets).toBeUndefined() |
| 34 | + }) |
| 35 | + |
| 36 | + it('publishes a CSS viewer background with the branding', () => { |
| 37 | + expect.assertions(2) |
| 38 | + |
| 39 | + const context = createContext() |
| 40 | + const ui = createUi({ branding: { background: 'transparent' } }) |
| 41 | + ui.setup?.(context) |
| 42 | + |
| 43 | + expect(context.staticConfig.ui).toEqual({ |
| 44 | + branding: { background: 'transparent' }, |
| 45 | + }) |
| 46 | + expect(ui.assets).toBeUndefined() |
| 47 | + }) |
| 48 | + |
| 49 | + it('publishes color-scheme viewer backgrounds with the branding', () => { |
| 50 | + expect.assertions(1) |
| 51 | + |
| 52 | + const context = createContext() |
| 53 | + const background = { |
| 54 | + light: 'linear-gradient(white, transparent)', |
| 55 | + dark: 'linear-gradient(#111, transparent)', |
| 56 | + } |
| 57 | + const ui = createUi({ branding: { background } }) |
| 58 | + ui.setup?.(context) |
| 59 | + |
| 60 | + expect(context.staticConfig.ui).toEqual({ branding: { background } }) |
| 61 | + }) |
| 62 | + |
| 63 | + it('disables the standalone viewer', () => { |
| 64 | + expect.assertions(1) |
| 65 | + |
| 66 | + const ui = createUi({ viewer: false }) |
| 67 | + |
| 68 | + expect(ui.viewer).toBeUndefined() |
| 69 | + }) |
| 70 | +}) |
0 commit comments