-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
/
create.test.js
136 lines (115 loc) · 3.41 KB
/
create.test.js
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import { create } from '../create';
describe('create base', () => {
it('should create a theme with minimal viable theme', () => {
const result = create({ base: 'light' });
expect(result).toBeDefined();
});
it('should pick `light` when `base` is missing', () => {
const result = create({ base: undefined });
expect(result.base).toBe('light');
});
it('should pick `light` when nothing is given', () => {
const result = create();
expect(result.base).toBe('light');
});
it('should pick `dark` when base is dark', () => {
const result = create({ base: 'dark' });
expect(result.base).toBe('dark');
});
it('should pick `light` when base is a unknown value', () => {
const result = create({ base: 'foobar' });
expect(result.base).toBe('light');
});
});
describe('create merge', () => {
it('should merge colorPrimary', () => {
const result = create({ base: 'light', colorPrimary: 'orange' });
expect(result).toHaveProperty('colorPrimary', 'orange');
});
it('should merge colorSecondary', () => {
const result = create({ base: 'light', colorSecondary: 'orange' });
expect(result).toHaveProperty('colorSecondary', 'orange');
});
it('should merge appBg', () => {
const result = create({ base: 'light', appBg: 'orange' });
expect(result).toHaveProperty('appBg', 'orange');
});
});
describe('create brand', () => {
it('should have default', () => {
const result = create({ base: 'light' });
expect(result.brandImage).not.toBeDefined();
expect(result.brandTitle).not.toBeDefined();
expect(result.brandUrl).not.toBeDefined();
expect(result.brandTarget).not.toBeDefined();
});
it('should accept null', () => {
const result = create({ base: 'light', brandTitle: null, brandUrl: null, brandImage: null, brandTarget: null });
expect(result).toMatchObject({
brandImage: null,
brandTitle: null,
brandUrl: null,
brandTarget: null,
});
});
it('should accept values', () => {
const result = create({
base: 'light',
brandImage: 'https://place-hold.it/350x150',
brandTitle: 'my custom storybook',
brandUrl: 'https://example.com',
brandTarget: '_top',
});
expect(result).toMatchObject({
brandImage: 'https://place-hold.it/350x150',
brandTitle: 'my custom storybook',
brandUrl: 'https://example.com',
brandTarget: '_top',
});
});
});
describe('create grid', () => {
it('should have default', () => {
const result = create({ base: 'light' });
expect(result.gridCellSize).not.toBeDefined();
});
it('should accept null', () => {
const result = create({ base: 'light', gridCellSize: null });
expect(result).toMatchObject({
gridCellSize: null,
});
});
it('should accept values', () => {
const result = create({
base: 'light',
gridCellSize: 12,
});
expect(result).toMatchObject({
gridCellSize: 12,
});
});
});
describe('create extend', () => {
it('should allow custom props', () => {
const result = create(
{
base: 'light',
},
{
myCustomProperty: 42,
}
);
expect(result.myCustomProperty).toEqual(42);
});
it('should not allow overriding known properties with custom props', () => {
const result = create(
{
base: 'light',
},
{
base: 42,
}
);
expect(result.base).toEqual('light');
});
});