@isTest
private class InventoryReportDetailControllerTest {
    // 创建 Asset & 盘点表头 & 盘点明细 数据
    static void setupTestData() {
        SS_Batch_Column_Mapping__c InventoryHeaderName = new SS_Batch_Column_Mapping__c(Name = 'Inventory_Header_Name', SS_TableName__c='Inventory_Header_Name');
        InventoryHeaderName.From_Column_001__c = '北京 备品中心';
        InventoryHeaderName.SS_Column_001__c = 'BJ';
        InventoryHeaderName.From_Column_002__c = '上海 备品中心';
        InventoryHeaderName.SS_Column_002__c = 'SH';
        InventoryHeaderName.From_Column_003__c = '广州 备品中心';
        InventoryHeaderName.SS_Column_003__c = 'GZ';
        insert new SS_Batch_Column_Mapping__c[] {InventoryHeaderName};
        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        hospital.Is_Active__c = '有効';
        hospital.Attribute_Type__c = '卫生部';
        hospital.Speciality_Type__c = '综合医院';
        hospital.Grade__c = '一级';
        hospital.OCM_Category__c = 'SLTV';
        hospital.Is_Medical__c = '医疗机构';
        //hospital.State_Master__c = al.id;
        //hospital.City_Master__c = al2.id;
        hospital.Town__c = '东京';
        insert hospital;

        // 戦略科室を得る
        Account[] strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_OTH'];
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id;
        dep.Name = 'test dep';
        dep.AgentCode_Ext__c = '9999998';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;

        Contact contact2 = new Contact();
        contact2.AccountId = dep.Id;
        contact2.FirstName = '責任者';
        contact2.LastName = 'test1经销商';
        insert contact2;

        // 产品
        Product2 pro1 = new Product2(Name='name01',IsActive=true,Family='GI',
                Fixture_Model_No__c='n01',Serial_Lot_No__c='S/N tracing',
                Fixture_Model_No_T__c = 'n01',
                ProductCode_Ext__c='pc01',Manual_Entry__c=false);
        Product2 pro2 = new Product2(Name='name02',IsActive=true,Family='GI',
                Fixture_Model_No__c='n02',Serial_Lot_No__c='Lot tracing',
                ProductCode_Ext__c='pc02',Manual_Entry__c=false);
        Product2 pro3 = new Product2(Name='name03',IsActive=true,Family='GI',
                Fixture_Model_No__c='n03',Serial_Lot_No__c='Lot tracing',
                ProductCode_Ext__c='pc03',Manual_Entry__c=false);
        insert new Product2[] {pro1, pro2, pro3};

        //---------------------------主体 两个附属品(个体管理 数量管理)
        // 保有设备A (主体)
        Asset assetA1 = new Asset(Asset_Owner__c = 'Olympus');
        assetA1.RecordTypeId = System.Label.Asset_RecordType;
        assetA1.SerialNumber = 'ass01';
        assetA1.Name = 'ass01';
        assetA1.AccountId = dep.Id;
        assetA1.Department_Class__c = strategicDep[0].Id;
        assetA1.Hospital__c = hospital.Id;
        assetA1.Product2Id = pro1.Id;
        assetA1.Quantity = 1;
        assetA1.Status = '有库存';
        assetA1.Manage_type__c = '个体管理';
        assetA1.Loaner_accsessary__c = false;
        assetA1.Product_category__c = 'GI';
        assetA1.Delete_Flag__c = false;
        assetA1.Freeze_sign__c = false;
        assetA1.Out_of_wh__c = 0;
        assetA1.Salesdepartment__c = '1.华北营业本部';
        assetA1.Internal_asset_location__c = '北京 备品中心';
        assetA1.Equipment_Type__c = '产品试用';
        assetA1.SalesProvince__c = '北京';
        assetA1.WH_location__c = '货架号1';
        // 保有设备A (附属品 数量管理)
        Asset assetA2 = new Asset(Asset_Owner__c = 'Olympus');
        assetA2.RecordTypeId = System.Label.Asset_RecordType;
        assetA2.SerialNumber = 'ass02';
        assetA2.Name = 'ass02';
        assetA2.AccountId = dep.Id;
        assetA2.Department_Class__c = strategicDep[0].Id;
        assetA2.Hospital__c = hospital.Id;
        assetA2.Product2Id = pro2.Id;
        assetA2.Quantity = 10;
        assetA2.Status = '有库存';
        assetA2.Manage_type__c = '数量管理';
        assetA2.Loaner_accsessary__c = true;
        assetA2.Product_category__c = 'GI';
        assetA2.Delete_Flag__c = false;
        assetA2.Freeze_sign__c = false;
        assetA2.Out_of_wh__c = 3;
        assetA2.Frozen_Quantity__c = 2;
        assetA2.Salesdepartment__c = '1.华北营业本部';
        assetA2.Internal_asset_location__c = '北京 备品中心';
        assetA2.Equipment_Type__c = '产品试用';
        assetA2.SalesProvince__c = '北京';
        assetA2.WH_location__c = '货架号2';
        // 保有设备A (附属品 个体管理)
        Asset assetA3 = new Asset(Asset_Owner__c = 'Olympus');
        assetA3.RecordTypeId = System.Label.Asset_RecordType;
        assetA3.SerialNumber = 'ass03';
        assetA3.Name = 'ass03';
        assetA3.AccountId = dep.Id;
        assetA3.Department_Class__c = strategicDep[0].Id;
        assetA3.Hospital__c = hospital.Id;
        assetA3.Product2Id = pro3.Id;
        assetA3.Quantity = 10;
        assetA3.Status = '有库存';
        assetA3.Manage_type__c = '数量管理';
        assetA3.Loaner_accsessary__c = true;
        assetA3.Product_category__c = 'GI';
        assetA3.Delete_Flag__c = false;
        assetA3.Freeze_sign__c = false;
        assetA3.Out_of_wh__c = 3;
        assetA3.Salesdepartment__c = '1.华北营业本部';
        assetA3.Internal_asset_location__c = '北京 备品中心';
        assetA3.Equipment_Type__c = '产品试用';
        assetA3.SalesProvince__c = '北京';
        assetA3.WH_location__c = '货架号3';
        assetA3.Abandoned_Inventory__c = 1;
        insert new Asset[] {assetA1, assetA2, assetA3};

        // 盘点表头
        List<Inventory_Header__c> invHeadTestList = new List<Inventory_Header__c>();
        Inventory_Header__c invHead1 = new Inventory_Header__c();
        invHead1.Internal_asset_location__c = '北京 备品中心';
        // invHead1.InventoryPIC__c = ;
        invHead1.Inventory_Start_Date__c = Date.today();
        invHead1.Inventory_Status__c = '盘点中';
        invHead1.UniqueKey__c = '备品中心：' + String.valueOf(Date.today());
        invHeadTestList.add(invHead1);
        insert invHeadTestList;
        List<Inventory_Header__c> invHeadList = [SELECT Id FROM Inventory_Header__c];
        System.assertEquals(1, invHeadList.size());

        // 盘点表明细 -- all 北京 备品中心
        List<Inventory_Detail__c> invDetailTestList = new List<Inventory_Detail__c>();
        // 盘盈 & 主体 & 固定资产 & GI & 产品试用 & 个体管理
        Inventory_Detail__c invDetail1 = new Inventory_Detail__c();
        invDetail1.Asset__c = assetA1.Id;
        invDetail1.Inventory_Header__c = invHead1.Id;
        invDetail1.Sync_Asset_Record_Flag__c  = true;
        invDetail1.toAbandon_amount__c = 1;             // 待废弃数
        // invDetail1.Inventory_Count__c = 15;             // 实盘数
        invDetail1.Amount__c = 14;                      // 应盘数
        invDetail1.Internal_Asset_number_key__c = 'abc';// 固定资产
        invDetail1.Internal_asset_location__c = '北京 备品中心';
        invDetail1.Asset_Status__c = '在库';
        invDetail1.Fixture_Model_No__c = 'n01';
        invDetail1.Internal_Asset_number__c = 'test';
        invDetail1.SerialNumber__c = 'serialNo1';
        invDetail1.WH_location__c = 'whLocation1';
        invDetail1.Main_OneToOne__c = true;
        invDetail1.Product_category__c = 'GI';
        invDetail1.Equipment_Type__c = '产品试用';
        invDetail1.Manage_type__c = '个体管理';
        // invDetail1.Inventory_Time__c = Date.today();
        invDetail1.UniqueKey__c = '备品中心：' + String.valueOf(Date.today()) + '1';
        invDetailTestList.add(invDetail1);
        // 盘亏 & 附属品 & 非固定资产 & SP & 数量管理
        Inventory_Detail__c invDetail2 = new Inventory_Detail__c();
        invDetail2.Asset__c = assetA2.Id;
        invDetail2.Inventory_Header__c = invHead1.Id;
        invDetail2.Sync_Asset_Record_Flag__c  = true;
        invDetail2.toAbandon_amount__c = 1;             // 待废弃数
        // invDetail2.Inventory_Count__c = 14;             // 实盘数
        invDetail2.Amount__c = 15;                      // 应盘数
        invDetail2.Internal_asset_location__c = '北京 备品中心';
        invDetail2.Asset_Status__c = '维修中';
        invDetail2.Fixture_Model_No__c = 'n01';
        invDetail2.Loaner_accsessary__c = true;         // 附属品
        invDetail2.Product_category__c = 'SP';
        invDetail2.Manage_type__c = '数量管理';
        // invDetail2.Inventory_Time__c = Date.today();
        invDetail2.UniqueKey__c = '备品中心：' + String.valueOf(Date.today()) + '2';
        invDetailTestList.add(invDetail2);
        Inventory_Detail__c invDetail3 = new Inventory_Detail__c();
        invDetail3.Asset__c = assetA3.Id;
        invDetail3.Inventory_Header__c = invHead1.Id;
        invDetail3.Sync_Asset_Record_Flag__c  = true;
        invDetail3.toAbandon_amount__c = 1;             // 待废弃数
        // invDetail3.Inventory_Count__c = 15;             // 实盘数
        invDetail3.Amount__c = 15;                      // 应盘数
        invDetail3.Internal_Asset_number_key__c = 'abc';// 固定资产
        invDetail3.Internal_asset_location__c = '北京 备品中心';
        invDetail3.Asset_Status__c = '出借中';
        invDetail3.Fixture_Model_No__c = 'n01';
        invDetail3.Internal_Asset_number__c = 'test';
        // invDetail3.Inventory_Time__c = Date.today();
        invDetail3.UniqueKey__c = '备品中心：' + String.valueOf(Date.today()) + '3';
        invDetailTestList.add(invDetail3);
        Inventory_Detail__c invDetail4 = new Inventory_Detail__c();
        invDetail4.Asset__c = assetA1.Id;
        invDetail4.Inventory_Header__c = invHead1.Id;
        invDetail4.Sync_Asset_Record_Flag__c  = true;
        invDetail4.toAbandon_amount__c = 1;             // 待废弃数
        // invDetail4.Inventory_Count__c = 15;             // 实盘数
        invDetail4.Amount__c = 15;                      // 应盘数
        invDetail4.Internal_Asset_number_key__c = 'abc';// 固定资产
        invDetail4.Internal_asset_location__c = '北京 备品中心';
        invDetail4.Asset_Status__c = '丢失';
        invDetail4.Fixture_Model_No__c = 'n01';
        // invDetail4.Inventory_Time__c = Date.today();
        invDetail4.UniqueKey__c = '备品中心：' + String.valueOf(Date.today()) + '4';
        invDetailTestList.add(invDetail4);
        Inventory_Detail__c invDetail5 = new Inventory_Detail__c();
        invDetail5.Asset__c = assetA2.Id;
        invDetail5.Inventory_Header__c = invHead1.Id;
        invDetail5.Sync_Asset_Record_Flag__c  = true;
        invDetail5.toAbandon_amount__c = 1;             // 待废弃数
        // invDetail5.Inventory_Count__c = 15;             // 实盘数
        invDetail5.Amount__c = 15;                      // 应盘数
        invDetail5.Internal_asset_location__c = '北京 备品中心';
        invDetail5.Asset_Status__c = '在库';
        invDetail5.Fixture_Model_No__c = 'n01';
        // invDetail5.Inventory_Time__c = Date.today();
        invDetail5.UniqueKey__c = '备品中心：' + String.valueOf(Date.today()) + '5';
        invDetailTestList.add(invDetail5);
        Inventory_Detail__c invDetail6 = new Inventory_Detail__c();
        invDetail6.Asset__c = assetA3.Id;
        invDetail6.Inventory_Header__c = invHead1.Id;
        invDetail6.Sync_Asset_Record_Flag__c  = true;
        invDetail6.toAbandon_amount__c = 1;             // 待废弃数
        // invDetail6.Inventory_Count__c = 15;             // 实盘数
        invDetail6.Amount__c = 15;                      // 应盘数
        invDetail6.Internal_asset_location__c = '北京 备品中心';
        invDetail6.Asset_Status__c = '冻结';
        // invDetail6.Inventory_Time__c = Date.today();
        invDetail6.UniqueKey__c = '备品中心：' + String.valueOf(Date.today()) + '6';
        invDetailTestList.add(invDetail6);
        insert invDetailTestList;

        List<Inventory_Detail__c> invDetailUpdateList = new List<Inventory_Detail__c>();
        invDetail1.Inventory_Count__c = 15;             // 实盘数
        invDetail2.Inventory_Count__c = 14;             // 实盘数
        invDetail3.Inventory_Count__c = 15;             // 实盘数
        invDetail4.Inventory_Count__c = 15;             // 实盘数
        invDetail5.Inventory_Count__c = 15;             // 实盘数
        invDetail6.Inventory_Count__c = 15;             // 实盘数
        invDetail1.Inventory_Time__c = Date.today();
        invDetail2.Inventory_Time__c = Date.today();
        invDetail3.Inventory_Time__c = Date.today();
        invDetail4.Inventory_Time__c = Date.today();
        invDetail5.Inventory_Time__c = Date.today();
        invDetail6.Inventory_Time__c = Date.today();
        invDetailUpdateList.add(invDetail1);
        invDetailUpdateList.add(invDetail2);
        invDetailUpdateList.add(invDetail3);
        invDetailUpdateList.add(invDetail4);
        invDetailUpdateList.add(invDetail5);
        invDetailUpdateList.add(invDetail6);
        update invDetailUpdateList;

        List<Inventory_Detail__c> invDetailList = [SELECT Id FROM Inventory_Detail__c];
        System.assertEquals(6, invDetailList.size());

    }

    static Inventory_Header__c invHeadObj { get {
        List<Inventory_Header__c> invObjs = [
                SELECT Id, Inventory_Status__c, Name, InventoryPIC__r.Name
                , Inventory_Submit_Date__c, Internal_asset_location__c, Inventory_Start_Date__c
                , Inventory_Date_From__c, Inventory_Date_To__c, Inventory_Persons__c
                , InventorySubmit_PIC__c, InventorySubmit_PIC__r.Post__c, InventoryCheck_PIC__c
                , InventoryCheck_PIC__r.Post__c, Checktime__c
                , Jingli_Equipment__r.Name, Buzhang_Equipment__r.Name, Zongjian_Equipment__r.Name
                , IvtDifference_Detail__c, IvtDifference_Comment__c
                , Buzhang_Equipment_Id__c, Zongjian_Equipment_Id__c, Jingli_Equipment_Id__c
                 FROM Inventory_Header__c
                ];
        System.assertEquals(invObjs.size(), 1);
        Inventory_Header__c invHeadObj = invObjs[0];

        return invHeadObj;
    }}

    static String invHeadId { get { return invHeadObj.Id; }}

    // 初始化画面
    static testMethod void testInitPage() {
        // システム管理者
        User user = new User(Test_staff__c = true);
        user.LastName = '_サンブリッジ';
        user.FirstName = 'う';
        user.Alias = 'う';
        user.Email = 'olympusTest03@sunbridge.com';
        user.Username = 'olympusTest03@sunbridge.com';
        user.CommunityNickname = 'う';
        user.IsActive = true;
        user.EmailEncodingKey = 'ISO-2022-JP';
        user.TimeZoneSidKey = 'Asia/Tokyo';
        user.LocaleSidKey = 'ja_JP';
        user.LanguageLocaleKey = 'ja';
        user.ProfileId = System.Label.ProfileId_SystemAdmin;
        user.Job_Category__c = '销售推广';
        user.Province__c = '北京市';
        user.Use_Start_Date__c = Date.today().addMonths(-6);
        user.SalesManager__c = UserInfo.getUserId();
        user.BuchangApprovalManagerSales__c = UserInfo.getUserId();
        user.JingliApprovalManager__c = UserInfo.getUserId();
        user.BuchangApprovalManager__c = UserInfo.getUserId();
        user.ZongjianApprovalManager__c = UserInfo.getUserId();

        System.runAs(new User(Id = Userinfo.getUserId())) {
            setupTestData();

            insert user;
            User currUser = [
                        SELECT Id, Name, Default_Referable_Apply_Equipment_Center__c
                        FROM User
                        WHERE Id = :UserInfo.getUserId()
                        ];
            System.assertEquals('北京 备品中心', currUser.Default_Referable_Apply_Equipment_Center__c);

            PageReference page = new PageReference('/apex/InventoryReportDetail');    // 不带id的url
            System.Test.setCurrentPage(page);
            InventoryReportDetailController controller = new InventoryReportDetailController(new ApexPages.StandardController(invHeadObj));
            CreateRelationListPagingCmpCtrl cmp = new CreateRelationListPagingCmpCtrl();
            cmp.pageController = controller;
            controller.init();

            page = new PageReference('/apex/InventoryReportDetail?ivt_headId=' + invHeadId);  // 带id的url
            System.Test.setCurrentPage(page);
            controller.init();

            System.Test.StartTest();

            System.Test.StopTest();
        }

    }

    // 添加检索条件
    static testMethod void testSearchOpp() {
        // システム管理者
        User user = new User(Test_staff__c = true);
        user.LastName = '_サンブリッジ';
        user.FirstName = 'う';
        user.Alias = 'う';
        user.Email = 'olympusTest03@sunbridge.com';
        user.Username = 'olympusTest03@sunbridge.com';
        user.CommunityNickname = 'う';
        user.IsActive = true;
        user.EmailEncodingKey = 'ISO-2022-JP';
        user.TimeZoneSidKey = 'Asia/Tokyo';
        user.LocaleSidKey = 'ja_JP';
        user.LanguageLocaleKey = 'ja';
        user.ProfileId = System.Label.ProfileId_SystemAdmin;
        user.Job_Category__c = '销售推广';
        user.Province__c = '北京市';
        user.Use_Start_Date__c = Date.today().addMonths(-6);
        user.SalesManager__c = UserInfo.getUserId();
        user.BuchangApprovalManagerSales__c = UserInfo.getUserId();
        user.JingliApprovalManager__c = UserInfo.getUserId();
        user.BuchangApprovalManager__c = UserInfo.getUserId();
        user.ZongjianApprovalManager__c = UserInfo.getUserId();

        System.runAs(new User(Id = Userinfo.getUserId())) {
            setupTestData();
            insert user;

            PageReference page = new PageReference('/apex/InventoryReportDetail?ivt_headId=' + invHeadId);
            System.Test.setCurrentPage(page);
            InventoryReportDetailController controller = new InventoryReportDetailController(new ApexPages.StandardController(invHeadObj));
            CreateRelationListPagingCmpCtrl cmp = new CreateRelationListPagingCmpCtrl();
            cmp.pageController = controller;
            controller.myComponentController.init();

            System.Test.StartTest();
            // I 无检索条件
            controller.searchOpp();
            System.assertEquals(6, controller.viewList.size());

            List<Inventory_Detail__c> idObjList = [
                                                    SELECT Id, UniqueKey__c
                                                      FROM Inventory_Detail__c
                                                     ORDER BY UniqueKey__c
                                                    ];
            System.assertEquals(6, idObjList.size());

            // II 盘亏 & 附属品 & 非固定资产 & SP & 数量管理
            controller.bpPankuiYing = controller.getbpPankuiYingOps()[2].getValue();        // Pankui
            controller.bpBodyFushupin = controller.getbpBodyFushupinOps()[2].getValue();    // Fushupin
            controller.ifInternalAsset = controller.getifInternalAssetOps()[2].getValue();  // false
            controller.bieChanPinFenLei = controller.getbieChanPinFenLeiOps()[2].getValue();// SP
            controller.bieManageType = controller.getbieManageTypeOps()[1].getValue();      // 数量管理
            controller.searchOpp();
            System.assertEquals(1, controller.viewList.size());
            Inventory_Detail__c idObj = (Inventory_Detail__c)controller.viewList[0].sobj;
            System.assertEquals(idObj.Id, idObjList[1].Id);     // invDetail2
            // System.assertEquals(true, idObj.Inventory_Count__c-idObj.Amount__c<0);     // Pankui
            // System.assertEquals(true, idObj.Loaner_accsessary__c);                     // Fushupin
            // System.assertEquals(true, idObj.Internal_Asset_number__c==null);           // 非固定资产
            // System.assertEquals('SP', idObj.Product_category__c);                      // 产品分类
            // System.assertEquals('数量管理', idObj.Manage_type__c);                      // 管理种类

            // III 盘盈 & 主体 & 固定资产 & GI & 产品试用 & 个体管理 & 备品型号 & 固定资产号 & 机身号 & 货架号
            controller.modelNo = 'n01';
            controller.assetNumberKey = 'test';
            controller.serialNo = 'serialNo1';
            controller.whLocation = 'whLocation1';
            controller.bpPankuiYing = controller.getbpPankuiYingOps()[1].getValue();        // Panying
            controller.bpBodyFushupin = controller.getbpBodyFushupinOps()[1].getValue();    // Zhuti
            controller.ifInternalAsset = controller.getifInternalAssetOps()[1].getValue();  // true
            controller.bieChanPinFenLei = controller.getbieChanPinFenLeiOps()[1].getValue();// GI
            controller.bieBeiPinFenLei = controller.getbieBeiPinFenLeiOps()[2].getValue();  // 产品试用
            controller.bieManageType = controller.getbieManageTypeOps()[2].getValue();      // 个体管理
            controller.searchOpp();
            System.assertEquals(1, controller.viewList.size());
            idObj = (Inventory_Detail__c)controller.viewList[0].sobj;
            System.assertEquals(idObj.Id, idObjList[0].Id);     // invDetail1
            // System.assertEquals(true, idObj.Inventory_Count__c-idObj.Amount__c>0);     // Panying
            // System.assertEquals(true, idObj.Main_OneToOne__c);                         // Zhuti
            // System.assertEquals(true, idObj.Internal_Asset_number__c!=null);           // 固定资产
            // System.assertEquals('GI', idObj.Product_category__c);                      // 产品分类
            // System.assertEquals('个体管理', idObj.Manage_type__c);                      // 管理种类

            System.Test.StopTest();
        }

    }

    // 保存备注和备注人
    static testMethod void testSave() {
        // システム管理者
        User user = new User(Test_staff__c = true);
        user.LastName = '_サンブリッジ';
        user.FirstName = 'う';
        user.Alias = 'う';
        user.Email = 'olympusTest03@sunbridge.com';
        user.Username = 'olympusTest03@sunbridge.com';
        user.CommunityNickname = 'う';
        user.IsActive = true;
        user.EmailEncodingKey = 'ISO-2022-JP';
        user.TimeZoneSidKey = 'Asia/Tokyo';
        user.LocaleSidKey = 'ja_JP';
        user.LanguageLocaleKey = 'ja';
        user.ProfileId = System.Label.ProfileId_SystemAdmin;
        user.Job_Category__c = '销售推广';
        user.Province__c = '北京市';
        user.Use_Start_Date__c = Date.today().addMonths(-6);
        user.SalesManager__c = UserInfo.getUserId();
        user.BuchangApprovalManagerSales__c = UserInfo.getUserId();
        user.JingliApprovalManager__c = UserInfo.getUserId();
        user.BuchangApprovalManager__c = UserInfo.getUserId();
        user.ZongjianApprovalManager__c = UserInfo.getUserId();

        System.runAs(new User(Id = Userinfo.getUserId())) {
            setupTestData();
            insert user;

            PageReference page = new PageReference('/apex/InventoryReportDetail?ivt_headId=' + invHeadId);
            System.Test.setCurrentPage(page);
            InventoryReportDetailController controller = new InventoryReportDetailController(new ApexPages.StandardController(invHeadObj));
            CreateRelationListPagingCmpCtrl cmp = new CreateRelationListPagingCmpCtrl();
            cmp.pageController = controller;
            controller.myComponentController.init();

            System.Test.StartTest();
            controller.searchOpp();
            System.assertEquals(6, controller.viewList.size());

            List<Inventory_Detail__c> idObjList = [
                                                    SELECT Id, UniqueKey__c
                                                      FROM Inventory_Detail__c
                                                     ORDER BY UniqueKey__c
                                                    ];
            System.assertEquals(6, idObjList.size());
            Inventory_Detail__c idObj = (Inventory_Detail__c)controller.viewList[0].sobj;
            controller.viewList[0].changeFlg = '1';
            idObj.Inventory_Remarks__c = 'remark test';
            controller.saveType = '1';
            controller.save();

            controller.keyword = 'remark';
            controller.searchOpp();
            System.assertEquals(1, controller.viewList.size());
            idObj = (Inventory_Detail__c)controller.viewList[0].sobj;
            idObjList = [
                        SELECT Id, Inventory_Remarks__c
                          FROM Inventory_Detail__c
                         WHERE Inventory_Remarks__c LIKE '%remark%'
                        ];
            System.assertEquals(1, idObjList.size());
            System.assertEquals(idObj.Id, idObjList[0].Id);
            System.Test.StopTest();
        }

    }
}