13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
14 # details. |
14 # details. |
15 # |
15 # |
16 # You should have received a copy of the GNU Lesser General Public License along |
16 # You should have received a copy of the GNU Lesser General Public License along |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 """cubicweb.web.views.navigation unit tests |
18 """cubicweb.web.views.navigation unit tests""" |
19 |
|
20 """ |
|
21 |
19 |
22 from logilab.common.testlib import unittest_main, mock_object |
20 from logilab.common.testlib import unittest_main, mock_object |
|
21 |
23 from cubicweb.devtools.testlib import CubicWebTC |
22 from cubicweb.devtools.testlib import CubicWebTC |
24 |
23 from cubicweb.web.views.navigation import (PageNavigation, SortedNavigation, |
25 from cubicweb.web.views.navigation import PageNavigation, SortedNavigation |
24 PageNavigationSelect) |
26 from cubicweb.web.views.ibreadcrumbs import BreadCrumbEntityVComponent |
25 from cubicweb.web.views.ibreadcrumbs import BreadCrumbEntityVComponent |
27 |
26 |
28 BreadCrumbEntityVComponent.visible = True |
27 BreadCrumbEntityVComponent.visible = True |
29 |
28 |
30 class NavigationTC(CubicWebTC): |
29 class NavigationTC(CubicWebTC): |
39 self.assertIsInstance(navcomp, PageNavigation) |
38 self.assertIsInstance(navcomp, PageNavigation) |
40 req.set_search_state('normal') |
39 req.set_search_state('normal') |
41 |
40 |
42 def test_navigation_selection_ordered(self): |
41 def test_navigation_selection_ordered(self): |
43 req = self.request() |
42 req = self.request() |
44 rset = self.execute('Any X,N ORDERBY N WHERE X name N') |
43 rset = self.execute('Any X,N ORDERBY N LIMIT 40 WHERE X name N') |
45 navcomp = self.vreg['components'].select('navigation', req, rset=rset) |
44 navcomp = self.vreg['components'].select('navigation', req, rset=rset, page_size=20) |
46 self.assertIsInstance(navcomp, SortedNavigation) |
45 self.assertIsInstance(navcomp, SortedNavigation) |
47 req.set_search_state('W:X:Y:Z') |
46 req.set_search_state('W:X:Y:Z') |
48 navcomp = self.vreg['components'].select('navigation', req, rset=rset) |
47 navcomp = self.vreg['components'].select('navigation', req, rset=rset, page_size=20) |
49 self.assertIsInstance(navcomp, SortedNavigation) |
48 self.assertIsInstance(navcomp, SortedNavigation) |
50 req.set_search_state('normal') |
49 req.set_search_state('normal') |
51 html = navcomp.render() |
50 html = navcomp.render() |
|
51 |
|
52 def test_navigation_selection_large_rset(self): |
|
53 req = self.request() |
|
54 rset = self.execute('Any X,N LIMIT 120 WHERE X name N') |
|
55 navcomp = self.vreg['components'].select('navigation', req, rset=rset, page_size=20) |
|
56 self.assertIsInstance(navcomp, PageNavigationSelect) |
|
57 rset = self.execute('Any X,N ORDERBY N LIMIT 120 WHERE X name N') |
|
58 navcomp = self.vreg['components'].select('navigation', req, rset=rset, page_size=20) |
|
59 self.assertIsInstance(navcomp, PageNavigationSelect) |
52 |
60 |
53 def test_navigation_selection_not_enough(self): |
61 def test_navigation_selection_not_enough(self): |
54 req = self.request() |
62 req = self.request() |
55 rset = self.execute('Any X,N LIMIT 10 WHERE X name N') |
63 rset = self.execute('Any X,N LIMIT 10 WHERE X name N') |
56 navcomp = self.vreg['components'].select_or_none('navigation', req, rset=rset) |
64 navcomp = self.vreg['components'].select_or_none('navigation', req, rset=rset) |