高章伟
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
@isTest
private class ConsumSelectControllerTest {
 
    static testMethod void testUnAssign() {
        ConsumTestDataFactory factory = new ConsumTestDataFactory();
        factory.setupTestData();
        factory.selectDetails();
        factory.approve();
 
        factory.unAssign();
        Consum_Apply_Equipment_Set_Detail__c caesd = [SELECT Id, RAESD_Status__c, Consum_Apply_Equipment_Set__c FROM Consum_Apply_Equipment_Set_Detail__c];
        System.assertEquals('待分配', caesd.RAESD_Status__c);
 
        PageReference ref = new PageReference('/apex/ConsumSelect?recid=' + caesd.Consum_Apply_Equipment_Set__c);
        Test.setCurrentPage(ref);
        ConsumSelectController controller = new ConsumSelectController();
        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;
        caesd = (Consum_Apply_Equipment_Set_Detail__c) controller.viewList[0].sobj;
        caesd.Fen_Pei_Shu_Liang_Jia__c = 1;
        controller.save();
        Test.stopTest();
 
        caesd = [SELECT RAESD_Status__c FROM Consum_Apply_Equipment_Set_Detail__c];
        System.assertEquals('已分配',caesd.RAESD_Status__c);
    }
 
    static testMethod void testSave() {
        ConsumTestDataFactory factory = new ConsumTestDataFactory();
        factory.setupTestData();
        factory.selectDetails();
        factory.approve();
 
        factory.defaultAssign();
        Consum_Apply_Equipment_Set_Detail__c caesd = [SELECT Id, RAESD_Status__c, Consum_Apply_Equipment_Set__c FROM Consum_Apply_Equipment_Set_Detail__c];
        System.assertEquals('已分配', caesd.RAESD_Status__c);
 
        PageReference ref = new PageReference('/apex/ConsumSelect?recid=' + caesd.Consum_Apply_Equipment_Set__c);
        Test.setCurrentPage(ref);
        ConsumSelectController controller = new ConsumSelectController();
        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;
        caesd = (Consum_Apply_Equipment_Set_Detail__c) controller.viewList[0].sobj;
        caesd.Fen_Pei_Shu_Liang_Jia__c = 0;
        controller.save();
        Test.stopTest();
        // 一览下全都已分配的话,就不能取消分配
        caesd = [SELECT RAESD_Status__c FROM Consum_Apply_Equipment_Set_Detail__c];
        System.assertEquals('已分配',caesd.RAESD_Status__c);
    }
 
    static testMethod void testCoverUp() {
        ConsumSelectController.test();
    }
}