]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | describe("Ext.plugin.PullRefresh", function() {\r |
2 | var store, proxy, list, plugin, model, supportsTouch, supportsTouchScroll;\r | |
3 | \r | |
4 | beforeEach(function() {\r | |
5 | // make sure we are testing "touch" scrolling\r | |
6 | supportsTouch = Ext.supports.Touch;\r | |
7 | supportsTouchScroll = Ext.supports.touchScroll;\r | |
8 | Ext.supports.Touch = true;\r | |
9 | Ext.supports.touchScroll = 2;\r | |
10 | \r | |
11 | store = new Ext.data.Store({\r | |
12 | fields: ['id', 'title'],\r | |
13 | \r | |
14 | data: [\r | |
15 | {id: 11, title: 'First Item'},\r | |
16 | {id: 12, title: 'Second Item'},\r | |
17 | {id: 13, title: 'Third Item'},\r | |
18 | {id: 14, title: 'Fourth Item'},\r | |
19 | {id: 15, title: 'Fifth Item'}\r | |
20 | ],\r | |
21 | \r | |
22 | proxy: {\r | |
23 | type: 'ajax',\r | |
24 | url: 'notreal'\r | |
25 | }\r | |
26 | });\r | |
27 | \r | |
28 | proxy = store.getProxy();\r | |
29 | model = store.getModel();\r | |
30 | \r | |
31 | list = new Ext.List({\r | |
32 | plugins: ['pullrefresh'],\r | |
33 | store: store,\r | |
34 | displayField: 'title'\r | |
35 | });\r | |
36 | \r | |
37 | plugin = list.getPlugins()[0];\r | |
38 | });\r | |
39 | \r | |
40 | afterEach(function() {\r | |
41 | list.destroy();\r | |
42 | list = null;\r | |
43 | \r | |
44 | Ext.supports.Touch = supportsTouch;\r | |
45 | Ext.supports.touchScroll = supportsTouchScroll;\r | |
46 | });\r | |
47 | \r | |
48 | describe("fetching latest items", function() {\r | |
49 | var operation;\r | |
50 | \r | |
51 | beforeEach(function() {\r | |
52 | spyOn(proxy, 'read').andCallFake(function(op) {\r | |
53 | operation = op;\r | |
54 | });\r | |
55 | });\r | |
56 | \r | |
57 | it("should send a read request via the Store's Proxy", function() {\r | |
58 | plugin.fetchLatest();\r | |
59 | \r | |
60 | expect(proxy.read).toHaveBeenCalled();\r | |
61 | });\r | |
62 | \r | |
63 | describe("the Operation", function() {\r | |
64 | beforeEach(function() {\r | |
65 | plugin.fetchLatest();\r | |
66 | });\r | |
67 | \r | |
68 | it("should be a read Operation", function() {\r | |
69 | expect(operation.getAction()).toBe('read');\r | |
70 | });\r | |
71 | \r | |
72 | it("should specify page 1", function() {\r | |
73 | expect(operation.getPage()).toBe(1);\r | |
74 | });\r | |
75 | \r | |
76 | it("should set start to 0", function() {\r | |
77 | expect(operation.getStart()).toBe(0);\r | |
78 | });\r | |
79 | \r | |
80 | it("should set page size to the Store's page size", function() {\r | |
81 | expect(operation.getLimit()).toBe(store.getPageSize());\r | |
82 | });\r | |
83 | });\r | |
84 | });\r | |
85 | \r | |
86 | describe("when latest fetched items come back", function() {\r | |
87 | describe("if there are no new items", function() {\r | |
88 | var operation;\r | |
89 | beforeEach(function() {\r | |
90 | operation = new Ext.data.operation.Read({\r | |
91 | model: model,\r | |
92 | records: []\r | |
93 | });\r | |
94 | });\r | |
95 | \r | |
96 | it("should leave all of the Store items unmolested", function() {\r | |
97 | plugin.onLatestFetched(operation);\r | |
98 | \r | |
99 | expect(store.getCount()).toBe(5);\r | |
100 | });\r | |
101 | });\r | |
102 | \r | |
103 | describe("if the fetched items overlap with records already in the store", function() {\r | |
104 | var newRecords, operation;\r | |
105 | \r | |
106 | beforeEach(function() {\r | |
107 | newRecords = [];\r | |
108 | \r | |
109 | var raw = [\r | |
110 | {id: 1, title: 'New First Item'},\r | |
111 | {id: 2, title: 'New Second Item'},\r | |
112 | {id: 3, title: 'New Third Item'},\r | |
113 | {id: 4, title: 'New Fourth Item'},\r | |
114 | {id: 5, title: 'New Fifth Item'},\r | |
115 | {id: 6, title: 'New Sixth Item'},\r | |
116 | {id: 7, title: 'New Seventh Item'},\r | |
117 | {id: 8, title: 'New Eighth Item'},\r | |
118 | {id: 9, title: 'New Ninth Item'},\r | |
119 | {id: 10, title: 'New Tenth Item'},\r | |
120 | {id: 11, title: 'Updated First Item'},\r | |
121 | {id: 12, title: 'Updated Second Item'}\r | |
122 | ];\r | |
123 | \r | |
124 | Ext.each(raw, function(data, i) {\r | |
125 | newRecords[i] = new model(data);\r | |
126 | }, this);\r | |
127 | \r | |
128 | operation = new Ext.data.operation.Read({\r | |
129 | records: newRecords,\r | |
130 | model: model\r | |
131 | });\r | |
132 | \r | |
133 | plugin.onLatestFetched(newRecords, operation);\r | |
134 | });\r | |
135 | \r | |
136 | it("should have the correct number of items in the Store", function() {\r | |
137 | expect(store.getCount()).toBe(15);\r | |
138 | });\r | |
139 | \r | |
140 | it("should update the data for any items that came back in the response but were already present", function() {\r | |
141 | expect(store.getById(11).get('title')).toBe('Updated First Item');\r | |
142 | expect(store.getById(12).get('title')).toBe('Updated Second Item');\r | |
143 | });\r | |
144 | });\r | |
145 | \r | |
146 | describe("if the fetched items do not overlap with records already in the store", function() {\r | |
147 | var newRecords, operation;\r | |
148 | \r | |
149 | beforeEach(function() {\r | |
150 | newRecords = [];\r | |
151 | \r | |
152 | var raw = [\r | |
153 | {id: 1, title: 'New First Item'},\r | |
154 | {id: 2, title: 'New Second Item'},\r | |
155 | {id: 3, title: 'New Third Item'},\r | |
156 | {id: 4, title: 'New Fourth Item'},\r | |
157 | {id: 5, title: 'New Fifth Item'}\r | |
158 | ];\r | |
159 | \r | |
160 | Ext.each(raw, function(data, i) {\r | |
161 | newRecords[i] = new model(data);\r | |
162 | }, this);\r | |
163 | \r | |
164 | operation = new Ext.data.operation.Read({\r | |
165 | records: newRecords,\r | |
166 | model: model\r | |
167 | });\r | |
168 | });\r | |
169 | \r | |
170 | it("should insert any new items at the front of the Store", function() {\r | |
171 | plugin.onLatestFetched(newRecords, operation);\r | |
172 | \r | |
173 | expect(store.getCount()).toBe(10);\r | |
174 | expect(store.getAt(0).getId()).toBe(1);\r | |
175 | expect(store.getAt(1).getId()).toBe(2);\r | |
176 | expect(store.getAt(2).getId()).toBe(3);\r | |
177 | expect(store.getAt(3).getId()).toBe(4);\r | |
178 | expect(store.getAt(4).getId()).toBe(5);\r | |
179 | });\r | |
180 | \r | |
181 | it("should record that a break occurred after the last new item", function() {\r | |
182 | \r | |
183 | });\r | |
184 | });\r | |
185 | });\r | |
186 | }); |