@@ -180,7 +180,7 @@ describe('Tile drag and drop', () => {
180180 expect ( dropTarget . position ) . to . equal ( 4 ) ;
181181 } ) ;
182182
183- it ( 'should adjust reflected tiles positions when using slide action ' , async ( ) => {
183+ it ( 'should adjust reflected tiles positions' , async ( ) => {
184184 const draggedTile = getTile ( 0 ) ;
185185 const dropTarget = getTile ( 1 ) ;
186186
@@ -206,7 +206,7 @@ describe('Tile drag and drop', () => {
206206 expect ( dropTarget . position ) . to . equal ( 0 ) ;
207207 } ) ;
208208
209- it ( 'should not change order when dragging a tile onto itself when using slide action ' , async ( ) => {
209+ it ( 'should not change order when dragging a tile onto itself' , async ( ) => {
210210 const initialTiles = tileManager . tiles ;
211211 const tile = getTile ( 0 ) ;
212212
@@ -220,38 +220,7 @@ describe('Tile drag and drop', () => {
220220 expect ( tileManager . tiles [ 1 ] . id ) . to . equal ( 'tile1' ) ;
221221 } ) ;
222222
223- it ( 'should swap the dragged tile with the drop target when using swap action' , async ( ) => {
224- const draggedTile = getTile ( 0 ) ;
225- const dropTarget = getTile ( 4 ) ;
226-
227- expect ( tileManager . tiles [ 0 ] . id ) . to . equal ( 'tile0' ) ;
228- expect ( tileManager . tiles [ 4 ] . id ) . to . equal ( 'tile4' ) ;
229- expect ( draggedTile . position ) . to . equal ( 0 ) ;
230- expect ( dropTarget . position ) . to . equal ( 4 ) ;
231-
232- await dragAndDrop ( draggedTile , dropTarget ) ;
233-
234- expect ( tileManager . tiles [ 0 ] . id ) . to . equal ( 'tile4' ) ;
235- expect ( tileManager . tiles [ 4 ] . id ) . to . equal ( 'tile0' ) ;
236- expect ( draggedTile . position ) . to . equal ( 4 ) ;
237- expect ( dropTarget . position ) . to . equal ( 0 ) ;
238- } ) ;
239-
240- it ( 'should not change order when dragging a tile onto itself when using swap action' , async ( ) => {
241- const initialTiles = tileManager . tiles ;
242- const tile = getTile ( 0 ) ;
243-
244- expect ( tileManager . tiles [ 0 ] . id ) . to . equal ( 'tile0' ) ;
245- expect ( tileManager . tiles [ 1 ] . id ) . to . equal ( 'tile1' ) ;
246-
247- await dragAndDrop ( tile , tile ) ;
248-
249- expect ( tileManager . tiles ) . eql ( initialTiles ) ;
250- expect ( tileManager . tiles [ 0 ] . id ) . to . equal ( 'tile0' ) ;
251- expect ( tileManager . tiles [ 1 ] . id ) . to . equal ( 'tile1' ) ;
252- } ) ;
253-
254- it ( 'should swap positions only once while dragging smaller tile over bigger tile when using slide action' , async ( ) => {
223+ it ( 'should swap positions only once while dragging smaller tile over bigger tile' , async ( ) => {
255224 tileManager . columnCount = 5 ;
256225 const draggedTile = getTile ( 0 ) ;
257226 const dropTarget = getTile ( 1 ) ;
@@ -282,9 +251,73 @@ describe('Tile drag and drop', () => {
282251 simulateLostPointerCapture ( draggedTile ) ;
283252 await elementUpdated ( draggedTile ) ;
284253 } ) ;
254+
255+ it ( 'should swap positions properly when row, column and span are specified' , async ( ) => {
256+ const draggedTile = getTile ( 0 ) ;
257+ const dropTarget = getTile ( 1 ) ;
258+
259+ draggedTile . colSpan = 2 ;
260+ draggedTile . rowSpan = 2 ;
261+ draggedTile . colStart = 3 ;
262+ draggedTile . rowStart = 3 ;
263+
264+ await elementUpdated ( tileManager ) ;
265+
266+ tileManager . tiles . forEach ( ( tile , index ) => {
267+ expect ( tile . id ) . to . equal ( `tile${ index } ` ) ;
268+ } ) ;
269+ expect ( draggedTile . position ) . to . equal ( 0 ) ;
270+ expect ( dropTarget . position ) . to . equal ( 1 ) ;
271+
272+ await dragAndDrop ( draggedTile , dropTarget ) ;
273+
274+ const expectedIdsAfterDrag = [
275+ 'tile1' ,
276+ 'tile0' ,
277+ 'tile2' ,
278+ 'tile3' ,
279+ 'tile4' ,
280+ ] ;
281+ tileManager . tiles . forEach ( ( tile , index ) => {
282+ expect ( tile . id ) . to . equal ( expectedIdsAfterDrag [ index ] ) ;
283+ } ) ;
284+ expect ( draggedTile . position ) . to . equal ( 1 ) ;
285+ expect ( draggedTile . colSpan ) . to . equal ( 2 ) ;
286+ expect ( draggedTile . rowSpan ) . to . equal ( 2 ) ;
287+ expect ( draggedTile . colStart ) . to . be . null ;
288+ expect ( draggedTile . rowStart ) . to . be . null ;
289+ expect ( dropTarget . position ) . to . equal ( 0 ) ;
290+ expect ( dropTarget . colSpan ) . to . equal ( 1 ) ;
291+ expect ( dropTarget . rowSpan ) . to . equal ( 1 ) ;
292+ } ) ;
293+
294+ it ( 'should adjust positions properly when both tiles have columns and rows specified' , async ( ) => {
295+ const draggedTile = getTile ( 0 ) ;
296+ const dropTarget = getTile ( 1 ) ;
297+
298+ draggedTile . colStart = 2 ;
299+ draggedTile . rowStart = 2 ;
300+
301+ dropTarget . colStart = 3 ;
302+ dropTarget . rowStart = 3 ;
303+
304+ await elementUpdated ( tileManager ) ;
305+
306+ expect ( draggedTile . position ) . to . equal ( 0 ) ;
307+ expect ( dropTarget . position ) . to . equal ( 1 ) ;
308+
309+ await dragAndDrop ( draggedTile , dropTarget ) ;
310+
311+ expect ( draggedTile . position ) . to . equal ( 1 ) ;
312+ expect ( draggedTile . colStart ) . to . equal ( 3 ) ;
313+ expect ( draggedTile . rowStart ) . to . equal ( 3 ) ;
314+
315+ expect ( dropTarget . position ) . to . equal ( 0 ) ;
316+ expect ( dropTarget . colStart ) . to . equal ( 2 ) ;
317+ expect ( dropTarget . rowStart ) . to . equal ( 3 ) ;
318+ } ) ;
285319 } ) ;
286320
287- // REVIEW after tile header is finalized
288321 describe ( 'Tile header drag' , ( ) => {
289322 beforeEach ( async ( ) => {
290323 tileManager = await fixture < IgcTileManagerComponent > (
@@ -296,7 +329,7 @@ describe('Tile drag and drop', () => {
296329 tile : IgcTileComponent ,
297330 target : IgcTileComponent
298331 ) {
299- const header = tile . renderRoot . querySelector ( '[part="title "]' ) ! ;
332+ const header = tile . renderRoot . querySelector ( '[part="header "]' ) ! ;
300333 const { x, y } = getCenterPoint ( target ) ;
301334
302335 simulatePointerDown ( header ) ;
0 commit comments