mirror of https://github.com/grafana/grafana
parent
dc6b27d123
commit
5ba3b0aa2c
@ -1,4 +1,4 @@ |
||||
import { GrafanaTheme } from "../types"; |
||||
|
||||
export function getTheme(themeName?: string): GrafanaTheme |
||||
export function mockTheme(themeMock: Partial<GrafanaTheme>): () => void |
||||
export function mockTheme(themeMock: (name: string) => object): () => void |
||||
|
@ -0,0 +1,51 @@ |
||||
import { GrafanaThemeType } from '../types/theme'; |
||||
import { selectThemeVariant } from './selectThemeVariant'; |
||||
import { mockTheme } from './index'; |
||||
|
||||
const lightThemeMock = { |
||||
color: { |
||||
red: '#ff0000', |
||||
green: '#00ff00', |
||||
}, |
||||
}; |
||||
|
||||
const darkThemeMock = { |
||||
color: { |
||||
red: '#ff0000', |
||||
green: '#00ff00', |
||||
}, |
||||
}; |
||||
|
||||
describe('Theme variable variant selector', () => { |
||||
const restoreTheme = mockTheme(name => (name === GrafanaThemeType.Light ? lightThemeMock : darkThemeMock)); |
||||
|
||||
afterAll(() => { |
||||
restoreTheme(); |
||||
}); |
||||
it('return correct variable value for given theme', () => { |
||||
const theme = lightThemeMock; |
||||
|
||||
const selectedValue = selectThemeVariant( |
||||
{ |
||||
dark: theme.color.red, |
||||
light: theme.color.green, |
||||
}, |
||||
GrafanaThemeType.Light |
||||
); |
||||
|
||||
expect(selectedValue).toBe(lightThemeMock.color.green); |
||||
}); |
||||
|
||||
it('return dark theme variant if no theme given', () => { |
||||
const theme = lightThemeMock; |
||||
|
||||
const selectedValue = selectThemeVariant( |
||||
{ |
||||
dark: theme.color.red, |
||||
light: theme.color.green, |
||||
} |
||||
); |
||||
|
||||
expect(selectedValue).toBe(lightThemeMock.color.red); |
||||
}); |
||||
}); |
@ -0,0 +1,9 @@ |
||||
import { GrafanaThemeType } from '../types/theme'; |
||||
|
||||
type VariantDescriptor = { |
||||
[key in GrafanaThemeType]: string | number; |
||||
}; |
||||
|
||||
export const selectThemeVariant = (variants: VariantDescriptor, currentTheme?: GrafanaThemeType) => { |
||||
return variants[currentTheme || GrafanaThemeType.Dark]; |
||||
}; |
Loading…
Reference in new issue