liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
@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();
    }
}