buli
2023-07-11 80a3f59e2d3df07805bc67e329300b8de90a5b3a
force-app/main/default/classes/LayoutDescriberHelperTest.cls
@@ -1,90 +1,102 @@
@isTest
private class LayoutDescriberHelperTest {
    static testMethod void testMethod1() {
       String userMode = 'classic';//classic  lightning
       String objectType = 'Contact';
       String recordTypeId = Schema.SObjectType.Contact.getRecordTypeInfosByDeveloperName().get('Doctor').getRecordTypeId();
        String userMode = 'classic'; //classic  lightning
        String objectType = 'Contact';
        String recordTypeId = Schema.SObjectType.Contact.getRecordTypeInfosByDeveloperName().get('Doctor').getRecordTypeId();
        System.debug('record type id ===>' + recordTypeId + ' object type===>' + objectType + ' userMode===>' + userMode);
        boolean useHeader = false;
        String baseurl = System.URL.getOrgDomainUrl().getHost();
        Map<String, object> detailsMap = new Map<String, object>();
        Map<String, object> detailsMap2 = new Map<String, object>();
        Map<String, object> detailsMap3 = new Map<String, object>();
        detailsMap.put('calculated', true);
        detailsMap.put('autoNumber', false);
        detailsMap.put('type', 'address');
        detailsMap2.put('calculated', false);
        detailsMap2.put('autoNumber', false);
        detailsMap2.put('type', 'repair');
        detailsMap3.put('calculated', false);
        detailsMap3.put('autoNumber', false);
        detailsMap3.put('type', 'repair');
        String fieldTypeDetail = (String) detailsMap.get('type');
       Map<String,object> detailsMap = new Map<String,object>();
       Map<String,object> detailsMap2 = new Map<String,object>();
       Map<String,object> detailsMap3 = new Map<String,object>();
       detailsMap.put('calculated',true);
       detailsMap.put('autoNumber',false);
       detailsMap.put('type','address');
       detailsMap2.put('calculated',false);
       detailsMap2.put('autoNumber',false);
       detailsMap2.put('type','repair');
       detailsMap3.put('calculated',false);
       detailsMap3.put('autoNumber',false);
       detailsMap3.put('type','repair');
        List<Map<String, object>> componentMapList = new List<Map<String, object>>();
        List<Map<String, object>> componentMapList2 = new List<Map<String, object>>();
        List<Map<String, object>> componentMapList3 = new List<Map<String, object>>();
        Map<String, object> componentMap = new Map<String, object>();
        Map<String, object> componentMap2 = new Map<String, object>();
        Map<String, object> componentMap3 = new Map<String, object>();
        componentMap.put('value', 'Name');
        componentMap.put('type', 'Field');
        componentMap.put('details', detailsMap);
        componentMapList.add(componentMap);
        componentMap2.put('value', 'Name');
        componentMap2.put('type', 'Field');
        componentMap2.put('details', detailsMap2);
        componentMapList2.add(componentMap2);
        componentMap3.put('value', 'LastName');
        componentMap3.put('type', 'Field');
        componentMap3.put('details', detailsMap3);
        componentMapList3.add(componentMap3);
        String apiName = (String) componentMap.get('value');
        String fieldType = (String) componentMap.get('type');
       List<Map<String, object>> componentMapList = new List<Map<String, object>>();
       List<Map<String, object>> componentMapList2 = new List<Map<String, object>>();
       List<Map<String, object>> componentMapList3 = new List<Map<String, object>>();
       Map<String, object> componentMap = new Map<String, object>();
       Map<String, object> componentMap2 = new Map<String, object>();
       Map<String, object> componentMap3 = new Map<String, object>();
       componentMap.put('value','Name');
       componentMap.put('type','Field');
       componentMap.put('details',detailsMap);
       componentMapList.add(componentMap);
       componentMap2.put('value','Name');
       componentMap2.put('type','Field');
       componentMap2.put('details',detailsMap2);
       componentMapList2.add(componentMap2);
       componentMap3.put('value','LastName');
       componentMap3.put('type','Field');
       componentMap3.put('details',detailsMap3);
       componentMapList3.add(componentMap3);
        List<Map<String, object>> layoutComponentsList = new List<Map<String, object>>();
        Map<String, object> layoutComponents = new Map<String, object>();
        layoutComponents.put('layoutComponents', componentMapList);
        layoutComponents.put('label', 'Address');
        layoutComponents.put('placeholder', true);
        layoutComponents.put('editableForNew', true);
        layoutComponents.put('editableForUpdate', true);
        layoutComponents.put('required', false);
        layoutComponentsList.add(layoutComponents);
        Map<String, object> layoutComponents2 = new Map<String, object>();
        layoutComponents2.put('layoutComponents', componentMapList2);
        layoutComponents2.put('label', 'Repair');
        layoutComponents2.put('placeholder', true);
        layoutComponents2.put('editableForNew', true);
        layoutComponents2.put('editableForUpdate', true);
        layoutComponents2.put('required', false);
        layoutComponentsList.add(layoutComponents2);
        Map<String, object> layoutComponents3 = new Map<String, object>();
        layoutComponents3.put('layoutComponents', componentMapList3);
        layoutComponents3.put('label', 'Repair');
        layoutComponents3.put('placeholder', true);
        layoutComponents3.put('editableForNew', true);
        layoutComponents3.put('editableForUpdate', true);
        layoutComponents3.put('required', false);
        layoutComponentsList.add(layoutComponents3);
       List<Map<String, object>> layoutComponentsList = new List<Map<String, object>>();
       Map<String, object> layoutComponents = new Map<String, object>();
       layoutComponents.put('layoutComponents',componentMapList);
       layoutComponents.put('label','Address');
       layoutComponents.put('placeholder',true);
       layoutComponents.put('editableForNew',true);
       layoutComponents.put('required',false);
       layoutComponentsList.add(layoutComponents);
       Map<String, object> layoutComponents2 = new Map<String, object>();
       layoutComponents2.put('layoutComponents',componentMapList2);
       layoutComponents2.put('label','Repair');
       layoutComponents2.put('placeholder',true);
       layoutComponents2.put('editableForNew',true);
       layoutComponents2.put('required',false);
       layoutComponentsList.add(layoutComponents2);
       Map<String, object> layoutComponents3 = new Map<String, object>();
       layoutComponents3.put('layoutComponents',componentMapList3);
       layoutComponents3.put('label','Repair');
       layoutComponents3.put('placeholder',true);
       layoutComponents3.put('editableForNew',true);
       layoutComponents3.put('required',false);
       layoutComponentsList.add(layoutComponents3);
        boolean placeholderF = (boolean) layoutComponents.get('placeholder');
        boolean isEditable = (boolean) layoutComponents.get('editableForUpdate') || (boolean) layoutComponents.get('editableForNew');
        System.debug('isEditable ===>' + isEditable);
        List<Map<String, object>> itemList = new List<Map<String, object>>();
        Map<String, object> item = new Map<String, object>();
        item.put('layoutItems', layoutComponentsList);
        itemList.add(item);
        useHeader = true;
        List<Map<String, object>> sectionList = new List<Map<String, object>>();
        Map<String, object> section = new Map<String, object>();
        section.put('heading', '');
        section.put('useHeading', useHeader);
        section.put('columns', 1);
        section.put('useCollapsibleSection', true);
        section.put('layoutRows', itemList);
        sectionList.add(section);
       List<Map<String,object>> itemList = new List<Map<String,object>>();
       Map<String,object> item = new Map<String,object>();
       item.put('layoutItems',layoutComponentsList);
       itemList.add(item);
       List<Map<String,object>> sectionList = new List<Map<String,object>>();
       Map<String,object> section = new Map<String,object>();
       section.put('heading','');
       section.put('useHeading',true);
       section.put('columns',1);
       section.put('useCollapsibleSection',true);
       section.put('layoutRows',itemList);
       sectionList.add(section);
      Map<String, Object> layoutSection = new Map<String,Object>();
       layoutSection.put('layouts','123');
       layoutSection.put('editLayoutSections',sectionList);
      String layoutSectionJson = JSON.serialize(layoutSection);
      LayoutDescriberHelper.ControllerUtil();
        Test.setMock(HttpCalloutMock.class, new TestDataUtility.BaseHttpMock(layoutSectionJson,'OK','200'));
        Map<String, Object> layoutSection = new Map<String, Object>();
        layoutSection.put('layouts', '123');
        layoutSection.put('editLayoutSections', sectionList);
        String layoutSectionJson = JSON.serialize(layoutSection);
        LayoutDescriberHelper.ControllerUtil();
        Test.setMock(HttpCalloutMock.class, new TestDataUtility.BaseHttpMock(layoutSectionJson, 'OK', '200'));
        Test.startTest();
        LayoutDescriberHelper.describeSectionWithFieldsWrapper(recordTypeId,objectType,userMode);
        LayoutDescriberHelper.describeSectionWithFieldsWrapper(null,objectType,userMode);
        LayoutDescriberHelper.describeSectionWithFieldsWrapper(recordTypeId, objectType, userMode);
        LayoutDescriberHelper.describeSectionWithFieldsWrapper(null, objectType, userMode);
        LayoutDescriberHelper.describeSectionWithFields(recordTypeId, objectType, userMode);
        LayoutDescriberHelper.getLayoutSchema(recordTypeId, objectType, userMode);
        LayoutDescriberHelper.getUrlPrefix();
        Test.stopTest();
    }
}
}