高章伟
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
@isTest
private class ConsumAssignCancelControllerTest {
    static ConsumTestDataFactory factory;
    @testSetup static void setupTestData(){
        factory = new ConsumTestDataFactory();
        factory.setupTestData();
        factory.selectDetails();
    }
    // 草案中取消
    //static testMethod void testSaveBeforeApprove() {
    static void testSaveBeforeApprove() {
        Consum_Apply__c ca = [SELECT Id FROM Consum_Apply__c LIMIT 1];
        List<Consum_Apply_Equipment_Set_Detail__c> caesdList = null;
        caesdList = [SELECT Id
                          , Cancel_Mem__c
                          , Cancel_Reason__c
                          , Cancel_Time__c
                          , Loaner_cancel_Remarks__c
                    FROM  Consum_Apply_Equipment_Set_Detail__c
                    WHERE Consum_Apply__c =: ca.Id
                ];
        System.assertEquals(null, caesdList[0].Cancel_Mem__c);
        System.assertEquals(null, caesdList[0].Cancel_Reason__c);
        System.assertEquals(null, caesdList[0].Cancel_Time__c);
        System.assertEquals(null, caesdList[0].Loaner_cancel_Remarks__c);
 
        PageReference ref = new PageReference('/apex/ConsumAssignCancel?pt_recid=' + ca.Id );
        Test.setCurrentPage(ref);
        ConsumAssignCancelController controller = new ConsumAssignCancelController();
        CreateRelationListPagingCmpCtrl cmp = new CreateRelationListPagingCmpCtrl();
        cmp.pageController = controller;
        controller.myComponentController.init();
        controller.init();
        controller.searchOpp();
        // 一条明细
        System.assertEquals(1, controller.viewlist.size());
 
        Test.startTest();
        controller.viewList[0].check=true;
        Consum_Apply_Equipment_Set__c caes = (Consum_Apply_Equipment_Set__c) controller.viewList[0].sobj;
        caes.VF_Cancel_Detail_Count__c = 1;
        caes.Cancel_Reason__c = '主动取消';
        controller.save();
        Test.stopTest();
 
        // 䓍案中取消,明细被删除
        caesdList =  [SELECT Cancel_Select__c FROM Consum_Apply_Equipment_Set_Detail__c WHERE Consum_Apply__c=:ca.Id];
        System.assertEquals(0, caesdList.size());
    }
    // 分配后取消
    static testMethod void testSaveAfterApprove() {
        ConsumTestDataFactory factory = new ConsumTestDataFactory();
        factory.approve();
        factory.defaultAssign();
        Consum_Apply__c ca = [SELECT Id
                                    , Request_approval_time__c
                                    , Status__c
                                 FROM Consum_Apply__c LIMIT 1];
        System.assertNotEquals(null, ca.Request_approval_time__c);
        System.assertEquals('已批准', ca.Status__c);
        List<Consum_Apply_Equipment_Set_Detail__c> caesdList = null;
        caesdList = [SELECT Id
                          , Cancel_Mem__c
                          , Cancel_Reason__c
                          , Cancel_Time__c
                          , Loaner_cancel_Remarks__c
                          , Cancel_Select__c
                          , RAESD_Status__c
                    FROM  Consum_Apply_Equipment_Set_Detail__c
                    WHERE Consum_Apply__c =: ca.Id
                ];
        System.assertEquals(null, caesdList[0].Cancel_Mem__c);
        System.assertEquals(null, caesdList[0].Cancel_Reason__c);
        System.assertEquals(null, caesdList[0].Cancel_Time__c);
        System.assertEquals(null, caesdList[0].Loaner_cancel_Remarks__c);
        System.assertEquals(false, caesdList[0].Cancel_Select__c);
        System.assertEquals('已分配', caesdList[0].RAESD_Status__c);
 
        PageReference ref = new PageReference('/apex/ConsumAssignCancel?pt_recid=' + ca.Id );
        Test.setCurrentPage(ref);
        ConsumAssignCancelController controller = new ConsumAssignCancelController();
        CreateRelationListPagingCmpCtrl cmp = new CreateRelationListPagingCmpCtrl();
        cmp.pageController = controller;
        controller.myComponentController.init();
        controller.init();
        controller.searchOpp();
        // 一个型号
        System.assertEquals(1, controller.viewlist.size());
 
        Test.startTest();
        controller.viewList[0].check=true;
        Consum_Apply_Equipment_Set__c caes = (Consum_Apply_Equipment_Set__c) controller.viewList[0].sobj;
        caes.VF_Cancel_Detail_Count__c = 1;
        caes.Cancel_Reason__c = '主动取消';
        caes.Loaner_cancel_Remarks__c = '取消理由';
        controller.save();
        Test.stopTest();
 
        caesdList = [SELECT Id
                          , Cancel_Mem__c
                          , Cancel_Reason__c
                          , Cancel_Time__c
                          , Loaner_cancel_Remarks__c
                          , Cancel_Select__c
                          , RAESD_Status__c
                    FROM  Consum_Apply_Equipment_Set_Detail__c
                    WHERE Consum_Apply__c =: ca.Id
                ];
        System.assertNotEquals(null, caesdList[0].Cancel_Mem__c);
        System.assertEquals('主动取消', caesdList[0].Cancel_Reason__c);
        System.assertNotEquals(null, caesdList[0].Cancel_Time__c);
        System.assertEquals('取消理由', caesdList[0].Loaner_cancel_Remarks__c);
        System.assertEquals(true, caesdList[0].Cancel_Select__c);
        System.assertEquals('取消', caesdList[0].RAESD_Status__c);
    }
}