UNPKG

2.44 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 'zoomsym': [
56 {
57 'index': 1,
58 'zoom': 10,
59 'offset': [0, 0]
60 },
61 {
62 'index': 2,
63 'zoom': 5.5
64 }
65 ],
66 'classes': 'primary blinking',
67 'id': 'cursor'
68 })).toBe('-CP10G_blue_D_red,Cyan_Z1.1-D01_ff00ff_D02_yellow,green_Z01,10,500x500Z02,5.5-primary blinking!cursor!');
69})
70
71it('should compose without breaking on bad data', () => {
72 expect(compose()).toBe(undefined);
73 expect(compose({
74 'colorize': 'C',
75 'padding': -1,
76 'background': '$color',
77 'detail': 'red',
78 'zoom': -2,
79 'detailsym':
80 {
81 'index': 0,
82 'detail': 'green'
83 },
84 'zoomsym':
85 {
86 'index': 'a',
87 'zoom': 'b',
88 'offset': '500x500'
89 },
90 'classes': '%ox',
91 'id': 'my@'
92 })).toBe('-CG_color_D_r,e_--ox!my!');
93 expect(compose({
94 'padding': 'a',
95 'background': 5,
96 'detail': [1],
97 'zoom': "B",
98 'detailsym': [0, 'green'],
99 'zoomsym': ["index", [0]],
100 'classes': ['%ox'],
101 'id': { 'index': 'what?' }
102 })).toBe('-');
103 expect(compose({
104 'padding': [3, 5],
105 'background': ['yellow'],
106 'detail': { 'a': 5 },
107 'zoom': [1],
108 'detailsym': [0, 'green'],
109 'id': 6
110 })).toBe('-P03Z1');
111})