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,201 +1,201 @@
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 box-sizing border-box to all elements': ({pass, fail}) => {
13
- const div = document.createElement('div');
14
- document.body.appendChild(div);
15
- const boxSizing = getStyle(div, 'boxSizing');
16
- div.remove();
17
- if(boxSizing === 'border-box'){
18
- pass('box-sizing is border-box');
19
- } else {
20
- fail(`Expected border-box, got ${boxSizing}`);
21
- }
22
- },
23
-
24
- 'should reset margin on body': ({pass, fail}) => {
25
- const margin = getStyle(document.body, 'margin');
26
- if(margin === '0px'){
27
- pass('Body margin is reset to 0');
28
- } else {
29
- fail(`Expected 0px margin, got ${margin}`);
30
- }
31
- },
32
-
33
- 'should set min-height 100vh on body': ({pass, fail}) => {
34
- const minHeight = getStyle(document.body, 'minHeight');
35
- const viewportHeight = window.innerHeight;
36
- const minHeightValue = parseFloat(minHeight);
37
- if(minHeightValue >= viewportHeight){
38
- pass('Body min-height is at least 100vh');
39
- } else {
40
- fail(`Expected min-height >= ${viewportHeight}px, got ${minHeight}`);
41
- }
42
- },
43
-
44
- 'should apply background color to body': ({pass, fail}) => {
45
- const bg = getStyle(document.body, 'backgroundColor');
46
- if(bg && bg !== 'transparent' && bg !== 'rgba(0, 0, 0, 0)'){
47
- pass(`Body has background color: ${bg}`);
48
- } else {
49
- fail('Body should have a background color');
50
- }
51
- },
52
-
53
- 'should apply text color to body': ({pass, fail}) => {
54
- const color = getStyle(document.body, 'color');
55
- if(color && color !== 'transparent' && color !== 'rgba(0, 0, 0, 0)'){
56
- pass(`Body has text color: ${color}`);
57
- } else {
58
- fail('Body should have a text color');
59
- }
60
- },
61
-
62
- 'should reset top margin on headings': ({pass, fail}) => {
63
- const headings = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
64
- const failed = [];
65
- headings.forEach(tag => {
66
- const el = document.createElement(tag);
67
- document.body.appendChild(el);
68
- const marginTop = getStyle(el, 'marginTop');
69
- el.remove();
70
- if(marginTop !== '0px'){
71
- failed.push(`${tag}: ${marginTop}`);
72
- }
73
- });
74
- if(failed.length === 0){
75
- pass('All headings have top margin reset to 0');
76
- } else {
77
- fail(`Headings with non-zero top margin: ${failed.join(', ')}`);
78
- }
79
- },
80
-
81
- 'should apply bottom margin to headings': ({pass, fail}) => {
82
- const h1 = document.createElement('h1');
83
- document.body.appendChild(h1);
84
- const marginBottom = parseFloat(getStyle(h1, 'marginBottom'));
85
- h1.remove();
86
- if(marginBottom > 0){
87
- pass(`Headings have bottom margin: ${marginBottom}px`);
88
- } else {
89
- fail('Headings should have bottom margin for spacing');
90
- }
91
- },
92
-
93
- 'should apply bottom margin to paragraphs': ({pass, fail}) => {
94
- const p = document.createElement('p');
95
- document.body.appendChild(p);
96
- const marginBottom = parseFloat(getStyle(p, 'marginBottom'));
97
- const marginTop = getStyle(p, 'marginTop');
98
- p.remove();
99
- if(marginTop === '0px' && marginBottom > 0){
100
- pass(`Paragraphs have 0 top margin and ${marginBottom}px bottom margin`);
101
- } else {
102
- fail(`Expected 0 top margin and positive bottom margin, got top: ${marginTop}, bottom: ${marginBottom}px`);
103
- }
104
- },
105
-
106
- 'should apply container max-width': ({pass, fail}) => {
107
- const container = document.createElement('div');
108
- container.className = 'container';
109
- document.body.appendChild(container);
110
- const maxWidth = getStyle(container, 'maxWidth');
111
- container.remove();
112
- if(maxWidth && maxWidth !== 'none'){
113
- pass(`Container has max-width: ${maxWidth}`);
114
- } else {
115
- fail('Container should have a max-width');
116
- }
117
- },
118
-
119
- 'should center container horizontally': ({pass, fail}) => {
120
- const container = document.createElement('div');
121
- container.className = 'container';
122
- document.body.appendChild(container);
123
- const marginLeft = getStyle(container, 'marginLeft');
124
- const marginRight = getStyle(container, 'marginRight');
125
- container.remove();
126
- // When container is narrower than viewport, auto margins compute to equal pixel values
127
- // When container fills viewport, they're both 0 or equal
128
- if(marginLeft === marginRight){
129
- pass('Container is horizontally centered');
130
- } else {
131
- fail(`Expected equal margins, got left: ${marginLeft}, right: ${marginRight}`);
132
- }
133
- },
134
-
135
- 'should apply padding to container': ({pass, fail}) => {
136
- const container = document.createElement('div');
137
- container.className = 'container';
138
- document.body.appendChild(container);
139
- const paddingLeft = parseFloat(getStyle(container, 'paddingLeft'));
140
- const paddingRight = parseFloat(getStyle(container, 'paddingRight'));
141
- container.remove();
142
- if(paddingLeft > 0 && paddingRight > 0){
143
- pass(`Container has padding: left ${paddingLeft}px, right ${paddingRight}px`);
144
- } else {
145
- fail('Container should have left and right padding');
146
- }
147
- },
148
-
149
- 'should style main element like container': ({pass, fail}) => {
150
- const main = document.createElement('main');
151
- document.body.appendChild(main);
152
- const maxWidth = getStyle(main, 'maxWidth');
153
- const marginLeft = getStyle(main, 'marginLeft');
154
- const marginRight = getStyle(main, 'marginRight');
155
- main.remove();
156
- if(maxWidth && maxWidth !== 'none' && marginLeft === marginRight){
157
- pass('Main element is styled like container');
158
- } else {
159
- fail(`Main should have max-width and centered margins, got maxWidth: ${maxWidth}, margins: ${marginLeft}/${marginRight}`);
160
- }
161
- },
162
-
163
- 'should hide overflow on body.no-scroll': ({pass, fail}) => {
164
- document.body.classList.add('no-scroll');
165
- const overflow = getStyle(document.body, 'overflow');
166
- document.body.classList.remove('no-scroll');
167
- if(overflow === 'hidden'){
168
- pass('body.no-scroll hides overflow');
169
- } else {
170
- fail(`Expected overflow hidden, got ${overflow}`);
171
- }
172
- },
173
-
174
- 'should style summary element with pointer cursor': ({pass, fail}) => {
175
- const details = document.createElement('details');
176
- const summary = document.createElement('summary');
177
- summary.textContent = 'Test';
178
- details.appendChild(summary);
179
- document.body.appendChild(details);
180
- const cursor = getStyle(summary, 'cursor');
181
- details.remove();
182
- if(cursor === 'pointer'){
183
- pass('Summary has pointer cursor');
184
- } else {
185
- fail(`Expected pointer cursor, got ${cursor}`);
186
- }
187
- },
188
-
189
- 'should reset menu margin and padding': ({pass, fail}) => {
190
- const menu = document.createElement('menu');
191
- document.body.appendChild(menu);
192
- const margin = getStyle(menu, 'margin');
193
- const padding = getStyle(menu, 'padding');
194
- menu.remove();
195
- if(margin === '0px' && padding === '0px'){
196
- pass('Menu margin and padding reset');
197
- } else {
198
- fail(`Menu should have 0 margin/padding, got margin: ${margin}, padding: ${padding}`);
199
- }
200
- }
201
- };
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 box-sizing border-box to all elements': ({pass, fail}) => {
13
+ const div = document.createElement('div');
14
+ document.body.appendChild(div);
15
+ const boxSizing = getStyle(div, 'boxSizing');
16
+ div.remove();
17
+ if(boxSizing === 'border-box'){
18
+ pass('box-sizing is border-box');
19
+ } else {
20
+ fail(`Expected border-box, got ${boxSizing}`);
21
+ }
22
+ },
23
+
24
+ 'should reset margin on body': ({pass, fail}) => {
25
+ const margin = getStyle(document.body, 'margin');
26
+ if(margin === '0px'){
27
+ pass('Body margin is reset to 0');
28
+ } else {
29
+ fail(`Expected 0px margin, got ${margin}`);
30
+ }
31
+ },
32
+
33
+ 'should set min-height 100vh on body': ({pass, fail}) => {
34
+ const minHeight = getStyle(document.body, 'minHeight');
35
+ const viewportHeight = window.innerHeight;
36
+ const minHeightValue = parseFloat(minHeight);
37
+ if(minHeightValue >= viewportHeight){
38
+ pass('Body min-height is at least 100vh');
39
+ } else {
40
+ fail(`Expected min-height >= ${viewportHeight}px, got ${minHeight}`);
41
+ }
42
+ },
43
+
44
+ 'should apply background color to body': ({pass, fail}) => {
45
+ const bg = getStyle(document.body, 'backgroundColor');
46
+ if(bg && bg !== 'transparent' && bg !== 'rgba(0, 0, 0, 0)'){
47
+ pass(`Body has background color: ${bg}`);
48
+ } else {
49
+ fail('Body should have a background color');
50
+ }
51
+ },
52
+
53
+ 'should apply text color to body': ({pass, fail}) => {
54
+ const color = getStyle(document.body, 'color');
55
+ if(color && color !== 'transparent' && color !== 'rgba(0, 0, 0, 0)'){
56
+ pass(`Body has text color: ${color}`);
57
+ } else {
58
+ fail('Body should have a text color');
59
+ }
60
+ },
61
+
62
+ 'should reset top margin on headings': ({pass, fail}) => {
63
+ const headings = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
64
+ const failed = [];
65
+ headings.forEach(tag => {
66
+ const el = document.createElement(tag);
67
+ document.body.appendChild(el);
68
+ const marginTop = getStyle(el, 'marginTop');
69
+ el.remove();
70
+ if(marginTop !== '0px'){
71
+ failed.push(`${tag}: ${marginTop}`);
72
+ }
73
+ });
74
+ if(failed.length === 0){
75
+ pass('All headings have top margin reset to 0');
76
+ } else {
77
+ fail(`Headings with non-zero top margin: ${failed.join(', ')}`);
78
+ }
79
+ },
80
+
81
+ 'should apply bottom margin to headings': ({pass, fail}) => {
82
+ const h1 = document.createElement('h1');
83
+ document.body.appendChild(h1);
84
+ const marginBottom = parseFloat(getStyle(h1, 'marginBottom'));
85
+ h1.remove();
86
+ if(marginBottom > 0){
87
+ pass(`Headings have bottom margin: ${marginBottom}px`);
88
+ } else {
89
+ fail('Headings should have bottom margin for spacing');
90
+ }
91
+ },
92
+
93
+ 'should apply bottom margin to paragraphs': ({pass, fail}) => {
94
+ const p = document.createElement('p');
95
+ document.body.appendChild(p);
96
+ const marginBottom = parseFloat(getStyle(p, 'marginBottom'));
97
+ const marginTop = getStyle(p, 'marginTop');
98
+ p.remove();
99
+ if(marginTop === '0px' && marginBottom > 0){
100
+ pass(`Paragraphs have 0 top margin and ${marginBottom}px bottom margin`);
101
+ } else {
102
+ fail(`Expected 0 top margin and positive bottom margin, got top: ${marginTop}, bottom: ${marginBottom}px`);
103
+ }
104
+ },
105
+
106
+ 'should apply container max-width': ({pass, fail}) => {
107
+ const container = document.createElement('div');
108
+ container.className = 'container';
109
+ document.body.appendChild(container);
110
+ const maxWidth = getStyle(container, 'maxWidth');
111
+ container.remove();
112
+ if(maxWidth && maxWidth !== 'none'){
113
+ pass(`Container has max-width: ${maxWidth}`);
114
+ } else {
115
+ fail('Container should have a max-width');
116
+ }
117
+ },
118
+
119
+ 'should center container horizontally': ({pass, fail}) => {
120
+ const container = document.createElement('div');
121
+ container.className = 'container';
122
+ document.body.appendChild(container);
123
+ const marginLeft = getStyle(container, 'marginLeft');
124
+ const marginRight = getStyle(container, 'marginRight');
125
+ container.remove();
126
+ // When container is narrower than viewport, auto margins compute to equal pixel values
127
+ // When container fills viewport, they're both 0 or equal
128
+ if(marginLeft === marginRight){
129
+ pass('Container is horizontally centered');
130
+ } else {
131
+ fail(`Expected equal margins, got left: ${marginLeft}, right: ${marginRight}`);
132
+ }
133
+ },
134
+
135
+ 'should apply padding to container': ({pass, fail}) => {
136
+ const container = document.createElement('div');
137
+ container.className = 'container';
138
+ document.body.appendChild(container);
139
+ const paddingLeft = parseFloat(getStyle(container, 'paddingLeft'));
140
+ const paddingRight = parseFloat(getStyle(container, 'paddingRight'));
141
+ container.remove();
142
+ if(paddingLeft > 0 && paddingRight > 0){
143
+ pass(`Container has padding: left ${paddingLeft}px, right ${paddingRight}px`);
144
+ } else {
145
+ fail('Container should have left and right padding');
146
+ }
147
+ },
148
+
149
+ 'should style main element like container': ({pass, fail}) => {
150
+ const main = document.createElement('main');
151
+ document.body.appendChild(main);
152
+ const maxWidth = getStyle(main, 'maxWidth');
153
+ const marginLeft = getStyle(main, 'marginLeft');
154
+ const marginRight = getStyle(main, 'marginRight');
155
+ main.remove();
156
+ if(maxWidth && maxWidth !== 'none' && marginLeft === marginRight){
157
+ pass('Main element is styled like container');
158
+ } else {
159
+ fail(`Main should have max-width and centered margins, got maxWidth: ${maxWidth}, margins: ${marginLeft}/${marginRight}`);
160
+ }
161
+ },
162
+
163
+ 'should hide overflow on body.no-scroll': ({pass, fail}) => {
164
+ document.body.classList.add('no-scroll');
165
+ const overflow = getStyle(document.body, 'overflow');
166
+ document.body.classList.remove('no-scroll');
167
+ if(overflow === 'hidden'){
168
+ pass('body.no-scroll hides overflow');
169
+ } else {
170
+ fail(`Expected overflow hidden, got ${overflow}`);
171
+ }
172
+ },
173
+
174
+ 'should style summary element with pointer cursor': ({pass, fail}) => {
175
+ const details = document.createElement('details');
176
+ const summary = document.createElement('summary');
177
+ summary.textContent = 'Test';
178
+ details.appendChild(summary);
179
+ document.body.appendChild(details);
180
+ const cursor = getStyle(summary, 'cursor');
181
+ details.remove();
182
+ if(cursor === 'pointer'){
183
+ pass('Summary has pointer cursor');
184
+ } else {
185
+ fail(`Expected pointer cursor, got ${cursor}`);
186
+ }
187
+ },
188
+
189
+ 'should reset menu margin and padding': ({pass, fail}) => {
190
+ const menu = document.createElement('menu');
191
+ document.body.appendChild(menu);
192
+ const margin = getStyle(menu, 'margin');
193
+ const padding = getStyle(menu, 'padding');
194
+ menu.remove();
195
+ if(margin === '0px' && padding === '0px'){
196
+ pass('Menu margin and padding reset');
197
+ } else {
198
+ fail(`Menu should have 0 margin/padding, got margin: ${margin}, padding: ${padding}`);
199
+ }
200
+ }
201
+ };