|
1 | 1 | /*global describe, beforeEach, module, it, expect, runTest */ |
2 | | -describe('uiScroll visibility. ', function() { |
| 2 | +describe('uiScroll visibility.', () => { |
3 | 3 | 'use strict'; |
4 | 4 |
|
5 | 5 | beforeEach(module('ui.scroll')); |
6 | 6 | beforeEach(module('ui.scroll.test.datasources')); |
7 | 7 |
|
8 | | - var getScrollSettings = function() { |
9 | | - return { |
10 | | - datasource: 'myMultipageDatasource', |
11 | | - viewportHeight: 200, |
12 | | - itemHeight: 40, |
13 | | - bufferSize: 3, |
14 | | - adapter: 'adapter' |
15 | | - }; |
| 8 | + const scrollSettings = { |
| 9 | + datasource: 'myMultipageDatasource', |
| 10 | + viewportHeight: 200, |
| 11 | + itemHeight: 40, |
| 12 | + bufferSize: 3, |
| 13 | + adapter: 'adapter' |
16 | 14 | }; |
17 | 15 |
|
18 | | - var checkContent = function(rows, count) { |
| 16 | + const checkContent = (rows, count) => { |
| 17 | + expect(rows.length).toBe(count); |
19 | 18 | for (var i = 1; i < count - 1; i++) { |
20 | | - var row = rows[i]; |
21 | | - expect(row.tagName.toLowerCase()).toBe('div'); |
22 | | - expect(row.innerHTML).toBe(i + ': item' + i); |
| 19 | + expect(rows[i].innerHTML).toBe(i + ': item' + i); |
23 | 20 | } |
24 | 21 | }; |
25 | 22 |
|
26 | | - describe('Viewport visibility changing. ', function() { |
27 | | - var onePackItemsCount = 3 + 2; |
28 | | - var twoPacksItemsCount = 3 * 3 + 2; |
| 23 | + const onePackItemsCount = 3 * 1 + 2; |
| 24 | + const twoPacksItemsCount = 3 * 2 + 2; |
| 25 | + const threePacksItemsCount = 3 * 3 + 2; |
29 | 26 |
|
30 | | - it('Should create 9 divs with data (+ 2 padding divs).', function() { |
31 | | - runTest(getScrollSettings(), |
32 | | - function(viewport) { |
33 | | - expect(viewport.children().length).toBe(twoPacksItemsCount); |
| 27 | + describe('Viewport visibility changing\n', () => { |
| 28 | + |
| 29 | + it('should create 9 divs with data (+ 2 padding divs)', () => |
| 30 | + runTest(scrollSettings, |
| 31 | + (viewport) => { |
34 | 32 | expect(viewport.scrollTop()).toBe(0); |
35 | | - expect(viewport.children().css('height')).toBe('0px'); |
36 | | - expect(angular.element(viewport.children()[twoPacksItemsCount - 1]).css('height')).toBe('0px'); |
37 | | - checkContent(viewport.children(), twoPacksItemsCount); |
| 33 | + checkContent(viewport.children(), threePacksItemsCount); |
38 | 34 | } |
39 | | - ); |
40 | | - }); |
| 35 | + ) |
| 36 | + ); |
41 | 37 |
|
42 | | - it('Should preserve elements after visibility switched off (display:none).', function() { |
43 | | - runTest(getScrollSettings(), |
44 | | - function(viewport, scope) { |
| 38 | + it('should preserve elements after visibility switched off (display:none)', () => |
| 39 | + runTest(scrollSettings, |
| 40 | + (viewport, scope) => { |
45 | 41 | viewport.css('display', 'none'); |
46 | 42 | scope.$apply(); |
47 | 43 |
|
48 | | - expect(viewport.children().length).toBe(twoPacksItemsCount); |
49 | 44 | expect(viewport.scrollTop()).toBe(0); |
50 | | - expect(viewport.children().css('height')).toBe('0px'); |
51 | | - expect(angular.element(viewport.children()[twoPacksItemsCount - 1]).css('height')).toBe('0px'); |
52 | | - checkContent(viewport.children(), twoPacksItemsCount); |
| 45 | + checkContent(viewport.children(), threePacksItemsCount); |
53 | 46 | } |
54 | | - ); |
55 | | - }); |
56 | | - |
| 47 | + ) |
| 48 | + ); |
57 | 49 |
|
58 | | - it('Should only load one batch with visibility switched off (display:none).', function() { |
59 | | - runTest(getScrollSettings(), |
60 | | - function(viewport, scope) { |
| 50 | + it('should only load one batch with visibility switched off (display:none)', () => |
| 51 | + runTest(scrollSettings, |
| 52 | + (viewport, scope) => { |
61 | 53 | viewport.css('display', 'none'); |
62 | 54 | scope.adapter.reload(); |
63 | 55 |
|
64 | | - expect(viewport.children().length).toBe(onePackItemsCount); |
65 | 56 | expect(viewport.scrollTop()).toBe(0); |
66 | | - expect(viewport.children().css('height')).toBe('0px'); |
67 | | - expect(angular.element(viewport.children()[onePackItemsCount - 1]).css('height')).toBe('0px'); |
68 | 57 | checkContent(viewport.children(), onePackItemsCount); |
69 | 58 | } |
70 | | - ); |
71 | | - }); |
| 59 | + ) |
| 60 | + ); |
72 | 61 |
|
73 | | - it('Should load full set after css-visibility switched back on.', function() { |
74 | | - var scrollSettings = getScrollSettings(); |
| 62 | + it('should load full set after css-visibility switched back on', () => |
75 | 63 | runTest(scrollSettings, |
76 | | - function(viewport, scope, $timeout) { |
| 64 | + (viewport, scope, $timeout) => { |
77 | 65 | viewport.css('display', 'none'); |
78 | 66 | scope.adapter.reload(); |
79 | 67 |
|
80 | 68 | viewport.css('display', 'block'); |
81 | 69 | scope.$apply(); |
82 | 70 | $timeout.flush(); |
83 | 71 |
|
84 | | - let rows = viewport.children(); |
85 | | - expect(rows.length).toBe(twoPacksItemsCount); |
86 | 72 | expect(viewport.scrollTop()).toBe(0); |
87 | | - expect(rows.css('height')).toBe('0px'); |
88 | | - expect(angular.element(rows[twoPacksItemsCount - 1]).css('height')).toBe('0px'); |
89 | | - checkContent(rows, onePackItemsCount); |
| 73 | + checkContent(viewport.children(), threePacksItemsCount); |
| 74 | + expect(scope.adapter.topVisible).toBe('item1'); |
90 | 75 | } |
91 | | - ); |
92 | | - }); |
93 | | - |
94 | | - it('Should load full set after scope-visibility switched back on.', function() { |
95 | | - var scrollSettings = getScrollSettings(); |
96 | | - scrollSettings.wrapper = { |
97 | | - start: '<div ng-if="show">', |
98 | | - end: '</div>' |
99 | | - }; |
100 | | - runTest(scrollSettings, |
101 | | - function(viewport, scope, $timeout) { |
| 76 | + ) |
| 77 | + ); |
| 78 | + |
| 79 | + it('should load full set after scope-visibility switched back on', () => |
| 80 | + runTest(Object.assign({}, scrollSettings, { |
| 81 | + wrapper: { |
| 82 | + start: '<div ng-if="show">', |
| 83 | + end: '</div>' |
| 84 | + } |
| 85 | + }), (viewport, scope) => { |
102 | 86 | scope.show = false; |
103 | | - scope.adapter.reload(); |
104 | 87 | scope.$apply(); |
| 88 | + expect(viewport.children().length).toBe(0); |
105 | 89 |
|
106 | 90 | scope.show = true; |
107 | 91 | scope.$apply(); |
108 | | - $timeout.flush(); |
109 | | - |
110 | | - let rows = viewport.children().children(); |
111 | | - expect(rows.length).toBe(twoPacksItemsCount); |
112 | 92 | expect(viewport.scrollTop()).toBe(0); |
113 | | - expect(rows.css('height')).toBe('0px'); |
114 | | - expect(angular.element(rows[twoPacksItemsCount - 1]).css('height')).toBe('0px'); |
115 | | - checkContent(rows, onePackItemsCount); |
| 93 | + checkContent(viewport.children().children(), threePacksItemsCount); |
116 | 94 | }, { |
117 | 95 | scope: { |
118 | 96 | show: true |
119 | 97 | } |
120 | 98 | } |
121 | | - ); |
122 | | - }); |
123 | | - |
124 | | - it('Should stay on the 1st item after the visibility is on (infinite list).', function() { |
125 | | - var scrollSettings = getScrollSettings(); |
126 | | - scrollSettings.datasource = 'myInfiniteDatasource'; |
127 | | - scrollSettings.topVisible = 'topVisible'; |
128 | | - runTest(scrollSettings, |
129 | | - function(viewport, scope, $timeout) { |
130 | | - viewport.css('display', 'none'); |
131 | | - scope.adapter.reload(); |
132 | | - scope.$apply(); |
133 | | - |
134 | | - viewport.css('display', 'block'); |
135 | | - scope.$apply(); |
136 | | - $timeout.flush(); |
137 | | - |
138 | | - expect(scope.topVisible).toBe('item1'); |
139 | | - } |
140 | | - ); |
141 | | - }); |
| 99 | + ) |
| 100 | + ); |
142 | 101 | }); |
143 | 102 |
|
144 | | - describe('Items visibility changing. ', function() { |
145 | | - var scrollSettings = getScrollSettings(); |
146 | | - scrollSettings.itemHeight = '0'; |
147 | | - var onePackItemsCount = 3 + 2; |
148 | | - var twoPacksItemsCount = 3 * 2 + 2; |
149 | | - |
150 | | - it('Should load only one batch with items height = 0', function() { |
151 | | - runTest(scrollSettings, |
152 | | - function(viewport) { |
| 103 | + describe('Items visibility changing\n', () => { |
153 | 104 |
|
| 105 | + it('should load only one batch with items height = 0', () => |
| 106 | + runTest(Object.assign({}, scrollSettings, { itemHeight: '0' }), |
| 107 | + (viewport) => { |
154 | 108 | expect(viewport.children().length).toBe(onePackItemsCount); |
155 | 109 | expect(viewport.scrollTop()).toBe(0); |
156 | 110 | checkContent(viewport.children(), onePackItemsCount); |
157 | 111 | } |
158 | | - ); |
159 | | - }); |
160 | | - |
161 | | - it('Should continue loading after the height of some item switched to non-zero.', function() { |
162 | | - runTest(scrollSettings, |
163 | | - function(viewport, scope, $timeout) { |
| 112 | + ) |
| 113 | + ); |
164 | 114 |
|
| 115 | + it('should load one more batch after the height of some item is set to a positive value', () => |
| 116 | + runTest(Object.assign({}, scrollSettings, { itemHeight: '0' }), |
| 117 | + (viewport, scope, $timeout) => { |
165 | 118 | angular.element(viewport.children()[onePackItemsCount - 2]).css('height', 40); |
166 | 119 | expect(angular.element(viewport.children()[onePackItemsCount - 2]).css('height')).toBe('40px'); |
167 | 120 | scope.$apply(); |
168 | 121 | $timeout.flush(); |
169 | 122 |
|
170 | | - expect(viewport.children().length).toBe(twoPacksItemsCount); |
171 | 123 | expect(viewport.scrollTop()).toBe(0); |
172 | 124 | checkContent(viewport.children(), twoPacksItemsCount); |
173 | 125 | } |
174 | | - ); |
175 | | - }); |
| 126 | + ) |
| 127 | + ); |
176 | 128 | }); |
177 | 129 |
|
178 | | - |
179 | 130 | }); |
0 commit comments