kempo-css 2.0.0 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,171 +1,171 @@
1
- const getStyle = (el, prop) => getComputedStyle(el)[prop];
2
-
3
- export const beforeAll = async () => {
4
- const link = document.createElement('link');
5
- link.rel = 'stylesheet';
6
- link.href = '/src/kempo.css';
7
- document.head.appendChild(link);
8
- await new Promise(resolve => link.onload = resolve);
9
- };
10
-
11
- export default {
12
- 'should apply flex display to .row': ({pass, fail}) => {
13
- const el = document.createElement('div');
14
- el.className = 'row';
15
- document.body.appendChild(el);
16
- const display = getStyle(el, 'display');
17
- const flexWrap = getStyle(el, 'flexWrap');
18
- el.remove();
19
- if(display === 'flex' && flexWrap === 'wrap'){
20
- pass('.row applies flex with wrap');
21
- } else {
22
- fail(`Expected flex/wrap, got display: ${display}, wrap: ${flexWrap}`);
23
- }
24
- },
25
-
26
- 'should apply flex to .col': ({pass, fail}) => {
27
- const el = document.createElement('div');
28
- el.className = 'col';
29
- document.body.appendChild(el);
30
- const flexGrow = getStyle(el, 'flexGrow');
31
- el.remove();
32
- if(flexGrow === '1'){
33
- pass('.col has flex-grow: 1');
34
- } else {
35
- fail(`Expected flex-grow: 1, got ${flexGrow}`);
36
- }
37
- },
38
-
39
- 'should apply span-6 as 50% width': ({pass, fail}) => {
40
- const row = document.createElement('div');
41
- row.className = 'row';
42
- row.style.width = '1000px';
43
- const col = document.createElement('div');
44
- col.className = 'span-6';
45
- row.appendChild(col);
46
- document.body.appendChild(row);
47
- const flexBasis = getStyle(col, 'flexBasis');
48
- row.remove();
49
- if(flexBasis === '50%'){
50
- pass('.span-6 sets flex-basis to 50%');
51
- } else {
52
- fail(`Expected 50%, got ${flexBasis}`);
53
- }
54
- },
55
-
56
- 'should apply span-12 as 100% width': ({pass, fail}) => {
57
- const col = document.createElement('div');
58
- col.className = 'span-12';
59
- document.body.appendChild(col);
60
- const flexBasis = getStyle(col, 'flexBasis');
61
- col.remove();
62
- if(flexBasis === '100%'){
63
- pass('.span-12 sets flex-basis to 100%');
64
- } else {
65
- fail(`Expected 100%, got ${flexBasis}`);
66
- }
67
- },
68
-
69
- 'should apply span-4 as ~33.333% width': ({pass, fail}) => {
70
- const col = document.createElement('div');
71
- col.className = 'span-4';
72
- document.body.appendChild(col);
73
- const flexBasis = getStyle(col, 'flexBasis');
74
- col.remove();
75
- if(flexBasis.includes('33.333')){
76
- pass(`.span-4 sets flex-basis to ${flexBasis}`);
77
- } else {
78
- fail(`Expected ~33.333%, got ${flexBasis}`);
79
- }
80
- },
81
-
82
- 'should apply span-3 as 25% width': ({pass, fail}) => {
83
- const col = document.createElement('div');
84
- col.className = 'span-3';
85
- document.body.appendChild(col);
86
- const flexBasis = getStyle(col, 'flexBasis');
87
- col.remove();
88
- if(flexBasis === '25%'){
89
- pass('.span-3 sets flex-basis to 25%');
90
- } else {
91
- fail(`Expected 25%, got ${flexBasis}`);
92
- }
93
- },
94
-
95
- 'should apply grid columns with .cols-2': ({pass, fail}) => {
96
- const el = document.createElement('div');
97
- el.className = 'd-g cols-2';
98
- document.body.appendChild(el);
99
- const cols = getStyle(el, 'gridTemplateColumns');
100
- el.remove();
101
- if(cols.split(' ').length === 2){
102
- pass(`.cols-2 creates 2 columns: ${cols}`);
103
- } else {
104
- fail(`Expected 2 columns, got ${cols}`);
105
- }
106
- },
107
-
108
- 'should apply grid columns with .cols-3': ({pass, fail}) => {
109
- const el = document.createElement('div');
110
- el.className = 'd-g cols-3';
111
- document.body.appendChild(el);
112
- const cols = getStyle(el, 'gridTemplateColumns');
113
- el.remove();
114
- if(cols.split(' ').length === 3){
115
- pass(`.cols-3 creates 3 columns: ${cols}`);
116
- } else {
117
- fail(`Expected 3 columns, got ${cols}`);
118
- }
119
- },
120
-
121
- 'should apply grid columns with .cols-4': ({pass, fail}) => {
122
- const el = document.createElement('div');
123
- el.className = 'd-g cols-4';
124
- document.body.appendChild(el);
125
- const cols = getStyle(el, 'gridTemplateColumns');
126
- el.remove();
127
- if(cols.split(' ').length === 4){
128
- pass(`.cols-4 creates 4 columns: ${cols}`);
129
- } else {
130
- fail(`Expected 4 columns, got ${cols}`);
131
- }
132
- },
133
-
134
- 'should have all span classes 1-12': ({pass, fail}) => {
135
- const missing = [];
136
- for(let i = 1; i <= 12; i++){
137
- const col = document.createElement('div');
138
- col.className = `span-${i}`;
139
- document.body.appendChild(col);
140
- const flexBasis = getStyle(col, 'flexBasis');
141
- col.remove();
142
- if(!flexBasis || flexBasis === '0%' || flexBasis === 'auto'){
143
- missing.push(i);
144
- }
145
- }
146
- if(missing.length === 0){
147
- pass('All span-1 through span-12 classes exist');
148
- } else {
149
- fail(`Missing spans: ${missing.join(', ')}`);
150
- }
151
- },
152
-
153
- 'should have cols classes 2-10': ({pass, fail}) => {
154
- const working = [];
155
- for(let i = 2; i <= 10; i++){
156
- const el = document.createElement('div');
157
- el.className = `d-g cols-${i}`;
158
- document.body.appendChild(el);
159
- const cols = getStyle(el, 'gridTemplateColumns');
160
- el.remove();
161
- if(cols.split(' ').length === i){
162
- working.push(i);
163
- }
164
- }
165
- if(working.length === 9){
166
- pass('All cols-2 through cols-10 classes work');
167
- } else {
168
- fail(`Working: ${working.join(', ')}, expected 2-10`);
169
- }
170
- }
171
- };
1
+ const getStyle = (el, prop) => getComputedStyle(el)[prop];
2
+
3
+ export const beforeAll = async () => {
4
+ const link = document.createElement('link');
5
+ link.rel = 'stylesheet';
6
+ link.href = '/src/kempo.css';
7
+ document.head.appendChild(link);
8
+ await new Promise(resolve => link.onload = resolve);
9
+ };
10
+
11
+ export default {
12
+ 'should apply flex display to .row': ({pass, fail}) => {
13
+ const el = document.createElement('div');
14
+ el.className = 'row';
15
+ document.body.appendChild(el);
16
+ const display = getStyle(el, 'display');
17
+ const flexWrap = getStyle(el, 'flexWrap');
18
+ el.remove();
19
+ if(display === 'flex' && flexWrap === 'wrap'){
20
+ pass('.row applies flex with wrap');
21
+ } else {
22
+ fail(`Expected flex/wrap, got display: ${display}, wrap: ${flexWrap}`);
23
+ }
24
+ },
25
+
26
+ 'should apply flex to .col': ({pass, fail}) => {
27
+ const el = document.createElement('div');
28
+ el.className = 'col';
29
+ document.body.appendChild(el);
30
+ const flexGrow = getStyle(el, 'flexGrow');
31
+ el.remove();
32
+ if(flexGrow === '1'){
33
+ pass('.col has flex-grow: 1');
34
+ } else {
35
+ fail(`Expected flex-grow: 1, got ${flexGrow}`);
36
+ }
37
+ },
38
+
39
+ 'should apply span-6 as 50% width': ({pass, fail}) => {
40
+ const row = document.createElement('div');
41
+ row.className = 'row';
42
+ row.style.width = '1000px';
43
+ const col = document.createElement('div');
44
+ col.className = 'span-6';
45
+ row.appendChild(col);
46
+ document.body.appendChild(row);
47
+ const flexBasis = getStyle(col, 'flexBasis');
48
+ row.remove();
49
+ if(flexBasis === '50%'){
50
+ pass('.span-6 sets flex-basis to 50%');
51
+ } else {
52
+ fail(`Expected 50%, got ${flexBasis}`);
53
+ }
54
+ },
55
+
56
+ 'should apply span-12 as 100% width': ({pass, fail}) => {
57
+ const col = document.createElement('div');
58
+ col.className = 'span-12';
59
+ document.body.appendChild(col);
60
+ const flexBasis = getStyle(col, 'flexBasis');
61
+ col.remove();
62
+ if(flexBasis === '100%'){
63
+ pass('.span-12 sets flex-basis to 100%');
64
+ } else {
65
+ fail(`Expected 100%, got ${flexBasis}`);
66
+ }
67
+ },
68
+
69
+ 'should apply span-4 as ~33.333% width': ({pass, fail}) => {
70
+ const col = document.createElement('div');
71
+ col.className = 'span-4';
72
+ document.body.appendChild(col);
73
+ const flexBasis = getStyle(col, 'flexBasis');
74
+ col.remove();
75
+ if(flexBasis.includes('33.333')){
76
+ pass(`.span-4 sets flex-basis to ${flexBasis}`);
77
+ } else {
78
+ fail(`Expected ~33.333%, got ${flexBasis}`);
79
+ }
80
+ },
81
+
82
+ 'should apply span-3 as 25% width': ({pass, fail}) => {
83
+ const col = document.createElement('div');
84
+ col.className = 'span-3';
85
+ document.body.appendChild(col);
86
+ const flexBasis = getStyle(col, 'flexBasis');
87
+ col.remove();
88
+ if(flexBasis === '25%'){
89
+ pass('.span-3 sets flex-basis to 25%');
90
+ } else {
91
+ fail(`Expected 25%, got ${flexBasis}`);
92
+ }
93
+ },
94
+
95
+ 'should apply grid columns with .cols-2': ({pass, fail}) => {
96
+ const el = document.createElement('div');
97
+ el.className = 'd-g cols-2';
98
+ document.body.appendChild(el);
99
+ const cols = getStyle(el, 'gridTemplateColumns');
100
+ el.remove();
101
+ if(cols.split(' ').length === 2){
102
+ pass(`.cols-2 creates 2 columns: ${cols}`);
103
+ } else {
104
+ fail(`Expected 2 columns, got ${cols}`);
105
+ }
106
+ },
107
+
108
+ 'should apply grid columns with .cols-3': ({pass, fail}) => {
109
+ const el = document.createElement('div');
110
+ el.className = 'd-g cols-3';
111
+ document.body.appendChild(el);
112
+ const cols = getStyle(el, 'gridTemplateColumns');
113
+ el.remove();
114
+ if(cols.split(' ').length === 3){
115
+ pass(`.cols-3 creates 3 columns: ${cols}`);
116
+ } else {
117
+ fail(`Expected 3 columns, got ${cols}`);
118
+ }
119
+ },
120
+
121
+ 'should apply grid columns with .cols-4': ({pass, fail}) => {
122
+ const el = document.createElement('div');
123
+ el.className = 'd-g cols-4';
124
+ document.body.appendChild(el);
125
+ const cols = getStyle(el, 'gridTemplateColumns');
126
+ el.remove();
127
+ if(cols.split(' ').length === 4){
128
+ pass(`.cols-4 creates 4 columns: ${cols}`);
129
+ } else {
130
+ fail(`Expected 4 columns, got ${cols}`);
131
+ }
132
+ },
133
+
134
+ 'should have all span classes 1-12': ({pass, fail}) => {
135
+ const missing = [];
136
+ for(let i = 1; i <= 12; i++){
137
+ const col = document.createElement('div');
138
+ col.className = `span-${i}`;
139
+ document.body.appendChild(col);
140
+ const flexBasis = getStyle(col, 'flexBasis');
141
+ col.remove();
142
+ if(!flexBasis || flexBasis === '0%' || flexBasis === 'auto'){
143
+ missing.push(i);
144
+ }
145
+ }
146
+ if(missing.length === 0){
147
+ pass('All span-1 through span-12 classes exist');
148
+ } else {
149
+ fail(`Missing spans: ${missing.join(', ')}`);
150
+ }
151
+ },
152
+
153
+ 'should have cols classes 2-10': ({pass, fail}) => {
154
+ const working = [];
155
+ for(let i = 2; i <= 10; i++){
156
+ const el = document.createElement('div');
157
+ el.className = `d-g cols-${i}`;
158
+ document.body.appendChild(el);
159
+ const cols = getStyle(el, 'gridTemplateColumns');
160
+ el.remove();
161
+ if(cols.split(' ').length === i){
162
+ working.push(i);
163
+ }
164
+ }
165
+ if(working.length === 9){
166
+ pass('All cols-2 through cols-10 classes work');
167
+ } else {
168
+ fail(`Working: ${working.join(', ')}, expected 2-10`);
169
+ }
170
+ }
171
+ };