-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
selector.test.js
139 lines (122 loc) · 3.97 KB
/
selector.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
let parse = require('postcss').parse
let Selector = require('../lib/selector')
let selector
beforeEach(() => {
selector = new Selector('::selection', ['-moz-', '-ms-'])
})
describe('prefixed()', () => {
it('adds prefix after non-letters symbols', () => {
expect(selector.prefixed('-moz-')).toEqual('::-moz-selection')
})
})
describe('regexp()', () => {
it('creates regexp for prefix', () => {
let regexp = selector.regexp('-moz-')
expect(regexp.test('::-moz-selection')).toBeTruthy()
expect(regexp.test('::selection')).toBeFalsy()
})
it('creates regexp without prefix', () => {
let regexp = selector.regexp()
expect(regexp.test('::-moz-selection')).toBeFalsy()
expect(regexp.test('::selection')).toBeTruthy()
})
})
describe('check()', () => {
it('checks rule selectors', () => {
let css = parse('body .selection {}, ' +
':::selection {}, body ::selection {}')
expect(selector.check(css.nodes[0])).toBeFalsy()
expect(selector.check(css.nodes[1])).toBeFalsy()
expect(selector.check(css.nodes[2])).toBeTruthy()
})
})
describe('prefixeds()', () => {
it('grouping rule gets correct _autoprefixerPrefixeds property', () => {
let css = parse('.c::selection, .d:read-only {}')
let rSel = new Selector(':read-only', ['-moz-'])
selector.prefixeds(css.first)
rSel.prefixeds(css.first)
expect(css.first._autoprefixerPrefixeds).toEqual({
'::selection': {
'-webkit-': '.c::-webkit-selection',
'-moz-': '.c::-moz-selection',
'-ms-': '.c::-ms-selection',
'-o-': '.c::-o-selection'
},
':read-only': {
'-webkit-': '.d:-webkit-read-only',
'-moz-': '.d:-moz-read-only',
'-ms-': '.d:-ms-read-only',
'-o-': '.d:-o-read-only'
}
})
})
it('returns all available prefixed selectors', () => {
let css = parse('::selection {}')
expect(selector.prefixeds(css.first)).toEqual({
'::selection': {
'-webkit-': '::-webkit-selection',
'-moz-': '::-moz-selection',
'-ms-': '::-ms-selection',
'-o-': '::-o-selection'
}
})
})
})
describe('already()', () => {
let prefixeds
beforeEach(() => {
let css = parse('::selection {}')
prefixeds = selector.prefixeds(css.first)
})
it('returns false on first element', () => {
let css = parse('::selection {}')
expect(selector.already(css.first, prefixeds, '-moz-'))
.toBeFalsy()
})
it('stops on another type', () => {
let css = parse('::-moz-selection {} ' +
'@keyframes anim {} ::selection {}')
expect(selector.already(css.nodes[2], prefixeds, '-moz-'))
.toBeFalsy()
})
it('stops on another selector', () => {
let css = parse('::-moz-selection {} a {} ::selection {}')
expect(selector.already(css.nodes[2], prefixeds, '-moz-'))
.toBeFalsy()
})
it('finds prefixed even if unknown prefix is between', () => {
let css = parse('::-moz-selection {} ' +
'::-o-selection {} ::selection {}')
expect(selector.already(css.nodes[2], prefixeds, '-moz-'))
.toBeTruthy()
})
})
describe('replace()', () => {
it('adds prefix to selectors', () => {
expect(
selector.replace('body ::selection, input::selection, a', '-ms-')
).toEqual('body ::-ms-selection, input::-ms-selection, a')
})
})
describe('process()', () => {
it('adds prefixes', () => {
let css = parse('b ::-moz-selection{} b ::selection{}')
selector.process(css.nodes[1])
expect(css.toString()).toEqual(
'b ::-moz-selection{} b ::-ms-selection{} b ::selection{}')
})
it('checks parents prefix', () => {
let css = parse('@-moz-page{ ::selection{} }')
selector.process(css.first.first)
expect(css.toString()).toEqual(
'@-moz-page{ ::-moz-selection{} ::selection{} }')
})
})
describe('old()', () => {
it('returns object to find old selector', () => {
let old = selector.old('-moz-')
expect(old.unprefixed).toEqual('::selection')
expect(old.prefix).toEqual('-moz-')
})
})