Skip to content

Commit ee6184c

Browse files
author
Jesse Streb
committed
Fixed issue in which we were changing the location.href to a hardcoded value rather then just the hash.
1 parent 35c2fe8 commit ee6184c

File tree

2 files changed

+325
-0
lines changed

2 files changed

+325
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
var listViewHelper = {};
2+
3+
(function ($, lvh, undefined ) {
4+
5+
var current_page
6+
, pageShowFired = false;
7+
8+
9+
lvh.resetForPage = function(new_page) {
10+
//remove any old event listeners from the current page if defined
11+
if(current_page)
12+
current_page.die('pageshow', lvh.pageshowHandler);
13+
14+
pageShowFired = false;
15+
current_page = new_page;
16+
current_page.live('pageshow', lvh.pageshowHandler);
17+
}
18+
19+
lvh.currentPage = function() {
20+
return current_page;
21+
}
22+
23+
lvh.transitionComplete = function() {
24+
return pageShowFired;
25+
}
26+
27+
lvh.pageshowHandler = function() {
28+
pageShowFired = true;
29+
}
30+
31+
lvh.showResultsWhenComplete = function() {
32+
if($('.jasmine_reporter .running').length == 0) {
33+
$('.ui-page-active').css('display', 'none');
34+
} else {
35+
setTimeout(lvh.showResultsWhenComplete, 500);
36+
}
37+
}
38+
39+
setTimeout(lvh.showResultsWhenComplete, 500);
40+
})(jQuery, listViewHelper)
Lines changed: 285 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
1+
describe("Listviews", function() {
2+
3+
describe("Basic Linked list", function() {
4+
it("should setup the listview correctly", function() {
5+
waitsFor(function() {
6+
return ($('.ui-page-active').length > 0)
7+
})
8+
9+
runs(function() {
10+
expect($('.ui-page-active .ui-listview').length).toEqual(1);
11+
expect($('.ui-page-active [role="option"]').length).toEqual(3);
12+
})
13+
});
14+
15+
it("should slide the listview page into view when the list view link is clicked", function() {
16+
listViewHelper.resetForPage($('#basic-link-results'))
17+
$('.ui-page-active li').first().click();
18+
19+
waitsFor(function() {
20+
return listViewHelper.transitionComplete();
21+
})
22+
23+
runs(function() {
24+
expect(listViewHelper.currentPage().hasClass('ui-page-active')).toBeTruthy();
25+
})
26+
});
27+
28+
it("should slide back to the main page when the back button is clicked", function() {
29+
listViewHelper.resetForPage($('#basic-linked-test'))
30+
$('#basic-link-results a:contains("Back")').click();
31+
32+
waitsFor(function() {
33+
return listViewHelper.transitionComplete();
34+
})
35+
36+
runs(function() {
37+
expect(listViewHelper.currentPage().hasClass('ui-page-active')).toBeTruthy();
38+
});
39+
});
40+
});
41+
42+
describe("Nested List", function() {
43+
it("should change the page to the nested list and make sure the page was enhanced.", function() {
44+
listViewHelper.resetForPage($('#nested-list-test'))
45+
location.href = location.href.split('#')[0] + "#nested-list-test";
46+
47+
/*
48+
* Calling change page directly does not update the history so breaks these tests. Checking in passing tests for now
49+
* but once pushState is tackled we should change some of these tests to also use changePage along with just hash changes.
50+
*/
51+
//$.mobile.changePage(listViewHelper.currentPage());
52+
53+
waitsFor(function() {
54+
return listViewHelper.transitionComplete();
55+
})
56+
57+
runs(function() {
58+
expect(listViewHelper.currentPage().hasClass('ui-page-active')).toBeTruthy();
59+
expect($('[role="option"]', listViewHelper.currentPage()).length).toEqual(2);
60+
expect($('body > [data-url="nested-list-test&ui-page=More-animals-0"]').length).toEqual(1);
61+
expect($('body > [data-url="nested-list-test&ui-page=Groups-of-animals-1"]').length).toEqual(1);
62+
});
63+
});
64+
65+
it("should change to nested page when it is clicked", function() {
66+
listViewHelper.resetForPage($('body > [data-url="nested-list-test&ui-page=More-animals-0"]'));
67+
$('.ui-page-active li:eq(1)').click();
68+
69+
waitsFor(function() {
70+
return listViewHelper.transitionComplete();
71+
});
72+
73+
runs(function() {
74+
expect(listViewHelper.currentPage().hasClass('ui-page-active')).toBeTruthy();
75+
expect($('[role="option"]', listViewHelper.currentPage()).length).toEqual(2);
76+
expect($('.ui-listview', listViewHelper.currentPage()).find(":contains('Rhumba of rattlesnakes')").length).toEqual(1);
77+
expect($('.ui-listview', listViewHelper.currentPage()).find(":contains('Shoal of Bass')").length).toEqual(1);
78+
});
79+
});
80+
81+
it("should go back to top level when the back button is clicked", function() {
82+
listViewHelper.resetForPage($('#nested-list-test'));
83+
$('body > [data-url="nested-list-test&ui-page=More-animals-0"]').find('a:contains("Back")').click();
84+
85+
waitsFor(function() {
86+
return listViewHelper.transitionComplete();
87+
});
88+
89+
runs(function() {
90+
expect(listViewHelper.currentPage().hasClass('ui-page-active')).toBeTruthy();
91+
});
92+
});
93+
});
94+
95+
describe("Ordered Lists", function() {
96+
it("should change the page to the numbered list and make sure the page was enhanced.", function() {
97+
listViewHelper.resetForPage($('#numbered-list-test'));
98+
location.href = location.href.split('#')[0] + "#numbered-list-test";
99+
//$.mobile.changePage(listViewHelper.currentPage());
100+
101+
waitsFor(function() {
102+
return listViewHelper.transitionComplete();
103+
});
104+
105+
runs(function() {
106+
expect(listViewHelper.currentPage().hasClass('ui-page-active')).toBeTruthy();
107+
expect($('[role="option"]', listViewHelper.currentPage()).length).toEqual(3);
108+
expect($('.ui-link-inherit', listViewHelper.currentPage()).first().text()).toEqual("Number 1");
109+
});
110+
});
111+
112+
it("should take us to number 1 page when click", function() {
113+
listViewHelper.resetForPage($('#numbered-list-results'));
114+
$('.ui-page-active li').first().click();
115+
116+
waitsFor(function() {
117+
return listViewHelper.transitionComplete();
118+
});
119+
120+
runs(function() {
121+
expect(listViewHelper.currentPage().hasClass('ui-page-active')).toBeTruthy();
122+
})
123+
});
124+
125+
it("should slide back to the main numbered page when the back button is clicked", function() {
126+
listViewHelper.resetForPage($('#numbered-list-test'));
127+
$('.ui-page-active a:contains("Back")').click();
128+
129+
waitsFor(function() {
130+
return listViewHelper.transitionComplete();
131+
});
132+
133+
runs(function() {
134+
expect(listViewHelper.currentPage().hasClass('ui-page-active')).toBeTruthy();
135+
});
136+
});
137+
});
138+
139+
describe("read only list", function() {
140+
it("should change the page to the Read only list and make sure the page was enhanced.", function() {
141+
listViewHelper.resetForPage($('#read-only-list-test'));
142+
location.href = location.href.split('#')[0] + "#read-only-list-test";
143+
//$.mobile.changePage(listViewHelper.currentPage());
144+
145+
waitsFor(function() {
146+
return listViewHelper.transitionComplete();
147+
});
148+
149+
runs(function() {
150+
expect(listViewHelper.currentPage().hasClass('ui-page-active')).toBeTruthy();
151+
expect($('[role="option"]', listViewHelper.currentPage()).length).toEqual(4);
152+
expect($('li', listViewHelper.currentPage()).first().text()).toEqual("Read");
153+
});
154+
});
155+
156+
it("should not take us to new page when a list item clicked", function() {
157+
var current_page = $('#read-only-list-test');
158+
$('li', current_page).first().click();
159+
160+
//wait a second to make sure that we give it time to transition if it is going to. It shouldn't
161+
waits(1000);
162+
163+
runs(function() {
164+
expect($('.ui-page-active').attr('id')).toEqual('read-only-list-test');
165+
})
166+
});
167+
});
168+
169+
describe("split view list", function() {
170+
it("should change the page to the split view and list view and enhance the page correctly.", function() {
171+
listViewHelper.resetForPage($('#split-list-test'));
172+
location.href = location.href.split('#')[0] + "#split-list-test";
173+
//$.mobile.changePage(listViewHelper.currentPage());
174+
175+
waitsFor(function() {
176+
return listViewHelper.transitionComplete();
177+
});
178+
179+
runs(function() {
180+
expect(listViewHelper.currentPage().hasClass('ui-page-active')).toBeTruthy();
181+
expect($('[role="option"]', listViewHelper.currentPage()).length).toEqual(3);
182+
expect($('.ui-li-link-alt', listViewHelper.currentPage()).length).toEqual(3);
183+
expect($('.ui-link-inherit', listViewHelper.currentPage()).length).toEqual(3);
184+
});
185+
});
186+
187+
it("should change the page to split view page 1 when the first link is clicked", function() {
188+
listViewHelper.resetForPage($('#split-list-link1'));
189+
$('.ui-page-active [role="option"]:eq(0)').click();
190+
191+
waitsFor(function() {
192+
return listViewHelper.transitionComplete();
193+
});
194+
195+
runs(function() {
196+
expect(listViewHelper.currentPage().hasClass('ui-page-active')).toBeTruthy();
197+
});
198+
});
199+
200+
it("should slide the page back to the split list view when the back button is clicked", function() {
201+
listViewHelper.resetForPage($('#split-list-test'));
202+
$('.ui-page-active a:contains("Back")').click();
203+
204+
waitsFor(function() {
205+
return listViewHelper.transitionComplete();
206+
});
207+
208+
runs(function() {
209+
expect(listViewHelper.currentPage().hasClass('ui-page-active')).toBeTruthy();
210+
});
211+
});
212+
213+
/*
214+
* Once the bug in which the changePage call does not update the hash correctly, resulting in the back button
215+
* going back to the wrong page is fixed, then we should implement these tests.
216+
*/
217+
it("should slide to the second link when the right icon is clicked", function() {
218+
//pending
219+
})
220+
221+
it("should slide back to the split list view page when teh back button is clicked", function() {
222+
//pending
223+
});
224+
});
225+
226+
describe("List dividers", function() {
227+
it("should make the list divider page the active page and enhance it correctly.", function() {
228+
listViewHelper.resetForPage($('#list-divider-test'));
229+
location.href = location.href.split('#')[0] + "#list-divider-test";
230+
//$.mobile.changePage(listViewHelper.currentPage());
231+
232+
waitsFor(function() {
233+
return listViewHelper.transitionComplete();
234+
});
235+
236+
runs(function() {
237+
expect($('.ui-page-active .ui-li-divider').length).toEqual(2);
238+
expect(listViewHelper.currentPage().hasClass('ui-page-active')).toBeTruthy();
239+
});
240+
});
241+
});
242+
243+
describe("Search Filter", function() {
244+
it("should make the search filter page the active page and enhance it correctly.", function() {
245+
listViewHelper.resetForPage($('#search-filter-test'));
246+
location.href = location.href.split('#')[0] + "#search-filter-test";
247+
//$.mobile.changePage(listViewHelper.currentPage());
248+
249+
waitsFor(function() {
250+
return listViewHelper.transitionComplete();
251+
});
252+
253+
runs(function() {
254+
expect($('.ui-page-active input').length).toEqual(1)
255+
expect(listViewHelper.currentPage().hasClass('ui-page-active')).toBeTruthy();
256+
});
257+
});
258+
259+
it("should filter down the results when the user enters information", function() {
260+
$('.ui-page-active input').val('at');
261+
$('.ui-page-active input').trigger('change');
262+
263+
waitsFor(function() {
264+
return $('.ui-page-active li[style="display: none; "]').length == 2;
265+
})
266+
267+
runs(function() {
268+
expect( $('.ui-page-active li[style="display: none; "]').length).toEqual(2);
269+
});
270+
});
271+
272+
it("if user removes values it should redisplay the results", function() {
273+
$('.ui-page-active input').val('a')
274+
$('.ui-page-active input').trigger('change');
275+
276+
waitsFor(function() {
277+
return $('.ui-page-active li[style="display: none; "]').length == 0;
278+
})
279+
280+
runs(function() {
281+
expect( $('.ui-page-active li[style="display: none; "]').length).toEqual(0);
282+
});
283+
});
284+
});
285+
});

0 commit comments

Comments
 (0)