@@ -156,6 +156,71 @@ describe('OptionsListUtils', () => {
156
156
} ,
157
157
} ;
158
158
159
+ const activePolicyID = 'DEF456' ;
160
+
161
+ const WORKSPACE_CHATS : ReportUtils . OptionData [ ] = [
162
+ {
163
+ reportID : '1' ,
164
+ text : 'Google Workspace' ,
165
+ policyID : '11' ,
166
+ isPolicyExpenseChat : true ,
167
+ } ,
168
+ {
169
+ reportID : '2' ,
170
+ text : 'Google Drive Workspace' ,
171
+ policyID : '22' ,
172
+ isPolicyExpenseChat : false ,
173
+ } ,
174
+ {
175
+ reportID : '3' ,
176
+ text : 'Slack Team Workspace' ,
177
+ policyID : '33' ,
178
+ isPolicyExpenseChat : false ,
179
+ } ,
180
+ {
181
+ reportID : '4' ,
182
+ text : 'Slack Development Workspace' ,
183
+ policyID : '44' ,
184
+ isPolicyExpenseChat : true ,
185
+ } ,
186
+ {
187
+ reportID : '5' ,
188
+ text : 'Microsoft Teams Workspace' ,
189
+ policyID : '55' ,
190
+ isPolicyExpenseChat : false ,
191
+ } ,
192
+ {
193
+ reportID : '6' ,
194
+ text : 'Microsoft Project Workspace' ,
195
+ policyID : '66' ,
196
+ isPolicyExpenseChat : false ,
197
+ } ,
198
+ {
199
+ reportID : '7' ,
200
+ text : 'Notion Design Workspace' ,
201
+ policyID : '77' ,
202
+ isPolicyExpenseChat : false ,
203
+ } ,
204
+ {
205
+ reportID : '8' ,
206
+ text : 'Notion Workspace for Marketing' ,
207
+ policyID : activePolicyID ,
208
+ isPolicyExpenseChat : true ,
209
+ } ,
210
+ {
211
+ reportID : '9' ,
212
+ text : 'Asana Task Workspace' ,
213
+ policyID : '99' ,
214
+ isPolicyExpenseChat : false ,
215
+ } ,
216
+ {
217
+ reportID : '10' ,
218
+ text : 'Asana Project Management' ,
219
+ policyID : '1010' ,
220
+ isPolicyExpenseChat : true ,
221
+ } ,
222
+ ] ;
223
+
159
224
// And a set of personalDetails some with existing reports and some without
160
225
const PERSONAL_DETAILS : PersonalDetailsList = {
161
226
// These exist in our reports
@@ -379,6 +444,7 @@ describe('OptionsListUtils', () => {
379
444
total : 1000 ,
380
445
} ,
381
446
[ `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` as const ] : POLICY ,
447
+ [ ONYXKEYS . NVP_ACTIVE_POLICY_ID ] : activePolicyID ,
382
448
} ,
383
449
} ) ;
384
450
Onyx . registerLogger ( ( ) => { } ) ;
@@ -1053,4 +1119,135 @@ describe('OptionsListUtils', () => {
1053
1119
expect ( newReports . at ( 9 ) ?. subtitle ) . toBe ( 'Espacio de trabajo' ) ;
1054
1120
} ) ;
1055
1121
} ) ;
1122
+
1123
+ describe ( 'filterWorkspaceChats' , ( ) => {
1124
+ it ( 'should return an empty array if there are no workspace chats' , ( ) => {
1125
+ const result = OptionsListUtils . filterWorkspaceChats ( [ ] , [ ] ) ;
1126
+
1127
+ expect ( result . length ) . toEqual ( 0 ) ;
1128
+ } ) ;
1129
+
1130
+ it ( 'should return all workspace chats if there are no search terms' , ( ) => {
1131
+ const result = OptionsListUtils . filterWorkspaceChats ( WORKSPACE_CHATS , [ ] ) ;
1132
+
1133
+ expect ( result ) . toEqual ( WORKSPACE_CHATS ) ;
1134
+ expect ( result . length ) . toEqual ( WORKSPACE_CHATS . length ) ;
1135
+ } ) ;
1136
+
1137
+ it ( 'should filter multiple workspace chats by search term' , ( ) => {
1138
+ const result = OptionsListUtils . filterWorkspaceChats ( WORKSPACE_CHATS , [ 'Google' ] ) ;
1139
+
1140
+ expect ( result . length ) . toEqual ( 2 ) ;
1141
+ } ) ;
1142
+
1143
+ it ( 'should filter workspace chat by exact name' , ( ) => {
1144
+ const result = OptionsListUtils . filterWorkspaceChats ( WORKSPACE_CHATS , [ 'Microsoft' , 'Teams' , 'Workspace' ] ) ;
1145
+
1146
+ expect ( result . length ) . toEqual ( 1 ) ;
1147
+ } ) ;
1148
+
1149
+ it ( 'should return an empty array if there are no matching workspace chats' , ( ) => {
1150
+ const result = OptionsListUtils . filterWorkspaceChats ( WORKSPACE_CHATS , [ 'XYZ' ] ) ;
1151
+
1152
+ expect ( result . length ) . toEqual ( 0 ) ;
1153
+ } ) ;
1154
+ } ) ;
1155
+
1156
+ describe ( 'orderWorkspaceOptions' , ( ) => {
1157
+ it ( 'should put the default workspace on top of the list' , ( ) => {
1158
+ const result = OptionsListUtils . orderWorkspaceOptions ( WORKSPACE_CHATS ) ;
1159
+
1160
+ expect ( result . at ( 0 ) ?. text ) . toEqual ( 'Notion Workspace for Marketing' ) ;
1161
+ } ) ;
1162
+ } ) ;
1163
+
1164
+ describe ( 'filterSelfDMChat' , ( ) => {
1165
+ const REPORT = {
1166
+ reportID : '1' ,
1167
+ text : 'Google Workspace' ,
1168
+ policyID : '11' ,
1169
+ isPolicyExpenseChat : true ,
1170
+ } ;
1171
+ const LOGIN = '[email protected] ' ;
1172
+ const ALTERNATE_TEXT = 'John William Doe' ;
1173
+ const SUBTITLE = 'Software Engineer' ;
1174
+
1175
+ it ( 'should return the report when there are no search terms' , ( ) => {
1176
+ const result = OptionsListUtils . filterSelfDMChat ( REPORT , [ ] ) ;
1177
+
1178
+ expect ( result ?. reportID ) . toEqual ( REPORT . reportID ) ;
1179
+ } ) ;
1180
+
1181
+ it ( 'should return undefined, when the search term does not match the report' , ( ) => {
1182
+ const result = OptionsListUtils . filterSelfDMChat ( REPORT , [ 'XYZ' ] ) ;
1183
+
1184
+ expect ( result ) . toBeUndefined ( ) ;
1185
+ } ) ;
1186
+
1187
+ it ( 'should filter report by text' , ( ) => {
1188
+ const result = OptionsListUtils . filterSelfDMChat ( REPORT , [ 'Google' ] ) ;
1189
+
1190
+ expect ( result ?. reportID ) . toEqual ( REPORT . reportID ) ;
1191
+ } ) ;
1192
+
1193
+ it ( 'should filter report by exact text' , ( ) => {
1194
+ const result = OptionsListUtils . filterSelfDMChat ( REPORT , [ 'Google' , 'Workspace' ] ) ;
1195
+
1196
+ expect ( result ?. reportID ) . toEqual ( REPORT . reportID ) ;
1197
+ } ) ;
1198
+
1199
+ it ( 'should filter report by login' , ( ) => {
1200
+ const result = OptionsListUtils . filterSelfDMChat ( { ...REPORT , login : LOGIN } , [ 'john' ] ) ;
1201
+
1202
+ expect ( result ?. reportID ) . toEqual ( REPORT . reportID ) ;
1203
+ } ) ;
1204
+
1205
+ it ( 'should filter report by exact login' , ( ) => {
1206
+ const result = OptionsListUtils . filterSelfDMChat ( { ...REPORT , login : LOGIN } , [ LOGIN ] ) ;
1207
+
1208
+ expect ( result ?. reportID ) . toEqual ( REPORT . reportID ) ;
1209
+ } ) ;
1210
+
1211
+ it ( 'should filter report by alternate text' , ( ) => {
1212
+ const result = OptionsListUtils . filterSelfDMChat ( { ...REPORT , alternateText : ALTERNATE_TEXT , isThread : true } , [ 'William' ] ) ;
1213
+
1214
+ expect ( result ?. reportID ) . toEqual ( REPORT . reportID ) ;
1215
+ } ) ;
1216
+
1217
+ it ( 'should filter report by exact alternate text' , ( ) => {
1218
+ const result = OptionsListUtils . filterSelfDMChat ( { ...REPORT , alternateText : ALTERNATE_TEXT , isThread : true } , [ 'John' , 'William' , 'Doe' ] ) ;
1219
+
1220
+ expect ( result ?. reportID ) . toEqual ( REPORT . reportID ) ;
1221
+ } ) ;
1222
+
1223
+ it ( 'should filter report by alternate text if it is not a thread' , ( ) => {
1224
+ const result = OptionsListUtils . filterSelfDMChat ( { ...REPORT , alternateText : ALTERNATE_TEXT , isThread : false } , [ 'William' ] ) ;
1225
+
1226
+ expect ( result ?. reportID ) . toBeUndefined ( ) ;
1227
+ } ) ;
1228
+
1229
+ it ( 'should filter report by subtitle' , ( ) => {
1230
+ const result = OptionsListUtils . filterSelfDMChat ( { ...REPORT , subtitle : SUBTITLE } , [ 'Software' ] ) ;
1231
+
1232
+ expect ( result ?. reportID ) . toEqual ( REPORT . reportID ) ;
1233
+ } ) ;
1234
+
1235
+ it ( 'should filter report by exact subtitle' , ( ) => {
1236
+ const result = OptionsListUtils . filterSelfDMChat ( { ...REPORT , subtitle : SUBTITLE } , [ 'Software' , 'Engineer' ] ) ;
1237
+
1238
+ expect ( result ?. reportID ) . toEqual ( REPORT . reportID ) ;
1239
+ } ) ;
1240
+
1241
+ it ( 'should not filter report by subtitle if it is not an expense chat nor a chat room' , ( ) => {
1242
+ const result = OptionsListUtils . filterSelfDMChat ( { ...REPORT , subtitle : SUBTITLE , isPolicyExpenseChat : false , isChatRoom : false } , [ 'Software' ] ) ;
1243
+
1244
+ expect ( result ) . toBeUndefined ( ) ;
1245
+ } ) ;
1246
+
1247
+ it ( 'should filter report by subtitle if it is a chat room' , ( ) => {
1248
+ const result = OptionsListUtils . filterSelfDMChat ( { ...REPORT , subtitle : SUBTITLE , isPolicyExpenseChat : false , isChatRoom : true } , [ 'Software' ] ) ;
1249
+
1250
+ expect ( result ?. reportID ) . toEqual ( REPORT . reportID ) ;
1251
+ } ) ;
1252
+ } ) ;
1056
1253
} ) ;
0 commit comments