Skip to content
This repository was archived by the owner on Jan 1, 2020. It is now read-only.

Commit 5385397

Browse files
committedJun 6, 2016
Add tests for callback data, closes #10
1 parent 4351c1e commit 5385397

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
 

‎tests.html

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<input type="text" class="test3 tag-input" name="test-input-2" id="test-input-2" placeholder="Enter tags" value="cat|dog|catfish|fish">
1414
<input type="text" class="tag-input test4" name="test-input-3" id="test-input-3" placeholder="Enter tags" value="">
1515
<input type="text" name="test-input-4" id="test-input-4" value="">
16+
<input type="text" name="test-input-5" id="test-input-5" value="cat|dog">
1617
</form>
1718
</div>
1819
<script type="text/javascript" src="lib/js/jquery-1.11.1.min.js"></script>

‎tests.js

+35
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,41 @@ test('inherits placeholder attribute', function() {
2121
equal(placeholder3, 'Enter tags', 'test input 3 placeholder attribute equals "Enter tags"');
2222
});
2323

24+
test('add callback', function() {
25+
var result = {};
26+
$('#test-input-4').tagInput({
27+
onTagDataChanged: function(added, removed) {
28+
result.value = this.val() || null;
29+
result.added = added;
30+
result.removed = removed;
31+
}
32+
});
33+
var tagInput = $('#test-input-4').parent().find('.mab-jquery-taginput-input').first();
34+
tagInput.val('test');
35+
// Simulate hitting ENTER
36+
tagInput.trigger(jQuery.Event('keydown', { which: 13, keyCode: 13 }));
37+
equal(result.value, 'test', 'test input 4 has value \'test\'');
38+
equal(result.added, 'test', 'added callback parameter is \'test\'');
39+
equal(result.removed, null, 'removed callback parameter is null');
40+
});
41+
42+
test('remove callback', function() {
43+
var result = {};
44+
$('#test-input-5').tagInput({
45+
onTagDataChanged: function(added, removed) {
46+
result.value = this.val() || null;
47+
result.added = added;
48+
result.removed = removed;
49+
}
50+
});
51+
var tagInput = $('#test-input-5').parent().find('.mab-jquery-taginput-input').first();
52+
// Simulate hitting BACKSPACE
53+
tagInput.trigger(jQuery.Event('keydown', { which: 8, keyCode: 8 }));
54+
equal(result.value, 'cat', 'test input 5 has value \'cat\'');
55+
equal(result.added, null, 'added callback parameter is null');
56+
equal(result.removed, 'dog', 'removed callback parameter is \'dog\'');
57+
});
58+
2459
QUnit.done(function() {
2560
// alert('test');
2661
});

0 commit comments

Comments
 (0)
This repository has been archived.