@isTest private class OPDSortManageControllerTest { public static User user = new User(); static testMethod void testMethod1() { // User user = [select id,Salesdepartment__c from User where Salesdepartment__c='1.华北' limit 1]; //OPD计划 OPDPlan__c oPDPlan1 = new OPDPlan__c(); oPDPlan1.Name = 'oPDPlan1'; oPDPlan1.Status__c = '计划中'; oPDPlan1.OPDPlan_ImplementDate__c = Date.today().addMonths(1); oPDPlan1.NoOpp_Reason__c = 'HCP对应'; //无询价理由 oPDPlan1.OPDLendSortDraft__c = 1; //备品借出优先度 oPDPlan1.OPDType__c = '事件'; // oPDPlan1.Owner = user.Id; insert oPDPlan1; OPDPlan__c oPDPlan2 = new OPDPlan__c(); oPDPlan2.Name = 'oPDPlan2'; oPDPlan2.Status__c = '计划中'; oPDPlan2.OPDPlan_ImplementDate__c = Date.today().addMonths(1); oPDPlan2.NoOpp_Reason__c = 'HCP对应'; oPDPlan2.OPDType__c = '事件'; insert oPDPlan2; OPDPlan__c oPDPlan3 = new OPDPlan__c(); oPDPlan3.Name = 'oPDPlan3'; oPDPlan3.Status__c = '计划中'; oPDPlan3.OPDPlan_ImplementDate__c = Date.today().addMonths(1); oPDPlan3.NoOpp_Reason__c = 'HCP对应'; oPDPlan3.OPDLendSortDraft__c = 2; oPDPlan3.OPDType__c = '事件'; insert oPDPlan3; OPDPlan__c oPDPlan4 = new OPDPlan__c(); oPDPlan4.Name = 'oPDPlan4'; oPDPlan4.Status__c = '计划中'; oPDPlan4.OPDPlan_ImplementDate__c = Date.today().addMonths(1); oPDPlan4.NoOpp_Reason__c = 'HCP对应'; oPDPlan4.OPDType__c = '事件'; insert oPDPlan4; OPDPlan__c oPDPlan5 = new OPDPlan__c(); oPDPlan5.Name = 'oPDPlan5'; oPDPlan5.Status__c = '计划中'; oPDPlan5.OPDPlan_ImplementDate__c = Date.today().addMonths(1); oPDPlan5.NoOpp_Reason__c = 'HCP对应'; oPDPlan5.OPDType__c = '事件'; oPDPlan5.IsJump__c = true; oPDPlan5.JumpCause__c = '想插队'; oPDPlan5.OPDLendSortDraft__c = 15; insert oPDPlan5; OPDPlan__c oPDPlan6 = new OPDPlan__c(); oPDPlan6.Name = 'oPDPlan6'; oPDPlan6.Status__c = '计划中'; oPDPlan6.OPDPlan_ImplementDate__c = Date.today().addMonths(1); oPDPlan6.NoOpp_Reason__c = 'HCP对应'; oPDPlan6.OPDType__c = '事件'; oPDPlan6.IsJump__c = true; oPDPlan6.JumpCause__c = '想插队'; oPDPlan6.OPDLendSort__c = 0; insert oPDPlan6; OPDPlan__c oPDPlan7 = new OPDPlan__c(); oPDPlan7.Name = 'oPDPlan7'; oPDPlan7.Status__c = '计划中'; oPDPlan7.OPDPlan_ImplementDate__c = Date.today().addMonths(1); oPDPlan7.NoOpp_Reason__c = 'HCP对应'; oPDPlan7.OPDType__c = '事件'; oPDPlan7.IsJump__c = true; oPDPlan7.JumpCause__c = '想插队'; insert oPDPlan7; OPDPlan__c oPDPlan8 = new OPDPlan__c(); oPDPlan8.Name = 'oPDPlan8'; oPDPlan8.Status__c = '计划中'; oPDPlan8.OPDPlan_ImplementDate__c = Date.today().addMonths(1); oPDPlan8.NoOpp_Reason__c = 'HCP对应'; oPDPlan8.OPDType__c = '事件'; oPDPlan8.IsJump__c = false; oPDPlan8.JumpCause__c = '想插队'; oPDPlan8.OPDLendSortDraft__c = 1; oPDPlan8.OPDLendSort__c = 1; insert oPDPlan8; user = getUser(); List oplist = [select id,IsJump__c,JumpCause__c,OPDLendSortDraft__c,OPDLendSort__c,IsSaveOrSubmit__c from OPDPlan__c where Status__c='计划中']; System.assertEquals(8, oplist.size()); PageReference ref = new PageReference('/apex/OPDSortManage'); Test.setCurrentPage(ref); OPDSortManageController target = new OPDSortManageController(); target.init(); // System.assertEquals(2, target.unCheckedOPDPlan.size()); //未排序的 // target.Salesdepartment = '1.华北'; target.searchBtn(); //System.assertEquals(2, target.unCheckedOPDPlan.size()); //未排序的 //target.unCheckedOPDPlan[0].check = true; target.saveAdd(); target.autoSort(); target.opdDelId = oPDPlan5.id; target.del(); //target.checkedOPDPlan[4].op.OPDLendSortDraft__c = 18; target.save(); //2020-12-02 mzy add 点击项目自行排序功能 target.sortTableFlagSort ='asc'; target.sortKey ='Sort'; target.sortTable(); target.sortTableFlagNDetail ='asc'; target.sortKey ='NDetail'; target.sortTable(); target.sortTableFlagNtime ='asc'; target.sortKey ='Ntime'; target.sortTable(); //2020-12-02 mzy add 点击项目自行排序功能 System.runAs(user) { List glist = [select id from group WHERE DeveloperName in ('X00_LOHBbeijing')]; GroupMember mb = new GroupMember(); mb.groupid = glist[0].id; mb.userOrGroupId = user.id; insert mb; target.submitBtn(); } } private static User getUser() { // 20230119 ljh start /*String timenow = Datetime.now().format('yyyyMMddHHmmss'); User usr = new User(Test_staff__c = true, LastName = 'TestZY', FirstName = 'TestZY', Alias = 'zy', CommunityNickname = 'TestMiao', Email = 'TestZY@test.com', Username = 'Test' + timenow + '@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = System.Label.ProfileId_SystemAdmin, Province__c = '北京市',Work_Location__c = '北京'); insert usr;*/ String ProfileId = System.Label.ProfileId_SystemAdmin; User usr = [SELECT Id,name from User WHERE ProfileId =:ProfileId AND Test_staff__c = true AND IsActive = true AND Province__c = '北京市' AND Work_Location__c = '北京'limit 1]; // 20230119 ljh end return usr; } }