@@ -5,55 +5,92 @@ import {
55 ZOOM_VALUES ,
66} from "@odoo/o-spreadsheet-engine/constants" ;
77import { setCellContent } from "./test_helpers/commands_helpers" ;
8- import { clickCell , clickHeader } from "./test_helpers/dom_helper" ;
8+ import { clickCell , clickHeader , hoverCell } from "./test_helpers/dom_helper" ;
99import { getSelectionAnchorCellXc } from "./test_helpers/getters_helpers" ;
10- import { mountSpreadsheet } from "./test_helpers/helpers" ;
10+ import { mountSpreadsheet , nextTick } from "./test_helpers/helpers" ;
1111
1212let fixture : HTMLElement ;
1313let model : Model ;
1414
15- describe . each ( ZOOM_VALUES . map ( ( zoom ) => zoom / 100 ) ) ( "Zoom tests selection %s" , ( zoom ) => {
16- beforeEach ( async ( ) => {
17- ( { model, fixture } = await mountSpreadsheet ( ) ) ;
18- model . dispatch ( "SET_ZOOM" , { zoom } ) ;
19- } ) ;
20- test ( "can render a sheet with zoom" , async ( ) => {
21- expect ( fixture . querySelector ( ".o-grid-overlay" ) ) . not . toBeNull ( ) ;
22- } ) ;
15+ jest . useFakeTimers ( ) ;
2316
24- test ( "can click on a cell to select it" , async ( ) => {
25- setCellContent ( model , "B2" , "b2" ) ;
26- setCellContent ( model , "B3" , "b3" ) ;
27- await clickCell ( model , "C8" , { } , { clickInMiddle : true } ) ;
28- expect ( getSelectionAnchorCellXc ( model ) ) . toBe ( "C8" ) ;
29- } ) ;
17+ afterAll ( ( ) => {
18+ jest . useRealTimers ( ) ;
19+ } ) ;
3020
31- test ( "can click on the edge of a cell to select it" , async ( ) => {
32- setCellContent ( model , "B2" , "b2" ) ;
33- setCellContent ( model , "B3" , "b3" ) ;
34- // by default we click on top left
35- await clickCell ( model , "C8" ) ;
36- expect ( getSelectionAnchorCellXc ( model ) ) . toBe ( "C8" ) ;
37- await clickCell (
38- model ,
39- "C8" ,
40- { } ,
41- { offsetX : DEFAULT_CELL_WIDTH * zoom - 1 , offsetY : DEFAULT_CELL_HEIGHT * zoom - 1 }
42- ) ;
43- expect ( getSelectionAnchorCellXc ( model ) ) . toBe ( "C8" ) ;
44- } ) ;
21+ describe ( "Spreadsheet zoom tests" , ( ) => {
22+ describe . each ( ZOOM_VALUES . map ( ( zoom ) => zoom / 100 ) ) ( "Zoom tests selection %s" , ( zoom ) => {
23+ beforeEach ( async ( ) => {
24+ ( { model, fixture } = await mountSpreadsheet ( ) ) ;
25+ model . dispatch ( "SET_ZOOM" , { zoom } ) ;
26+ await nextTick ( ) ;
27+ } ) ;
28+ test ( "can render a sheet with zoom" , async ( ) => {
29+ expect ( fixture . querySelector ( ".o-grid-overlay" ) ) . not . toBeNull ( ) ;
30+ } ) ;
31+
32+ test ( "can click on a cell to select it" , async ( ) => {
33+ setCellContent ( model , "B2" , "b2" ) ;
34+ setCellContent ( model , "B3" , "b3" ) ;
35+ await clickCell ( model , "C8" , { } , { clickInMiddle : true } ) ;
36+ expect ( getSelectionAnchorCellXc ( model ) ) . toBe ( "C8" ) ;
37+ } ) ;
4538
46- test ( "can select a COL header" , async ( ) => {
47- setCellContent ( model , "B2" , "b2" ) ;
48- setCellContent ( model , "B3" , "b3" ) ;
49- await clickHeader ( model , "COL" , 2 , { } ) ;
50- expect ( getSelectionAnchorCellXc ( model ) ) . toBe ( "C1" ) ;
39+ test ( "can click on the edge of a cell to select it" , async ( ) => {
40+ setCellContent ( model , "B2" , "b2" ) ;
41+ setCellContent ( model , "B3" , "b3" ) ;
42+ // by default we click on top left
43+ await clickCell ( model , "C8" ) ;
44+ expect ( getSelectionAnchorCellXc ( model ) ) . toBe ( "C8" ) ;
45+ await clickCell (
46+ model ,
47+ "C8" ,
48+ { } ,
49+ { offsetX : DEFAULT_CELL_WIDTH * zoom - 1 , offsetY : DEFAULT_CELL_HEIGHT * zoom - 1 }
50+ ) ;
51+ expect ( getSelectionAnchorCellXc ( model ) ) . toBe ( "C8" ) ;
52+ } ) ;
53+
54+ test ( "can select a COL header" , async ( ) => {
55+ setCellContent ( model , "B2" , "b2" ) ;
56+ setCellContent ( model , "B3" , "b3" ) ;
57+ await clickHeader ( model , "COL" , 2 , { } ) ;
58+ expect ( getSelectionAnchorCellXc ( model ) ) . toBe ( "C1" ) ;
59+ } ) ;
60+
61+ test ( "can select a ROW header" , async ( ) => {
62+ setCellContent ( model , "B2" , "b2" ) ;
63+ setCellContent ( model , "B3" , "b3" ) ;
64+ await clickHeader ( model , "ROW" , 2 , { } ) ;
65+ expect ( getSelectionAnchorCellXc ( model ) ) . toBe ( "A4" ) ;
66+ } ) ;
67+
68+ test ( "can hover a cell to show its error" , async ( ) => {
69+ setCellContent ( model , "A10" , "=1/0" ) ;
70+ expect ( fixture . querySelector ( ".o-error-tooltip" ) ) . toBeFalsy ( ) ;
71+ await hoverCell ( model , "A10" , 400 ) ;
72+ expect ( fixture . querySelector ( ".o-error-tooltip" ) ) . toBeTruthy ( ) ;
73+ } ) ;
5174 } ) ;
75+ } ) ;
76+
77+ describe ( "Dashboard zoom tests" , ( ) => {
78+ describe . each ( ZOOM_VALUES . map ( ( zoom ) => zoom / 100 ) ) ( "Zoom tests selection %s" , ( zoom ) => {
79+ beforeEach ( async ( ) => {
80+ ( { model, fixture } = await mountSpreadsheet ( ) ) ;
81+ model . dispatch ( "SET_ZOOM" , { zoom } ) ;
82+ setCellContent ( model , "C8" , "=1/0" ) ;
83+ model . updateMode ( "dashboard" ) ;
84+ await nextTick ( ) ;
85+ } ) ;
86+ test ( "can render a sheet with zoom" , async ( ) => {
87+ expect ( fixture . querySelector ( ".o-grid-overlay" ) ) . not . toBeNull ( ) ;
88+ } ) ;
5289
53- test ( "can select a ROW header " , async ( ) => {
54- setCellContent ( model , "B2" , "b2" ) ;
55- setCellContent ( model , "B3 " , "b3" ) ;
56- await clickHeader ( model , "ROW" , 2 , { } ) ;
57- expect ( getSelectionAnchorCellXc ( model ) ) . toBe ( "A4" ) ;
90+ test ( "can hover a cell to show its error " , async ( ) => {
91+ expect ( fixture . querySelector ( ".o-error-tooltip" ) ) . toBeNull ( ) ;
92+ await hoverCell ( model , "C8 " , 400 ) ;
93+ expect ( fixture . querySelector ( ".o-error-tooltip" ) ) . toBeTruthy ( ) ;
94+ } ) ;
5895 } ) ;
5996} ) ;
0 commit comments