Repository navigation
Expand file tree
/
Copy pathplugin.js
More file actions
122 lines (78 loc) · 2.92 KB
/
Copy pathplugin.js
File metadata and controls
122 lines (78 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* Tests EasyAutocomplete - plugin
*
* @author Łukasz Pawełczak
*/
QUnit.test( "JQuery method exists", function( assert ) {
//assert
assert.ok($.fn.easyAutocomplete, "Method $.easyAutocomplete exists");
assert.ok($.fn.getSelectedItemIndex, "Method $.getSelectedItemIndex exists");
assert.ok($.fn.getItemData, "Method $.getItemData exists");
assert.ok($.fn.getSelectedItemData, "Method $.getSelectedItemData exists");
expect(4);
});
QUnit.test("Input field has no id property", function( assert ) {
//given
$(".inputOne").attr("id", "");
var completerOne = $(".inputOne").easyAutocomplete({
data: ["black", "white", "magenta", "yellow"],
});
//execute
var e = $.Event('keyup');
e.keyCode = 50;
$(".inputOne").val("a").trigger(e);
//assert
var elements = $(".inputOne").next().find("ul li");
assert.equal(4, elements.length, "Response size");
assert.equal("black", elements.eq(0).text(), "First element is 'black'");
assert.equal("white", elements.eq(1).text(), "Second element is 'white'");
assert.equal("magenta", elements.eq(2).text(), "Third element is 'magenta'");
assert.equal("yellow", elements.eq(3).text(), "Fourth element is 'yellow'");
assert.ok($(".inputOne").attr("id").length > 0, "id is defined");
expect(6);
});
QUnit.test("Invoke plugin function on input that is dynamically added", function( assert ) {
//given
//create text field
var $dynamicInput = $("<input type='text' />").attr("id", "inputThree");
$(".inputOne").after($dynamicInput);
var completerOne = $("#inputThree").easyAutocomplete({
data: ["black", "white", "magenta", "yellow"],
});
//execute
var e = $.Event('keyup');
e.keyCode = 50;
$("#inputThree").val("more").trigger(e);
//assert
var elements = $("#inputThree").next().find("ul li");
assert.equal(4, elements.length, "Response size");
assert.equal("black", elements.eq(0).text(), "First element is 'black'");
assert.equal("white", elements.eq(1).text(), "Second element is 'white'");
assert.equal("magenta", elements.eq(2).text(), "Third element is 'magenta'");
assert.equal("yellow", elements.eq(3).text(), "Fourth element is 'yellow'");
expect(5);
});
QUnit.test(".easyAutocomplete function should return jQuery object", function( assert ) {
//given
$("#inputThree").attr("justice", "");
//execute
var completerOne = $("#inputThree").easyAutocomplete({
data: ["black", "white", "magenta", "yellow"],
list: {
match: {
enabled: true
}
}
})
.attr("justice", "beaver");
var e = $.Event('keyup');
e.keyCode = 50;
$("#inputThree").val("a").trigger(e);
//assert
var elements = $("#inputThree").next().find("ul li");
assert.equal("beaver", $("#inputThree").attr("justice"), "Setted attribute.");
assert.equal(2, elements.length, "Response size");
assert.equal("black", elements.eq(0).text(), "First element is 'black'");
assert.equal("magenta", elements.eq(1).text(), "Second element is 'magenta'");
expect(4);
});