-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspec.js
More file actions
executable file
·87 lines (64 loc) · 3.18 KB
/
spec.js
File metadata and controls
executable file
·87 lines (64 loc) · 3.18 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
describe("neatList", function() {
var $example = $(
"<select multiple='true' size='5'>" +
"<option value='1'>First</option>" +
"<option value='2' selected>Second</option>" +
"<option value='3'>Third</option>" +
"<option value='4' selected>Forth</option>" +
"</select>");
var $original = null
beforeEach(function() {
$("#scratchPad").children().remove().end()
.append($example.clone());
$original = $("#scratchPad select");
});
it("it should hide the original list", function() {
var $list = $original.neatList();
expect($original.filter(":hidden").length).toEqual(1);
});
it("it should copy the original list and remove the size/multiple attributes", function() {
var $list = $original.neatList();
expect($list.filter($original).length).toEqual(0);
expect($original.attr("size")).toNotEqual(null);
expect($list.attr("size")).toEqual(null);
expect($list.attr("multiple")).toEqual(null);
});
it("should use the default caption and it should be selected", function() {
var $list = $original.neatList();
expect($list.find("option:selected").text()).toEqual("(select to add)");
});
it("should add an item to the selected list when selected from the drop down", function() {
var $list = $original.neatList();
$list.children("[value=3]").prop("selected", true);
$list.trigger("change");
var $selected = $list.siblings("ul");
expect($selected.children("[data-value=3]").length).toEqual(1);
});
it("should mark the backing original list item to selected when selected from the drop down", function() {
var $list = $original.neatList();
$list.children("[value=3]").prop("selected", true);
$list.trigger("change");
expect($original.children("[value=3]").prop("selected")).toEqual(true);
});
it("should not add an item if the item is already selected", function() {
var $list = $original.neatList();
var $selected = $list.siblings("ul");
expect($selected.children("[data-value=2]").length).toEqual(1);
$list.children("[value=2]").prop("selected", true);
$list.trigger("change");
expect($selected.children("[data-value=2]").length).toEqual(1);
});
it("should mark the backing original list item as not selected with the delete button is clicked", function() {
var $list = $original.neatList();
var $listItem = $list.siblings("ul").children("li[data-value=2]");
$listItem.find("input").trigger("click");
expect($original.children("[value=2]").prop("selected")).toEqual(false);
});
it("should remove the item from the selected list when the delete button is clicked", function() {
var $list = $original.neatList();
var $selected = $list.siblings("ul")
var $listItem = $selected.children("li[data-value=2]");
$listItem.find("input").trigger("click");
expect($selected.children("li[data-value=2]").length).toEqual(0);
});
});