als-layout 3.0.1 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/0-change-log.md +10 -0
- package/docs/1-basic-usage.md +0 -1
- package/index.js +150 -1
- package/package.json +5 -9
- package/readme.md +10 -46
- package/tests/constructor.test.js +2 -14
- package/tests/description.test.js +33 -0
- package/tests/favicon.test.js +36 -0
- package/tests/image.test.js +42 -0
- package/tests/{layout.test.js → integrative.test.js} +1 -2
- package/tests/keywords.test.js +47 -0
- package/tests/link.test.js +83 -0
- package/tests/script.test.js +57 -0
- package/tests/style.test.js +41 -0
- package/tests/url.test.js +50 -0
- package/tests/viewport.test.js +41 -0
- package/docs/4-render.md +0 -44
- package/lib/elements/add-meta.js +0 -11
- package/lib/elements/charset.js +0 -8
- package/lib/elements/description.js +0 -9
- package/lib/elements/favicon.js +0 -10
- package/lib/elements/image.js +0 -11
- package/lib/elements/index.js +0 -15
- package/lib/elements/keywords.js +0 -20
- package/lib/elements/link.js +0 -13
- package/lib/elements/script.js +0 -18
- package/lib/elements/style.js +0 -30
- package/lib/elements/title.js +0 -11
- package/lib/elements/url.js +0 -17
- package/lib/elements/viewport.js +0 -8
- package/lib/layout.js +0 -30
- package/lib/onload.js +0 -9
- package/lib/render.js +0 -12
- package/tests/counter/App.js +0 -6
- package/tests/counter/build.js +0 -14
- package/tests/counter/counter.js +0 -14
- package/tests/elements.test.js +0 -437
- package/tests/render/App.js +0 -10
- package/tests/render/Some.js +0 -8
- package/tests/render.test.js +0 -31
package/tests/elements.test.js
DELETED
|
@@ -1,437 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const Layout = require('../lib/layout');
|
|
3
|
-
const { describe, it, beforeEach } = require('node:test')
|
|
4
|
-
const Simple = require('als-simple-css')
|
|
5
|
-
const { SingleNode } = require('als-document')
|
|
6
|
-
const keywords = require('../lib/elements/keywords')
|
|
7
|
-
|
|
8
|
-
describe('Charset tests', () => {
|
|
9
|
-
let layout;
|
|
10
|
-
|
|
11
|
-
beforeEach(() => layout = new Layout());
|
|
12
|
-
|
|
13
|
-
it('should update charset if meta[charset] already exists', () => {
|
|
14
|
-
layout.head.insert(1, new SingleNode('meta', { charset: 'old-charset' }));
|
|
15
|
-
const newCharset = 'new-charset';
|
|
16
|
-
layout.charset(newCharset);
|
|
17
|
-
assert.strictEqual(layout.root.$('meta[charset]').getAttribute('charset'), newCharset, 'Charset should be updated');
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('should insert charset at second position if not present', () => {
|
|
21
|
-
const charset = 'UTF-8';
|
|
22
|
-
layout.charset(charset);
|
|
23
|
-
assert.strictEqual(layout.head.childNodes[0].tagName, 'META', 'Meta should be at second position');
|
|
24
|
-
assert.strictEqual(layout.head.childNodes[0].getAttribute('charset'), charset, 'Charset not set correctly');
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('should add charset correctly', () => {
|
|
28
|
-
const charset = 'test';
|
|
29
|
-
layout.charset(charset);
|
|
30
|
-
assert.strictEqual(layout.root.$('meta[charset]').getAttribute('charset'), charset, 'Charset not set correctly');
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
describe('Favicon tests', () => {
|
|
35
|
-
let layout;
|
|
36
|
-
|
|
37
|
-
beforeEach(() => {
|
|
38
|
-
layout = new Layout();
|
|
39
|
-
// layout.head.insert(1, new SingleNode('title', {})); // Добавляем элемент title для проверки позиции
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should update favicon href if link[rel="icon"] already exists', () => {
|
|
43
|
-
const oldHref = 'old-favicon.ico';
|
|
44
|
-
layout.head.insert(2, new SingleNode('link', { rel: 'icon', href: oldHref, type: 'image/x-icon' }));
|
|
45
|
-
const newHref = 'new-favicon.ico';
|
|
46
|
-
layout.favicon(newHref);
|
|
47
|
-
assert.strictEqual(layout.root.$('link[rel="icon"]').getAttribute('href'), newHref, 'Favicon href should be updated');
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('should insert favicon at the end of head if not present', () => {
|
|
51
|
-
const faviconHref = 'favicon.ico';
|
|
52
|
-
layout.favicon(faviconHref);
|
|
53
|
-
const element = layout.head.childNodes[layout.head.childNodes.length - 1]
|
|
54
|
-
assert.strictEqual(element.tagName, 'LINK', 'Favicon link should be at second position');
|
|
55
|
-
assert.strictEqual(element.getAttribute('href'), faviconHref, 'Favicon href not set correctly');
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('should add favicon correctly', () => {
|
|
59
|
-
const faviconHref = 'favicon.ico';
|
|
60
|
-
layout.favicon(faviconHref);
|
|
61
|
-
assert.strictEqual(layout.root.$('link[rel="icon"]').getAttribute('href'), faviconHref, 'Favicon not set correctly');
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe('Image tests', () => {
|
|
67
|
-
let layout;
|
|
68
|
-
|
|
69
|
-
beforeEach(() => {
|
|
70
|
-
layout = new Layout();
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('should add twitter:card meta tag', () => {
|
|
74
|
-
const imageUrl = 'test-image.jpg';
|
|
75
|
-
layout.image(imageUrl);
|
|
76
|
-
assert.strictEqual(layout.root.$('meta[name="twitter:card"]').getAttribute('content'), 'summary_large_image', 'twitter:card not set correctly');
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('should add image correctly', () => {
|
|
80
|
-
const imageUrl = 'test-image.jpg';
|
|
81
|
-
layout.image(imageUrl);
|
|
82
|
-
assert.strictEqual(layout.root.$('meta[property="og:image"]').getAttribute('content'), imageUrl, 'Image not set correctly');
|
|
83
|
-
assert.strictEqual(layout.root.$('meta[name="twitter:image"]').getAttribute('content'), imageUrl, 'Image not set correctly');
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('should handle cases where image URL already has query parameters', () => {
|
|
87
|
-
const imageUrl = 'test-image.jpg?existing=param';
|
|
88
|
-
const version = '456';
|
|
89
|
-
layout.image(imageUrl, version);
|
|
90
|
-
const expectedUrl = imageUrl + '&v=' + version;
|
|
91
|
-
const img = layout.root.$('meta[property="og:image"]').getAttribute('content')
|
|
92
|
-
assert(img === expectedUrl, 'Versioned image URL with existing parameters not set correctly');
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('should add version parameter to image URL if version is provided', () => {
|
|
96
|
-
const imageUrl = 'test-image.jpg';
|
|
97
|
-
const version = '123';
|
|
98
|
-
layout.image(imageUrl, version);
|
|
99
|
-
const expectedUrl = imageUrl + '?v=' + version;
|
|
100
|
-
assert.strictEqual(layout.root.$('meta[property="og:image"]').getAttribute('content'), expectedUrl, 'Versioned image URL not set correctly in og:image');
|
|
101
|
-
assert.strictEqual(layout.root.$('meta[name="twitter:image"]').getAttribute('content'), expectedUrl, 'Versioned image URL not set correctly in twitter:image');
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
describe('Keywords tests', () => {
|
|
106
|
-
let layout;
|
|
107
|
-
|
|
108
|
-
beforeEach(() => {
|
|
109
|
-
layout = new Layout();
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('should add new keywords to an existing meta tag', () => {
|
|
113
|
-
layout.head.insert(2, new SingleNode('meta', { name: 'keywords', content: 'initial' }));
|
|
114
|
-
const additionalKeywords = ['keyword1', 'keyword2'];
|
|
115
|
-
keywords(additionalKeywords, layout);
|
|
116
|
-
const expectedContent = 'initial,keyword1,keyword2';
|
|
117
|
-
assert.strictEqual(layout.root.$('meta[name="keywords"]').getAttribute('content'), expectedContent, 'Existing keywords not updated correctly');
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('should not add duplicate keywords', () => {
|
|
121
|
-
layout.head.insert(2, new SingleNode('meta', { name: 'keywords', content: 'keyword1,keyword2' }));
|
|
122
|
-
const additionalKeywords = ['keyword2', 'keyword3'];
|
|
123
|
-
keywords(additionalKeywords, layout);
|
|
124
|
-
const expectedContent = 'keyword1,keyword2,keyword3';
|
|
125
|
-
assert.strictEqual(layout.root.$('meta[name="keywords"]').getAttribute('content'), expectedContent, 'Duplicate keywords were added');
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('should handle keywords with leading or trailing spaces', () => {
|
|
129
|
-
const messyKeywords = [' keyword1', 'keyword2 '];
|
|
130
|
-
keywords(messyKeywords, layout);
|
|
131
|
-
const expectedContent = 'keyword1,keyword2';
|
|
132
|
-
assert.strictEqual(layout.root.$('meta[name="keywords"]').getAttribute('content'), expectedContent, 'Keywords with spaces not trimmed correctly');
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('should add keywords correctly', () => {
|
|
136
|
-
const keywords = ['keyword1', 'keyword2'];
|
|
137
|
-
layout.keywords(keywords);
|
|
138
|
-
assert(layout.root.$('meta[name="keywords"]').getAttribute('content') === keywords.join(), 'Keywords not set correctly');
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('should handle empty keywords array', () => {
|
|
142
|
-
keywords([], layout);
|
|
143
|
-
assert(!layout.root.$('meta[name="keywords"]'), 'Meta tag for empty keywords should not be created');
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
describe('Link', () => {
|
|
149
|
-
let layout;
|
|
150
|
-
beforeEach(() => layout = new Layout());
|
|
151
|
-
|
|
152
|
-
it('should add a new link element without version', () => {
|
|
153
|
-
const href = 'style.css';
|
|
154
|
-
layout.link(href);
|
|
155
|
-
assert.strictEqual(layout.root.$('link[rel="stylesheet"]').getAttribute('href'), href, 'Link href should match the provided href');
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it('should add a new link element with version', () => {
|
|
159
|
-
const href = 'style.css';
|
|
160
|
-
const version = '1.0';
|
|
161
|
-
layout.link(href, version);
|
|
162
|
-
assert.strictEqual(layout.root.$('link[rel="stylesheet"]').getAttribute('href'), `${href}?v=${version}`, 'Link href should include version query parameter');
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it('should not add a link if one with the same href and version already exists', () => {
|
|
166
|
-
const href = 'style.css';
|
|
167
|
-
const version = '1.0';
|
|
168
|
-
layout.link(href, version);
|
|
169
|
-
layout.link(href, version);
|
|
170
|
-
assert.strictEqual(layout.root.$$(`link[rel="stylesheet"][href="${href}?v=${version}"]`).length, 1, 'Should not add duplicate link with the same version');
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it('should handle invalid href or version correctly', () => {
|
|
174
|
-
layout.link('', '1.0');
|
|
175
|
-
layout.link(null, '1.0');
|
|
176
|
-
// layout.link('style.css', '');
|
|
177
|
-
// layout.link('style.css', null);
|
|
178
|
-
assert.strictEqual(layout.root.$('link[rel="stylesheet"]'), null, 'Should not add a link when href or version are invalid');
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it('should add link correctly', () => {
|
|
182
|
-
const href = 'style.css';
|
|
183
|
-
layout.link(href);
|
|
184
|
-
assert.strictEqual(layout.root.$('link[rel="stylesheet"]').getAttribute('href'), href, 'Link not set correctly');
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
it('should not add a new link element if one already exists with the same href and no version', () => {
|
|
188
|
-
const href = 'style.css';
|
|
189
|
-
layout.link(href); // Добавление ссылки без версии
|
|
190
|
-
layout.link(href); // Повторное добавление той же ссылки без версии
|
|
191
|
-
assert.strictEqual(layout.root.$$(`link[rel="stylesheet"][href="${href}"]`).length, 1, 'Should not add duplicate link without version');
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it('should not add a link if href is undefined or null', () => {
|
|
195
|
-
layout.link(undefined, '1.0');
|
|
196
|
-
layout.link(null);
|
|
197
|
-
assert.strictEqual(layout.root.$('link[rel="stylesheet"]'), null, 'Should not add a link when href is undefined or null');
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
it('should handle different versions for the same href', () => {
|
|
201
|
-
const href = 'style.css';
|
|
202
|
-
const version1 = '1.0';
|
|
203
|
-
const version2 = '1.1';
|
|
204
|
-
layout.link(href, version1);
|
|
205
|
-
layout.link(href, version2);
|
|
206
|
-
assert.strictEqual(layout.root.$$(`link[rel="stylesheet"]`).length, 2, 'Should add different links for different versions');
|
|
207
|
-
assert.strictEqual(layout.root.$$(`link[rel="stylesheet"][href="${href}?v=${version1}"]`).length, 1, 'First version link should exist');
|
|
208
|
-
assert.strictEqual(layout.root.$$(`link[rel="stylesheet"][href="${href}?v=${version2}"]`).length, 1, 'Second version link should exist');
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it('should correctly add version when href already has parameters', () => {
|
|
212
|
-
const href = 'style.css?param=value';
|
|
213
|
-
const version = '1.0';
|
|
214
|
-
layout.link(href, version);
|
|
215
|
-
assert.strictEqual(layout.root.$('link[rel="stylesheet"]').getAttribute('href'), `${href}&v=${version}`, 'Href should include version appended with &');
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
it('should not add a link when one with a similar href prefix exists', () => {
|
|
219
|
-
const href = 'style.css';
|
|
220
|
-
layout.link(href);
|
|
221
|
-
layout.link(href + '?param=value', '1.0');
|
|
222
|
-
assert.strictEqual(layout.root.$$(`link[rel="stylesheet"]`).length, 2, 'Should recognize different full hrefs as different links');
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
})
|
|
226
|
-
|
|
227
|
-
describe('Scripts', () => {
|
|
228
|
-
let layout;
|
|
229
|
-
|
|
230
|
-
beforeEach(() => layout = new Layout());
|
|
231
|
-
|
|
232
|
-
it('should not add script if attributes are not an object', () => {
|
|
233
|
-
layout.script("not-an-object");
|
|
234
|
-
assert.strictEqual(layout.root.$('script'), null, 'Script should not be added when attributes are not an object');
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
it('should not add script if src already exists', () => {
|
|
238
|
-
layout.script({ src: 'existingscript.js' }, 'console.log("test");');
|
|
239
|
-
layout.script({ src: 'existingscript.js' }, 'console.log("duplicate");');
|
|
240
|
-
assert.strictEqual(layout.root.$$(`script[src="existingscript.js"]`).length, 1, 'Duplicate script should not be added');
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
it('should handle empty innerHTML correctly', () => {
|
|
244
|
-
layout.script({ src: 'test.js' }, '');
|
|
245
|
-
assert.strictEqual(layout.root.$('script').innerHTML, '', 'Script innerHTML should be empty');
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
it('should add script correctly', () => {
|
|
249
|
-
const scriptContent = 'console.log("Hello, world!");';
|
|
250
|
-
layout.script({}, scriptContent);
|
|
251
|
-
assert.strictEqual(layout.root.$('script').innerHTML, scriptContent, 'Script content not set correctly');
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it('should add version to script src', () => {
|
|
255
|
-
const src = 'script.js';
|
|
256
|
-
const version = '1.0';
|
|
257
|
-
layout.script({ src }, '', true, version);
|
|
258
|
-
assert.strictEqual(layout.root.$('script').getAttribute('src'), `${src}?v=${version}`, 'Script src should include version');
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
it('should not add script if no attributes and no innerHTML', () => {
|
|
262
|
-
layout.script({}, '');
|
|
263
|
-
assert.strictEqual(layout.root.$('script'), null, 'Script should not be added if there are no attributes and no innerHTML');
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
it('should add script after body when head is false', () => {
|
|
267
|
-
const scriptContent = 'console.log("Script in body");';
|
|
268
|
-
layout.script({ src: 'scriptbody.js' }, scriptContent, false);
|
|
269
|
-
assert.strictEqual(layout.body.next.innerHTML, scriptContent, 'Script should be added to body');
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
it('should append version parameter correctly when src already has parameters', () => {
|
|
273
|
-
const srcWithParams = 'script.js?existing=param';
|
|
274
|
-
const version = '1.0';
|
|
275
|
-
layout.script({ src: srcWithParams }, '', true, version);
|
|
276
|
-
assert.strictEqual(layout.root.$('script').getAttribute('src'), `${srcWithParams}&v=${version}`, 'Version parameter should be appended with &');
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
})
|
|
280
|
-
|
|
281
|
-
describe('Styles', () => {
|
|
282
|
-
let layout;
|
|
283
|
-
beforeEach(() => layout = new Layout());
|
|
284
|
-
|
|
285
|
-
it('should not add style if styles are invalid', () => {
|
|
286
|
-
layout.style(123);
|
|
287
|
-
assert.strictEqual(layout.root.$('style'), null, 'Style should not be added when styles are invalid');
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
it('should add minified style', () => {
|
|
291
|
-
const styles = 'body { color: blue; } div { font-size: 12px; }';
|
|
292
|
-
layout.style(styles, true);
|
|
293
|
-
console.log(layout.root.$('style').innerHTML)
|
|
294
|
-
assert.strictEqual(layout.root.$('style').innerHTML, 'body{color:blue}div{font-size:12px}', 'Styles should be minified');
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
it('should add style correctly', () => {
|
|
298
|
-
const styles = 'body { background-color: black; }';
|
|
299
|
-
layout.style(styles);
|
|
300
|
-
assert(layout.root.$('style').innerHTML.includes(styles), 'Styles not set correctly');
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
it('Should add simple styles', () => {
|
|
304
|
-
const styles = [{ body: { bgc: 'black' } }]
|
|
305
|
-
const css = new Simple(styles).stylesheet()
|
|
306
|
-
layout.style(styles);
|
|
307
|
-
assert(layout.root.$('style').innerHTML.includes(css), 'Styles not set correctly');
|
|
308
|
-
})
|
|
309
|
-
|
|
310
|
-
it('should add styles to existing style tag', () => {
|
|
311
|
-
assert(layout.root.$$('style').length === 0)
|
|
312
|
-
const styles1 = 'body { background-color: black; }';
|
|
313
|
-
const styles2 = 'body { margin: 0; }';
|
|
314
|
-
layout.style(styles1);
|
|
315
|
-
assert(layout.root.$$('style').length === 1)
|
|
316
|
-
layout.style(styles2);
|
|
317
|
-
assert(layout.root.$$('style').length === 1)
|
|
318
|
-
const inner = layout.root.$('style').innerHTML
|
|
319
|
-
assert(inner.includes(styles1));
|
|
320
|
-
assert(inner.includes(styles2));
|
|
321
|
-
});
|
|
322
|
-
})
|
|
323
|
-
|
|
324
|
-
describe('Url', () => {
|
|
325
|
-
let layout;
|
|
326
|
-
beforeEach(() => layout = new Layout());
|
|
327
|
-
|
|
328
|
-
it('should not add canonical URL if URL is invalid', () => {
|
|
329
|
-
layout.url('not-a-url', 'aa');
|
|
330
|
-
assert.strictEqual(layout.root.$('link[rel="canonical"]'), null, 'Canonical URL should not be added for invalid URLs');
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
it('should add url correctly', () => {
|
|
334
|
-
const url = 'http://localhost';
|
|
335
|
-
layout.url(url);
|
|
336
|
-
assert(layout.root.$('link[rel="canonical"]').getAttribute('href') === url, 'Canonical URL not set correctly');
|
|
337
|
-
});
|
|
338
|
-
|
|
339
|
-
it('should add og:url meta correctly', () => {
|
|
340
|
-
const url = 'http://example.com';
|
|
341
|
-
const host = 'http://example.com';
|
|
342
|
-
layout.url(url, host);
|
|
343
|
-
assert.strictEqual(layout.root.$('meta[property="og:url"]').getAttribute('content'), url, 'og:url meta not set correctly');
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
it('should add canonical link if not already present', () => {
|
|
347
|
-
const url = 'http://example.com';
|
|
348
|
-
const host = 'http://example.com';
|
|
349
|
-
layout.url(url, host);
|
|
350
|
-
assert.strictEqual(layout.root.$('link[rel="canonical"]').getAttribute('href'), url, 'Canonical link should be added if not present');
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
it('should update existing canonical link', () => {
|
|
354
|
-
const initialUrl = 'http://example.com/initial';
|
|
355
|
-
const newUrl = 'http://example.com/new';
|
|
356
|
-
const host = 'http://example.com';
|
|
357
|
-
layout.url(initialUrl, host);
|
|
358
|
-
layout.url(newUrl, host);
|
|
359
|
-
assert.strictEqual(layout.root.$('link[rel="canonical"]').getAttribute('href'), newUrl, 'Canonical link should be updated with new URL');
|
|
360
|
-
});
|
|
361
|
-
|
|
362
|
-
it('should handle invalid URL with valid host', () => {
|
|
363
|
-
layout.url('http://', 'http://example.com');
|
|
364
|
-
assert.strictEqual(layout.root.$('meta[property="og:url"]'), null, 'Meta og:url should not be added for invalid URL');
|
|
365
|
-
assert.strictEqual(layout.root.$('link[rel="canonical"]'), null, 'Canonical link should not be added for invalid URL');
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
})
|
|
370
|
-
|
|
371
|
-
describe('layout.viewport',() => {
|
|
372
|
-
let layout;
|
|
373
|
-
|
|
374
|
-
beforeEach(() => layout = new Layout());
|
|
375
|
-
|
|
376
|
-
it('should update existing viewport meta correctly', () => {
|
|
377
|
-
// Добавляем изначальный viewport
|
|
378
|
-
const initialContent = 'width=device-width, initial-scale=1.0';
|
|
379
|
-
layout.viewport(initialContent);
|
|
380
|
-
|
|
381
|
-
// Обновляем viewport
|
|
382
|
-
const updatedContent = 'width=device-width, initial-scale=2.0';
|
|
383
|
-
layout.viewport(updatedContent);
|
|
384
|
-
|
|
385
|
-
// Проверяем, что содержимое meta обновлено
|
|
386
|
-
assert.strictEqual(layout.root.$('meta[name="viewport"]').getAttribute('content'), updatedContent, 'Existing viewport meta content should be updated');
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
it('should not add a second viewport meta if one already exists', () => {
|
|
390
|
-
// Добавляем изначальный viewport
|
|
391
|
-
const initialContent = 'width=device-width, initial-scale=1.0';
|
|
392
|
-
layout.viewport(initialContent);
|
|
393
|
-
|
|
394
|
-
// Пытаемся добавить ещё один
|
|
395
|
-
const secondContent = 'width=device-width, initial-scale=2.0';
|
|
396
|
-
layout.viewport(secondContent);
|
|
397
|
-
|
|
398
|
-
// Проверяем, что в документе только один элемент meta viewport
|
|
399
|
-
assert.strictEqual(layout.root.$$(`meta[name="viewport"]`).length, 1, 'Only one viewport meta should exist');
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
it('should add viewport correctly', () => {
|
|
403
|
-
const viewportContent = 'width=device-width, initial-scale=1.0';
|
|
404
|
-
layout.viewport(viewportContent);
|
|
405
|
-
assert.strictEqual(layout.root.$('meta[name="viewport"]').getAttribute('content'), viewportContent, 'Viewport not set correctly');
|
|
406
|
-
});
|
|
407
|
-
})
|
|
408
|
-
|
|
409
|
-
describe('description and title', () => {
|
|
410
|
-
let layout;
|
|
411
|
-
|
|
412
|
-
beforeEach(() => layout = new Layout());
|
|
413
|
-
|
|
414
|
-
it('should add description correctly', () => {
|
|
415
|
-
const description = 'Test Description';
|
|
416
|
-
layout.description(description);
|
|
417
|
-
assert.strictEqual(layout.root.$('meta[name="description"]').getAttribute('content'), description, 'Description not set correctly');
|
|
418
|
-
assert.strictEqual(layout.root.$('meta[property="og:description"]').getAttribute('content'), description, 'Description not set correctly');
|
|
419
|
-
assert.strictEqual(layout.root.$('meta[property="twitter:description"]').getAttribute('content'), description, 'Description not set correctly');
|
|
420
|
-
});
|
|
421
|
-
|
|
422
|
-
it('should add title correctly', () => {
|
|
423
|
-
const title = 'Test Title';
|
|
424
|
-
layout.title(title);
|
|
425
|
-
assert(layout.root.$('title').innerHTML === title, 'Title not set correctly');
|
|
426
|
-
assert(layout.root.$('[property="og:title"]').getAttribute('content') === title, 'Title not set correctly');
|
|
427
|
-
});
|
|
428
|
-
|
|
429
|
-
it('should add title if no title tag', () => {
|
|
430
|
-
layout.$('title').remove()
|
|
431
|
-
const title = 'Test Title';
|
|
432
|
-
layout.title(title);
|
|
433
|
-
assert(layout.root.$('title').innerHTML === title, 'Title not set correctly');
|
|
434
|
-
assert(layout.root.$('[property="og:title"]').getAttribute('content') === title, 'Title not set correctly');
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
});
|
package/tests/render/App.js
DELETED
package/tests/render/Some.js
DELETED
package/tests/render.test.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const { describe, it,beforeEach } = require('node:test')
|
|
3
|
-
const Layout = require('../lib/layout')
|
|
4
|
-
|
|
5
|
-
describe('Basic tests', () => {
|
|
6
|
-
let layout
|
|
7
|
-
beforeEach(() => layout = new Layout())
|
|
8
|
-
it('Should render without bundle',() => {
|
|
9
|
-
const { rawHtml } = layout.render('./render/App', 'body')
|
|
10
|
-
const expected =
|
|
11
|
-
'<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title></title></head><body><div>\n' +
|
|
12
|
-
' <div>Hello from App!</div>\n' +
|
|
13
|
-
' <div component="Some">\n' +
|
|
14
|
-
' Hello From Some!\n' +
|
|
15
|
-
' </div>\n' +
|
|
16
|
-
' </div></body></html>'
|
|
17
|
-
|
|
18
|
-
assert(rawHtml === expected)
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
it('Should render with bundle',() => {
|
|
22
|
-
const { rawHtml } = layout.render('./render/App', 'body',{})
|
|
23
|
-
assert(rawHtml.includes('<script>'))
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
it('Should do nothing if element not exists',() => {
|
|
27
|
-
const { rawHtml } = layout.render('./render/App', 'main')
|
|
28
|
-
const expected = '<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title></title></head><body></body></html>'
|
|
29
|
-
assert(rawHtml === expected)
|
|
30
|
-
})
|
|
31
|
-
})
|