-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.test.js
193 lines (169 loc) · 6.35 KB
/
index.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
const postcss = require('postcss');
const plugin = require('./');
async function run(input, output, opts) {
let result = await postcss([plugin(opts)]).process(input, {
from: undefined,
});
expect(result.css).toEqual(output);
expect(result.warnings()).toHaveLength(0);
}
describe('postcss-shopify-settings-variables', () => {
it('replace single variable in value', async () => {
await run(
'a{ color: $(headline_color); }',
'a{ color: {{ settings.headline_color }}; }',
{},
);
});
it('replace multiple variables in multiple values', async () => {
await run(
'a{ color: $(headline_color); background-color: $(healine_bg_color); }',
'a{ color: {{ settings.headline_color }}; background-color: {{ settings.healine_bg_color }}; }',
{},
);
});
it('replace single variable in value with pixel unit', async () => {
await run(
'body{ font-size: $(headline_size)px; }',
'body{ font-size: {{ settings.headline_size }}px; }',
{},
);
});
it('replace single variable in value with liquid filter', async () => {
await run(
'a{ font-size: $(headline_size | divided_by: 2)px; }',
'a{ font-size: {{ settings.headline_size | divided_by: 2 }}px; }',
{},
);
});
it('replace single variable in value with liquid string filter', async () => {
await run(
"a{ font-family: $(font_family | replace: '+', ' '); }",
"a{ font-family: {{ settings.font_family | replace: '+', ' ' }}; }",
{},
);
});
it('replace single variable in value which has multiple variables', async () => {
await run(
'a{ border-bottom: 1px dotted $(border_color); }',
'a{ border-bottom: 1px dotted {{ settings.border_color }}; }',
{},
);
});
it('replace single variable in value when there is quotes', async () => {
await run(
'a{ font-family: "$(headline_google_webfont_font)"; }',
'a{ font-family: "{{ settings.headline_google_webfont_font }}"; }',
{},
);
});
it('replace single variable in value when there is parenthesis', async () => {
await run(
'a{ background: rgba($(header_bg_color), 0.9); }',
'a{ background: rgba({{ settings.header_bg_color }}, 0.9); }',
{},
);
});
describe('replace background url with asset_url filter', () => {
it('no quote', async () => {
await run(
'a{ background: url(logo.png); }',
'a{ background: url({{ "logo.png" | asset_url }}); }',
{},
);
});
it('with space', async () => {
await run(
'a{ background: url( logo.png ); }',
'a{ background: url({{ "logo.png" | asset_url }}); }',
{},
);
});
it('single quote', async () => {
await run(
"a{ background: url('logo.png'); }",
'a{ background: url({{ "logo.png" | asset_url }}); }',
{},
);
});
it('double quote', async () => {
await run(
'a{ background: url("logo.png"); }',
'a{ background: url({{ "logo.png" | asset_url }}); }',
{},
);
});
it('only replace url', async () => {
await run(
'a{ background-image: url(logo.png) no-repeat; }',
'a{ background-image: url({{ "logo.png" | asset_url }}) no-repeat; }',
{},
);
});
it('multiple url', async () => {
await run(
'a{ background: url("logo.png"), url([email protected]); }',
'a{ background: url({{ "logo.png" | asset_url }}), url({{ "[email protected]" | asset_url }}); }',
{},
);
});
it('not replace url with full path', async () => {
await run(
'a{ background: url("http://a.com/logo.png"); }',
'a{ background: url("http://a.com/logo.png"); }',
{},
);
});
it('not replace url with data uri', async () => {
await run(
'a{ background: url(data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7); }',
'a{ background: url(data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7); }',
{},
);
});
});
it('replace variable and url together', async () => {
await run(
'a{ background: $(modal_background_color) url("newsletter_bg.png"); }',
'a{ background: {{ settings.modal_background_color }} url({{ "newsletter_bg.png" | asset_url }}); }',
{},
);
});
describe('insert asset_url filter between background url and associated filters', () => {
it('single url with filters', async () => {
await run(
'a{ background: url(logo.png | split: "?" | first); }',
'a{ background: url({{ "logo.png" | asset_url | split: "?" | first }}); }',
{},
);
});
it('variable and single url with filters', async () => {
await run(
'a{ background: url(logo.png | split: "?" | first) $(modal_background_color); }',
'a{ background: url({{ "logo.png" | asset_url | split: "?" | first }}) {{ settings.modal_background_color }}; }',
{},
);
});
it('multiple url with filters', async () => {
await run(
'a{ background: url(logo.png | split: "?" | first), url("[email protected]" | downcase); }',
'a{ background: url({{ "logo.png" | asset_url | split: "?" | first }}), url({{ "[email protected]" | asset_url | downcase }}); }',
{},
);
});
it('one url with filters, another without filters', async () => {
await run(
"a{ background: url( logo.png ), url('[email protected]' | downcase); }",
'a{ background: url({{ "logo.png" | asset_url }}), url({{ "[email protected]" | asset_url | downcase }}); }',
{},
);
});
});
it('multiple settings on same line', async () => {
await run(
'a{ font-family: $(type_header_font_family.family), $(type_header_font_family.fallback_families); }',
'a{ font-family: {{ settings.type_header_font_family.family }}, {{ settings.type_header_font_family.fallback_families }}; }',
{},
);
});
});