Commit 2515867b authored by Ryan Herbert's avatar Ryan Herbert

tokeniser_test.js adapt tests to refactored class

parent 26751dfc
......@@ -2,37 +2,35 @@ QUnit.module("Tokeniser", {
});
QUnit.test("tokeniser", function(assert) {
var tokeniser = new Tokeniser();
var mock_div = document.createElement('div');
mock_div.id = "mock_div"
var mock_target = document.createElement('input');
var tokeniser = new Tokeniser(mock_div, mock_target);
var mock_input = document.createElement('input');
mock_input.value = "foobar";
$(mock_input).data('set-id', ":p foobar");
var token_value = ":p foobar"
var token = tokeniser.createToken($(mock_input));
var token = tokeniser.createToken(token_value);
assert.equal(token.innerText, "foobar", "check whether the token text is correct");
var mock_div = document.createElement('div');
var mock_target = document.createElement('input');
tokeniser.tokenise(mock_input, mock_div, mock_target);
assert.equal(mock_input.value, "", "check that input value is reset");
assert.equal($(mock_input).data('set-id'), undefined, "check that input data set-id is reset");
tokeniser.tokenise(token_value);
assert.equal(mock_target.value, token_value, "check whether input field is populated");
var token_span = $(mock_div).find('span');
assert.equal(token_span.length, 1, 'check whether the token span was created properly');
var mock_div_2 = document.createElement('div');
var mock_span;
for(var i = 0; i < 2; i++) {
mock_span = document.createElement('span');
mock_span.className = 'set_token';
mock_span.innerText = i;
$(mock_span).data('set-id', i);
mock_div_2.appendChild(mock_span);
mock_div.appendChild(mock_span);
}
var wrong_span = document.createElement('span');
$(wrong_span).data('set-id', 'barfoo');
mock_div_2.appendChild(wrong_span);
mock_div.appendChild(wrong_span);
var read = tokeniser.readTokens(mock_div_2);
assert.equal(read, "0,1", "check whether the token spans are read correctly");
var read = tokeniser.readTokens();
assert.equal(read, ":p foobar,0,1", "check whether the token spans are read correctly");
});
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