Debian Codegraph @

autoprefixer/test/selector.test.js

raw symbols SCIP
1 let { parse } = require('postcss')
2 let { test } = require('uvu')
3 let { equal, is } = require('uvu/assert')
4
5 let Selector = require('../lib/selector')
6
7 let prefixeds, selector
8 test.before.each(() => {
9 selector = new Selector('::selection', ['-moz-', '-ms-'])
10 prefixeds = selector.prefixeds(parse('::selection {}').first)
11 })
12
13 test('adds prefix after non-letters symbols', () => {
14 equal(selector.prefixed('-moz-'), '::-moz-selection')
15 })
16
17 test('creates regexp for prefix', () => {
18 let regexp = selector.regexp('-moz-')
19 is(regexp.test('::-moz-selection'), true)
20 is(regexp.test('::selection'), false)
21 })
22
23 test('creates regexp without prefix', () => {
24 let regexp = selector.regexp()
25 is(regexp.test('::-moz-selection'), false)
26 is(regexp.test('::selection'), true)
27 })
28
29 test('checks rule selectors', () => {
30 let css = parse(
31 'body .selection {}, ' + ':::selection {}, body ::selection {}'
32 )
33 is(selector.check(css.nodes[0]), false)
34 is(selector.check(css.nodes[1]), false)
35 is(selector.check(css.nodes[2]), true)
36 })
37
38 test('grouping rule gets correct _autoprefixerPrefixeds property', () => {
39 let css = parse('.c::selection, .d:read-only {}')
40 let rSel = new Selector(':read-only', ['-moz-'])
41 selector.prefixeds(css.first)
42 rSel.prefixeds(css.first)
43 equal(css.first._autoprefixerPrefixeds, {
44 '::selection': {
45 '-moz-': '.c::-moz-selection',
46 '-ms-': '.c::-ms-selection',
47 '-o-': '.c::-o-selection',
48 '-webkit-': '.c::-webkit-selection'
49 },
50 ':read-only': {
51 '-moz-': '.d:-moz-read-only',
52 '-ms-': '.d:-ms-read-only',
53 '-o-': '.d:-o-read-only',
54 '-webkit-': '.d:-webkit-read-only'
55 }
56 })
57 })
58
59 test('returns all available prefixed selectors', () => {
60 let css = parse('::selection {}')
61 equal(selector.prefixeds(css.first), {
62 '::selection': {
63 '-moz-': '::-moz-selection',
64 '-ms-': '::-ms-selection',
65 '-o-': '::-o-selection',
66 '-webkit-': '::-webkit-selection'
67 }
68 })
69 })
70
71 test('returns false on first element', () => {
72 let css = parse('::selection {}')
73 is(selector.already(css.first, prefixeds, '-moz-'), false)
74 })
75
76 test('stops on another type', () => {
77 let css = parse('::-moz-selection {} ' + '@keyframes anim {} ::selection {}')
78 is(selector.already(css.nodes[2], prefixeds, '-moz-'), false)
79 })
80
81 test('stops on another selector', () => {
82 let css = parse('::-moz-selection {} a {} ::selection {}')
83 is(selector.already(css.nodes[2], prefixeds, '-moz-'), false)
84 })
85
86 test('finds prefixed even if unknown prefix is between', () => {
87 let css = parse('::-moz-selection {} ' + '::-o-selection {} ::selection {}')
88 is(selector.already(css.nodes[2], prefixeds, '-moz-'), true)
89 })
90
91 test('adds prefix to selectors', () => {
92 equal(
93 selector.replace('body ::selection, input::selection, a', '-ms-'),
94 'body ::-ms-selection, input::-ms-selection, a'
95 )
96 })
97
98 test('adds prefixes', () => {
99 let css = parse('b ::-moz-selection{} b ::selection{}')
100 selector.process(css.nodes[1])
101 equal(
102 css.toString(),
103 'b ::-moz-selection{} b ::-ms-selection{} b ::selection{}'
104 )
105 })
106
107 test('checks parents prefix', () => {
108 let css = parse('@-moz-page{ ::selection{} }')
109 selector.process(css.first.first)
110 equal(css.toString(), '@-moz-page{ ::-moz-selection{} ::selection{} }')
111 })
112
113 test('returns object to find old selector', () => {
114 let old = selector.old('-moz-')
115 equal(old.unprefixed, '::selection')
116 equal(old.prefix, '-moz-')
117 })
118
119 test.run()