2023-02-12 14:26:18 -05:00
|
|
|
import template from '../src/middlewares/web/utils/template';
|
2021-10-29 10:33:05 -05:00
|
|
|
|
2021-03-06 12:56:45 -05:00
|
|
|
const manifest = require('./partials/manifest/manifest.json');
|
|
|
|
|
2024-07-30 16:20:18 -05:00
|
|
|
// manifest expected to have leading slash
|
|
|
|
// see packages\middleware\test\partials\manifest\manifest.json
|
2021-03-06 12:56:45 -05:00
|
|
|
const exampleManifest = {
|
|
|
|
css: ['main.css'],
|
|
|
|
js: ['runtime.js', 'main.js'],
|
2024-07-30 16:20:18 -05:00
|
|
|
ico: 'favicon.ico',
|
2021-03-06 12:56:45 -05:00
|
|
|
};
|
|
|
|
|
2024-07-30 16:20:18 -05:00
|
|
|
// "base" is expected to be result of getPublicUrl
|
|
|
|
// i.e. it must be valid URL with trailing slash
|
2021-03-06 12:56:45 -05:00
|
|
|
describe('template', () => {
|
|
|
|
test('custom render', () => {
|
2021-04-02 08:59:47 -05:00
|
|
|
expect(
|
2024-07-30 16:20:18 -05:00
|
|
|
template({ options: { base: 'http://domain.com/' }, manifest: exampleManifest }, manifest)
|
2021-04-02 08:59:47 -05:00
|
|
|
).toMatchSnapshot();
|
2021-03-06 12:56:45 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test('custom title', () => {
|
|
|
|
expect(
|
2021-04-02 08:59:47 -05:00
|
|
|
template(
|
2024-07-30 16:20:18 -05:00
|
|
|
{ options: { base: 'http://domain.com/', title: 'foo title' }, manifest: exampleManifest },
|
2021-04-02 08:59:47 -05:00
|
|
|
manifest
|
|
|
|
)
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('meta scripts', () => {
|
|
|
|
expect(
|
|
|
|
template(
|
|
|
|
{
|
2024-07-30 16:20:18 -05:00
|
|
|
options: { base: 'http://domain.com/' },
|
2021-04-02 08:59:47 -05:00
|
|
|
metaScripts: [`<style>.someclass{font-size:10px;}</style>`],
|
|
|
|
manifest: exampleManifest,
|
|
|
|
},
|
|
|
|
manifest
|
|
|
|
)
|
2021-03-06 12:56:45 -05:00
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('custom body after', () => {
|
|
|
|
expect(
|
2021-04-02 08:59:47 -05:00
|
|
|
template(
|
|
|
|
{
|
2024-07-30 16:20:18 -05:00
|
|
|
options: { base: 'http://domain.com/' },
|
2021-04-02 08:59:47 -05:00
|
|
|
scriptsBodyAfter: [`<script src="foo"/>`],
|
|
|
|
manifest: exampleManifest,
|
|
|
|
},
|
|
|
|
manifest
|
|
|
|
)
|
2021-03-06 12:56:45 -05:00
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('custom body before', () => {
|
|
|
|
expect(
|
|
|
|
template(
|
|
|
|
{
|
2024-07-30 16:20:18 -05:00
|
|
|
options: { base: 'http://domain.com/' },
|
2021-04-02 08:59:47 -05:00
|
|
|
scriptsbodyBefore: [`<script src="fooBefore"/>`, `<script src="barBefore"/>`],
|
2021-03-06 12:56:45 -05:00
|
|
|
manifest: exampleManifest,
|
|
|
|
},
|
|
|
|
manifest
|
|
|
|
)
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|