File size: 2,586 Bytes
5893f8f | 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 | 'use strict';
const assert = require('assert').strict;
const { files } = require('../config');
const helpers = require('./test_helpers');
function format(str, name) {
return str.replace('SWATCH_NAME', name)
.replace('SWATCH_VERSION', files.bootswatch4.version);
}
describe('bootswatch4', () => {
const uri = helpers.getURI('bootswatch');
let response = {};
before((done) => {
helpers.prefetch(uri, (res) => {
response = res;
done();
});
});
it('works', (done) => {
helpers.assert.itWorks(response.statusCode, done);
});
it('valid html', (done) => {
helpers.assert.validHTML(response)
.then(() => done());
});
it('contains canonical URL', (done) => {
helpers.assert.canonicalUrl('/bootswatch/', response, done);
});
it.skip('contains authors', (done) => {
helpers.assert.authors(response, done);
});
it('has page header', (done) => {
helpers.assert.pageHeader('Bootswatch 4', response, done);
});
it('has body class', (done) => {
helpers.assert.bodyClass('page-bootswatch', response, done);
});
const invalidQueries = [
-1,
500,
'123abc',
'5',
'foobar'
];
invalidQueries.forEach((query) => {
it(`handles invalid theme query parameter (${query})`, (done) => {
const invalidUri = helpers.getURI(`bootswatch/?theme=${query}`);
let invalidResponse = {};
helpers.prefetch(invalidUri, (res) => {
invalidResponse = res;
helpers.assert.itWorks(invalidResponse.statusCode, done);
});
});
});
files.bootswatch4.themes.forEach((theme) => {
describe(theme.name, () => {
const themeImage = format(files.bootswatch4.image, theme.name);
const themeUri = format(files.bootswatch4.bootstrap, theme.name);
const themeSri = theme.sri;
it('has image', (done) => {
assert.ok(response.body.includes(themeImage),
`Expects response body to include "${themeImage}"`);
done();
});
['html', 'pug', 'haml'].forEach((fmt) => {
it(`has ${fmt}`, (done) => {
const str = helpers.css[fmt](themeUri, themeSri);
assert.ok(response.body.includes(str), `Expects response body to include "${str}"`);
done();
});
});
});
});
});
|