高章伟
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
@isTest
private class ReceivingNoteListFirstControllerTest {
    static ReceivingNoteTestDataFactory factory;
    static User user;
    /**
    @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);
        User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
        System.runAs (thisUser) {
            Profile p = [SELECT Id FROM Profile WHERE Name LIKE '%2B3%' Limit 1];
            UserRole r = [SELECT Id FROM UserRole WHERE DeveloperName = 'Stock_Article_Management_Member' Limit 1];
            user = new User(alias = 'test', email='test@acme.com', 
                emailencodingkey='UTF-8', lastname='test', 
                languagelocalekey='en_US', 
                localesidkey='en_US', profileid = p.Id, userroleid = r.Id,
                timezonesidkey='Asia/Shanghai', 
                username='test@acme.com' + Datetime.now().getTime());
            insert user;
        }
 
    }
 
    /**
    @description 测试检索功能:按不同条件检索,并检查检索结果
    */
    static testMethod void unitTestSearch() {
        setupTestData('');
 
        System.runAs(user){
 
        PageReference ref = new PageReference('/apex/ReceivingNoteListFirst');
        Test.setCurrentPage(ref);
 
        ReceivingNoteListFirstController controller = new ReceivingNoteListFirstController();
        CreateRelationListPagingCmpCtrl cmp = new CreateRelationListPagingCmpCtrl();
        cmp.pageController = controller;
        controller.myComponentController.init();
 
        Test.startTest();
        controller.init();
        controller.getbieCunFangDiOps();
        controller.getbieBenBuOps();
        controller.getbieChanPinFenLeiOps();
        controller.getbieBeiPinFenLeiOps();
        controller.getAsset_loaner_categoryOps();
        controller.getRNStatusOpss();
        controller.searchOpp();
 
        // 不加检索条件显示所有清单
        System.assertEquals(5, controller.viewList.size());
        // 存放地
        controller.bieCunFangDi = '北京 备品中心';
        controller.orderCode = null;
        controller.approvalNumber = null;
        controller.asset_loaner_category = null;
        controller.dateOfDelivery = null;
        controller.status = null;
        controller.searchOpp();
        System.assertEquals(5, controller.viewList.size());
        for(CreateRelationListPagingCtrlBase.WrapperInfo v : controller.viewList){
            ReceivingNote__c rn = (ReceivingNote__c) v.sobj ;
            System.assertEquals('北京 备品中心', rn.Internal_asset_location__c );
        }
 
        // 订单编码
        controller.bieCunFangDi = null;
        controller.orderCode='SB-ORDERCODE-1';
        controller.approvalNumber = null;
        controller.asset_loaner_category = null;
        controller.dateOfDelivery = null;
        controller.status = null;
 
        controller.searchOpp();
        System.assertEquals(1, controller.viewList.size());
        ReceivingNote__c rn1 = (ReceivingNote__c) controller.viewList[0].sobj ;
        System.assertEquals('SB-ORDERCODE-1', rn1.OrderCode__c);
 
        //裁决号
        controller.bieCunFangDi = null;
        controller.orderCode = null;
        controller.approvalNumber = 'SB-APPROVALNUMBER-2';
        controller.asset_loaner_category = null;
        controller.dateOfDelivery = null;
        controller.status = null;
 
        controller.searchOpp();
        System.assertEquals(1, controller.viewList.size());
        ReceivingNote__c rn2 = (ReceivingNote__c) controller.viewList[0].sobj ;
        System.assertEquals('SB-APPROVALNUMBER-2', rn2.ApprovalNumber__c);
 
        // 备品类别
        controller.bieCunFangDi = null;
        controller.orderCode = null;
        controller.approvalNumber = null;
        controller.asset_loaner_category = '附属品';
        controller.dateOfDelivery = null;
        controller.status = null;
 
        controller.searchOpp();
        System.assertEquals(2, controller.viewList.size());
        for(CreateRelationListPagingCtrlBase.WrapperInfo v : controller.viewList){
            ReceivingNote__c rn = (ReceivingNote__c) v.sobj ;
            System.assertEquals('附属品', rn.Asset_loaner_category__c );
        }
 
        // 发货日
        controller.bieCunFangDi = null;
        controller.orderCode = null;
        controller.approvalNumber = null;
        controller.asset_loaner_category = null;
        String todayStr =  System.Now().format('yyyy-MM-dd');
        controller.dateOfDelivery = todayStr;
 
        controller.status = null;
 
        controller.searchOpp();
 
        System.assertEquals(5, controller.viewList.size());
        for(CreateRelationListPagingCtrlBase.WrapperInfo v : controller.viewList){
            ReceivingNote__c rn = (ReceivingNote__c) v.sobj ;
            System.assertEquals(Date.Today(), rn.DateOfDelivery__c);
        }
 
        // 收货状态
        controller.bieCunFangDi = null;
        controller.orderCode = null;
        controller.approvalNumber = null;
        controller.asset_loaner_category = null;
        controller.dateOfDelivery = null;
        controller.status = '待数据确认';
 
        controller.searchOpp();
        System.assertEquals(5, controller.viewList.size());
        for(CreateRelationListPagingCtrlBase.WrapperInfo v : controller.viewList){
            ReceivingNote__c rn = (ReceivingNote__c) v.sobj ;
            System.assertEquals('待数据确认', rn.RN_Status__c);
        }
 
        Test.stopTest();
        }
    }
    /**
    @description 测试入库指示
    */
    static testMethod void unitTestInStockRequest() {
        // 造出可以做入库指示的明细
        setupTestData('固定资产,个体管理');
 
        ReceivingNoteDetail__c rnd = factory.rndMap.get('固定资产,个体管理');
        ReceivingNoteSummary__c rns = factory.rnsMap.get('固定资产,个体管理');
        // 数据确认
        rnd.unknow_serial_NO_product__c = 'TRUE';
        rnd.Loaner_accsessary__c = 'TRUE';
        rnd.DataConfirmation__c = true;
        // 收货
        rns.Received_Confirm_Time__c = Datetime.now();
        rns.Package_Status__c = 'OK';
        upsert rns Id;
        // 清点
        rnd.AcceptanceResult__c = 'OK';
        rnd.AcceptanceTime__c = Datetime.now();
        // 验收
        rnd.Inspection_result_after__c = 'OK';
        rnd.After_Inspection_time__c = Datetime.now();
        // 再确认
        rnd.DataConfirmationAgain__c = true;
        upsert rnd Id;
 
        System.runAs(user){
        PageReference ref = new PageReference('/apex/ReceivingNoteListFirst');
        Test.setCurrentPage(ref);
        ReceivingNoteListFirstController controller = new ReceivingNoteListFirstController();
        CreateRelationListPagingCmpCtrl cmp = new CreateRelationListPagingCmpCtrl();
        cmp.pageController = controller;
        controller.myComponentController.init();
 
        Test.startTest();
 
        controller.init();
        controller.status = '待入库指示';
        controller.searchOpp();
        // 不加检索条件显示所有清单
        System.assertEquals(1, controller.viewList.size());
 
        // 入库指示
        controller.viewList[0].check = true;
        controller.inStockRequest();
        ReceivingNoteDetail__c newRnd = [
                SELECT Arrival_wh_Request_time__c
                  FROM ReceivingNoteDetail__c
                 WHERE Id =: rnd.Id
            ];
        System.assertNotEquals(null, newRnd.Arrival_wh_Request_time__c);
 
        Test.stopTest();
        }
    }
}