11import { module , test } from 'qunit' ;
22import hbs from 'htmlbars-inline-precompile' ;
33import a11yAudit from 'ember-a11y-testing/test-support/audit' ;
4+ import { set } from '@ember/object' ;
45
56import { generateTable , generateColumns , generateRows } from '../../helpers/generate-table' ;
67import { componentModule } from '../../helpers/module' ;
@@ -118,11 +119,6 @@ module('Integration | basic', function() {
118119 let rect = element . getBoundingClientRect ( ) ;
119120 let diff = Math . abs ( container [ measurement ] - rect [ measurement ] ) ;
120121
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
126122 assert . ok ( diff < 10 , `${ diff } is with tolerance` ) ;
127123 }
128124 }
@@ -139,33 +135,132 @@ module('Integration | basic', function() {
139135
140136 let tableContainerRect = find ( '.ember-table' ) . getBoundingClientRect ( ) ;
141137
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+ */
142147 validateElements ( tableContainerRect , findAll ( 'thead th' ) , 'top' ) ;
143148 validateElements ( tableContainerRect , findAll ( 'tr > *:first-child' ) , 'left' ) ;
144149 validateElements ( tableContainerRect , findAll ( 'tr > *:last-child' ) , 'right' ) ;
145150 validateElements ( tableContainerRect , findAll ( 'tfoot td' ) , 'bottom' ) ;
146151
147152 await scrollTo ( '[data-test-ember-table-overflow]' , 10000 , 0 ) ;
148153
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+ */
149163 validateElements ( tableContainerRect , findAll ( 'thead th' ) , 'top' ) ;
150164 validateElements ( tableContainerRect , findAll ( 'tr > *:first-child' ) , 'left' ) ;
151165 validateElements ( tableContainerRect , findAll ( 'tr > *:last-child' ) , 'right' ) ;
152166 validateElements ( tableContainerRect , findAll ( 'tfoot td' ) , 'bottom' ) ;
153167
154168 await scrollTo ( '[data-test-ember-table-overflow]' , 10000 , 10000 ) ;
155169
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+ */
156179 validateElements ( tableContainerRect , findAll ( 'thead th' ) , 'top' ) ;
157180 validateElements ( tableContainerRect , findAll ( 'tr > *:first-child' ) , 'left' ) ;
158181 validateElements ( tableContainerRect , findAll ( 'tr > *:last-child' ) , 'right' ) ;
159182 validateElements ( tableContainerRect , findAll ( 'tfoot td' ) , 'bottom' ) ;
160183
161184 await scrollTo ( '[data-test-ember-table-overflow]' , 0 , 10000 ) ;
162185
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+ */
163195 validateElements ( tableContainerRect , findAll ( 'thead th' ) , 'top' ) ;
164196 validateElements ( tableContainerRect , findAll ( 'tr > *:first-child' ) , 'left' ) ;
165197 validateElements ( tableContainerRect , findAll ( 'tr > *:last-child' ) , 'right' ) ;
166198 validateElements ( tableContainerRect , findAll ( 'tfoot td' ) , 'bottom' ) ;
167199 } ) ;
168200
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+
169264 test ( 'Accessibility test' , async function ( assert ) {
170265 await generateTable ( this , { hasFixedColumn : true } ) ;
171266
0 commit comments