@@ -10,6 +10,7 @@ import {
1010 getDraggable ,
1111 getElementFromCell ,
1212 getRemoveButton ,
13+ getResizeHandle ,
1314 setGap ,
1415 setMaximumColumnWidth ,
1516 setMinimumColumnWidth ,
@@ -19,11 +20,11 @@ type TestDashboardItem = DashboardItem & { id: string; component?: Element | str
1920
2021describe ( 'dashboard' , ( ) => {
2122 let dashboard : Dashboard < TestDashboardItem > ;
22- const columnWidth = 100 ;
23+ const columnWidth = 200 ;
2324
2425 beforeEach ( async ( ) => {
2526 dashboard = fixtureSync ( '<vaadin-dashboard></vaadin-dashboard>' ) ;
26- dashboard . style . width = `${ columnWidth * 100 } px` ;
27+ dashboard . style . width = `${ columnWidth * 2 } px` ;
2728 setMinimumColumnWidth ( dashboard , columnWidth ) ;
2829 setMaximumColumnWidth ( dashboard , columnWidth ) ;
2930 setGap ( dashboard , 0 ) ;
@@ -51,7 +52,7 @@ describe('dashboard', () => {
5152 dashboard . items = [ ...dashboard . items , { id : 'Item 2' } ] ;
5253 await nextFrame ( ) ;
5354
54- const newWidget = getElementFromCell ( dashboard , 0 , 2 ) ;
55+ const newWidget = getElementFromCell ( dashboard , 1 , 0 ) ;
5556 expect ( newWidget ) . to . be . ok ;
5657 expect ( newWidget ?. localName ) . to . equal ( 'vaadin-dashboard-widget' ) ;
5758 expect ( newWidget ) . to . have . property ( 'widgetTitle' , 'Item 2 title' ) ;
@@ -220,6 +221,95 @@ describe('dashboard', () => {
220221 const draggable = getDraggable ( widget ) ;
221222 expect ( draggable . getBoundingClientRect ( ) . height ) . to . be . above ( 0 ) ;
222223 } ) ;
224+
225+ it ( 'should hide remove button by default' , ( ) => {
226+ const widget = getElementFromCell ( dashboard , 0 , 0 ) as DashboardWidget ;
227+ const removeButton = getRemoveButton ( widget ) ;
228+ expect ( removeButton . getBoundingClientRect ( ) . height ) . to . equal ( 0 ) ;
229+ } ) ;
230+
231+ it ( 'should unhide remove button when editable' , async ( ) => {
232+ dashboard . editable = true ;
233+ await nextFrame ( ) ;
234+ const widget = getElementFromCell ( dashboard , 0 , 0 ) as DashboardWidget ;
235+ const removeButton = getRemoveButton ( widget ) ;
236+ expect ( removeButton . getBoundingClientRect ( ) . height ) . to . be . above ( 0 ) ;
237+ } ) ;
238+
239+ it ( 'should hide resize handle by default' , ( ) => {
240+ const widget = getElementFromCell ( dashboard , 0 , 0 ) as DashboardWidget ;
241+ const resizeHandle = getResizeHandle ( widget ) ;
242+ expect ( resizeHandle . getBoundingClientRect ( ) . height ) . to . equal ( 0 ) ;
243+ } ) ;
244+
245+ it ( 'should unhide resize handle when editable' , async ( ) => {
246+ dashboard . editable = true ;
247+ await nextFrame ( ) ;
248+ const widget = getElementFromCell ( dashboard , 0 , 0 ) as DashboardWidget ;
249+ const resizeHandle = getResizeHandle ( widget ) ;
250+ expect ( resizeHandle . getBoundingClientRect ( ) . height ) . to . be . above ( 0 ) ;
251+ } ) ;
252+
253+ it ( 'should unhide resize handle when editable with a lazy renderer' , async ( ) => {
254+ // Assign a renderer that initially renders nothing
255+ const syncRenderer = dashboard . renderer ! ;
256+ dashboard . renderer = ( root , _ , model ) => {
257+ root . textContent = '' ;
258+ requestAnimationFrame ( ( ) => {
259+ syncRenderer ( root , _ , model ) ;
260+ } ) ;
261+ } ;
262+ await nextFrame ( ) ;
263+
264+ dashboard . editable = true ;
265+ await nextFrame ( ) ;
266+ const widget = getElementFromCell ( dashboard , 0 , 0 ) as DashboardWidget ;
267+ const resizeHandle = getResizeHandle ( widget ) ;
268+ expect ( resizeHandle . getBoundingClientRect ( ) . height ) . to . be . above ( 0 ) ;
269+ } ) ;
270+
271+ describe ( 'section' , ( ) => {
272+ beforeEach ( async ( ) => {
273+ dashboard . items = [
274+ { id : 'Item 0' } ,
275+ { id : 'Item 1' } ,
276+ { title : 'Section' , items : [ { id : 'Item 2' } , { id : 'Item 3' } ] } ,
277+ ] ;
278+ await nextFrame ( ) ;
279+ } ) ;
280+
281+ it ( 'should hide draggable handle by default' , ( ) => {
282+ const widget = getElementFromCell ( dashboard , 1 , 0 ) ! ;
283+ const section = widget . closest ( 'vaadin-dashboard-section' ) as DashboardSection ;
284+ const draggable = getDraggable ( section ) ;
285+ expect ( draggable . getBoundingClientRect ( ) . height ) . to . equal ( 0 ) ;
286+ } ) ;
287+
288+ it ( 'should unhide draggable handle when editable' , async ( ) => {
289+ dashboard . editable = true ;
290+ await nextFrame ( ) ;
291+ const widget = getElementFromCell ( dashboard , 1 , 0 ) ! ;
292+ const section = widget . closest ( 'vaadin-dashboard-section' ) as DashboardSection ;
293+ const draggable = getDraggable ( section ) ;
294+ expect ( draggable . getBoundingClientRect ( ) . height ) . to . be . above ( 0 ) ;
295+ } ) ;
296+
297+ it ( 'should hide remove button by default' , ( ) => {
298+ const widget = getElementFromCell ( dashboard , 1 , 0 ) as DashboardSection ;
299+ const section = widget . closest ( 'vaadin-dashboard-section' ) as DashboardSection ;
300+ const removeButton = getRemoveButton ( section ) ;
301+ expect ( removeButton . getBoundingClientRect ( ) . height ) . to . equal ( 0 ) ;
302+ } ) ;
303+
304+ it ( 'should unhide remove button when editable' , async ( ) => {
305+ dashboard . editable = true ;
306+ await nextFrame ( ) ;
307+ const widget = getElementFromCell ( dashboard , 1 , 0 ) as DashboardSection ;
308+ const section = widget . closest ( 'vaadin-dashboard-section' ) as DashboardSection ;
309+ const removeButton = getRemoveButton ( section ) ;
310+ expect ( removeButton . getBoundingClientRect ( ) . height ) . to . be . above ( 0 ) ;
311+ } ) ;
312+ } ) ;
223313 } ) ;
224314
225315 describe ( 'item components' , ( ) => {
@@ -347,5 +437,28 @@ describe('dashboard', () => {
347437 await nextFrame ( ) ;
348438 expect ( document . activeElement ) . to . equal ( getElementFromCell ( dashboard , 0 , 0 ) ! ) ;
349439 } ) ;
440+
441+ it ( 'should unhide resize handle when editable' , async ( ) => {
442+ getElementFromCell ( dashboard , 0 , 0 ) ! . focus ( ) ;
443+ await nextFrame ( ) ;
444+ dashboard . editable = true ;
445+ await nextFrame ( ) ;
446+ const widget = getElementFromCell ( dashboard , 0 , 0 ) as DashboardWidget ;
447+ const resizeHandle = getResizeHandle ( widget ) ;
448+ expect ( resizeHandle . getBoundingClientRect ( ) . height ) . to . be . above ( 0 ) ;
449+ } ) ;
450+
451+ it ( 'should unhide remove button of a section when editable' , async ( ) => {
452+ dashboard . items = [ { title : 'Section' , items : [ { id : 'Item 0' } ] } , { id : 'Item 1' } ] ;
453+ await nextFrame ( ) ;
454+ getElementFromCell ( dashboard , 0 , 0 ) ! . focus ( ) ;
455+ await nextFrame ( ) ;
456+ dashboard . editable = true ;
457+ await nextFrame ( ) ;
458+ const widget = getElementFromCell ( dashboard , 0 , 0 ) as DashboardWidget ;
459+ const section = widget . closest ( 'vaadin-dashboard-section' ) as DashboardSection ;
460+ const removeButton = getRemoveButton ( section ) ;
461+ expect ( removeButton . getBoundingClientRect ( ) . height ) . to . be . above ( 0 ) ;
462+ } ) ;
350463 } ) ;
351464} ) ;
0 commit comments