]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | describe("Ext.util.Point", function() {\r |
2 | var Point = Ext.util.Point,\r | |
3 | point;\r | |
4 | \r | |
5 | describe("constructor()", function() {\r | |
6 | it("should instantiate with x=0 and y=0 if not provided", function() {\r | |
7 | point = new Point();\r | |
8 | expect(point.x).toBe(0);\r | |
9 | expect(point.y).toBe(0);\r | |
10 | });\r | |
11 | \r | |
12 | it("should instantiate with the provided x and y", function() {\r | |
13 | point = new Point(100, 200);\r | |
14 | expect(point.x).toBe(100);\r | |
15 | expect(point.y).toBe(200);\r | |
16 | });\r | |
17 | });\r | |
18 | \r | |
19 | describe("members", function() {\r | |
20 | beforeEach(function() {\r | |
21 | point = new Point(100, 200);\r | |
22 | });\r | |
23 | \r | |
24 | describe("copy()", function() {\r | |
25 | it("should create a new instance with the same x and y values", function() {\r | |
26 | var newPoint = point.copy();\r | |
27 | \r | |
28 | expect(newPoint).not.toBe(point);\r | |
29 | expect(newPoint.x).toEqual(point.x);\r | |
30 | expect(newPoint.y).toEqual(point.y);\r | |
31 | });\r | |
32 | });\r | |
33 | \r | |
34 | describe("copyFrom()", function() {\r | |
35 | it("should copy x and y value to the current instance", function() {\r | |
36 | point.copyFrom({\r | |
37 | x: 300,\r | |
38 | y: 400\r | |
39 | });\r | |
40 | \r | |
41 | expect(point.x).toBe(300);\r | |
42 | expect(point.y).toBe(400);\r | |
43 | });\r | |
44 | });\r | |
45 | \r | |
46 | describe("equal()", function() {\r | |
47 | it("should return true if both x and y values are the same", function() {\r | |
48 | expect(point.equals({\r | |
49 | x: 100,\r | |
50 | y: 200\r | |
51 | })).toBe(true);\r | |
52 | });\r | |
53 | \r | |
54 | it("should return false otherwise", function() {\r | |
55 | expect(point.equals({\r | |
56 | x: 101,\r | |
57 | y: 200\r | |
58 | })).toBe(false);\r | |
59 | \r | |
60 | expect(point.equals({\r | |
61 | x: 100,\r | |
62 | y: 200.1\r | |
63 | })).toBe(false);\r | |
64 | });\r | |
65 | });\r | |
66 | \r | |
67 | describe("isWithin()", function() {\r | |
68 | it("should return true if point.x=108, point.y=194 and threshold=10", function() {\r | |
69 | expect(point.isWithin({\r | |
70 | x: 108,\r | |
71 | y: 194\r | |
72 | }, 10)).toBe(true);\r | |
73 | });\r | |
74 | \r | |
75 | it("should return false if point.x=108.1, point.y=194 and threshold=10", function() {\r | |
76 | expect(point.isWithin({\r | |
77 | x: 108.1,\r | |
78 | y: 194\r | |
79 | }, 10)).toBe(false);\r | |
80 | });\r | |
81 | });\r | |
82 | \r | |
83 | describe("translate()", function() {\r | |
84 | it("should translate x and y by the given amounts", function() {\r | |
85 | point.translate(10, -20);\r | |
86 | expect(point.x).toBe(110);\r | |
87 | expect(point.y).toBe(180);\r | |
88 | });\r | |
89 | });\r | |
90 | \r | |
91 | describe("roundedEquals()", function() {\r | |
92 | it("should return true if point.x=100.3 and point.y=199.7", function() {\r | |
93 | var compare = {\r | |
94 | x: 100.3,\r | |
95 | y: 199.7\r | |
96 | };\r | |
97 | \r | |
98 | expect(point.roundedEquals(compare)).toBe(true);\r | |
99 | });\r | |
100 | \r | |
101 | it("should return true if point.x=100.6 and point.y=199.7", function() {\r | |
102 | var compare = {\r | |
103 | x: 100.6,\r | |
104 | y: 199.7\r | |
105 | };\r | |
106 | \r | |
107 | expect(point.roundedEquals(compare)).toBe(false);\r | |
108 | });\r | |
109 | });\r | |
110 | });\r | |
111 | \r | |
112 | });\r |