59 lines
2.4 KiB
JavaScript
59 lines
2.4 KiB
JavaScript
// Generated, do not edit. sha256:a7ea6b1b573eee126d96f50fe1a254b6a09a05cea53026a6d40a986ee55bbb21
|
|
import { describe, it } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
|
|
const { emptyStateHtml } = await import('../../client/ui/empty-state.js');
|
|
|
|
describe('emptyStateHtml: the three parts', () => {
|
|
it('renders the bare form as one line, without a frame or an icon', () => {
|
|
const html = emptyStateHtml('Nog geen trades.');
|
|
assert.equal(html, '<div class="empty-state">Nog geen trades.</div>');
|
|
assert.doesNotMatch(html, /alert|icon|svg/);
|
|
});
|
|
|
|
it('puts the reason behind the message, muted', () => {
|
|
const html = emptyStateHtml('Nog geen trades.', { why: 'Voeg eerst een asset toe.' });
|
|
assert.match(html, /Nog geen trades\. <span class="empty-state-why">Voeg eerst een asset toe\.<\/span>/);
|
|
});
|
|
|
|
it('adds the link last, so you read what is missing before where to fix it', () => {
|
|
const html = emptyStateHtml('Nog geen trades.', { href: '#/system/assets', linkText: 'Assets beheren' });
|
|
assert.match(html, /Nog geen trades\. <a href="#\/system\/assets">Assets beheren<\/a><\/div>$/);
|
|
});
|
|
});
|
|
|
|
describe('emptyStateHtml: what is left out leaves nothing behind', () => {
|
|
it('writes no span when there is no reason', () => {
|
|
assert.doesNotMatch(emptyStateHtml('Leeg.'), /span/);
|
|
});
|
|
|
|
it('writes no anchor when only one half of the link is given', () => {
|
|
assert.doesNotMatch(emptyStateHtml('Leeg.', { href: '#/x' }), /<a /);
|
|
assert.doesNotMatch(emptyStateHtml('Leeg.', { linkText: 'Ga' }), /<a /);
|
|
});
|
|
|
|
it('survives being called with no options at all', () => {
|
|
assert.equal(emptyStateHtml('Leeg.'), '<div class="empty-state">Leeg.</div>');
|
|
});
|
|
});
|
|
|
|
describe('emptyStateHtml: everything is text', () => {
|
|
it('escapes the message', () => {
|
|
assert.doesNotMatch(emptyStateHtml('<img src=x onerror=alert(1)>'), /<img/);
|
|
});
|
|
|
|
it('escapes the reason', () => {
|
|
assert.doesNotMatch(emptyStateHtml('x', { why: '<script>alert(1)</script>' }), /<script/);
|
|
});
|
|
|
|
it('escapes the link text', () => {
|
|
assert.doesNotMatch(emptyStateHtml('x', { href: '#/a', linkText: '<b>go</b>' }), /<b>/);
|
|
});
|
|
|
|
it('escapes the href, quote included', () => {
|
|
const html = emptyStateHtml('x', { href: '#/a" onmouseover="alert(1)', linkText: 'go' });
|
|
assert.doesNotMatch(html, /onmouseover="/);
|
|
assert.match(html, /"/);
|
|
});
|
|
});
|