1
1
import { Model } from "../../src" ;
2
+ import { args , functionRegistry } from "../../src/functions" ;
2
3
import { toZone } from "../../src/helpers" ;
3
4
import { SearchOptions } from "../../src/plugins/ui_feature/find_and_replace" ;
4
5
import {
@@ -52,28 +53,6 @@ describe("basic search", () => {
52
53
expect ( model . getters . getSelection ( ) . zones ) . toEqual ( [ toZone ( "A6" ) ] ) ;
53
54
} ) ;
54
55
55
- test ( "modifying cells won't change the search" , ( ) => {
56
- model . dispatch ( "UPDATE_SEARCH" , { toSearch : "1" , searchOptions } ) ;
57
- let matches = model . getters . getSearchMatches ( ) ;
58
- let matchIndex = model . getters . getCurrentSelectedMatchIndex ( ) ;
59
- expect ( matches . length ) . toBe ( 4 ) ;
60
- expect ( matchIndex ) . toStrictEqual ( 0 ) ;
61
- expect ( matches [ 0 ] ) . toStrictEqual ( { col : 0 , row : 1 , selected : true } ) ;
62
- expect ( matches [ 1 ] ) . toStrictEqual ( { col : 0 , row : 2 , selected : false } ) ;
63
- expect ( matches [ 2 ] ) . toStrictEqual ( { col : 0 , row : 3 , selected : false } ) ;
64
- expect ( matches [ 3 ] ) . toStrictEqual ( { col : 0 , row : 4 , selected : false } ) ;
65
- setCellContent ( model , "A2" , "hello" ) ;
66
- setCellContent ( model , "B1" , "1" ) ;
67
- matches = model . getters . getSearchMatches ( ) ;
68
- matchIndex = model . getters . getCurrentSelectedMatchIndex ( ) ;
69
- expect ( matches . length ) . toBe ( 4 ) ;
70
- expect ( matchIndex ) . toStrictEqual ( 0 ) ;
71
- expect ( matches [ 0 ] ) . toStrictEqual ( { col : 0 , row : 1 , selected : true } ) ;
72
- expect ( matches [ 1 ] ) . toStrictEqual ( { col : 0 , row : 2 , selected : false } ) ;
73
- expect ( matches [ 2 ] ) . toStrictEqual ( { col : 0 , row : 3 , selected : false } ) ;
74
- expect ( matches [ 3 ] ) . toStrictEqual ( { col : 0 , row : 4 , selected : false } ) ;
75
- } ) ;
76
-
77
56
test ( "change the search" , async ( ) => {
78
57
model . dispatch ( "UPDATE_SEARCH" , { toSearch : "hello" , searchOptions } ) ;
79
58
model . dispatch ( "SELECT_SEARCH_NEXT_MATCH" ) ;
@@ -95,6 +74,54 @@ describe("basic search", () => {
95
74
expect ( matches [ 3 ] ) . toStrictEqual ( { col : 0 , row : 4 , selected : false } ) ;
96
75
} ) ;
97
76
77
+ test ( "refresh search when cell is updated" , async ( ) => {
78
+ model . dispatch ( "UPDATE_SEARCH" , { toSearch : "hello" , searchOptions } ) ;
79
+ let matches = model . getters . getSearchMatches ( ) ;
80
+ let matchIndex = model . getters . getCurrentSelectedMatchIndex ( ) ;
81
+ expect ( matches ) . toHaveLength ( 2 ) ;
82
+ expect ( matchIndex ) . toStrictEqual ( 0 ) ;
83
+ expect ( matches [ 0 ] ) . toStrictEqual ( { col : 0 , row : 0 , selected : true } ) ;
84
+ expect ( matches [ 1 ] ) . toStrictEqual ( { col : 0 , row : 1 , selected : false } ) ;
85
+ setCellContent ( model , "B1" , "hello" ) ;
86
+ setCellContent ( model , "B2" , '="hello"' ) ;
87
+ matches = model . getters . getSearchMatches ( ) ;
88
+ matchIndex = model . getters . getCurrentSelectedMatchIndex ( ) ;
89
+ expect ( matches ) . toHaveLength ( 4 ) ;
90
+ expect ( matchIndex ) . toStrictEqual ( 0 ) ;
91
+ expect ( matches [ 0 ] ) . toStrictEqual ( { col : 0 , row : 0 , selected : true } ) ;
92
+ expect ( matches [ 1 ] ) . toStrictEqual ( { col : 1 , row : 0 , selected : false } ) ;
93
+ expect ( matches [ 2 ] ) . toStrictEqual ( { col : 0 , row : 1 , selected : false } ) ;
94
+ expect ( matches [ 3 ] ) . toStrictEqual ( { col : 1 , row : 1 , selected : false } ) ;
95
+ } ) ;
96
+
97
+ test ( "refresh search when cell is update with EVALUATE_CELLS" , async ( ) => {
98
+ model . dispatch ( "UPDATE_SEARCH" , { toSearch : "hello" , searchOptions } ) ;
99
+ let matches = model . getters . getSearchMatches ( ) ;
100
+ let matchIndex = model . getters . getCurrentSelectedMatchIndex ( ) ;
101
+ expect ( matches ) . toHaveLength ( 2 ) ;
102
+ expect ( matchIndex ) . toStrictEqual ( 0 ) ;
103
+ expect ( matches [ 0 ] ) . toStrictEqual ( { col : 0 , row : 0 , selected : true } ) ;
104
+ expect ( matches [ 1 ] ) . toStrictEqual ( { col : 0 , row : 1 , selected : false } ) ;
105
+ let value = "3" ;
106
+ functionRegistry . add ( "GETVALUE" , {
107
+ description : "Get value" ,
108
+ compute : ( ) => value ,
109
+ args : args ( `` ) ,
110
+ returns : [ "NUMBER" ] ,
111
+ } ) ;
112
+ setCellContent ( model , "B1" , "=GETVALUE()" ) ;
113
+ value = '="hello"' ;
114
+ model . dispatch ( "EVALUATE_CELLS" , { sheetId : model . getters . getActiveSheetId ( ) } ) ;
115
+ matches = model . getters . getSearchMatches ( ) ;
116
+ matchIndex = model . getters . getCurrentSelectedMatchIndex ( ) ;
117
+ expect ( getCellContent ( model , "B1" ) ) . toBe ( '="hello"' ) ;
118
+ expect ( matches ) . toHaveLength ( 3 ) ;
119
+ expect ( matchIndex ) . toStrictEqual ( 0 ) ;
120
+ expect ( matches [ 0 ] ) . toStrictEqual ( { col : 0 , row : 0 , selected : true } ) ;
121
+ expect ( matches [ 1 ] ) . toStrictEqual ( { col : 1 , row : 0 , selected : false } ) ;
122
+ expect ( matches [ 2 ] ) . toStrictEqual ( { col : 0 , row : 1 , selected : false } ) ;
123
+ } ) ;
124
+
98
125
test ( "search on empty string does not match anything" , ( ) => {
99
126
model . dispatch ( "UPDATE_SEARCH" , { toSearch : "" , searchOptions } ) ;
100
127
expect ( model . getters . getSearchMatches ( ) ) . toHaveLength ( 0 ) ;
0 commit comments