高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
@isTest
private class ReceivingNoteListControllerTest {
    static ReceivingNoteTestDataFactory factory;
    /**
    @description 安装master数据
    */
    @testSetup static void setupMasterData(){
        factory = new ReceivingNoteTestDataFactory();
        factory.setupMasterData();
    }
    /**
    @param typeStringListString 格式:'备品类型,管理种类;备品类型,管理种类...'
    @description 造出指定类型的清单数据,并插入数据库
    */
    static void setupTestData(String typeStringListString){
        factory = new ReceivingNoteTestDataFactory();
        if(String.isBlank(typeStringListString)){
            typeStringListString = '固定资产,个体管理;附属品,个体管理;附属品,数量管理;耗材,数量管理;低值易耗品,数量管理';
        }
        List<String> typeStringList = typeStringListString.split(';');
        factory.setupReceivingNoteData(typeStringList);
    }
 
    /**
    @description 获取一个清单下的所有一览
    */
    static testMethod void testInit() {
        setupTestData('固定资产,个体管理');
        ReceivingNote__c rn = factory.rnMap.get('固定资产,个体管理');
        ReceivingNoteSummary__c rns = factory.rnsMap.get('固定资产,个体管理');
        rn = [
                SELECT ReceivingNoteNo__c,ReceivingNoteNo_New__c
                  FROM ReceivingNote__c
                 WHERE Id=:rn.Id
            ];
 
 
        PageReference ref = new PageReference('/apex/ReceivingNoteList?id=' + rn.ReceivingNoteNo_New__c);
        Test.setCurrentPage(ref);
        ReceivingNoteListController controller = new ReceivingNoteListController();
        Test.startTest();
        controller.init();
        //System.assertEquals(1, controller.summaryInfoList.size());
        System.assertEquals(rns.Id, controller.summaryInfoList[0].rns.Id);
        Test.stopTest();
    }
 
    /**
    @description 记忆上一次操作
    */
    static testMethod void testSetType() {
        setupTestData('固定资产,个体管理');
        ReceivingNote__c rn = factory.rnMap.get('固定资产,个体管理');
        rn = [
                SELECT ReceivingNoteNo__c,ReceivingNoteNo_New__c
                  FROM ReceivingNote__c
                 WHERE Id=:rn.Id
            ];
 
        PageReference ref = new PageReference('/apex/ReceivingNoteList?id=' + rn.ReceivingNoteNo_New__c);
        Test.setCurrentPage(ref);
        ReceivingNoteListController controller = new ReceivingNoteListController();
        Test.startTest();
        controller.init();
        // 读出现有的操作
        String userId = Userinfo.getUserId();
        System_UserSetting__c config = System_UserSetting__c.getInstance(userId);
        System.assertEquals(null, config.ReceivingNote_Action_Type__c);
        // 修改操作类型
        controller.selectedType = '验收';
        controller.setType();
        // 再次查看修改后的操作类型
        config = System_UserSetting__c.getInstance(userId);
        System.assertEquals('验收', config.ReceivingNote_Action_Type__c);
 
        Test.stopTest();
    }
 
    /**
    @description 收货确认 与 取消收货确认
    */
    static testMethod void testReceivedConfirm() {
        // 收货状态调整为‘已数据确认’
        setupTestData('固定资产,个体管理');
        ReceivingNoteDetail__c rnd = factory.rndMap.get('固定资产,个体管理');
        rnd.DataConfirmation__c = true;
        rnd.unknow_serial_NO_product__c = 'TRUE';
        rnd.Loaner_accsessary__c = 'TRUE';
        upsert rnd Product_Serial_No__c;
 
        ReceivingNote__c rn = factory.rnMap.get('固定资产,个体管理');
        rn = [
                SELECT ReceivingNoteNo__c,ReceivingNoteNo_New__c
                  FROM ReceivingNote__c
                 WHERE Id=:rn.Id
            ];
 
        PageReference ref = new PageReference('/apex/ReceivingNoteList?id=' + rn.ReceivingNoteNo_New__c);
        Test.setCurrentPage(ref);
        ReceivingNoteListController controller = new ReceivingNoteListController();
        Test.startTest();
        controller.init();
 
        // 读出初始收货状态
        ReceivingNoteSummary__c rns = [
                SELECT Received_Confirm_Time__c
                     , Received_Confirm_Staff__c
                     , RNS_Status__c
                     , Package_Status_Memo__c
                     , Package_Status__c
                  FROM ReceivingNoteSummary__c
            ];
        // 当前状态为‘已收货确认’
        System.assertEquals(FixtureUtil.RNSStatusMap.get(FixtureUtil.RNSStatus.Yi_Shu_Ju_Que_Ren.ordinal()), rns.RNS_Status__c);
        System.assertEquals(true, String.isBlank(rns.Package_Status_Memo__c));
        System.assertEquals(true, String.isBlank(rns.Package_Status__c));
        System.assertEquals(null, rns.Received_Confirm_Time__c);
        System.assertEquals(null, rns.Received_Confirm_Staff__c);
 
        // 改为确认收货状态
        controller.selectedType = '收货确认';
        controller.summaryInfoList[0].isChecked=true;
        controller.summaryInfoList[0].rns.Package_Status_Memo__c = 'MEMO';
        controller.summaryInfoList[0].rns.Package_Status__c = 'OK';
 
        controller.receivedConfirm();
 
        // 再次查看收货状态
        rns = [
                SELECT Received_Confirm_Time__c
                     , Received_Confirm_Staff__c
                     , RNS_Status__c
                     , Package_Status_Memo__c
                     , Package_Status__c
                  FROM ReceivingNoteSummary__c
            ];
        // 当前状态为‘已收货确认’
        System.assertEquals(FixtureUtil.RNSStatusMap.get(FixtureUtil.RNSStatus.Yi_Shou_Huo_Que_Ren.ordinal()),rns.RNS_Status__c);
        System.assertEquals('MEMO', rns.Package_Status_Memo__c);
        System.assertEquals('OK', rns.Package_Status__c);
        System.assertNotEquals(null, rns.Received_Confirm_Time__c);
        System.assertNotEquals(null, rns.Received_Confirm_Staff__c);
 
        // 取消确认收货状态
        controller.selectedType = '取消收货确认';
        controller.summaryInfoList[0].isChecked=true;
        controller.receivedConfirm();
 
        // 再次查看收货状态
        rns = [
                SELECT Received_Confirm_Time__c
                     , Received_Confirm_Staff__c
                     , RNS_Status__c
                  FROM ReceivingNoteSummary__c];
        System.assertEquals(FixtureUtil.RNSStatusMap.get(FixtureUtil.RNSStatus.Yi_Shu_Ju_Que_Ren.ordinal()),rns.RNS_Status__c);
        System.assertEquals(null, rns.Received_Confirm_Time__c);
        System.assertEquals(null, rns.Received_Confirm_Staff__c);
 
        Test.stopTest();
    }
}