-
Notifications
You must be signed in to change notification settings - Fork 67
/
methods.js
119 lines (96 loc) · 4.55 KB
/
methods.js
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
// ==========================================================================
// Project: SproutCore - JavaScript Application Framework
// Copyright: ©2006-2009 Sprout Systems, Inc. and contributors.
// portions copyright @2009 Apple Inc.
// License: Licensed under MIT license (see license.js)
// ==========================================================================
/*global module test htmlbody ok equals same stop start */
var iconURL= "http://www.freeiconsweb.com/Icons/16x16_people_icons/People_046.gif";
var pane, view, elem, rect1, rect2, rect3;
module("SC.SegmentedView", {
setup: function() {
SC.RunLoop.begin();
pane = SC.MainPane.create({
childViews: [
SC.SegmentedView.extend({
items: [
{ value: "Item1", icon: iconURL },
{ value: "Item2", icon: iconURL },
{ value: "Item3", icon: iconURL }],
itemTitleKey: 'value',
itemValueKey: 'value',
itemIconKey: 'icon',
value: "Item1 Item3".w(),
allowsEmptySelection: NO,
layout: { height: 25 }
})]
});
pane.append(); // make sure there is a layer...
SC.RunLoop.end();
view = pane.childViews[0];
elem = view.get('layer').childNodes[0];
rect1 = elem.getBoundingClientRect();
elem = view.get('layer').childNodes[1];
rect2 = elem.getBoundingClientRect();
elem = view.get('layer').childNodes[2];
rect3 = elem.getBoundingClientRect();
},
teardown: function() {
pane.remove();
pane = view = elem = rect1 = rect2 = rect3 = null ;
}
});
test("Check that properties are mapped correctly", function() {
view.triggerItemAtIndex(1);
SC.RunLoop.begin();
view.set('isEnabled', YES);
SC.RunLoop.end();
equals(view.get('value'), "Item2", "the second item should be selected.");
var items=view.displayItems();
equals(items[0][0], "Item1", 'Computed properties should match');
equals(items[0][1], "Item1", 'Computed properties should match');
equals(items[0][2], true, 'Computed properties should match');
equals(items[0][3], iconURL, 'Computed properties should match');
equals(items[0][4], null, 'Computed properties should match');
equals(items[0][5], null, 'Computed properties should match');
equals(items[0][6], 0, 'Computed properties should match');
var firstItemEvent = SC.Event.simulateEvent(elem, 'mousedown', { pageX: rect1.left + 1, pageY: rect1.top + 1 });
view.mouseDown(firstItemEvent);
equals(view._isMouseDown, YES, 'mousedown');
equals(view.get('activeIndex'), 0, '');
});
test("Check that mouse actions work", function() {
view.triggerItemAtIndex(1);
SC.RunLoop.begin();
view.set('isEnabled', YES);
SC.RunLoop.end();
// Test Mouse Down
// it now gets the item by the position, so we have to pass a position
var firstItemEvent = SC.Event.simulateEvent(elem, 'mousedown', { pageX: rect1.left + 1, pageY: rect1.top + 1 });
view.mouseDown(firstItemEvent);
equals(view._isMouseDown, YES, 'Mouse down flag on mousedown should be ');
equals(view.get('activeIndex'), 0, 'The active item is the first segment.');
// Test Mouse Up
elem = view.get('layer').childNodes[1];
view.mouseUp(firstItemEvent);
equals(view._isMouseDown, NO, 'Mouse down flag on mouseup should be ');
equals(view.get('activeIndex'), -1, 'There shouldnt be any active item');
// Test third item
elem = view.get('layer').childNodes[2];
var thirdItemEvent = SC.Event.simulateEvent(elem, 'mousedown', { pageX: rect3.left + 1, pageY: rect3.top + 1 });
// mouse down and move
view.mouseDown(thirdItemEvent);
view.mouseMoved(thirdItemEvent);
equals(view._isMouseDown, YES, 'Mouse down flag on mousemoved should be ');
equals(view.get('activeIndex'), 2, 'The active item is the third segment.');
// try moving mouse while mouse down
var secondItemEvent = SC.Event.simulateEvent(elem, 'mousedown', { pageX: rect2.left + 1, pageY: rect2.top + 1 });
view.mouseMoved(secondItemEvent);
equals(view._isMouseDown, YES, 'Mouse down flag on mousemoved should be ');
equals(view.get('activeIndex'), 1, 'The active item should have changed to the second segment.');
// and check that mouse out cancels.
var noItemEvent = SC.Event.simulateEvent(elem, 'mousedown', { pageX: rect1.left - 5, pageY: rect1.top - 5 });
view.mouseExited(noItemEvent);
equals(view._isMouseDown, YES, 'Mouse down flag on mouseout should still be ');
equals(view.get('activeIndex'), -1, 'The active item is no longer specified.');
});