shaman-website-compiler
Version:
Compile raw HTML, CSS and Javascript into the smallest possible, SEO friendly website.
95 lines • 4.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
require("mocha");
var chai_1 = require("chai");
var app_composition_1 = require("./composition/app.composition");
var models_1 = require("./models");
var compiler_context_spec_1 = require("./data/compiler.context.spec");
var dynamic_route_1 = require("./models/dynamic-route");
var website_router_1 = require("./website-router");
describe('WebsiteRouter', function () {
beforeEach(function () {
app_composition_1.IoC.snapshot();
app_composition_1.IoC.bind(app_composition_1.TYPES.WebsiteConfig).toConstantValue(new models_1.WebsiteConfig());
});
afterEach(function () {
app_composition_1.IoC.restore();
});
it('getAllRoutes should return sample.html route', function (done) {
(0, compiler_context_spec_1.CreateDataContext)(app_composition_1.IoC)
.then(addTestFileToContext)
.then(function (_) {
var router = new website_router_1.WebsiteRouter();
return router.getAllRoutes();
})
.then(function (routes) {
(0, chai_1.expect)(routes.findIndex(function (r) { return r.path == 'sample.html'; })).not.to.equal(-1);
done();
});
});
it('getAllRoutes should return bundle1.js route', function (done) {
(0, compiler_context_spec_1.CreateDataContext)(app_composition_1.IoC)
.then(addTestBundleToContext)
.then(function (_) {
var router = new website_router_1.WebsiteRouter();
return router.getAllRoutes();
})
.then(function (routes) {
(0, chai_1.expect)(routes.findIndex(function (r) { return r.path == 'bundle1.js'; })).not.to.equal(-1);
done();
});
});
it('getAllRoutes should return dynamic1.html route', function (done) {
(0, compiler_context_spec_1.CreateDataContext)(app_composition_1.IoC)
.then(addDynamicRouteToContext)
.then(function (_) {
var router = new website_router_1.WebsiteRouter();
return router.getAllRoutes();
})
.then(function (routes) {
(0, chai_1.expect)(routes.findIndex(function (r) { return r.path == 'dynamic1.html'; })).not.to.equal(-1);
done();
});
});
it('getAllRoutes should not create route for private.html file', function (done) {
(0, compiler_context_spec_1.CreateDataContext)(app_composition_1.IoC)
.then(addTestFileToContext)
.then(addPrivateFileToContext)
.then(function (_) {
var router = new website_router_1.WebsiteRouter();
return router.getAllRoutes();
})
.then(function (routes) {
(0, chai_1.expect)(routes.findIndex(function (r) { return r.path == 'private.html'; })).to.equal(-1);
done();
});
});
});
function addTestFileToContext(context) {
var file = new models_1.FileData('sample.html', './sample.html');
file.available = true;
file.model.shaman;
context.models.files.add('sample.html', file);
return context.saveChanges().then(function (_) { return (context); });
}
function addTestBundleToContext(context) {
var bundle = new models_1.Bundle({ name: 'bundle1', type: 'js', files: [], path: '' });
bundle.content = 'var $ = {}';
context.models.bundles.add('bundle1', bundle);
return context.saveChanges().then(function (_) { return (context); });
}
function addDynamicRouteToContext(context) {
var route = new dynamic_route_1.DynamicRoute();
route.path = 'dynamic1.html';
route.content = 'test content';
context.models.dynamicRoutes.add(route.path, route);
return context.saveChanges().then(function (_) { return (context); });
}
function addPrivateFileToContext(context) {
var file = new models_1.FileData('private.html', './private.html');
file.available = true;
file.model.shaman = { private: true };
context.models.files.add('private.html', file);
return context.saveChanges().then(function (_) { return (context); });
}
//# sourceMappingURL=website-router.spec.js.map