File size: 2,884 Bytes
b456468
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import Theme from '@/ui/theme/theme';
import defaultTheme from '@/ui/theme/standard';

describe('Theme', () => {
  let theme;

  beforeEach(() => {
    theme = new Theme(defaultTheme);
  });

  describe('getStyle()', () => {
    it('should have "path" and "name" when the user sets the icon file location', () => {
      const userIconPath = 'fixtures/icon-d.svg';
      const userIconName = 'icon-d';
      const themeForIconPathSet = new Theme({
        ...defaultTheme,
        'menu.normalIcon.path': userIconPath,
        'menu.normalIcon.name': userIconName,
      });
      const {
        normal: { path, name },
      } = themeForIconPathSet.getStyle('menu.icon');

      expect(path).toBe(userIconPath);
      expect(name).toBe(userIconName);
    });

    it('should return default icon color information', () => {
      const { normal, active, disabled, hover } = theme.getStyle('menu.icon');

      expect(normal.color).toBe('#8a8a8a');
      expect(active.color).toBe('#555555');
      expect(disabled.color).toBe('#434343');
      expect(hover.color).toBe('#e9e9e9');
    });

    it('should return cssText in normal types', () => {
      theme.styles.normal = {
        backgroundColor: '#fdba3b',
        border: '1px solid #fdba3b',
        color: '#fff',
        fontFamily: 'NotoSans, sans-serif',
        fontSize: '12px',
      };

      expect(theme.getStyle('normal')).toMatchSnapshot();
    });

    it('should return cssText if all members are objects', () => {
      theme.styles['submenu.normalLabel'] = {
        color: '#858585',
        fontWeight: 'normal',
      };
      theme.styles['submenu.activeLabel'] = {
        color: '#000',
        fontWeight: 'normal',
      };

      expect(theme.getStyle('submenu.label')).toMatchSnapshot();
    });
  });

  describe('_makeCssText()', () => {
    it('should return the cssText of the expected value for the object', () => {
      const styleObject = {
        backgroundColor: '#fff',
        backgroundImage: './img/bg.png',
        border: '1px solid #ddd',
        color: '#222',
        fontFamily: 'NotoSans, sans-serif',
        fontSize: '12px',
      };

      expect(theme._makeCssText(styleObject)).toMatchSnapshot();
    });
  });

  describe('_makeSvgItem()', () => {
    it('should create path prefix and use-default class when using the default icon', () => {
      const useTagString = theme._makeSvgItem(['normal'], 'crop');

      expect(useTagString).toMatchSnapshot();
    });

    it('should create a svg path with the prefix when set the icon file', () => {
      const themeForIconPathSet = new Theme({
        ...defaultTheme,
        'menu.normalIcon.path': 'fixtures/icon-d.svg',
        'menu.normalIcon.name': 'icon-d',
      });
      const useTagString = themeForIconPathSet._makeSvgItem(['normal'], 'crop');

      expect(useTagString).toMatchSnapshot();
    });
  });
});