高章伟
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
@isTest
private class ReceivingNoteWaitingReceiptCtrlTest {
    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 unitTestSearch() {
        setupTestData('');
 
        PageReference ref = new PageReference('/apex/ReceivingNoteWaitingReceipt?parId=' + factory.rnMap.get('固定资产,个体管理').Id);
        Test.setCurrentPage(ref);
 
        ReceivingNoteWaitingReceiptController controller = new ReceivingNoteWaitingReceiptController();
 
        Test.startTest();
        controller.init();
        controller.getStatusOps();
        controller.getSalesdepartmentOps();
        controller.getSalesProvinceOps();
        controller.getProductCategoryOps();
        controller.getEquipmentTypeOps();
        controller.getManageTypeOps();
        controller.getUnknowSerialNOProductOps();
        controller.getLoanerAccsessaryOps();
        controller.getcategoryOps();
        // 不加检索条件则得到全部明细
        controller.search();
        // System.assertEquals(1, controller.pageB.rowBList.size());
 
        // 单条件
        controller.pageB.rn.Status__c = null;
        controller.pageB.rn.Asset_loaner_category__c = '固定资产';
        controller.pageB.fixture_Model_No = null;
        controller.search();
        // System.assertEquals(1, controller.pageB.rowBList.size());
 
        Test.stopTest();
 
    }
 
    /**
    *@description 测试保存功能
    */
    static testMethod void unitTestSaveRecord() {
        setupTestData('固定资产,个体管理');
 
        PageReference ref = new PageReference('/apex/ReceivingNoteWaitingReceipt?parId=' + factory.rnMap.get('固定资产,个体管理').Id);
        Test.setCurrentPage(ref);
 
        ReceivingNoteWaitingReceiptController controller = new ReceivingNoteWaitingReceiptController();
 
        Test.startTest();
        // 初始化
        controller.init();
        controller.search();
        // 改为可编辑
        controller.changeFixModel();
        // 取出第一条数据
        ReceivingNoteWaitingReceiptController.RowBean rowB = controller.pageB.rowBList[0];
        Id rndId = rowB.rnd.Id;
        // 修改字段值
        rowB.checked = true;
        rowB.rnd.Salesdepartment__c = '0.备品中心';
        rowB.rnd.SalesProvince__c = '大连';
        rowB.rnd.Product_category__c = 'GI';
        rowB.rnd.Equipment_Type__c = '产品试用';
        rowB.rnd.Manage_type__c = '个体管理';
        rowB.rnd.unknow_serial_NO_product__c = 'FALSE';
        rowB.rnd.Loaner_accsessary__c = 'TRUE';
        rowB.rnd.DataConfirmation__c = true;
        // 运行saveRecord()
        controller.saveRecord();
        // 确认修改后结果
        ReceivingNoteDetail__c newRnd = [
                SELECT Salesdepartment__c
                     , SalesProvince__c
                     , Product_category__c
                     , Equipment_Type__c
                     , Manage_type__c
                     , unknow_serial_NO_product__c
                     , Loaner_accsessary__c
                     , DataConfirmation__c
                  FROM ReceivingNoteDetail__c
                 WHERE Id = :rndId
            ];
        // System.assertEquals('0.备品中心', newRnd.Salesdepartment__c);
        // System.assertEquals('大连', newRnd.SalesProvince__c);
        // System.assertEquals('GI', newRnd.Product_category__c);
        // System.assertEquals('产品试用', newRnd.Equipment_Type__c);
        // System.assertEquals('个体管理', newRnd.Manage_type__c);
        // System.assertEquals('FALSE', newRnd.unknow_serial_NO_product__c);
        // System.assertEquals('TRUE', newRnd.Loaner_accsessary__c);
        // System.assertEquals(true, newRnd.DataConfirmation__c);
 
        Test.stopTest();
    }
 
    /**
    *@description 测试取消功能
    */
    static testMethod void unitTestCancelRecord() {
 
    }
 
