kempo-css 1.1.0 → 1.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.
@@ -0,0 +1,223 @@
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 style button element': ({pass, fail}) => {
13
+ const btn = document.createElement('button');
14
+ btn.textContent = 'Test';
15
+ document.body.appendChild(btn);
16
+ const display = getStyle(btn, 'display');
17
+ const cursor = getStyle(btn, 'cursor');
18
+ const borderRadius = parseFloat(getStyle(btn, 'borderRadius'));
19
+ btn.remove();
20
+ if(display === 'inline-block' && cursor === 'pointer' && borderRadius > 0){
21
+ pass('Button has correct base styling');
22
+ } else {
23
+ fail(`Expected inline-block/pointer/radius, got display: ${display}, cursor: ${cursor}, radius: ${borderRadius}`);
24
+ }
25
+ },
26
+
27
+ 'should style .btn class': ({pass, fail}) => {
28
+ const el = document.createElement('a');
29
+ el.className = 'btn';
30
+ document.body.appendChild(el);
31
+ const display = getStyle(el, 'display');
32
+ const cursor = getStyle(el, 'cursor');
33
+ el.remove();
34
+ if(display === 'inline-block' && cursor === 'pointer'){
35
+ pass('.btn class applies button styling');
36
+ } else {
37
+ fail(`Expected inline-block/pointer, got ${display}/${cursor}`);
38
+ }
39
+ },
40
+
41
+ 'should style input[type="button"]': ({pass, fail}) => {
42
+ const input = document.createElement('input');
43
+ input.type = 'button';
44
+ input.value = 'Test';
45
+ document.body.appendChild(input);
46
+ const cursor = getStyle(input, 'cursor');
47
+ input.remove();
48
+ if(cursor === 'pointer'){
49
+ pass('input[type="button"] has pointer cursor');
50
+ } else {
51
+ fail(`Expected pointer, got ${cursor}`);
52
+ }
53
+ },
54
+
55
+ 'should style input[type="submit"]': ({pass, fail}) => {
56
+ const input = document.createElement('input');
57
+ input.type = 'submit';
58
+ document.body.appendChild(input);
59
+ const cursor = getStyle(input, 'cursor');
60
+ input.remove();
61
+ if(cursor === 'pointer'){
62
+ pass('input[type="submit"] has pointer cursor');
63
+ } else {
64
+ fail(`Expected pointer, got ${cursor}`);
65
+ }
66
+ },
67
+
68
+ 'should apply .primary button style': ({pass, fail}) => {
69
+ const btn = document.createElement('button');
70
+ btn.className = 'primary';
71
+ document.body.appendChild(btn);
72
+ const bg = getStyle(btn, 'backgroundColor');
73
+ btn.remove();
74
+ if(bg && bg !== 'rgba(0, 0, 0, 0)'){
75
+ pass(`.primary button has background: ${bg}`);
76
+ } else {
77
+ fail('Primary button should have background color');
78
+ }
79
+ },
80
+
81
+ 'should apply .secondary button style': ({pass, fail}) => {
82
+ const btn = document.createElement('button');
83
+ btn.className = 'secondary';
84
+ document.body.appendChild(btn);
85
+ const bg = getStyle(btn, 'backgroundColor');
86
+ btn.remove();
87
+ if(bg && bg !== 'rgba(0, 0, 0, 0)'){
88
+ pass(`.secondary button has background: ${bg}`);
89
+ } else {
90
+ fail('Secondary button should have background color');
91
+ }
92
+ },
93
+
94
+ 'should apply .success button style': ({pass, fail}) => {
95
+ const btn = document.createElement('button');
96
+ btn.className = 'success';
97
+ document.body.appendChild(btn);
98
+ const bg = getStyle(btn, 'backgroundColor');
99
+ btn.remove();
100
+ if(bg && bg.includes('0, 1') || bg.includes('rgb(0')){
101
+ pass(`.success button has green background: ${bg}`);
102
+ } else {
103
+ fail(`Expected green, got ${bg}`);
104
+ }
105
+ },
106
+
107
+ 'should apply .warning button style': ({pass, fail}) => {
108
+ const btn = document.createElement('button');
109
+ btn.className = 'warning';
110
+ document.body.appendChild(btn);
111
+ const bg = getStyle(btn, 'backgroundColor');
112
+ btn.remove();
113
+ if(bg && bg !== 'rgba(0, 0, 0, 0)'){
114
+ pass(`.warning button has background: ${bg}`);
115
+ } else {
116
+ fail('Warning button should have background color');
117
+ }
118
+ },
119
+
120
+ 'should apply .danger button style': ({pass, fail}) => {
121
+ const btn = document.createElement('button');
122
+ btn.className = 'danger';
123
+ document.body.appendChild(btn);
124
+ const bg = getStyle(btn, 'backgroundColor');
125
+ btn.remove();
126
+ if(bg && bg !== 'rgba(0, 0, 0, 0)'){
127
+ pass(`.danger button has background: ${bg}`);
128
+ } else {
129
+ fail('Danger button should have background color');
130
+ }
131
+ },
132
+
133
+ 'should apply .link button style': ({pass, fail}) => {
134
+ const btn = document.createElement('button');
135
+ btn.className = 'link';
136
+ document.body.appendChild(btn);
137
+ const bg = getStyle(btn, 'backgroundColor');
138
+ const border = getStyle(btn, 'borderStyle');
139
+ btn.remove();
140
+ if(bg === 'rgba(0, 0, 0, 0)' || bg === 'transparent'){
141
+ pass('.link button has transparent background');
142
+ } else {
143
+ fail(`Expected transparent, got ${bg}`);
144
+ }
145
+ },
146
+
147
+ 'should reduce opacity on disabled button': ({pass, fail}) => {
148
+ const btn = document.createElement('button');
149
+ btn.disabled = true;
150
+ document.body.appendChild(btn);
151
+ const opacity = parseFloat(getStyle(btn, 'opacity'));
152
+ btn.remove();
153
+ if(opacity < 1){
154
+ pass(`Disabled button has reduced opacity: ${opacity}`);
155
+ } else {
156
+ fail(`Expected opacity < 1, got ${opacity}`);
157
+ }
158
+ },
159
+
160
+ 'should style .btn-grp as inline-flex': ({pass, fail}) => {
161
+ const grp = document.createElement('div');
162
+ grp.className = 'btn-grp';
163
+ document.body.appendChild(grp);
164
+ const display = getStyle(grp, 'display');
165
+ grp.remove();
166
+ if(display === 'inline-flex'){
167
+ pass('.btn-grp displays as inline-flex');
168
+ } else {
169
+ fail(`Expected inline-flex, got ${display}`);
170
+ }
171
+ },
172
+
173
+ 'should remove border radius on middle buttons in .btn-grp': ({pass, fail}) => {
174
+ const grp = document.createElement('div');
175
+ grp.className = 'btn-grp';
176
+ const btn1 = document.createElement('button');
177
+ const btn2 = document.createElement('button');
178
+ const btn3 = document.createElement('button');
179
+ grp.appendChild(btn1);
180
+ grp.appendChild(btn2);
181
+ grp.appendChild(btn3);
182
+ document.body.appendChild(grp);
183
+ const btn2TLRadius = parseFloat(getStyle(btn2, 'borderTopLeftRadius'));
184
+ const btn2TRRadius = parseFloat(getStyle(btn2, 'borderTopRightRadius'));
185
+ grp.remove();
186
+ if(btn2TLRadius === 0 && btn2TRRadius === 0){
187
+ pass('Middle button in .btn-grp has no border radius');
188
+ } else {
189
+ fail(`Expected 0 radius, got TL: ${btn2TLRadius}, TR: ${btn2TRRadius}`);
190
+ }
191
+ },
192
+
193
+ 'should style .no-btn as unstyled button': ({pass, fail}) => {
194
+ const btn = document.createElement('button');
195
+ btn.className = 'no-btn';
196
+ document.body.appendChild(btn);
197
+ const bg = getStyle(btn, 'backgroundColor');
198
+ const border = getStyle(btn, 'borderStyle');
199
+ btn.remove();
200
+ if((bg === 'rgba(0, 0, 0, 0)' || bg === 'transparent') && border === 'none'){
201
+ pass('.no-btn removes button styling');
202
+ } else {
203
+ fail(`Expected transparent/none, got bg: ${bg}, border: ${border}`);
204
+ }
205
+ },
206
+
207
+ 'should apply .full class for full width': ({pass, fail}) => {
208
+ const container = document.createElement('div');
209
+ container.style.width = '500px';
210
+ const btn = document.createElement('button');
211
+ btn.className = 'full';
212
+ container.appendChild(btn);
213
+ document.body.appendChild(container);
214
+ const btnWidth = parseFloat(getStyle(btn, 'width'));
215
+ container.remove();
216
+ // .full should make the button take full container width
217
+ if(btnWidth >= 490){
218
+ pass(`.full makes button full width: ${btnWidth}px`);
219
+ } else {
220
+ fail(`Expected ~500px width, got ${btnWidth}px`);
221
+ }
222
+ }
223
+ };
@@ -0,0 +1,221 @@
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 .bg-default': ({pass, fail}) => {
13
+ const el = document.createElement('div');
14
+ el.className = 'bg-default';
15
+ document.body.appendChild(el);
16
+ const bg = getStyle(el, 'backgroundColor');
17
+ el.remove();
18
+ if(bg && bg !== 'rgba(0, 0, 0, 0)'){
19
+ pass(`.bg-default applies background: ${bg}`);
20
+ } else {
21
+ fail('bg-default should apply background');
22
+ }
23
+ },
24
+
25
+ 'should apply .bg-alt': ({pass, fail}) => {
26
+ const el = document.createElement('div');
27
+ el.className = 'bg-alt';
28
+ document.body.appendChild(el);
29
+ const bg = getStyle(el, 'backgroundColor');
30
+ el.remove();
31
+ if(bg && bg !== 'rgba(0, 0, 0, 0)'){
32
+ pass(`.bg-alt applies background: ${bg}`);
33
+ } else {
34
+ fail('bg-alt should apply background');
35
+ }
36
+ },
37
+
38
+ 'should apply .bg-inv with inverted colors': ({pass, fail}) => {
39
+ const el = document.createElement('div');
40
+ el.className = 'bg-inv';
41
+ document.body.appendChild(el);
42
+ const bg = getStyle(el, 'backgroundColor');
43
+ const color = getStyle(el, 'color');
44
+ el.remove();
45
+ if(bg && bg !== 'rgba(0, 0, 0, 0)'){
46
+ pass(`.bg-inv applies inverted background: ${bg}`);
47
+ } else {
48
+ fail('bg-inv should apply background');
49
+ }
50
+ },
51
+
52
+ 'should apply .bg-primary': ({pass, fail}) => {
53
+ const el = document.createElement('div');
54
+ el.className = 'bg-primary';
55
+ document.body.appendChild(el);
56
+ const bg = getStyle(el, 'backgroundColor');
57
+ el.remove();
58
+ if(bg && bg.includes('51') && bg.includes('102') && bg.includes('255')){
59
+ pass(`.bg-primary applies primary color: ${bg}`);
60
+ } else {
61
+ fail(`Expected primary blue, got ${bg}`);
62
+ }
63
+ },
64
+
65
+ 'should apply .bg-secondary': ({pass, fail}) => {
66
+ const el = document.createElement('div');
67
+ el.className = 'bg-secondary';
68
+ document.body.appendChild(el);
69
+ const bg = getStyle(el, 'backgroundColor');
70
+ el.remove();
71
+ if(bg && bg.includes('153') && bg.includes('51') && bg.includes('255')){
72
+ pass(`.bg-secondary applies secondary color: ${bg}`);
73
+ } else {
74
+ fail(`Expected secondary purple, got ${bg}`);
75
+ }
76
+ },
77
+
78
+ 'should apply .bg-success': ({pass, fail}) => {
79
+ const el = document.createElement('div');
80
+ el.className = 'bg-success';
81
+ document.body.appendChild(el);
82
+ const bg = getStyle(el, 'backgroundColor');
83
+ el.remove();
84
+ if(bg && bg.includes('136') && bg.includes('0')){
85
+ pass(`.bg-success applies green: ${bg}`);
86
+ } else {
87
+ fail(`Expected green, got ${bg}`);
88
+ }
89
+ },
90
+
91
+ 'should apply .bg-warning': ({pass, fail}) => {
92
+ const el = document.createElement('div');
93
+ el.className = 'bg-warning';
94
+ document.body.appendChild(el);
95
+ const bg = getStyle(el, 'backgroundColor');
96
+ el.remove();
97
+ if(bg && bg.includes('255') && bg.includes('102')){
98
+ pass(`.bg-warning applies orange: ${bg}`);
99
+ } else {
100
+ fail(`Expected orange, got ${bg}`);
101
+ }
102
+ },
103
+
104
+ 'should apply .bg-danger': ({pass, fail}) => {
105
+ const el = document.createElement('div');
106
+ el.className = 'bg-danger';
107
+ document.body.appendChild(el);
108
+ const bg = getStyle(el, 'backgroundColor');
109
+ el.remove();
110
+ if(bg && bg.includes('255') && bg.includes('51')){
111
+ pass(`.bg-danger applies red: ${bg}`);
112
+ } else {
113
+ fail(`Expected red, got ${bg}`);
114
+ }
115
+ },
116
+
117
+ 'should apply .tc-default': ({pass, fail}) => {
118
+ const el = document.createElement('div');
119
+ el.className = 'tc-default';
120
+ document.body.appendChild(el);
121
+ const color = getStyle(el, 'color');
122
+ el.remove();
123
+ if(color && color !== 'rgba(0, 0, 0, 0)'){
124
+ pass(`.tc-default applies color: ${color}`);
125
+ } else {
126
+ fail('tc-default should apply color');
127
+ }
128
+ },
129
+
130
+ 'should apply .tc-primary': ({pass, fail}) => {
131
+ const el = document.createElement('div');
132
+ el.className = 'tc-primary';
133
+ document.body.appendChild(el);
134
+ const color = getStyle(el, 'color');
135
+ el.remove();
136
+ if(color && color !== 'rgba(0, 0, 0, 0)'){
137
+ pass(`.tc-primary applies color: ${color}`);
138
+ } else {
139
+ fail('tc-primary should apply color');
140
+ }
141
+ },
142
+
143
+ 'should apply .tc-secondary': ({pass, fail}) => {
144
+ const el = document.createElement('div');
145
+ el.className = 'tc-secondary';
146
+ document.body.appendChild(el);
147
+ const color = getStyle(el, 'color');
148
+ el.remove();
149
+ if(color && color !== 'rgba(0, 0, 0, 0)'){
150
+ pass(`.tc-secondary applies color: ${color}`);
151
+ } else {
152
+ fail('tc-secondary should apply color');
153
+ }
154
+ },
155
+
156
+ 'should apply .tc-success': ({pass, fail}) => {
157
+ const el = document.createElement('div');
158
+ el.className = 'tc-success';
159
+ document.body.appendChild(el);
160
+ const color = getStyle(el, 'color');
161
+ el.remove();
162
+ if(color && color !== 'rgba(0, 0, 0, 0)'){
163
+ pass(`.tc-success applies color: ${color}`);
164
+ } else {
165
+ fail('tc-success should apply color');
166
+ }
167
+ },
168
+
169
+ 'should apply .tc-warning': ({pass, fail}) => {
170
+ const el = document.createElement('div');
171
+ el.className = 'tc-warning';
172
+ document.body.appendChild(el);
173
+ const color = getStyle(el, 'color');
174
+ el.remove();
175
+ if(color && color !== 'rgba(0, 0, 0, 0)'){
176
+ pass(`.tc-warning applies color: ${color}`);
177
+ } else {
178
+ fail('tc-warning should apply color');
179
+ }
180
+ },
181
+
182
+ 'should apply .tc-danger': ({pass, fail}) => {
183
+ const el = document.createElement('div');
184
+ el.className = 'tc-danger';
185
+ document.body.appendChild(el);
186
+ const color = getStyle(el, 'color');
187
+ el.remove();
188
+ if(color && color !== 'rgba(0, 0, 0, 0)'){
189
+ pass(`.tc-danger applies color: ${color}`);
190
+ } else {
191
+ fail('tc-danger should apply color');
192
+ }
193
+ },
194
+
195
+ 'should apply .tc-muted': ({pass, fail}) => {
196
+ const el = document.createElement('div');
197
+ el.className = 'tc-muted';
198
+ document.body.appendChild(el);
199
+ const color = getStyle(el, 'color');
200
+ el.remove();
201
+ if(color && color.includes('0.5')){
202
+ pass(`.tc-muted applies muted color: ${color}`);
203
+ } else {
204
+ fail(`Expected muted (50% opacity), got ${color}`);
205
+ }
206
+ },
207
+
208
+ 'should set text color on .bg-primary': ({pass, fail}) => {
209
+ const el = document.createElement('div');
210
+ el.className = 'bg-primary';
211
+ el.textContent = 'Test';
212
+ document.body.appendChild(el);
213
+ const color = getStyle(el, 'color');
214
+ el.remove();
215
+ if(color && color.includes('255')){
216
+ pass(`.bg-primary sets light text color: ${color}`);
217
+ } else {
218
+ fail(`Expected light text, got ${color}`);
219
+ }
220
+ }
221
+ };
@@ -0,0 +1,144 @@
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 style .card with border': ({pass, fail}) => {
13
+ const el = document.createElement('div');
14
+ el.className = 'card';
15
+ document.body.appendChild(el);
16
+ const border = parseFloat(getStyle(el, 'borderWidth'));
17
+ el.remove();
18
+ if(border > 0){
19
+ pass(`.card has border: ${border}px`);
20
+ } else {
21
+ fail('card should have border');
22
+ }
23
+ },
24
+
25
+ 'should style .card with border radius': ({pass, fail}) => {
26
+ const el = document.createElement('div');
27
+ el.className = 'card';
28
+ document.body.appendChild(el);
29
+ const radius = parseFloat(getStyle(el, 'borderRadius'));
30
+ el.remove();
31
+ if(radius > 0){
32
+ pass(`.card has border-radius: ${radius}px`);
33
+ } else {
34
+ fail('card should have border radius');
35
+ }
36
+ },
37
+
38
+ 'should style .card with padding': ({pass, fail}) => {
39
+ const el = document.createElement('div');
40
+ el.className = 'card';
41
+ document.body.appendChild(el);
42
+ const paddingTop = parseFloat(getStyle(el, 'paddingTop'));
43
+ const paddingLeft = parseFloat(getStyle(el, 'paddingLeft'));
44
+ const paddingRight = parseFloat(getStyle(el, 'paddingRight'));
45
+ el.remove();
46
+ if(paddingTop > 0 && paddingLeft > 0 && paddingRight > 0){
47
+ pass('.card has padding on top, left, and right');
48
+ } else {
49
+ fail(`Expected padding, got top: ${paddingTop}, left: ${paddingLeft}, right: ${paddingRight}`);
50
+ }
51
+ },
52
+
53
+ 'should style .card with margin-bottom': ({pass, fail}) => {
54
+ const el = document.createElement('div');
55
+ el.className = 'card';
56
+ document.body.appendChild(el);
57
+ const marginBottom = parseFloat(getStyle(el, 'marginBottom'));
58
+ el.remove();
59
+ if(marginBottom > 0){
60
+ pass(`.card has margin-bottom: ${marginBottom}px`);
61
+ } else {
62
+ fail('card should have margin-bottom');
63
+ }
64
+ },
65
+
66
+ 'should have .drop-shadow class that sets box-shadow': ({pass, fail}) => {
67
+ const el = document.createElement('div');
68
+ el.className = 'drop-shadow';
69
+ document.body.appendChild(el);
70
+ const shadow = getStyle(el, 'boxShadow');
71
+ el.remove();
72
+ if(shadow && shadow !== 'none'){
73
+ pass(`.drop-shadow has box-shadow: ${shadow}`);
74
+ } else {
75
+ fail(`Expected box-shadow, got ${shadow}`);
76
+ }
77
+ },
78
+
79
+ 'should style .icon as inline-block': ({pass, fail}) => {
80
+ const el = document.createElement('span');
81
+ el.className = 'icon';
82
+ document.body.appendChild(el);
83
+ const display = getStyle(el, 'display');
84
+ el.remove();
85
+ if(display === 'inline-block'){
86
+ pass('.icon displays as inline-block');
87
+ } else {
88
+ fail(`Expected inline-block, got ${display}`);
89
+ }
90
+ },
91
+
92
+ 'should style .icon with width': ({pass, fail}) => {
93
+ const el = document.createElement('span');
94
+ el.className = 'icon';
95
+ document.body.appendChild(el);
96
+ const width = getStyle(el, 'width');
97
+ el.remove();
98
+ if(width && width !== 'auto'){
99
+ pass(`.icon has width: ${width}`);
100
+ } else {
101
+ fail('icon should have width');
102
+ }
103
+ },
104
+
105
+ 'should style .icon with vertical-align top': ({pass, fail}) => {
106
+ const el = document.createElement('span');
107
+ el.className = 'icon';
108
+ document.body.appendChild(el);
109
+ const verticalAlign = getStyle(el, 'verticalAlign');
110
+ el.remove();
111
+ if(verticalAlign === 'top'){
112
+ pass('.icon has vertical-align: top');
113
+ } else {
114
+ fail(`Expected top, got ${verticalAlign}`);
115
+ }
116
+ },
117
+
118
+ 'should remove iframe border': ({pass, fail}) => {
119
+ const iframe = document.createElement('iframe');
120
+ document.body.appendChild(iframe);
121
+ const border = getStyle(iframe, 'borderStyle');
122
+ iframe.remove();
123
+ if(border === 'none'){
124
+ pass('iframe has no border');
125
+ } else {
126
+ fail(`Expected none, got ${border}`);
127
+ }
128
+ },
129
+
130
+ 'should make iframe full width': ({pass, fail}) => {
131
+ const container = document.createElement('div');
132
+ container.style.width = '500px';
133
+ const iframe = document.createElement('iframe');
134
+ container.appendChild(iframe);
135
+ document.body.appendChild(container);
136
+ const width = getStyle(iframe, 'width');
137
+ container.remove();
138
+ if(width === '100%' || parseFloat(width) >= 490){
139
+ pass(`iframe has full width: ${width}`);
140
+ } else {
141
+ fail(`Expected 100%, got ${width}`);
142
+ }
143
+ }
144
+ };