getThemeVariable.test.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. const sass = require('node-sass');
  2. const getThemeVariable = require('./getThemeVariable');
  3. const { mockTheme } = require('@grafana/ui');
  4. const themeMock = {
  5. color: {
  6. background: '#ff0000',
  7. },
  8. spacing: {
  9. padding: '2em',
  10. },
  11. typography: {
  12. fontFamily: 'Arial, sans-serif',
  13. },
  14. };
  15. describe('Variables retrieval', () => {
  16. const restoreTheme = mockTheme(() => themeMock);
  17. afterAll(() => {
  18. restoreTheme();
  19. });
  20. it('returns sass Color for color values', () => {
  21. const result = getThemeVariable({ getValue: () => 'color.background' }, { getValue: () => {} });
  22. expect(result).toBeInstanceOf(sass.types.Color);
  23. });
  24. it('returns sass Number for dimension values', () => {
  25. const result = getThemeVariable({ getValue: () => 'spacing.padding' }, { getValue: () => {} });
  26. expect(result).toBeInstanceOf(sass.types.Number);
  27. });
  28. it('returns sass String for string values', () => {
  29. const result = getThemeVariable({ getValue: () => 'typography.fontFamily' }, { getValue: () => {} });
  30. expect(result).toBeInstanceOf(sass.types.String);
  31. });
  32. it('throws for unknown theme paths', () => {
  33. expect(() => getThemeVariable({ getValue: () => 'what.ever' }, { getValue: () => {} })).toThrow();
  34. });
  35. });