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
@isTest
private class ConsumApplySplitControllerTest {
    static ConsumTestDataFactory factory;
    // 造 两个一览,各一条明细,草案中
    @testSetup static void setupTestData(){
        ConsumTestDataFactory factory = new ConsumTestDataFactory();
        factory.setupTestData();
        factory.selectDetails(2);
        TestDataUtility.CreatePIPolicyConfiguration();
    }
    // 䓍案中分单
    static testMethod void testSaveSplitError() {
        Consum_Apply__c ca = [SELECT Id FROM Consum_Apply__c];
        List<Consum_Apply_Equipment_Set__c> caesList = [SELECT Id FROM Consum_Apply_Equipment_Set__c WHERE Consum_Apply__c=:ca.Id];
        System.assertEquals(2, caesList .size());
 
        PageReference ref = new PageReference('/apex/ConsumApplySplit');
        ref.getParameters().put('objId', ca.Id);
        ref.getParameters().put('raesIds', caesList[0].Id);
        Test.setCurrentPage(ref);
        ConsumApplySplitController controller = new ConsumApplySplitController();
        controller.init();
 
        Test.startTest();
        controller.cloneRas.Split_Apply_Reason__c = '分批发货分单';
        controller.saveSplit();
        Test.stopTest();
 
        // 分单失败,只有一个申请
        List<Consum_Apply__c> caList = [SELECT Id FROM Consum_Apply__c];
        System.assertEquals(1, caList.size());
    }
 
    // 批准后分单
    static testMethod void testSaveSplit() {
        // 变成已批准
        ConsumTestDataFactory factory = new ConsumTestDataFactory();
        factory.approve();
 
        List<Consum_Apply_Equipment_Set__c> caesList = [SELECT Id FROM Consum_Apply_Equipment_Set__c WHERE Consum_Apply__c=:factory.ca.Id];
        System.assertEquals(2, caesList .size());
 
        PageReference ref = new PageReference('/apex/ConsumApplySplit');
        ref.getParameters().put('objId', factory.ca.Id);
        ref.getParameters().put('raesIds', caesList[0].Id);
        Test.setCurrentPage(ref);
        ConsumApplySplitController controller = new ConsumApplySplitController();
        controller.init();
 
        Test.startTest();
        controller.cloneRas.Split_Apply_Reason__c = '分批发货分单';
        controller.saveSplit();
        Test.stopTest();
 
        // 分单成功,有两个申请
        List<Consum_Apply__c> caList = [SELECT Id FROM Consum_Apply__c];
        System.assertEquals(2, caList.size());
    }
}