-
Notifications
You must be signed in to change notification settings - Fork 11
/
test.js
130 lines (109 loc) · 3.05 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
var test = require('tape')
var gr8 = require('.')
test('output', function (t) {
t.ok(typeof gr8() === 'string', 'outputs string')
t.end()
})
test('selector', function (t) {
var css = gr8({
selector: s => `.gr8-${s}`
})
t.ok(css.indexOf('.gr8-') >= 0, 'supports custom selector')
t.end()
})
test('disable breakpoints', function (t) {
var css = gr8({
breakpoints: false
})
t.ok(css.indexOf('@media') < 0, 'supports disabling breakpoints')
t.end()
})
test('breakpoint selector', function (t) {
var cssA = gr8({
breakpointSelector: 'attribute'
})
t.ok(cssA.indexOf('[sm~=') >= 0, 'supports attribute breakpoint selector shortcut')
var cssB = gr8({
breakpointSelector: 'class'
})
t.ok(cssB.indexOf('.sm-') >= 0, 'supports class breakpoint selector shortcut')
var cssC = gr8({
breakpointSelector: key => s => `.gr8 [${key}~="${s}"]`
})
t.ok(cssC.indexOf('.gr8 [sm~=') >= 0, 'supports custom breakpoint selector')
t.end()
})
test('custom breakpoints', function (t) {
var css = gr8({
breakpoints: {
a: '(max-width:768px)',
b: 1024,
c: '(orientation:landscape)'
}
})
t.ok(css.indexOf('@media (max-width:768px)') >= 0, 'supports custom breakpoints A')
t.ok(css.indexOf('@media (min-width:1024px)') >= 0, 'supports custom breakpoints B')
t.ok(css.indexOf('@media (orientation:landscape)') >= 0, 'supports custom breakpoints C')
t.end()
})
test('unit', function (t) {
var css = gr8({
unit: 'px'
})
t.ok(css.indexOf('.fs6-4{font-size:6.4px}') >= 0, 'supports unit option')
t.end()
})
test('values', function (t) {
var css = gr8({
spacing: [99],
fontSize: [99],
lineHeight: [99],
size: [99],
viewport: [99],
zIndex: [99],
flexOrder: [99],
opacity: [99],
aspectRatio: [99],
textColumn: [99]
})
var hasAll = css.indexOf('.p99') >= 0 &&
css.indexOf('.fs99') >= 0 &&
css.indexOf('.lh99') >= 0 &&
css.indexOf('.w99') >= 0 &&
css.indexOf('.vw99') >= 0 &&
css.indexOf('.z99') >= 0 &&
css.indexOf('.xo99') >= 0 &&
css.indexOf('.op99') >= 0 &&
css.indexOf('.ar99') >= 0 &&
css.indexOf('.tc99') >= 0
t.ok(hasAll, 'custom values succesfully passed to gr8-util')
t.end()
})
test('custom util', function (t) {
var css = gr8({
utils: [
{
prop: 'foo',
vals: 'bar'
}
]
})
t.ok(css.indexOf('.fb{foo:bar}') >= 0, 'custom utils succesfully generated')
t.ok(css.indexOf('[sm~="fb"]{foo:bar}') >= 0, 'custom utils succesfully generated per breakpoint')
t.end()
})
test('custom raw util', function (t) {
var css = gr8({
utils: [
{
raw: {
'trans-center-x': 'left:50%;transform:translateX(-50%)',
'trans-center-y': 'top:50%;transform:translateY(-50%)'
}
}
]
})
t.ok(css.indexOf('.trans-center-x{left:50%;transform:translateX(-50%)}') >= 0, 'custom raw utils succesfully generated')
t.ok(css.indexOf('[sm~="trans-center-x"]{left:50%;transform:translateX(-50%)}') >= 0, 'custom raw utils succesfully generated per breakpoint')
t.end()
})