UNPKG

2.24 kBJavaScriptView Raw
1
2import { compose } from './style-compose';
3
4it('should compose style strings', () => {
5 expect(compose({})).toBe('-');
6 expect(compose({
7 'colorize': true,
8 'padding': 10,
9 'background': 'blue',
10 'detail': ['red', 'Cyan']
11 })).toBe('-CP10G_blue_D_red,Cyan_');
12 expect(compose({
13 'detailsym': [
14 {
15 'index': 1,
16 'detail': ['yellow']
17 }
18 ]
19 })).toBe('--D01_yellow_');
20 expect(compose({
21 'zoom': 'x'
22 })).toBe('-Zx');
23 expect(compose({
24 'background': '#eee',
25 'detail': ['#fff'],
26 'detailsym': [
27 {
28 'index': 1,
29 'detail': ['#aaa', '#bababa']
30 }
31 ]
32 })).toBe('-G_eee_D_fff_-D01_aaa,bababa_');
33 expect(compose({
34 'classes': 'myclass'
35 })).toBe('---myclass!');
36 expect(compose({
37 'id': 'myid'
38 })).toBe('---!myid!');
39 expect(compose({
40 'colorize': true,
41 'padding': 10,
42 'background': 'blue',
43 'detail': ['red', 'Cyan'],
44 'zoom': 1.1,
45 'detailsym': [
46 {
47 'index': 1,
48 'detail': ['#ff00ff']
49 },
50 {
51 'index': 2,
52 'detail': ['yellow', 'green']
53 }
54 ],
55 'classes': 'primary blinking',
56 'id': 'cursor'
57 })).toBe('-CP10G_blue_D_red,Cyan_Z1.1-D01_ff00ff_D02_yellow,green_-primary blinking!cursor!');
58})
59
60it('should compose without breaking on bad data', () => {
61 expect(compose()).toBe(undefined);
62 expect(compose({
63 'colorize': 'C',
64 'padding': -1,
65 'background': '$color',
66 'detail': 'red',
67 'zoom': -2,
68 'detailsym':
69 {
70 'index': 0,
71 'detail': 'green'
72 },
73 'zoomsym':
74 {
75 'index': 'a',
76 'zoom': 'b',
77 'offset': '500x500'
78 },
79 'classes': '%ox',
80 'id': 'my@'
81 })).toBe('-CG_color_D_r,e_--ox!my!');
82 expect(compose({
83 'padding': 'a',
84 'background': 5,
85 'detail': [1],
86 'zoom': "B",
87 'detailsym': [0, 'green'],
88 'zoomsym': ["index", [0]],
89 'classes': ['%ox'],
90 'id': { 'index': 'what?' }
91 })).toBe('-');
92 expect(compose({
93 'padding': [3, 5],
94 'background': ['yellow'],
95 'detail': { 'a': 5 },
96 'zoom': [1],
97 'detailsym': [0, 'green'],
98 'id': 6
99 })).toBe('-P03Z1');
100})