@isTest
private class SearchManagementControllerTest {

    public static TS_Repair__c tsr;

    public static User_FaultInfo__c uf;
    public static User_FaultInfo__c uf2;

    public static BusinessActivity__c ba;

    static void basicData() {
        System.runAs(new User(Id = Userinfo.getUserId())) {
            uf = new User_FaultInfo__c();
            uf.UserFaultInfoReportDate__c = Date.today();
            uf.RecordTypeId = System.label.Case_RecordTypeTSTSReport;
            insert uf;

            uf2 = new User_FaultInfo__c();
            uf2.RecordTypeId = System.label.Case_RecordTypeTSTSReport;
            uf2.UserFaultInfoReportDate__c = Date.today();
            insert uf2;
            tsr = new TS_Repair__c();
            insert tsr;

            ba = new BusinessActivity__c();
            insert ba;
        }


    }
    // 选择一个 用户/故障信息
    static testMethod void testMethod1() {
        
        basicData();
        System.runAs(new User(Id = Userinfo.getUserId())) {
            PageReference page = new PageReference('/apex/SearchManagementCode?lineno=0&baId='+ba.Id+'&repairId='+tsr.Id+'&ufId='+uf.Id);
            List<User_FaultInfo__c> ufList = [select Id,Name from User_FaultInfo__c];
            System.Test.setCurrentPage(page);
            SearchManagementController controller = new SearchManagementController();
            controller.init(); 
            //controller.searchManagementCode = ufList[0].Name;
            controller.UserFaultInfo.UserFaultInfoReportDate__c = Date.today();

            controller.serUserFaultInfo();
            controller.UserFaultInfoList[0].UserFaultInfoBeSelected__c = true;
            controller.save();
        }
        
    }
    // 选择两个 用户/故障信息 报错
    static testMethod void testMethod2() {
        
        basicData();
        System.runAs(new User(Id = Userinfo.getUserId())) {
            PageReference page = new PageReference('/apex/SearchManagementCode?lineno=0&baId='+ba.Id+'&repairId='+tsr.Id+'&ufId='+uf.Id);
            
            List<User_FaultInfo__c> ufList = [select Id,Name from User_FaultInfo__c];
            System.Test.setCurrentPage(page);
            SearchManagementController controller = new SearchManagementController();
            controller.init(); 
            controller.UserFaultInfo.UserFaultInfoReportDate__c = Date.today();
            controller.serUserFaultInfo();
            controller.UserFaultInfoList[0].UserFaultInfoBeSelected__c = true;
            controller.UserFaultInfoList[1].UserFaultInfoBeSelected__c = true;
            controller.save();
        }
        
    }
    // 不选择 用户/故障信息 报错
    static testMethod void testMethod3() {
        
        basicData();
        System.runAs(new User(Id = Userinfo.getUserId())) {
            PageReference page = new PageReference('/apex/SearchManagementCode?lineno=0&baId='+ba.Id+'&repairId='+tsr.Id+'&ufId='+uf.Id);
            
            List<User_FaultInfo__c> ufList = [select Id,Name from User_FaultInfo__c];
            System.Test.setCurrentPage(page);
            SearchManagementController controller = new SearchManagementController();
            controller.init(); 
            controller.UserFaultInfo.UserFaultInfoReportDate__c = Date.today();
            controller.serUserFaultInfo();
            controller.save();
        }
        
    }
}