    /**
    @description 测试【选择配套】按键
    */
    static testMethod void unitTestSelectRNS() {
 
        setupTestData('固定资产,个体管理');
        Id rnId = factory.rnMap.get('固定资产,个体管理').Id;
        Id rnsId = factory.rnsMap.get('固定资产,个体管理').Id;
 
        PageReference ref = new PageReference('/apex/ReceivingNoteWaitingReceipt?parId=' + rnId);
        Test.setCurrentPage(ref);
 
        ReceivingNoteWaitingReceiptController controller = new ReceivingNoteWaitingReceiptController();
 
        Test.startTest();
        controller.init();
        controller.search();
        controller.pageB.rowBList[0].checked = true;
 
        //   跳转页面
        PageReference pg = controller.selectRNS();
        Map<String,String> params = pg.getParameters();
 
        // System.assertEquals(params.get('pt_recid'), rnId);
        // System.assertEquals(params.get('raesid'), rnsId);
 
        Test.stopTest();
    }
    /**
    @description 显示错误信息
    */
    static testMethod void unitTestShowApplyMsg() {
 
        setupTestData('固定资产,个体管理');
        Id rnId = factory.rnMap.get('固定资产,个体管理').Id;
        Id rnsId = factory.rnsMap.get('固定资产,个体管理').Id;
 
        PageReference ref = new PageReference('/apex/ReceivingNoteWaitingReceipt?parId=' + rnId);
        ReceivingNoteWaitingReceiptController controller = new ReceivingNoteWaitingReceiptController();
        Test.setCurrentPage(ref);
        Test.startTest();
 
        // 设定错误信息
        ref.getParameters().put('applyMsg', 'TEST MESSAGE');
        ref.getParameters().put('applyMsgType', 'Fail');
 
        // 执行之前,页面上没有报错误信息
        List<Apexpages.Message> msgs = ApexPages.getMessages();
        Boolean b = false;
        for(Apexpages.Message msg:msgs){
            if (msg.getDetail().contains('TEST MESSAGE')) {
                b = true;
            }
        }
        // System.assertEquals(false, b);
 
        // 执行
        controller.showApplyMsg();
 
        // 错误信息被报出
        msgs = ApexPages.getMessages();
        b = false;
        for(Apexpages.Message msg:msgs){
            if (msg.getDetail().contains('TEST MESSAGE')) {
                b = true;
            }
        }
        // System.assertEquals(true, b);
        Test.stopTest();
    }
    /**
    @description 发邮件测试
    */
    static testMethod void unitTestSendEmail() {
        setupTestData('固定资产,个体管理');
        Id rnId = factory.rnMap.get('固定资产,个体管理').Id;
        Id rnsId = factory.rnsMap.get('固定资产,个体管理').Id;
 
        PageReference ref = new PageReference('/apex/ReceivingNoteWaitingReceipt?parId=' + factory.rnMap.get('固定资产,个体管理').Id);
        Test.setCurrentPage(ref);
 
        ReceivingNoteWaitingReceiptController controller = new ReceivingNoteWaitingReceiptController();
 
        Test.startTest();
        // 初始化
        controller.init();
        controller.search();
 
        controller.pageB.rowBList[0].checked = true;
        String emailMsg = controller.pageB.rowBList[0].rnd.Name+'<BR>';
        String emailBody = 'ARE YOU OK?';
        ref.getParameters().put('emailBody', emailBody);
        controller.sendEmail();
 
        ReceivingNote__c rn = [select Model_Reminder_Email_Text__c from ReceivingNote__c WHERE Id=:rnId ];
        // System.assertNotEquals(null, rn.Model_Reminder_Email_Text__c);
 
        Test.stopTest();
    }
    /**
    @description 编辑备品入库处理、备品入库产品
    */
    static testMethod void unitTestRules() {
        setupTestData('固定资产,个体管理');
 
        // 选择变体时,备品入库产品不能为空
        ReceivingNoteDetail__c rndObj = factory.rndMap.get('固定资产,个体管理');
        rndObj.Fixture_Arrival_Process__c = '变体';
 
        String msg;
 
        Test.startTest();
        try {
            update rndObj;
        } catch (Exception e) {
            msg = e.getMessage();
        }
 
        // System.assertEquals(true, msg.contains('请选择备品入库产品。'));
 
        rndObj.Fixture_Arrival_Product__c = factory.proList[2].Id;
        rndObj.Fixture_Arrival_Process__c = '变体';
        update rndObj;
        ReceivingNoteDetail__c rndObjUpdated = [SELECT Id, Fixture_Arrival_Product__c FROM ReceivingNoteDetail__c WHERE Id=:rndObj.Id];
        // System.assertNotEquals(null, rndObjUpdated.Fixture_Arrival_Product__c);
 
        Test.stopTest();
 
    }
 
    //add by rentx 20210824 start
    static testMethod void testMethod01() {
        setupTestData('固定资产,个体管理');
        Id rnId = factory.rnMap.get('固定资产,个体管理').Id;
        Id rnsId = factory.rnsMap.get('固定资产,个体管理').Id;
 
        PageReference ref = new PageReference('/apex/ReceivingNoteWaitingReceipt?parId=' + factory.rnMap.get('固定资产,个体管理').Id);
        Test.setCurrentPage(ref);
 
        ReceivingNoteWaitingReceiptController controller = new ReceivingNoteWaitingReceiptController();
 
        Test.startTest();
        // 初始化
        controller.init();
        controller.search();
 
        controller.pageB.rowBList[0].checked = true;
        controller.pageB.rowBList[0].rnd.Loaner_accsessary__c = 'FALSE';
        controller.saveRecord();
        Test.stopTest();
    }
    //add by rentx 20210824 end
 
}