1
1
import { module , test } from 'qunit' ;
2
2
import hbs from 'htmlbars-inline-precompile' ;
3
3
import a11yAudit from 'ember-a11y-testing/test-support/audit' ;
4
+ import { set } from '@ember/object' ;
4
5
5
6
import { generateTable , generateColumns , generateRows } from '../../helpers/generate-table' ;
6
7
import { componentModule } from '../../helpers/module' ;
@@ -118,11 +119,6 @@ module('Integration | basic', function() {
118
119
let rect = element . getBoundingClientRect ( ) ;
119
120
let diff = Math . abs ( container [ measurement ] - rect [ measurement ] ) ;
120
121
121
- // Travis reports pretty wide differences for some reason, possibly
122
- // their Chrome version. It does validate that the elements are moving
123
- // and that should be enough to know if we messed something up majorly.
124
- //
125
- // TODO(sticky): Try to lower the tolerance as sticky becomes more prevalent
126
122
assert . ok ( diff < 10 , `${ diff } is with tolerance` ) ;
127
123
}
128
124
}
@@ -139,33 +135,132 @@ module('Integration | basic', function() {
139
135
140
136
let tableContainerRect = find ( '.ember-table' ) . getBoundingClientRect ( ) ;
141
137
138
+ /**
139
+ * No scroll.
140
+ *
141
+ * Assert the special cases:
142
+ *
143
+ * - Horizontally, the last column is stuck at the edge of the
144
+ * container.
145
+ * - Vertically, the footer is stuck at the edge of the container.
146
+ */
142
147
validateElements ( tableContainerRect , findAll ( 'thead th' ) , 'top' ) ;
143
148
validateElements ( tableContainerRect , findAll ( 'tr > *:first-child' ) , 'left' ) ;
144
149
validateElements ( tableContainerRect , findAll ( 'tr > *:last-child' ) , 'right' ) ;
145
150
validateElements ( tableContainerRect , findAll ( 'tfoot td' ) , 'bottom' ) ;
146
151
147
152
await scrollTo ( '[data-test-ember-table-overflow]' , 10000 , 0 ) ;
148
153
154
+ /**
155
+ * Scrolled to the far right.
156
+ *
157
+ * Assert the special cases:
158
+ *
159
+ * - Horizontally, the first column is stuck at the edge of the
160
+ * container.
161
+ * - Vertically, the footer is stuck at the edge of the container.
162
+ */
149
163
validateElements ( tableContainerRect , findAll ( 'thead th' ) , 'top' ) ;
150
164
validateElements ( tableContainerRect , findAll ( 'tr > *:first-child' ) , 'left' ) ;
151
165
validateElements ( tableContainerRect , findAll ( 'tr > *:last-child' ) , 'right' ) ;
152
166
validateElements ( tableContainerRect , findAll ( 'tfoot td' ) , 'bottom' ) ;
153
167
154
168
await scrollTo ( '[data-test-ember-table-overflow]' , 10000 , 10000 ) ;
155
169
170
+ /**
171
+ * Scrolled to the far bottom and far right.
172
+ *
173
+ * Assert the special cases:
174
+ *
175
+ * - Horizontally, the first column is stuck at the edge of the
176
+ * container.
177
+ * - Vertically, the header is stuck at the edge of the container.
178
+ */
156
179
validateElements ( tableContainerRect , findAll ( 'thead th' ) , 'top' ) ;
157
180
validateElements ( tableContainerRect , findAll ( 'tr > *:first-child' ) , 'left' ) ;
158
181
validateElements ( tableContainerRect , findAll ( 'tr > *:last-child' ) , 'right' ) ;
159
182
validateElements ( tableContainerRect , findAll ( 'tfoot td' ) , 'bottom' ) ;
160
183
161
184
await scrollTo ( '[data-test-ember-table-overflow]' , 0 , 10000 ) ;
162
185
186
+ /**
187
+ * Scrolled to the far bottom.
188
+ *
189
+ * Assert the special cases:
190
+ *
191
+ * - Horizontally, the last column is stuck at the edge of the
192
+ * container.
193
+ * - Vertically, the header is stuck at the edge of the container.
194
+ */
163
195
validateElements ( tableContainerRect , findAll ( 'thead th' ) , 'top' ) ;
164
196
validateElements ( tableContainerRect , findAll ( 'tr > *:first-child' ) , 'left' ) ;
165
197
validateElements ( tableContainerRect , findAll ( 'tr > *:last-child' ) , 'right' ) ;
166
198
validateElements ( tableContainerRect , findAll ( 'tfoot td' ) , 'bottom' ) ;
167
199
} ) ;
168
200
201
+ test ( 'mutating fixed cells work' , async function ( assert ) {
202
+ await generateTable ( this , {
203
+ rowCount : 100 ,
204
+ columnCount : 30 ,
205
+ footerRowCount : 1 ,
206
+ columnOptions : {
207
+ fixedLeftCount : 1 ,
208
+ fixedRightCount : 1 ,
209
+ } ,
210
+ } ) ;
211
+
212
+ let tableContainerRect = find ( '.ember-table' ) . getBoundingClientRect ( ) ;
213
+
214
+ /**
215
+ * Just scroll around. See the prior test for assertions that the
216
+ * behaviors after these actions are performed are correct.
217
+ */
218
+ await scrollTo ( '[data-test-ember-table-overflow]' , 10000 , 10000 ) ;
219
+ await scrollTo ( '[data-test-ember-table-overflow]' , 0 , 0 ) ;
220
+
221
+ /**
222
+ * Mutate the fixed state of the first and last column
223
+ */
224
+ set ( this . columns [ 0 ] , 'isFixed' , null ) ;
225
+ set ( this . columns [ this . columns . length - 1 ] , 'isFixed' , null ) ;
226
+
227
+ await settled ( ) ;
228
+
229
+ /**
230
+ * No scroll.
231
+ *
232
+ * Assert the special cases:
233
+ *
234
+ * - Horizontally, the last column is no longer stuck at the edge of
235
+ * the container.
236
+ */
237
+ let lastColumnRight = this . element . querySelector ( 'tr > *:last-child' ) . getBoundingClientRect ( )
238
+ . right ;
239
+ let tableContainerRight = tableContainerRect . right ;
240
+ assert . true (
241
+ lastColumnRight > tableContainerRight + 20 ,
242
+ `last column right (${ lastColumnRight } ) is safely greater than the container's right (${ tableContainerRight } + 20)`
243
+ ) ;
244
+
245
+ await scrollTo ( '[data-test-ember-table-overflow]' , 10000 , 0 ) ;
246
+
247
+ /**
248
+ * Scrolled to far right.
249
+ *
250
+ * Assert the special cases:
251
+ *
252
+ * - Horizontally, the first column is no longer stuck at the edge of
253
+ * the container.
254
+ */
255
+ let firstColumnLeft = this . element . querySelector ( 'tr > *:first-child' ) . getBoundingClientRect ( )
256
+ . left ;
257
+ let tableContainerLeft = tableContainerRect . left ;
258
+ assert . true (
259
+ firstColumnLeft < tableContainerLeft - 20 ,
260
+ `first column left (${ firstColumnLeft } ) is safely less than the container's left (${ tableContainerLeft } - 20)`
261
+ ) ;
262
+ } ) ;
263
+
169
264
test ( 'Accessibility test' , async function ( assert ) {
170
265
await generateTable ( this , { hasFixedColumn : true } ) ;
171
266
0 commit comments