@isTest
private class BatchSelectRepairPageControllerTest {
    // static Repair__c repair02
    @TestSetup
    public static void init(){

        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
        User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        insert hpOwner;
        List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'];
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'];
        if (rectDpt.size() == 0) {
            return;
        }
        Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'SoakupTestHp', OwnerId = hpOwner.Id,Speciality_Type__c = '综合医院');
        insert hp;
        Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI'];
        Account dpt = new Account(RecordTypeId = rectDpt[0].Id);
        dpt.Name         = '*';
        dpt.Department_Name__c  = 'TestDepart';
        dpt.ParentId            = dc.Id;
        dpt.Department_Class__c = dc.Id;
        dpt.Hospital__c         = hp.Id;
        insert dpt;
        Asset asset = new Asset();
        asset.Name = 'テスト機器';
        asset.AccountId = dpt.Id;
        asset.Department_Class__c = dc.Id;
        asset.Hospital__c = hp.Id;
        asset.SerialNumber = 'testserial';
        insert asset;
    
        Repair__c repair01 = new Repair__c();
        repair01.Account__c = dpt.Id;
        repair01.Department_Class__c = dc.Id;
        repair01.Hospital__c = hp.Id;
        repair01.Delivered_Product__c = asset.Id;
        repair01.SERVICE_CONTRACT_JUDEGE_DAY__C = Date.today().addDays(0); 
        repair01.FSE_Work_Location__c = '上海';
        repair01.Service_Repair_No__c = 'SAP0001';
        repair01.Incharge_Staff__c = hpOwner.Id;
        repair01.On_site_repair__c = 'RC修理';
        repair01.work_location_select__c = '北京办事处';
        // repair01.Final_complete_day__c = Date.today().addDays(-1);
        insert repair01;
    }
    static testMethod void testSample_01() {
        PageReference page = new PageReference('/apex/BatchSelectRepairPage');
        System.Test.setCurrentPage(page);
        System.Test.StartTest();
        BatchSelectRepairPageController br = new BatchSelectRepairPageController();
        StaticParameter.ContentDocumentLink = false;
        br.init();
        Repair__c repair01 = [SELECT Id,Status2__c,Name,Incharge_Staff__c,SAP_Service_Repair_No__c,Aware_date2__c,State_Hospital__c,SerialNumber__c,work_location_select__c,FSE_ApplyForRepair_Day__c,On_site_repair__c,Aware_date__c FROM Repair__c LIMIT 1];
        br.RevalInfo.repair = repair01;
        br.RevalInfo.Status2 = repair01.Status2__c;
        br.RevalInfo.RepairName = repair01.Name + ',';
        br.RevalInfo.SerialNumber = repair01.SerialNumber__c + ',' + repair01.SerialNumber__c;
        br.RevalInfo.SAPRepairNo = repair01.SAP_Service_Repair_No__c + ',';
        // br.RevalInfo.repair.Aware_date__c = repair01.FSE_ApplyForRepair_Day__c.addDays(-1);
        // br.RevalInfo.repair.Aware_date2__c = repair01.FSE_ApplyForRepair_Day__c.addDays(1);
        br.RevalInfo.onSiteRepair = repair01.On_site_repair__c;
        br.RevalInfo.workLocationSelect = repair01.work_location_select__c;
        br.RevalInfo.State_Hospital = repair01.State_Hospital__c;
        br.RetrievalBtn();
        BatchSelectRepairPageController.RepairData reparedata = new BatchSelectRepairPageController.RepairData(repair01);
        reparedata.IFCheck = true;
        br.RAInfoList.add(reparedata);
        br.RAInfoList[0].IFCheck = true;
        system.assertEquals(br.RAInfoList[0].IFCheck,true);
        br.showPDF();  
        List<Repair__c> repList = new List<Repair__c>();
        repList.add(repair01);
        BatchSelectRepairPageController.generateAttachment(repList);       
        
        System.Test.StopTest();

    }
    
}