@isTest 
public class AttachmentDisplayControllerTest {
    static testMethod void TestInit01(){
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name IN ('診療科 消化科', '診療科 呼吸科') order by Name desc];
        if (rectDpt.size() == 0) {
            return;
        }
         List<RecordType> rectAs = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '备品'];
        if (rectAs.size() == 0) {
            return;
        }

     
        // insert hospital
        Account company1 = new Account();
        company1.RecordTypeId = rectCo[0].Id;
        company1.Name = '病院テスト1';
        company1.OCM_man_province_txt__c = '江西';
        company1.AgentCode_Ext__c = '888888';
        List<Account> hps = new Account[]{company1};
        insert hps;
          
        List<Account> dc1s = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = :company1.Id order by Department_Class_Label__c];
        
        Account depart1 = new Account();
        depart1.RecordTypeId = rectDpt[0].Id;
        depart1.Name         = '*';
        depart1.Department_Name__c  = '診療科1';
        depart1.ParentId            = dc1s[0].Id;
        depart1.Department_Class__c = dc1s[0].Id;
        depart1.Hospital__c         = company1.Id;
        depart1.OCM_man_province_txt__c = '江西';
        // depart1.AgentCode_Ext__c = '888888';
        
        insert new Account[] {depart1};

        List<Product2> prdList = new List<Product2>();
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'HistoryPrd1';
        prd1.ProductCode            = 'HistoryPrd1';
        prd1.Repair_Product_Code__c = 'HistoryPrd1_RP';
        prd1.Name                   = 'HistoryPrd1';
        prd1.Manual_Entry__c        = false;
        prd1.Extend_new_product_gurantee__c = true;
        prd1.Extend_Gurantee_Start__c = Date.today().addDays(-60);
        prd1.Extend_Gurantee_End__c = Date.today().addDays(60);
        prd1.HomeBuy__c=true;
        prdList.add(prd1);
        insert prdList;
    
        Asset ast = new Asset();

        ast.RecordTypeId = rectAs[0].Id;
        ast.SerialNumber = 'abcdefg';
        ast.Name = '测试资产1';
        ast.AccountId              = depart1.Id;
        ast.Department_Class__c    = dc1s[0].Id;
        ast.Hospital__c            = company1.Id;
        ast.Product2Id             = prd1.Id;
        ast.Guarantee_period_for_products__c = Date.today();
        ast.InstallDate                      = Date.today();
        ast.Manage_type__c = '个体管理';
        ast.FirstApproveDate_old__c = Date.today().addDays(-30);

        Oly_TriggerHandler.bypass('AssetHandler');

        insert ast;
        
        Asset ast1 = [select RecordTypeID__c from Asset where Id =: ast.Id];
        
        String RecordTypeID = ast1.RecordTypeID__c;
           
        System.assertEquals(RecordTypeID , ast.RecordTypeId);

        RecordType rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity' ];
        Opportunity opp = new Opportunity(
               Name='testOpp1',
               StageName='引合',
               CloseDate=Date.today(),
               AccountId=depart1.Id,
               Sales_Root__c = '販売店',
               Competitor__c ='A',
               Click_Close_Date__c = null,
               RecordType = rectOpp
        );
        insert opp;

        //注残
        Statu_Achievements__c Sac = new Statu_Achievements__c(
            name = 'zhucan_one',
            Opportunity__c = opp.id,
            DeliveryDate__c = Date.today(),
            ContractNO__c = 'ContractNO1',
            ContractAmount__c = 1000
        );
        insert Sac;



        //新建电子签收单
    	eSignForm__c eSignForm = new eSignForm__c();
    	eSignForm.Statu_Achievements__c = Sac.Id;
    	eSignForm.Name = '::测试电子签收单';
    	eSignForm.DNName__c = '65210306';

    	insert eSignForm;

        eSignForm__c eSignForm1 = new eSignForm__c();
    	eSignForm1.Statu_Achievements__c = Sac.Id;
    	eSignForm1.Name = '::测试电子签收单2';
    	eSignForm1.DNName__c = '65210307';

    	insert eSignForm1;

        eSignFormEntry__c eSignFormEntry1 = new eSignFormEntry__c();
        eSignFormEntry1.Name = '::电子签收单录入表1';
        eSignFormEntry1.eSignForm__c = eSignForm.Id;
        eSignFormEntry1.entryType__c = '经销商收货';
        
        insert eSignFormEntry1;

    	eSignFormEntry__c eSignFormEntry2 = new eSignFormEntry__c();
    	eSignFormEntry2.Name = '::电子签收单录入表2';
    	eSignFormEntry2.eSignForm__c = eSignForm.Id;
    	eSignFormEntry2.entryType__c = '经销商收货';
        eSignFormEntry2.IsSubmit__c = true;
        eSignFormEntry2.IsHPSubmit__c = true;
    	// eSignFormEntry2.createdDate = Date.today().addDays(-2);
    	insert eSignFormEntry2;

        eSignFormEntry__c eSignFormEntry3 = new eSignFormEntry__c();
    	eSignFormEntry3.Name = '::电子签收单录入表3';
    	eSignFormEntry3.eSignForm__c = eSignForm1.Id;
    	eSignFormEntry3.entryType__c = '经销商收货';
        eSignFormEntry3.IsSubmit__c = true;
        eSignFormEntry3.IsHPSubmit__c = true;
    	insert eSignFormEntry3;


        //新建电子签收单明细
        eSignFormLineItem__c eSignFormLineItem = new eSignFormLineItem__c();
        eSignFormLineItem.Name = '::电子签收单明细';
        eSignFormLineItem.eSignForm__c = eSignForm.Id;

        insert eSignFormLineItem;

        eSignFormLineItem__c eSignFormLineItem1 = new eSignFormLineItem__c();
        eSignFormLineItem1.Name = '::电子签收单明细';
        eSignFormLineItem1.eSignForm__c = eSignForm1.Id;

        insert eSignFormLineItem1;

        //新建电子签收单明细录入表

        eSignFormLineItemEntry__c eSignFormLineItemEntry1 = new eSignFormLineItemEntry__c();
        eSignFormLineItemEntry1.Name = '::电子签收单明细录入1';
        eSignFormLineItemEntry1.eSignFormEntry__c =eSignFormEntry1.Id;
        eSignFormLineItemEntry1.eSignFormLineItem__c = eSignFormLineItem.Id;

        insert eSignFormLineItemEntry1;

        eSignFormLineItemEntry__c eSignFormLineItemEntry2 = new eSignFormLineItemEntry__c();
        eSignFormLineItemEntry2.Name = '::电子签收单明细录入2';
        eSignFormLineItemEntry2.eSignFormEntry__c =eSignFormEntry2.Id;
        eSignFormLineItemEntry2.eSignFormLineItem__c = eSignFormLineItem.Id;


        insert eSignFormLineItemEntry2;

        FileAddress__c FileName1 = new FileAddress__c();
        FileName1.FileName__c = 'ceshiyi1';
        FileName1.ViewLink__c = 'ceshiyi1';
        insert FileName1;

        FileAddress__c FileName2 = new FileAddress__c();
        FileName2.FileName__c = 'ceshiyi2';
        FileName2.ViewLink__c = 'ceshiyi2';
        insert FileName2;

        FrameNumManage__c FrameNumManage1 = new FrameNumManage__c();
        FrameNumManage1.Name = '测试1';
        FrameNumManage1.ManagementCode__c ='KVZFI';
        FrameNumManage1.ApplyList__c = 'ceshiyi1';
        FrameNumManage1.Num__c = 2;
        FrameNumManage1.SerialNumber__c = '22R';
        FrameNumManage1.Material__c = 'wuliaoceshi';
        FrameNumManage1.MaterialDepict__c = 'wuliaomiaoshu';
        FrameNumManage1.signInForm__c = eSignForm.Id;

        insert FrameNumManage1;

        FrameNumManage__c FrameNumManage2 = new FrameNumManage__c();
        FrameNumManage2.Name = '测试2';
        FrameNumManage2.ManagementCode__c ='KVZFI';
        FrameNumManage2.ApplyList__c = 'ceshiyi2';
        FrameNumManage2.Num__c = 2;
        FrameNumManage2.SerialNumber__c = '22R';
        FrameNumManage2.Material__c = 'wuliaoceshi';
        FrameNumManage2.MaterialDepict__c = 'wuliaomiaoshu';
        FrameNumManage2.signInForm__c = eSignForm.Id;
        FrameNumManage2.InspectionCard_Select__c =FileName2.Id;
        FrameNumManage2.ApplyList_Select__c =FileName2.Id;

        insert FrameNumManage2;
        FrameNumManage__c FrameNumManage3 = new FrameNumManage__c();
        FrameNumManage3.Name = '测试3';
        FrameNumManage3.ManagementCode__c ='KVZFI';
        FrameNumManage3.ApplyList__c = 'ceshiyi2';
        FrameNumManage3.Num__c = 2;
        FrameNumManage3.SerialNumber__c = '22R';
        FrameNumManage3.Material__c = 'wuliaoceshi3';
        FrameNumManage3.MaterialDepict__c = 'wuliaomiaoshu3';
        FrameNumManage3.signInForm__c = eSignForm.Id;
        FrameNumManage3.InspectionCard_Select__c =FileName1.Id;
        FrameNumManage3.ApplyList_Select__c =FileName1.Id;

        insert FrameNumManage3;
        FrameNumManage__c FrameNumManage4 = new FrameNumManage__c();
        FrameNumManage4.Name = '测试4';
        FrameNumManage4.ManagementCode__c ='KVZFI4';
        FrameNumManage4.ApplyList__c = 'ceshiyi4';
        FrameNumManage4.Num__c = 2;
        FrameNumManage4.SerialNumber__c = '22R';
        FrameNumManage4.Material__c = 'wuliaoceshi4';
        FrameNumManage4.MaterialDepict__c = 'wuliaomiaoshu4';
        FrameNumManage4.signInForm__c = eSignForm.Id;
        FrameNumManage4.Asset__c = ast.Id;

        insert FrameNumManage4;

        FrameNumManage__c FrameNumManage5 = new FrameNumManage__c();
        FrameNumManage5.Name = '测试5';
        FrameNumManage5.ManagementCode__c ='KVZFI5';
        FrameNumManage5.ApplyList__c = 'ceshiyi5';
        FrameNumManage5.Num__c = 2;
        FrameNumManage5.SerialNumber__c = '22R';
        FrameNumManage5.Material__c = 'wuliaoceshi5';
        FrameNumManage5.MaterialDepict__c = 'wuliaomiaoshu5';
        FrameNumManage5.InspectionCard__c = '不出证';
        FrameNumManage5.signInForm__c = eSignForm.Id;

        insert FrameNumManage5;

        FrameNumManage__c FrameNumManage6 = new FrameNumManage__c();
        FrameNumManage6.Name = '测试6';
        FrameNumManage6.ManagementCode__c ='KVZFI6';
        FrameNumManage6.ApplyList__c = 'ceshiyi6';
        FrameNumManage6.Num__c = 2;
        FrameNumManage6.SerialNumber__c = '22R';
        FrameNumManage6.Material__c = 'wuliaoceshi6';
        FrameNumManage6.MaterialDepict__c = 'wuliaomiaoshu6';
        FrameNumManage6.InspectionCard__c = 'ceshiyi2';
        FrameNumManage6.signInForm__c = eSignForm.Id;

        insert FrameNumManage6;

        FrameNumManage__c FrameNumManage7 = new FrameNumManage__c();
        FrameNumManage7.Name = '测试7';
        FrameNumManage7.ManagementCode__c ='KVZFI7';
        FrameNumManage7.ApplyList__c = 'ceshiyi6';
        FrameNumManage7.Num__c = 2;
        FrameNumManage7.SerialNumber__c = '22R';
        FrameNumManage7.Material__c = 'wuliaoceshi6';
        FrameNumManage7.MaterialDepict__c = 'wuliaomiaoshu6';
        FrameNumManage7.InspectionCard__c = 'ceshiyi2';
        FrameNumManage7.signInForm__c = eSignForm.Id;

        insert FrameNumManage7;

        FrameNumManage__c FrameNumManage8 = new FrameNumManage__c();
        FrameNumManage8.Name = '测试8';
        FrameNumManage8.ManagementCode__c ='KVZFI5';
        FrameNumManage8.ApplyList__c = 'ceshiyi8';
        FrameNumManage8.Num__c = 2;
        FrameNumManage8.SerialNumber__c = '22R';
        FrameNumManage8.Material__c = 'wuliaoceshi5';
        FrameNumManage8.MaterialDepict__c = 'wuliaomiaoshu5';
        FrameNumManage8.InspectionCard__c = 'ceshiyi1';
        FrameNumManage8.signInForm__c = eSignForm.Id;

        insert FrameNumManage8;

        FrameNumManage__c FrameNumManage9 = new FrameNumManage__c();
        FrameNumManage9.Name = '测试9';
        FrameNumManage9.ManagementCode__c ='KVZFI9';
        FrameNumManage9.ApplyList__c = '';
        FrameNumManage9.Num__c = 2;
        FrameNumManage9.SerialNumber__c = '22R';
        FrameNumManage9.Material__c = 'wuliaoceshi9';
        FrameNumManage9.MaterialDepict__c = 'wuliaomiaoshu9';
        FrameNumManage9.InspectionCard__c = '';
        FrameNumManage9.signInForm__c = eSignForm1.Id;

        insert FrameNumManage9;
        FrameNumManage__c FrameNumManage10 = new FrameNumManage__c();
        FrameNumManage10.Name = '测试10';
        FrameNumManage10.ManagementCode__c ='KVZFI10';
        FrameNumManage10.ApplyList__c = '';
        FrameNumManage10.Num__c = 2;
        FrameNumManage10.SerialNumber__c = '22R';
        FrameNumManage10.Material__c = 'wuliaoceshi10';
        FrameNumManage10.MaterialDepict__c = 'wuliaomiaoshu10';
        FrameNumManage10.InspectionCard__c = '';
        FrameNumManage10.signInForm__c = eSignForm1.Id;

        insert FrameNumManage10;

        FrameNumManage__c FrameNumManage11 = new FrameNumManage__c();
        FrameNumManage11.Name = '测试11';
        FrameNumManage11.ManagementCode__c ='KVZFI11';
        FrameNumManage11.ApplyList__c = null;
        FrameNumManage11.Num__c = 2;
        FrameNumManage11.SerialNumber__c = '22R';
        FrameNumManage11.Material__c = 'wuliaoceshi11';
        FrameNumManage11.MaterialDepict__c = 'wuliaomiaoshu11';
        FrameNumManage11.InspectionCard__c = '';
        FrameNumManage11.signInForm__c = eSignForm1.Id;

        insert FrameNumManage11;

    	// create ContentVersions
        list<ContentVersion> cvList = new list<ContentVersion>();
        cvList.add( new ContentVersion(Title = 'test1',PathOnClient = 'Test1.txt',VersionData = Blob.valueOf('test data 1'), IsMajorVersion = true) );
        cvList.add( new ContentVersion(Title = 'test2',PathOnClient = 'Test2.txt',VersionData = Blob.valueOf('test data 2'), IsMajorVersion = true) );
        cvList.add( new ContentVersion(Title = 'test3',PathOnClient = 'Test3.txt',VersionData = Blob.valueOf('test data 3'), IsMajorVersion = true) );
        insert cvList;

        Test.startTest();
        // retrieve Ids for ContentDocuments created on insert of ContentVersions
        list<Id> cdIdList = new list<Id>();
        for (ContentDocument cd : [SELECT Id, LatestPublishedVersionId
                                   FROM ContentDocument
                                   WHERE (LatestPublishedVersionId = :cvList[0].Id 
                                          OR LatestPublishedVersionId = :cvList[1].Id
                                          OR LatestPublishedVersionId = :cvList[2].Id)
                                   ORDER BY Title]) {
            cdIdList.add(cd.Id);
        }
        system.assertEquals(3, cdIdList.size());


        // create ContentDocumentLink links. 2 for TestAcct (1) and 1 for TestAcct (2)
        list<ContentDocumentLink> cdlList = new list<ContentDocumentLink>();
        cdlList.add(new ContentDocumentLink(ContentDocumentId=cdIdList[0], LinkedEntityId=eSignFormEntry1.Id, ShareType='V'));
      
        insert cdlList; 
        string aid = String.valueOf(depart1.Id);
        eSignHomePageController.getDNSignUpStatus('65210306');
        eSignHomePageController.eSignWrapperList esceshi = eSignHomePageController.getDNSignUpLists(aid,'Agency');
        eSignHomePageController.getAccount('888888');
        AttachmentDisplayController.getFrameNumManage(eSignForm.Id);

        eSignHomePageController.getDNSignUpStatus('65210307');
        eSignHomePageController.eSignWrapperList esceshi1 = eSignHomePageController.getDNSignUpLists(aid,'Agency');
        eSignHomePageController.getAccount('888888');
        AttachmentDisplayController.getFrameNumManage(eSignForm1.Id);
        Test.stopTest();
    }
}