1+ import { CHECKBOX_CHECKED } from "@odoo/o-spreadsheet-engine/components/icons/icons" ;
12import {
23 DEFAULT_CELL_HEIGHT ,
34 DEFAULT_CELL_WIDTH ,
@@ -6,7 +7,11 @@ import {
67 MIN_CELL_TEXT_MARGIN ,
78} from "@odoo/o-spreadsheet-engine/constants" ;
89import { Model } from "@odoo/o-spreadsheet-engine/model" ;
9- import { Spreadsheet } from "../../src" ;
10+ import {
11+ GridIcon ,
12+ iconsOnCellRegistry ,
13+ } from "@odoo/o-spreadsheet-engine/registries/icons_on_cell_registry" ;
14+ import { Align , Spreadsheet } from "../../src" ;
1015import { toZone } from "../../src/helpers" ;
1116import { clickableCellRegistry } from "../../src/registries/cell_clickable_registry" ;
1217import {
@@ -221,4 +226,74 @@ describe("Grid component in dashboard mode", () => {
221226 "hello Magical Françoise"
222227 ) ;
223228 } ) ;
229+
230+ const TEST_GRID_ICON : GridIcon = {
231+ horizontalAlign : "left" ,
232+ size : 20 ,
233+ margin : 2 ,
234+ type : "debug_icon" ,
235+ position : { sheetId : "s1" , col : 0 , row : 0 } ,
236+ priority : 1 ,
237+ svg : CHECKBOX_CHECKED ,
238+ onClick : ( ) => { } ,
239+ } ;
240+
241+ test ( "Clickable cell size is reduced based on the icon on the cell" , async ( ) => {
242+ let horizontalAlign : Exclude < Align , undefined > = "center" ;
243+
244+ addToRegistry ( clickableCellRegistry , "fake" , {
245+ condition : ( position , getters ) => position . row === 0 && position . col === 0 ,
246+ execute : ( ) => ( ) => { } ,
247+ sequence : 5 ,
248+ } ) ;
249+ addToRegistry ( iconsOnCellRegistry , "test_icon" , ( getters , position ) =>
250+ position . col === 0 && position . row === 0 ? { ...TEST_GRID_ICON , horizontalAlign } : undefined
251+ ) ;
252+
253+ model . updateMode ( "dashboard" ) ;
254+ await nextTick ( ) ;
255+
256+ expect ( "div.o-dashboard-clickable-cell" ) . toHaveCount ( 0 ) ; // because center icon => no clickable cell
257+
258+ horizontalAlign = "right" ;
259+ model . dispatch ( "EVALUATE_CELLS" ) ;
260+ await nextTick ( ) ;
261+ expect ( "div.o-dashboard-clickable-cell" ) . toHaveStyle ( {
262+ left : "0px" ,
263+ width : DEFAULT_CELL_WIDTH - TEST_GRID_ICON . size - TEST_GRID_ICON . margin + "px" ,
264+ height : DEFAULT_CELL_HEIGHT + "px" ,
265+ } ) ;
266+
267+ horizontalAlign = "left" ;
268+ model . dispatch ( "EVALUATE_CELLS" ) ;
269+ await nextTick ( ) ;
270+ expect ( "div.o-dashboard-clickable-cell" ) . toHaveStyle ( {
271+ left : 20 + 2 + "px" ,
272+ width : DEFAULT_CELL_WIDTH - TEST_GRID_ICON . size - TEST_GRID_ICON . margin + "px" ,
273+ height : DEFAULT_CELL_HEIGHT + "px" ,
274+ } ) ;
275+ } ) ;
276+
277+ test ( "Clickable cell size is not reduced if the icon has no onClick action" , async ( ) => {
278+ addToRegistry ( clickableCellRegistry , "fake" , {
279+ condition : ( position , getters ) => position . row === 0 && position . col === 0 ,
280+ execute : ( ) => ( ) => { } ,
281+ sequence : 5 ,
282+ } ) ;
283+ addToRegistry ( iconsOnCellRegistry , "test_icon" , ( getters , position ) =>
284+ position . col === 0 && position . row === 0
285+ ? { ...TEST_GRID_ICON , onClick : undefined }
286+ : undefined
287+ ) ;
288+
289+ model . updateMode ( "dashboard" ) ;
290+ await nextTick ( ) ;
291+ await nextTick ( ) ; // Need to wait one render to have correct grid position with the resize observers
292+
293+ expect ( "div.o-dashboard-clickable-cell" ) . toHaveStyle ( {
294+ left : "0px" ,
295+ width : DEFAULT_CELL_WIDTH + "px" ,
296+ height : DEFAULT_CELL_HEIGHT + "px" ,
297+ } ) ;
298+ } ) ;
224299} ) ;
0 commit comments