forked from vadimdemedes/tailwind-rn
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
146 lines (125 loc) · 3.16 KB
/
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
137
138
139
140
141
142
143
144
145
146
import test from 'ava';
import tailwind, {getColor} from '.';
test('get styles for one class', t => {
t.deepEqual(tailwind('text-blue-500'), {color: 'rgba(59, 130, 246, 1)'});
});
test('get styles for multiple classes', t => {
t.deepEqual(tailwind('text-blue-500 bg-blue-100'), {
color: 'rgba(59, 130, 246, 1)',
backgroundColor: 'rgba(219, 234, 254, 1)'
});
});
test('ignore unknown classes', t => {
t.deepEqual(tailwind('text-blue-500 unknown'), {
color: 'rgba(59, 130, 246, 1)'
});
});
test('support color opacity', t => {
t.deepEqual(
tailwind(
'text-blue-500 text-opacity-50 bg-blue-100 bg-opacity-50 border-blue-100 border-opacity-50'
),
{
color: 'rgba(59, 130, 246, 0.5)',
backgroundColor: 'rgba(219, 234, 254, 0.5)',
borderTopColor: 'rgba(219, 234, 254, 0.5)',
borderRightColor: 'rgba(219, 234, 254, 0.5)',
borderBottomColor: 'rgba(219, 234, 254, 0.5)',
borderLeftColor: 'rgba(219, 234, 254, 0.5)'
}
);
});
test('ignore non-string values when transforming CSS variables', t => {
t.deepEqual(tailwind('bg-blue-500 p-12'), {
backgroundColor: 'rgba(59, 130, 246, 1)',
paddingTop: 48,
paddingRight: 48,
paddingBottom: 48,
paddingLeft: 48
});
});
test('get color value', t => {
t.is(getColor('blue-500'), 'rgba(59, 130, 246, 1)');
});
test('get color with opacity value', t => {
t.is(getColor('blue-500 opacity-50'), 'rgba(59, 130, 246, 0.5)');
});
test('ignore no value param', t => {
t.deepEqual(tailwind(null), {});
t.deepEqual(tailwind(false), {});
t.deepEqual(tailwind(undefined), {});
t.deepEqual(tailwind(0), {});
});
test('ignore extra spaces', t => {
t.deepEqual(tailwind('text-blue-500 bg-blue-100'), {
color: 'rgba(59, 130, 246, 1)',
backgroundColor: 'rgba(219, 234, 254, 1)'
});
t.deepEqual(
tailwind(`
text-blue-500
bg-blue-100
`),
{
color: 'rgba(59, 130, 246, 1)',
backgroundColor: 'rgba(219, 234, 254, 1)'
}
);
});
test('support font-variant-numeric', t => {
t.deepEqual(tailwind('oldstyle-nums'), {
fontVariant: ['oldstyle-nums']
});
t.deepEqual(tailwind('lining-nums'), {
fontVariant: ['lining-nums']
});
t.deepEqual(tailwind('tabular-nums'), {
fontVariant: ['tabular-nums']
});
t.deepEqual(tailwind('proportional-nums'), {
fontVariant: ['proportional-nums']
});
t.deepEqual(
tailwind('oldstyle-nums lining-nums tabular-nums proportional-nums'),
{
fontVariant: [
'oldstyle-nums',
'lining-nums',
'tabular-nums',
'proportional-nums'
]
}
);
});
test('support letter spacing', t => {
t.deepEqual(tailwind('text-base tracking-tighter'), {
fontSize: 16,
letterSpacing: -0.8,
lineHeight: 24
});
t.deepEqual(tailwind('text-base tracking-tight'), {
fontSize: 16,
letterSpacing: -0.4,
lineHeight: 24
});
t.deepEqual(tailwind('text-base tracking-normal'), {
fontSize: 16,
letterSpacing: 0,
lineHeight: 24
});
t.deepEqual(tailwind('text-base tracking-wide'), {
fontSize: 16,
letterSpacing: 0.4,
lineHeight: 24
});
t.deepEqual(tailwind('text-base tracking-wider'), {
fontSize: 16,
letterSpacing: 0.8,
lineHeight: 24
});
t.deepEqual(tailwind('text-base tracking-widest'), {
fontSize: 16,
letterSpacing: 1.6,
lineHeight: 24
});
});