UNPKG

shaman-website-compiler

Version:

Compile raw HTML, CSS and Javascript into the smallest possible, SEO friendly website.

62 lines 3.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); require("mocha"); var sinon = require("sinon"); var chai_1 = require("chai"); var app_composition_1 = require("../composition/app.composition"); var models_1 = require("../models"); var ts_auto_mock_1 = require("ts-auto-mock"); var add_text_handler_1 = require("./add-text.handler"); var compiler_context_spec_1 = require("../data/compiler.context.spec"); describe('AddTextHandler', function () { var sandbox; var eventService; var logger; var fileImportService; beforeEach(function () { app_composition_1.IoC.snapshot(); sandbox = sinon.createSandbox(); eventService = (0, ts_auto_mock_1.createMock)(); logger = (0, ts_auto_mock_1.createMock)(); fileImportService = (0, ts_auto_mock_1.createMock)(); app_composition_1.IoC.bind(app_composition_1.TYPES.WebsiteConfig).toConstantValue(new models_1.WebsiteConfig()); app_composition_1.IoC.bind(app_composition_1.TYPES.CompilerEvents).toConstantValue(eventService); app_composition_1.IoC.bind(app_composition_1.TYPES.Logger).toConstantValue(logger); app_composition_1.IoC.bind(app_composition_1.TYPES.FileImportService).toConstantValue(fileImportService); }); afterEach(function () { app_composition_1.IoC.restore(); sandbox.restore(); }); it('processEvent should update content in database', function (done) { (0, compiler_context_spec_1.CreateDataContext)(app_composition_1.IoC).then(addTestFileToContext).then(function (context) { var fileImportResult = Promise.resolve({ text: 'content' }); fileImportService.importFileText = sandbox.stub().returns(fileImportResult); var subject = new add_text_handler_1.AddTextHandler(); subject.processEvent(new models_1.FileData("sample.html", "./sample.html")).then(function (_) { var file = context.models.files.find('sample.html'); (0, chai_1.expect)(file.text).to.equal('content'); done(); }); }); }); it('processEvent should call raise "file-contents-added" event', function (done) { (0, compiler_context_spec_1.CreateDataContext)(app_composition_1.IoC).then(addTestFileToContext).then(function (_) { var fileImportResult = Promise.resolve({ text: 'content' }); fileImportService.importFileText = sandbox.stub().returns(fileImportResult); var stub = eventService.publish = sandbox.stub(); var subject = new add_text_handler_1.AddTextHandler(); subject.processEvent(new models_1.FileData("sample.html", "./sample.html")).then(function (_) { (0, chai_1.expect)(stub.getCall(0).args[0]).to.equal('file-contents-added'); done(); }); }); }); }); function addTestFileToContext(context) { var file = new models_1.FileData('sample.html', './sample.html'); file.available = true; context.models.files.add('sample.html', file); return context.saveChanges().then(function (_) { return (context); }); } //# sourceMappingURL=add-text.handler.spec.js.map