als-layout
Version:
HTML layout constructor with dynamic meta, styles, and scripts
48 lines (39 loc) • 2.13 kB
JavaScript
const assert = require('assert');
const { describe, it, beforeEach } = require('node:test')
const Layout = require('../src/layout.js');
const { SingleNode } = require('als-document')
describe('Keywords tests', () => {
let layout;
beforeEach(() => {
layout = new Layout();
});
it('should add new keywords to an existing meta tag', () => {
layout.head.insert(2, new SingleNode('meta', { name: 'keywords', content: 'initial' }));
const additionalKeywords = ['keyword1', 'keyword2'];
layout.keywords(additionalKeywords);
const expectedContent = 'initial,keyword1,keyword2';
assert.strictEqual(layout.root.$('meta[name="keywords"]').getAttribute('content'), expectedContent, 'Existing keywords not updated correctly');
});
it('should not add duplicate keywords', () => {
layout.head.insert(2, new SingleNode('meta', { name: 'keywords', content: 'keyword1,keyword2' }));
const additionalKeywords = ['keyword2', 'keyword3'];
layout.keywords(additionalKeywords);
const expectedContent = 'keyword1,keyword2,keyword3';
assert.strictEqual(layout.root.$('meta[name="keywords"]').getAttribute('content'), expectedContent, 'Duplicate keywords were added');
});
it('should handle keywords with leading or trailing spaces', () => {
const messyKeywords = [' keyword1', 'keyword2 '];
layout.keywords(messyKeywords);
const expectedContent = 'keyword1,keyword2';
assert.strictEqual(layout.root.$('meta[name="keywords"]').getAttribute('content'), expectedContent, 'Keywords with spaces not trimmed correctly');
});
it('should add keywords correctly', () => {
const keywords = ['keyword1', 'keyword2'];
layout.keywords(keywords);
assert(layout.root.$('meta[name="keywords"]').getAttribute('content') === keywords.join(), 'Keywords not set correctly');
});
it('should handle empty keywords array', () => {
layout.keywords([]);
assert(!layout.root.$('meta[name="keywords"]'), 'Meta tag for empty keywords should not be created');
});
});