Refactor simple JS to be main JS tests

[MAILPOET-2455]
This commit is contained in:
Rostislav Wolny
2019-11-27 11:06:41 +01:00
committed by Jack Kitterhing
parent a6dfab1178
commit 6015a1370d
30 changed files with 29 additions and 16 deletions

View File

@@ -0,0 +1,27 @@
var fs = require('fs');
module.exports = {
loadFileToContainer: function (path, window, containerTagName, opts) {
var contents = fs.readFileSync(path);
var container = window.document.createElement(containerTagName);
var options = opts || {};
container.innerHTML = contents;
if (options.type) {
container.type = options.type;
}
if (options.id) {
container.id = options.id;
}
global.window.document.body.appendChild(container);
},
loadScript: function (scriptPath, window, options) {
this.loadFileToContainer(scriptPath, window, 'script', options);
},
loadTemplate: function (path, window, opts) {
var w = window || global.window;
var options = opts || {};
options.type = 'text/x-handlebars-template';
this.loadScript('views/newsletter/templates/' + path, w, options);
},
};