Commit ded59ab8 authored by Robert Knight's avatar Robert Knight

Add tests for settings function's `settingsClass` parameter

parent cb5246e5
......@@ -64,7 +64,7 @@ describe('annotator configuration', function () {
});
});
it('merges the config from the "hypothesis-config" meta tag', function () {
it('merges the config from the "js-hypothesis-config" <script> tag', function () {
fakeScriptConfig = '{"annotations":"456"}';
assert.deepEqual(config(fakeWindowBase), {
app: 'app.html',
......
'use strict';
var settings = require('../settings');
function createJSONScriptTag(obj) {
function createJSONScriptTag(obj, className) {
var el = document.createElement('script');
el.type = 'application/json';
el.textContent = JSON.stringify(obj);
el.classList.add('js-hypothesis-settings');
el.classList.add(className);
el.classList.add('js-settings-test');
return el;
}
function removeJSONScriptTags() {
var elements = document.querySelectorAll('.js-settings-test');
for (var i=0; i < elements.length; i++) {
elements[i].parentNode.removeChild(elements[i]);
}
}
describe('settings', function () {
afterEach(function () {
var elements = document.querySelectorAll('.js-hypothesis-settings');
for (var i=0; i < elements.length; i++) {
elements[i].parentNode.removeChild(elements[i]);
}
afterEach(removeJSONScriptTags);
it('reads config from .js-hypothesis-settings <script> tags', function () {
document.body.appendChild(createJSONScriptTag({key:'value'},
'js-hypothesis-settings'));
assert.deepEqual(settings(document), {key:'value'});
});
it('reads config from <script> tags with the specified class name', function () {
document.body.appendChild(createJSONScriptTag({foo:'bar'},
'js-custom-settings'));
assert.deepEqual(settings(document), {});
assert.deepEqual(settings(document, 'js-custom-settings'), {foo:'bar'});
});
it('should merge settings', function () {
document.body.appendChild(createJSONScriptTag({ a: 1 }));
document.body.appendChild(createJSONScriptTag({ b: 2 }));
assert.deepEqual(settings(document), { a: 1, b: 2 });
it('merges settings from all config <script> tags', function () {
document.body.appendChild(createJSONScriptTag({a: 1}, 'settings'));
document.body.appendChild(createJSONScriptTag({b: 2}, 'settings'));
assert.deepEqual(settings(document, 'settings'), {a: 1, b: 2});
});
});
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