]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | describe("Ext.picker.Color", function() {\r |
2 | var colorPicker,\r | |
3 | createPicker = function(config) {\r | |
4 | colorPicker = new Ext.picker.Color(Ext.apply({\r | |
5 | renderTo: Ext.getBody()\r | |
6 | }, config));\r | |
7 | };\r | |
8 | \r | |
9 | beforeEach(function() {\r | |
10 | this.addMatchers({\r | |
11 | toHaveSelected: function(color) {\r | |
12 | var el = this.actual.el.down('a.color-' + color, true);\r | |
13 | return Ext.fly(el).hasCls(colorPicker.selectedCls);\r | |
14 | }\r | |
15 | });\r | |
16 | });\r | |
17 | \r | |
18 | afterEach(function() {\r | |
19 | if (colorPicker) {\r | |
20 | colorPicker.destroy();\r | |
21 | colorPicker = null;\r | |
22 | }\r | |
23 | });\r | |
24 | \r | |
25 | describe("initialisation", function() {\r | |
26 | beforeEach(function() {\r | |
27 | createPicker({\r | |
28 | value: "003300"\r | |
29 | });\r | |
30 | });\r | |
31 | \r | |
32 | it("should select the element corresponding to the initial value", function() {\r | |
33 | expect(colorPicker).toHaveSelected("003300");\r | |
34 | });\r | |
35 | \r | |
36 | it("should set the value", function() {\r | |
37 | expect(colorPicker.value).toBe("003300");\r | |
38 | });\r | |
39 | });\r | |
40 | \r | |
41 | describe("mouse click", function() {\r | |
42 | beforeEach(function() {\r | |
43 | var a, xy;\r | |
44 | createPicker();\r | |
45 | a = colorPicker.el.down('a.color-339966', true);\r | |
46 | xy = Ext.fly(a).getAnchorXY('c');\r | |
47 | \r | |
48 | jasmine.fireMouseEvent(a, "click", xy[0], xy[1]);\r | |
49 | });\r | |
50 | \r | |
51 | it("should select the element corresponding to the initial value", function() {\r | |
52 | expect(colorPicker).toHaveSelected("339966");\r | |
53 | });\r | |
54 | \r | |
55 | it("should set the value", function() {\r | |
56 | expect(colorPicker.value).toBe("339966");\r | |
57 | });\r | |
58 | });\r | |
59 | \r | |
60 | \r | |
61 | describe("select", function() {\r | |
62 | describe("when picker is rendered", function() {\r | |
63 | beforeEach(function() {\r | |
64 | createPicker();\r | |
65 | });\r | |
66 | \r | |
67 | it("should handle color with #", function() {\r | |
68 | colorPicker.select("#339966");\r | |
69 | \r | |
70 | expect(colorPicker).toHaveSelected("339966");\r | |
71 | expect(colorPicker.value).toBe("339966");\r | |
72 | });\r | |
73 | \r | |
74 | it("should handle color without #", function() {\r | |
75 | colorPicker.select("339966");\r | |
76 | \r | |
77 | expect(colorPicker).toHaveSelected("339966");\r | |
78 | expect(colorPicker.value).toBe("339966");\r | |
79 | });\r | |
80 | \r | |
81 | it("should be able to supress event", function() {\r | |
82 | spyOn(colorPicker, "fireEvent");\r | |
83 | colorPicker.select("#339966", true);\r | |
84 | \r | |
85 | expect(colorPicker.fireEvent).not.toHaveBeenCalled();\r | |
86 | });\r | |
87 | });\r | |
88 | \r | |
89 | describe("when picker isn't rendered", function() {\r | |
90 | beforeEach(function() {\r | |
91 | createPicker({\r | |
92 | renderTo: undefined\r | |
93 | });\r | |
94 | });\r | |
95 | \r | |
96 | it("should handle color with #", function() {\r | |
97 | colorPicker.select("#339966");\r | |
98 | \r | |
99 | expect(colorPicker.value).toBe("339966");\r | |
100 | });\r | |
101 | \r | |
102 | it("should handle color without #", function() {\r | |
103 | colorPicker.select("339966");\r | |
104 | \r | |
105 | expect(colorPicker.value).toBe("339966");\r | |
106 | });\r | |
107 | \r | |
108 | it("should be able to supress event", function() {\r | |
109 | spyOn(colorPicker, "fireEvent");\r | |
110 | colorPicker.select("#339966", true);\r | |
111 | \r | |
112 | expect(colorPicker.fireEvent).not.toHaveBeenCalled();\r | |
113 | });\r | |
114 | });\r | |
115 | });\r | |
116 | \r | |
117 | describe("getValue", function() {\r | |
118 | beforeEach(function() {\r | |
119 | createPicker();\r | |
120 | });\r | |
121 | \r | |
122 | it("should return the value if a value was selected", function() {\r | |
123 | colorPicker.select("339966");\r | |
124 | \r | |
125 | expect(colorPicker.getValue()).toBe("339966");\r | |
126 | });\r | |
127 | \r | |
128 | it("should return null if no value was selected", function() {\r | |
129 | expect(colorPicker.getValue()).toBeNull();\r | |
130 | });\r | |
131 | });\r | |
132 | \r | |
133 | }); |