@@ -15,6 +15,17 @@ import IgcResizeComponent from './resize-element.js';
1515import IgcTileManagerComponent from './tile-manager.js' ;
1616import IgcTileComponent from './tile.js' ;
1717
18+ type ResizeCallbackParams = {
19+ event : PointerEvent ;
20+ state : {
21+ initial : DOMRect ;
22+ current : DOMRect ;
23+ dx : number ;
24+ dy : number ;
25+ ghost : HTMLElement | null ;
26+ } ;
27+ } ;
28+
1829describe ( 'Tile resize' , ( ) => {
1930 before ( ( ) => {
2031 defineComponents ( IgcTileManagerComponent ) ;
@@ -46,16 +57,6 @@ describe('Tile resize', () => {
4657 } ;
4758 }
4859
49- function getTileBaseWrapper ( element : IgcTileComponent ) {
50- const resizeElement = element . renderRoot . querySelector ( 'igc-resize' ) ;
51-
52- if ( resizeElement ) {
53- return resizeElement . querySelector < HTMLDivElement > ( '[part~="base"]' ) ! ;
54- }
55-
56- return element . renderRoot . querySelector < HTMLDivElement > ( '[part~="base"]' ) ! ;
57- }
58-
5960 function createTileManager ( ) {
6061 const result = Array . from ( range ( 5 ) ) . map (
6162 ( i ) => html `
@@ -73,7 +74,6 @@ describe('Tile resize', () => {
7374 return html `< igc-tile-manager > ${ result } </ igc-tile-manager > ` ;
7475 }
7576
76- // TODO: Review and modify the tests to correspond to the new resize logic
7777 describe ( 'Tile resize behavior' , ( ) => {
7878 beforeEach ( async ( ) => {
7979 tileManager = await fixture < IgcTileManagerComponent > ( createTileManager ( ) ) ;
@@ -92,7 +92,7 @@ describe('Tile resize', () => {
9292 expect ( eventSpy ) . calledWith ( 'igcResizeStart' ) ;
9393 } ) ;
9494
95- it ( 'should update ghost element styles during pointer move - columns ' , async ( ) => {
95+ it ( 'should update ghost element styles during pointer move' , async ( ) => {
9696 const tile = first ( getTiles ( ) ) ;
9797 const tileDOM = getTileDOM ( tile ) ;
9898 const tileRect = tile . getBoundingClientRect ( ) ;
@@ -107,116 +107,102 @@ describe('Tile resize', () => {
107107
108108 simulatePointerMove ( tileDOM . resizeTrigger , {
109109 clientX : ( tileRect . x + tileRect . width ) * 2 ,
110+ clientY : ( tileRect . y + tileRect . height ) * 2 ,
110111 } ) ;
111112 await elementUpdated ( tileDOM . resizeElement ) ;
112113
113- expect ( eventSpy ) . calledWith ( 'igcResize' ) ;
114- // FIXME: Check event arguments, ghost dimensions etc.
115-
116- simulateLostPointerCapture ( tileDOM . resizeTrigger ) ;
117- await elementUpdated ( tileDOM . resizeElement ) ;
118-
119- expect ( eventSpy ) . calledWith ( 'igcResizeEnd' ) ;
114+ const resizeCall = eventSpy . getCall ( 1 ) ;
115+ expect ( resizeCall ) . to . exist ;
116+ expect ( resizeCall . args [ 0 ] ) . to . equal ( 'igcResize' ) ;
117+
118+ const { detail } = resizeCall
119+ . args [ 1 ] as CustomEvent < ResizeCallbackParams > ;
120+ expect ( detail ) . to . not . be . null ;
121+ expect ( detail . event ) . to . be . an . instanceOf ( PointerEvent ) ;
122+ expect ( detail . state . initial ) . to . eql ( tile . getBoundingClientRect ( ) ) ;
123+ // FIXME rounding issue here; why?
124+ //expect(detail.state.current).to.eql(tileDOM.resizeGhost!.getBoundingClientRect());
125+ expect ( detail . state . ghost ) . to . eql ( tileDOM . resizeGhost ) ;
120126 } ) ;
121127
122- xit ( 'should set the styles on the tile and remove the ghost element on resize end' , async ( ) => {
123- const tile = first ( tileManager . tiles ) ;
124- const eventSpy = spy ( tile , 'emitEvent' ) ;
128+ it ( 'should set the styles on the tile and remove the ghost element on resize end' , async ( ) => {
129+ const tile = first ( getTiles ( ) ) ;
130+ const tileDOM = getTileDOM ( tile ) ;
131+ const tileRect = tile . getBoundingClientRect ( ) ;
132+ const eventSpy = spy ( tileDOM . resizeElement , 'emitEvent' ) ;
125133
126- const { x , y , width , height } = tile . getBoundingClientRect ( ) ;
127- const resizeHandle = tile . shadowRoot ! . querySelector ( '.resize-handle' ) ;
134+ simulatePointerDown ( tileDOM . resizeTrigger ) ;
135+ await elementUpdated ( tileDOM . resizeElement ) ;
128136
129- simulatePointerDown ( resizeHandle ! ) ;
130- await elementUpdated ( resizeHandle ! ) ;
137+ expect ( eventSpy ) . calledWith ( 'igcResizeStart' ) ;
131138
132- simulatePointerMove ( resizeHandle ! , {
133- clientX : x + width * 2 ,
134- clientY : y + height * 2 ,
139+ simulatePointerMove ( tileDOM . resizeTrigger , {
140+ clientX : ( tileRect . x + tileRect . width ) * 2 ,
141+ clientY : ( tileRect . y + tileRect . height ) * 2 ,
135142 } ) ;
136- await elementUpdated ( resizeHandle ! ) ;
137-
138- let ghostElement = tileManager . querySelector ( '#resize-ghost' ) ;
139- const ghostGridColumn = ( ghostElement ! as HTMLElement ) . style . gridColumn ;
140- const ghostGridRow = ( ghostElement ! as HTMLElement ) . style . gridRow ;
143+ await elementUpdated ( tileDOM . resizeElement ) ;
141144
142- simulateLostPointerCapture ( resizeHandle ! ) ;
143- await elementUpdated ( resizeHandle ! ) ;
145+ expect ( eventSpy ) . calledWith ( 'igcResize' ) ;
144146
145- expect ( eventSpy ) . calledWith ( 'igcResizeEnd' , {
146- detail : tile ,
147- cancelable : true ,
148- } ) ;
147+ simulateLostPointerCapture ( tileDOM . resizeTrigger ) ;
148+ await elementUpdated ( tileDOM . resizeElement ) ;
149149
150- ghostElement = tileManager . querySelector ( '#resize-ghost' ) ;
151- expect ( tile . style . gridColumn ) . to . equal ( ghostGridColumn ) ;
152- expect ( tile . style . gridRow ) . to . equal ( ghostGridRow ) ;
153- expect ( ghostElement ) . to . be . null ;
150+ const resizeCall = eventSpy . getCall ( 2 ) ;
151+ expect ( resizeCall ) . to . exist ;
152+ expect ( resizeCall . args [ 0 ] ) . to . equal ( 'igcResizeEnd' ) ;
153+
154+ const { detail } = resizeCall
155+ . args [ 1 ] as CustomEvent < ResizeCallbackParams > ;
156+ expect ( detail ) . to . not . be . null ;
157+ expect ( detail . event ) . to . be . an . instanceOf ( PointerEvent ) ;
158+ expect ( detail . state . initial ) . to . eql ( tileRect ) ; // Should the initial be the current of resizeMove i.e. the updated tile?
159+ // FIXME
160+ //expect(detail.state.ghost).to.eql(tileDOM.resizeGhost); // Should the detail.state.ghost be null here
161+ expect ( tileDOM . resizeGhost ) . to . be . null ;
162+ expect ( tile . getBoundingClientRect ( ) . width ) . to . be . greaterThan (
163+ tileRect . width
164+ ) ;
165+ expect ( tile . getBoundingClientRect ( ) . height ) . to . be . greaterThan (
166+ tileRect . height
167+ ) ;
154168 } ) ;
155169
156- it . skip ( 'should cancel resize by pressing ESC key' , async ( ) => {
157- const tile = first ( tileManager . tiles ) ;
158- const { x, y, width, height } = tile . getBoundingClientRect ( ) ;
159- const resizeHandle = tile . shadowRoot ! . querySelector ( '.resize-handle' ) ! ;
170+ it ( 'should cancel resize by pressing ESC key' , async ( ) => {
171+ const tile = first ( getTiles ( ) ) ;
172+ const tileDOM = getTileDOM ( tile ) ;
173+ const tileRect = tile . getBoundingClientRect ( ) ;
174+ const eventSpy = spy ( tileDOM . resizeElement , 'emitEvent' ) ;
160175
161- simulatePointerDown ( resizeHandle ) ;
162- await elementUpdated ( resizeHandle ) ;
176+ simulatePointerDown ( tileDOM . resizeTrigger ) ;
177+ await elementUpdated ( tileDOM . resizeElement ) ;
163178
164- simulatePointerMove ( resizeHandle ! , {
165- clientX : x + width * 2 ,
166- clientY : y + height * 2 ,
179+ expect ( eventSpy ) . calledWith ( 'igcResizeStart' ) ;
180+
181+ simulatePointerMove ( tileDOM . resizeTrigger , {
182+ clientX : ( tileRect . x + tileRect . width ) * 2 ,
183+ clientY : ( tileRect . y + tileRect . height ) * 2 ,
167184 } ) ;
168- await elementUpdated ( resizeHandle ) ;
185+ await elementUpdated ( tileDOM . resizeElement ) ;
169186
170- let ghostElement = tileManager . querySelector ( '#resize-ghost' ) ;
171- expect ( ghostElement ) . not . to . be . null ;
187+ expect ( tileDOM . resizeGhost ) . not . to . be . null ;
172188
173- simulateKeyboard ( resizeHandle , escapeKey ) ;
174- await elementUpdated ( resizeHandle ) ;
189+ simulateKeyboard ( tileDOM . resizeElement , escapeKey ) ;
190+ await elementUpdated ( tileDOM . resizeElement ) ;
175191
176- ghostElement = tileManager . querySelector ( '#resize-ghost' ) ;
177- expect ( ghostElement ) . to . be . null ;
178- expect ( tile . style . gridColumn ) . to . equal ( '' ) ;
179- expect ( tile . style . gridRow ) . to . equal ( '' ) ;
192+ expect ( tileDOM . resizeGhost ) . to . be . null ;
193+ expect ( tile . getBoundingClientRect ( ) ) . to . eql ( tileRect ) ;
180194 } ) ;
181195
182- xit ( 'should not resize when `disableResize` is true' , async ( ) => {
183- const tile = first ( tileManager . tiles ) ;
184- const { x, y, width, height } = tile . getBoundingClientRect ( ) ;
185- const resizeHandle = tile . shadowRoot ! . querySelector (
186- '.resize-handle'
187- ) ! as HTMLElement ;
188- const eventSpy = spy ( tile , 'emitEvent' ) ;
189- const tileWrapper = getTileBaseWrapper ( tile ) ;
196+ it ( 'should not have resizeElement when `disableResize` is true' , async ( ) => {
197+ const tile = first ( getTiles ( ) ) ;
198+ const tileDOM = getTileDOM ( tile ) ;
190199
191- expect ( tileWrapper . getAttribute ( 'part' ) ) . to . include ( 'resizable' ) ;
192- expect ( resizeHandle . hasAttribute ( 'hidden' ) ) . to . be . false ;
200+ expect ( tileDOM . resizeElement ) . to . exist ;
193201
194202 tile . disableResize = true ;
195203 await elementUpdated ( tile ) ;
196204
197- expect ( tileWrapper . getAttribute ( 'part' ) ) . to . not . include ( 'resizable' ) ;
198- expect ( resizeHandle . hasAttribute ( 'hidden' ) ) . to . be . true ;
199-
200- simulatePointerDown ( resizeHandle ) ;
201- await elementUpdated ( resizeHandle ) ;
202-
203- expect ( eventSpy ) . not . calledWith ( 'igcResizeStart' ) ;
204-
205- simulatePointerMove ( resizeHandle ! , {
206- clientX : x + width * 2 ,
207- clientY : y + height * 2 ,
208- } ) ;
209- await elementUpdated ( tile ) ;
210-
211- expect ( eventSpy ) . not . calledWith ( 'igcResizeMove' ) ;
212-
213- const ghostElement = tileManager . querySelector ( '#resize-ghost' ) ;
214- expect ( ghostElement ) . to . be . null ;
215-
216- simulateLostPointerCapture ( resizeHandle ! ) ;
217- await elementUpdated ( resizeHandle ! ) ;
218-
219- expect ( eventSpy ) . not . calledWith ( 'igcResizeEnd' ) ;
205+ expect ( tileDOM . resizeElement ) . to . not . exist ;
220206 } ) ;
221207 } ) ;
222208} ) ;
0 commit comments