Commit d026bccf authored by Nick Stenning's avatar Nick Stenning

Use a self-contained template to test CreateGroupFormController

Pulling the server-side template and rendering it with swig is bound to
break if we change the way the form is rendered on the server-side (as I
am in the process of doing).

So, convert this from a sort-of-integrated test to a unit test.
parent 2863e008
var fetch = require('isomorphic-fetch');
var swig = require('swig');
"use strict";
var CreateGroupFormController = require('../create-group-form');
......@@ -16,41 +15,20 @@ function sendEvent(element, eventType) {
element.dispatchEvent(event);
}
// fetch the text for Karma resource which matches the given regex.
// The resource must have been included in the list of files for the test
// specified in the karma.config.js file
function fetchTemplate(pathRegex) {
var templateUrl = Object.keys(window.__karma__.files).filter(function (path) {
return path.match(pathRegex);
})[0];
return fetch(templateUrl).then(function (response) {
return response.text();
});
}
describe('CreateGroupFormController', function () {
var element;
var template;
before(function () {
return fetchTemplate(/create\.html\.jinja2$/).then(function (text) {
// extract the 'content' block from the template
var contentBlock = text.match(/{% block content %}([^]*){% endblock content %}/)[1];
template = swig.compile(contentBlock);
});
template = '<input type="text" class="js-group-name-input">' +
'<input type="submit" class="js-create-group-create-btn">' +
'<a href="" class="js-group-info-link">Tell me more!</a>' +
'<div class="js-group-info-text is-hidden">More!</div>';
});
beforeEach(function () {
var context = {
form: {
csrf_token: {
render: function() {}
},
name: ''
}
};
element = document.createElement('div');
element.innerHTML = template(context);
element.innerHTML = template;
});
it('should enable submission if form is valid', function () {
......
......@@ -35,7 +35,6 @@
"extend": "^2.0.0",
"frame-rpc": "^1.3.1",
"hammerjs": "^2.0.4",
"isomorphic-fetch": "^2.1.1",
"jquery": "1.11.1",
"js-polyfills": "^0.1.11",
"moment": "^2.10.6",
......@@ -65,8 +64,7 @@
"proxyquire": "^1.6.0",
"proxyquire-universal": "^1.0.8",
"proxyquireify": "^3.0.0",
"sinon": "1.16.1",
"swig": "^1.4.2"
"sinon": "1.16.1"
},
"engines": {
"node": "0.10.x"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment