@isTest
private class NotReceivingNoteWaitingReceiptCtrlTest {
    
    static ReceivingNoteTestDataFactory factory;
    /**
    @param typeStringListString 格式：'备品类型,管理种类;备品类型,管理种类...'
    @description 造出指定类型的清单数据,并插入数据库
    */
    static void setupTestData(String typeStringListString){
        factory = new ReceivingNoteTestDataFactory();
        factory.setupMasterData();
        if(String.isBlank(typeStringListString)){
            typeStringListString = '固定资产,个体管理;附属品,个体管理;附属品,数量管理;耗材,数量管理;低值易耗品,数量管理';
        }
        List<String> typeStringList = typeStringListString.split(';');
        factory.setupReceivingNoteData(typeStringList);
    }
    /**
    *@description 保存
    */
    static testMethod void unitTestSave() {
        setupTestData('');
        PageReference ref = new PageReference('/apex/NotReceivingNoteWaitingReceipt?parId=' + factory.rnMap.get('固定资产,个体管理').Id);
        Test.setCurrentPage(ref);
        NotReceivingNoteWaitingReceiptController controller = new NotReceivingNoteWaitingReceiptController();
        Test.startTest();
        controller.init();
        controller.getStatusOps();
        controller.changeFixModel();
        // 不加检索条件则得到全部明细
        controller.search();
        System.assertEquals(1, controller.pageB.rowBList.size());
        //条件检索
        controller.pageB.status = '待数据确认';
        controller.search();
        Id rndId = controller.pageB.rowBList[0].rnd.Id;
        controller.pageB.rowBList[0].checked = true;
        controller.pageB.rowBList[0].rnd.SerialNumber__c = 'test';
        System.assertEquals(1, controller.pageB.rowBList.size());
        controller.saveRecord();
        Test.stopTest();

    }
    /**
    *@description 数据确认
    */
    static testMethod void unitTestdefineSaveRecord() {
        setupTestData('');
        PageReference ref = new PageReference('/apex/NotReceivingNoteWaitingReceipt?parId=' + factory.rnMap.get('固定资产,个体管理').Id);
        Test.setCurrentPage(ref);
        NotReceivingNoteWaitingReceiptController controller = new NotReceivingNoteWaitingReceiptController();
        Test.startTest();
        controller.init();
        // 改为可编辑
        controller.changeFixModel();
        //条件检索
        controller.pageB.status = '待数据确认';
        controller.search();
        System.assertEquals(1, controller.pageB.rowBList.size());
        // 取出第一条数据
        Id rndId = controller.pageB.rowBList[0].rnd.Id;
        controller.pageB.rowBList[0].checked = true;
        controller.pageB.rowBList[0].rnd.SerialNumber__c = 'test';
        controller.defineSaveRecord();
         // 确认修改后结果
        ReceivingNoteDetail__c newRnd = [
                SELECT SerialNumber__c
                  FROM ReceivingNoteDetail__c
                 WHERE Id = :rndId
            ];
        System.assertEquals('test', newRnd.SerialNumber__c);
        Test.stopTest();
    }
}