11
11
* found in the LICENSE file at https://angular.io/license
12
12
*/
13
13
14
- import { convertScopedToShadow } from '../../runtime/styles' ;
15
14
import { scopeCss } from '../shadow-css' ;
16
15
17
16
describe ( 'ShadowCss' , function ( ) {
18
- function s ( cssText : string , scopeId : string , commentOriginalSelector = false ) {
19
- const shim = scopeCss ( cssText , scopeId , commentOriginalSelector ) ;
17
+ function s ( cssText : string , scopeId : string ) {
18
+ const shim = scopeCss ( cssText , scopeId ) ;
20
19
21
20
const nlRegexp = / \n / g;
22
21
return normalizeCSS ( shim . replace ( nlRegexp , '' ) ) ;
@@ -26,21 +25,6 @@ describe('ShadowCss', function () {
26
25
expect ( s ( '' , 'a' ) ) . toEqual ( '' ) ;
27
26
} ) ;
28
27
29
- it ( 'should handle empty string, commented org selector' , ( ) => {
30
- expect ( s ( '' , 'a' , true ) ) . toEqual ( '' ) ;
31
- } ) ;
32
-
33
- it ( 'div' , ( ) => {
34
- const r = s ( 'div {}' , 'sc-ion-tag' , true ) ;
35
- expect ( r ) . toEqual ( '/*!@div*/div.sc-ion-tag {}' ) ;
36
- } ) ;
37
-
38
- it ( 'should add an attribute to every rule, commented org selector' , ( ) => {
39
- const css = 'one {color: red;}two {color: red;}' ;
40
- const expected = '/*!@one*/one.a {color:red;}/*!@two*/two.a {color:red;}' ;
41
- expect ( s ( css , 'a' , true ) ) . toEqual ( expected ) ;
42
- } ) ;
43
-
44
28
it ( 'should add an attribute to every rule' , ( ) => {
45
29
const css = 'one {color: red;}two {color: red;}' ;
46
30
const expected = 'one.a {color:red;}two.a {color:red;}' ;
@@ -71,24 +55,12 @@ describe('ShadowCss', function () {
71
55
expect ( s ( css , 'a' ) ) . toEqual ( expected ) ;
72
56
} ) ;
73
57
74
- it ( 'should handle media rules, commentOriginalSelector' , ( ) => {
75
- const css = '@media screen and (max-width:800px, max-height:100%) {div {font-size:50px;}}' ;
76
- const expected = '@media screen and (max-width:800px, max-height:100%) {/*!@div*/div.a {font-size:50px;}}' ;
77
- expect ( s ( css , 'a' , true ) ) . toEqual ( expected ) ;
78
- } ) ;
79
-
80
58
it ( 'should handle page rules' , ( ) => {
81
59
const css = '@page {div {font-size:50px;}}' ;
82
60
const expected = '@page {div.a {font-size:50px;}}' ;
83
61
expect ( s ( css , 'a' ) ) . toEqual ( expected ) ;
84
62
} ) ;
85
63
86
- it ( 'should handle page rules, commentOriginalSelector' , ( ) => {
87
- const css = '@page {div {font-size:50px;}}' ;
88
- const expected = '@page {/*!@div*/div.a {font-size:50px;}}' ;
89
- expect ( s ( css , 'a' , true ) ) . toEqual ( expected ) ;
90
- } ) ;
91
-
92
64
it ( 'should handle document rules' , ( ) => {
93
65
const css = '@document url(http://www.w3.org/) {div {font-size:50px;}}' ;
94
66
const expected = '@document url(http://www.w3.org/) {div.a {font-size:50px;}}' ;
@@ -113,11 +85,6 @@ describe('ShadowCss', function () {
113
85
expect ( s ( css , 'a' ) ) . toEqual ( css ) ;
114
86
} ) ;
115
87
116
- it ( 'should handle keyframes rules, commentOriginalSelector' , ( ) => {
117
- const css = '@keyframes foo {0% {transform:translate(-50%) scaleX(0);}}' ;
118
- expect ( s ( css , 'a' , true ) ) . toEqual ( css ) ;
119
- } ) ;
120
-
121
88
it ( 'should handle -webkit-keyframes rules' , ( ) => {
122
89
const css = '@-webkit-keyframes foo {0% {-webkit-transform:translate(-50%) scaleX(0);}}' ;
123
90
expect ( s ( css , 'a' ) ) . toEqual ( css ) ;
@@ -153,10 +120,6 @@ describe('ShadowCss', function () {
153
120
} ) ;
154
121
155
122
describe ( ':host' , ( ) => {
156
- it ( 'should handle no context, commentOriginalSelector' , ( ) => {
157
- expect ( s ( ':host {}' , 'a' , true ) ) . toEqual ( '/*!@:host*/.a-h {}' ) ;
158
- } ) ;
159
-
160
123
it ( 'should handle no context' , ( ) => {
161
124
expect ( s ( ':host {}' , 'a' ) ) . toEqual ( '.a-h {}' ) ;
162
125
} ) ;
@@ -174,11 +137,6 @@ describe('ShadowCss', function () {
174
137
expect ( s ( ':host([a=b]) {}' , 'a' ) ) . toEqual ( '[a="b"].a-h {}' ) ;
175
138
} ) ;
176
139
177
- it ( 'should handle multiple tag selectors, commenting the original selector' , ( ) => {
178
- expect ( s ( ':host(ul,li) {}' , 'a' , true ) ) . toEqual ( '/*!@:host(ul,li)*/ul.a-h, li.a-h {}' ) ;
179
- expect ( s ( ':host(ul,li) > .z {}' , 'a' , true ) ) . toEqual ( '/*!@:host(ul,li) > .z*/ul.a-h > .z.a, li.a-h > .z.a {}' ) ;
180
- } ) ;
181
-
182
140
it ( 'should handle multiple tag selectors' , ( ) => {
183
141
expect ( s ( ':host(ul,li) {}' , 'a' ) ) . toEqual ( 'ul.a-h, li.a-h {}' ) ;
184
142
expect ( s ( ':host(ul,li) > .z {}' , 'a' ) ) . toEqual ( 'ul.a-h > .z.a, li.a-h > .z.a {}' ) ;
@@ -193,10 +151,6 @@ describe('ShadowCss', function () {
193
151
expect ( s ( ':host([a="b"],[c=d]) {}' , 'a' ) ) . toEqual ( '[a="b"].a-h, [c="d"].a-h {}' ) ;
194
152
} ) ;
195
153
196
- it ( 'should handle multiple attribute selectors, commentOriginalSelector' , ( ) => {
197
- expect ( s ( ':host([a="b"],[c=d]) {}' , 'a' , true ) ) . toEqual ( '/*!@:host([a="b"],[c=d])*/[a="b"].a-h, [c="d"].a-h {}' ) ;
198
- } ) ;
199
-
200
154
it ( 'should handle pseudo selectors' , ( ) => {
201
155
expect ( s ( ':host(:before) {}' , 'a' ) ) . toEqual ( '.a-h:before {}' ) ;
202
156
expect ( s ( ':host:before {}' , 'a' ) ) . toEqual ( '.a-h:before {}' ) ;
@@ -215,13 +169,6 @@ describe('ShadowCss', function () {
215
169
} ) ;
216
170
217
171
describe ( ':host-context' , ( ) => {
218
- it ( 'should handle tag selector, commentOriginalSelector' , ( ) => {
219
- expect ( s ( ':host-context(div) {}' , 'a' , true ) ) . toEqual ( '/*!@:host-context(div)*/div.a-h, div .a-h {}' ) ;
220
- expect ( s ( ':host-context(ul) > .y {}' , 'a' , true ) ) . toEqual (
221
- '/*!@:host-context(ul) > .y*/ul.a-h > .y.a, ul .a-h > .y.a {}' ,
222
- ) ;
223
- } ) ;
224
-
225
172
it ( 'should handle tag selector' , ( ) => {
226
173
expect ( s ( ':host-context(div) {}' , 'a' ) ) . toEqual ( 'div.a-h, div .a-h {}' ) ;
227
174
expect ( s ( ':host-context(ul) > .y {}' , 'a' ) ) . toEqual ( 'ul.a-h > .y.a, ul .a-h > .y.a {}' ) ;
@@ -247,11 +194,6 @@ describe('ShadowCss', function () {
247
194
} ) ;
248
195
249
196
describe ( '::slotted' , ( ) => {
250
- it ( 'should handle *, commentOriginalSelector' , ( ) => {
251
- const r = s ( '::slotted(*) {}' , 'sc-ion-tag' , true ) ;
252
- expect ( r ) . toEqual ( '/*!@::slotted(*)*/.sc-ion-tag-s > * {}' ) ;
253
- } ) ;
254
-
255
197
it ( 'should handle *' , ( ) => {
256
198
const r = s ( '::slotted(*) {}' , 'sc-ion-tag' ) ;
257
199
expect ( r ) . toEqual ( '.sc-ion-tag-s > * {}' ) ;
@@ -306,62 +248,18 @@ describe('ShadowCss', function () {
306
248
expect ( r ) . toEqual ( '.sc-ion-tag-s > * {}, .sc-ion-tag-s > * {}, .sc-ion-tag-s > * {}' ) ;
307
249
} ) ;
308
250
309
- it ( 'same selectors, commentOriginalSelector' , ( ) => {
310
- const r = s ( '::slotted(*) {}, ::slotted(*) {}, ::slotted(*) {}' , 'sc-ion-tag' , true ) ;
311
- expect ( r ) . toEqual (
312
- '/*!@::slotted(*)*/.sc-ion-tag-s > * {}/*!@, ::slotted(*)*/.sc-ion-tag, .sc-ion-tag-s > * {}/*!@, ::slotted(*)*/.sc-ion-tag, .sc-ion-tag-s > * {}' ,
313
- ) ;
314
- } ) ;
315
-
316
251
it ( 'should combine parent selector when comma' , ( ) => {
317
252
const r = s ( '.a .b, .c ::slotted(*) {}' , 'sc-ion-tag' ) ;
318
253
expect ( r ) . toEqual ( '.a.sc-ion-tag .b.sc-ion-tag, .c.sc-ion-tag-s > *, .c .sc-ion-tag-s > * {}' ) ;
319
254
} ) ;
320
255
321
- it ( 'should handle multiple selector, commentOriginalSelector' , ( ) => {
322
- const r = s ( '::slotted(ul), ::slotted(li) {}' , 'sc-ion-tag' , true ) ;
323
- expect ( r ) . toEqual ( '/*!@::slotted(ul), ::slotted(li)*/.sc-ion-tag-s > ul, .sc-ion-tag-s > li {}' ) ;
324
- } ) ;
325
-
326
256
it ( 'should not replace the selector in a `@supports` rule' , ( ) => {
327
257
expect ( s ( '@supports selector(::slotted(*)) {::slotted(*) {color: red; }}' , 'sc-cmp' ) ) . toEqual (
328
258
'@supports selector(::slotted(*)) {.sc-cmp-s > * {color:red;}}' ,
329
259
) ;
330
260
} ) ;
331
261
} ) ;
332
262
333
- describe ( 'convertScopedToShadow' , ( ) => {
334
- it ( 'media query' , ( ) => {
335
- const input = `@media screen and (max-width:800px, max-height:100%) {/*!@div*/div.a {font-size:50px;}}` ;
336
- const expected = `@media screen and (max-width:800px, max-height:100%) {div{font-size:50px;}}` ;
337
- expect ( convertScopedToShadow ( input ) ) . toBe ( expected ) ;
338
- } ) ;
339
-
340
- it ( 'div' , ( ) => {
341
- const input = `/*!@div*/div.sc-ion-tag {}` ;
342
- const expected = `div{}` ;
343
- expect ( convertScopedToShadow ( input ) ) . toBe ( expected ) ;
344
- } ) ;
345
-
346
- it ( 'new lines' , ( ) => {
347
- const input = `/*!@div*/div.sc-ion-tag \n\n\n \t{}` ;
348
- const expected = `div{}` ;
349
- expect ( convertScopedToShadow ( input ) ) . toBe ( expected ) ;
350
- } ) ;
351
-
352
- it ( ':host' , ( ) => {
353
- const input = `/*!@:host*/.a-h {}` ;
354
- const expected = `:host{}` ;
355
- expect ( convertScopedToShadow ( input ) ) . toBe ( expected ) ;
356
- } ) ;
357
-
358
- it ( '::slotted' , ( ) => {
359
- const input = `/*!@::slotted(ul), ::slotted(li)*/.sc-ion-tag-s > ul, .sc-ion-tag-s > li {}` ;
360
- const expected = `::slotted(ul), ::slotted(li){}` ;
361
- expect ( convertScopedToShadow ( input ) ) . toBe ( expected ) ;
362
- } ) ;
363
- } ) ;
364
-
365
263
it ( 'should handle ::shadow' , ( ) => {
366
264
const css = s ( 'x::shadow > y {}' , 'a' ) ;
367
265
expect ( css ) . toEqual ( 'x.a > y.a {}' ) ;
0 commit comments