forked from hplush/slowreader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
theme-classes.test.ts
113 lines (104 loc) · 3.5 KB
/
theme-classes.test.ts
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
import { equal } from 'node:assert'
import { test } from 'node:test'
import postcss from 'postcss'
import plugin from '../postcss/theme-classes.cjs'
function run(input: string, output: string): void {
let result = postcss([plugin]).process(input, { from: undefined })
equal(result.css, output)
}
test('adds theme classes to media inside :root', () => {
run(
':root {' +
'@media (prefers-color-scheme:light) {--a: 1}' +
'@media (prefers-color-scheme:dark) {--a: 1}' +
'}',
':root {' +
'@media (prefers-color-scheme:light) {--a: 1}' +
'@media (prefers-color-scheme:dark) {--a: 1}' +
'}' +
'.is-dark-theme {--a: 1}' +
'.is-light-theme {--a: 1}'
)
})
test('inserts in the same order by before next nodes', () => {
run(
':root {' +
'@media (prefers-color-scheme:light) {--a: 1}' +
'@media (prefers-color-scheme:dark) {--a: 1}' +
'}' +
'.is-slow-theme.is-light-theme {--a: 2}',
':root {' +
'@media (prefers-color-scheme:light) {--a: 1}' +
'@media (prefers-color-scheme:dark) {--a: 1}' +
'}' +
'.is-dark-theme {--a: 1}' +
'.is-light-theme {--a: 1}' +
'.is-slow-theme.is-light-theme {--a: 2}'
)
})
test('adds theme classes to media outside of :root', () => {
run(
'@media (prefers-color-scheme:light) {:root {--a: 1}}' +
'@media (prefers-color-scheme:dark) {:root {--a: 1}}',
'@media (prefers-color-scheme:light) {:root {--a: 1}}' +
'@media (prefers-color-scheme:dark) {:root {--a: 1}}' +
'.is-light-theme {--a: 1}' +
'.is-dark-theme {--a: 1}'
)
})
test('adds theme classes to media inside component', () => {
run(
'.block {' +
'@media (prefers-color-scheme:light) {--a: 1}' +
'@media (prefers-color-scheme:dark) {--a: 1}' +
'}',
'.block {' +
'@media (prefers-color-scheme:light) {--a: 1}' +
'@media (prefers-color-scheme:dark) {--a: 1}' +
'}' +
':where(.is-dark-theme) .block {--a: 1}' +
':where(.is-light-theme) .block {--a: 1}'
)
})
test('adds theme classes to media inside slow theme', () => {
run(
'.is-slow-theme {' +
'@media (prefers-color-scheme:light) {--a: 1}' +
'@media (prefers-color-scheme:dark) {--a: 1}' +
'}',
'.is-slow-theme {' +
'@media (prefers-color-scheme:light) {--a: 1}' +
'@media (prefers-color-scheme:dark) {--a: 1}' +
'}' +
':where(.is-dark-theme) .is-slow-theme, ' +
'.is-slow-theme:where(.is-dark-theme) {--a: 1}' +
':where(.is-light-theme) .is-slow-theme, ' +
'.is-slow-theme:where(.is-light-theme) {--a: 1}'
)
})
test('adds theme classes to media inside components', () => {
run(
'.a, .b {' +
'@media (prefers-color-scheme:light) {--a: 1}' +
'@media (prefers-color-scheme:dark) {--a: 1}' +
'}',
'.a, .b {' +
'@media (prefers-color-scheme:light) {--a: 1}' +
'@media (prefers-color-scheme:dark) {--a: 1}' +
'}' +
':where(.is-dark-theme) .a,' +
':where(.is-dark-theme) .b {--a: 1}' +
':where(.is-light-theme) .a,' +
':where(.is-light-theme) .b {--a: 1}'
)
})
test('adds theme classes to media outside of component', () => {
run(
'@media (prefers-color-scheme:light) {.block {--a: 1}}' +
'@media (prefers-color-scheme:dark) {.block {--a: 1}}',
'@media (prefers-color-scheme:light) {.block {--a: 1}}' +
'@media (prefers-color-scheme:dark) {.block {--a: 1}}' +
':where(.is-light-theme) .block {--a: 1}' +
':where(.is-dark-theme) .block {--a: 1}'
)
})