1010 * See the License for the specific language governing permissions and
1111 * limitations under the License.
1212 */
13+ import { MULTISELECT_FIELD_OPERATORS } from '../constants/AdvancedSearch.constants' ;
1314import { EntityFields } from '../enums/AdvancedSearch.enum' ;
1415import { SearchIndex } from '../enums/search.enum' ;
16+ import { CustomPropertySummary } from '../rest/metadataTypeAPI.interface' ;
1517import { AdvancedSearchClassBase } from './AdvancedSearchClassBase' ;
18+ import { getCustomPropertyAdvanceSearchEnumOptions } from './AdvancedSearchUtils' ;
19+ import { getEntityName } from './EntityUtils' ;
1620
1721jest . mock ( '../rest/miscAPI' , ( ) => ( {
1822 getAggregateFieldOptions : jest . fn ( ) . mockImplementation ( ( ) =>
@@ -26,6 +30,14 @@ jest.mock('./JSONLogicSearchClassBase', () => ({
2630 getQueryBuilderFields : jest . fn ( ) ,
2731} ) ) ;
2832
33+ jest . mock ( './EntityUtils' , ( ) => ( {
34+ getEntityName : jest . fn ( ) ,
35+ } ) ) ;
36+
37+ jest . mock ( './AdvancedSearchUtils' , ( ) => ( {
38+ getCustomPropertyAdvanceSearchEnumOptions : jest . fn ( ) ,
39+ } ) ) ;
40+
2941describe ( 'AdvancedSearchClassBase' , ( ) => {
3042 let advancedSearchClassBase : AdvancedSearchClassBase ;
3143
@@ -198,3 +210,62 @@ describe('getEntitySpecificQueryBuilderFields', () => {
198210 expect ( Object . keys ( result ) ) . toEqual ( [ ] ) ;
199211 } ) ;
200212} ) ;
213+
214+ describe ( 'getCustomPropertiesSubFields' , ( ) => {
215+ let advancedSearchClassBase : AdvancedSearchClassBase ;
216+ const mockGetEntityName = getEntityName as jest . Mock ;
217+ const mockGetCustomPropertyAdvanceSearchEnumOptions =
218+ getCustomPropertyAdvanceSearchEnumOptions as jest . Mock ;
219+
220+ beforeEach ( ( ) => {
221+ advancedSearchClassBase = new AdvancedSearchClassBase ( ) ;
222+ jest . clearAllMocks ( ) ;
223+ } ) ;
224+
225+ it ( 'should return correct configuration for enum type custom property' , ( ) => {
226+ const mockField = {
227+ name : 'statusField' ,
228+ type : 'enum' ,
229+ customPropertyConfig : {
230+ config : {
231+ values : [ 'ACTIVE' , 'INACTIVE' , 'PENDING' ] ,
232+ } ,
233+ } ,
234+ } ;
235+
236+ const mockLabel = 'Status Field' ;
237+ const mockEnumOptions = [
238+ { value : 'ACTIVE' , title : 'Active' } ,
239+ { value : 'INACTIVE' , title : 'Inactive' } ,
240+ { value : 'PENDING' , title : 'Pending' } ,
241+ ] ;
242+
243+ mockGetEntityName . mockReturnValue ( mockLabel ) ;
244+ mockGetCustomPropertyAdvanceSearchEnumOptions . mockReturnValue (
245+ mockEnumOptions
246+ ) ;
247+
248+ const result = advancedSearchClassBase . getCustomPropertiesSubFields (
249+ mockField as CustomPropertySummary
250+ ) ;
251+
252+ expect ( mockGetEntityName ) . toHaveBeenCalledWith ( mockField ) ;
253+ expect ( mockGetCustomPropertyAdvanceSearchEnumOptions ) . toHaveBeenCalledWith ( [
254+ 'ACTIVE' ,
255+ 'INACTIVE' ,
256+ 'PENDING' ,
257+ ] ) ;
258+
259+ expect ( result ) . toEqual ( {
260+ subfieldsKey : 'statusField' ,
261+ dataObject : {
262+ type : 'multiselect' ,
263+ label : mockLabel ,
264+ operators : MULTISELECT_FIELD_OPERATORS ,
265+ fieldSettings : {
266+ listValues : mockEnumOptions ,
267+ } ,
268+ } ,
269+ } ) ;
270+ } ) ;
271+ } ) ;
0 commit comments