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
60
61
62
63
64
65
66
67
68
@isTest
private class ConsumUploadPictureControllerTest {
    // 造出已出库
    @testSetup static void setupTestData(){
        ConsumTestDataFactory factory = new ConsumTestDataFactory();
        factory.setupTestData();
        factory.selectDetails();
        factory.approve();
        factory.defaultAssign();
        factory.shippmentRequest();
        factory.shipment();
    }
    // 正常上传
    static testMethod void testSave() {
        Consum_Apply__c ca = null ;
        List<Consum_Apply_Equipment_Set_Detail__c> caesdList = null;
        caesdList = [SELECT Picture1__c, Picture2__c, Has_Picture__c FROM Consum_Apply_Equipment_Set_Detail__c];
        System.assertEquals(null, caesdList[0].Picture1__c);
        System.assertEquals(null, caesdList[0].Picture2__c);
        System.assertEquals(false, caesdList[0].Has_Picture__c);
 
        PageReference ref = new PageReference('/apex/ConsumUploadPicture?caesd_id=' + caesdList[0].Id);
        Test.setCurrentPage(ref);
        ConsumUploadPictureController controller = new ConsumUploadPictureController();
 
        Test.startTest();
        controller.init();
        controller.caesd.Picture1__c = 'aaa';
        controller.caesd.Picture2__c = 'bbb';
        controller.save();
        controller.goback();
        Test.stopTest();
 
        caesdList = [SELECT Picture1__c, Picture2__c, Has_Picture__c FROM Consum_Apply_Equipment_Set_Detail__c];
        System.assertEquals('aaa', caesdList[0].Picture1__c);
        System.assertEquals('bbb', caesdList[0].Picture2__c);
        System.assertEquals(true, caesdList[0].Has_Picture__c);
    }
    // 已消耗的无法上传
    static testMethod void testSave1() {
        Consum_Apply__c ca = null ;
        ca = [SELECT Id FROM Consum_Apply__c];
        ca.HP_received_sign_rich__c = '试用表';
        update ca;
 
        List<Consum_Apply_Equipment_Set_Detail__c> caesdList = null;
        caesdList = [SELECT Picture1__c, Picture2__c, Has_Picture__c FROM Consum_Apply_Equipment_Set_Detail__c];
        System.assertEquals(null, caesdList[0].Picture1__c);
        System.assertEquals(null, caesdList[0].Picture2__c);
        System.assertEquals(false, caesdList[0].Has_Picture__c);
 
        PageReference ref = new PageReference('/apex/ConsumUploadPicture?caesd_id=' + caesdList[0].Id);
        Test.setCurrentPage(ref);
        ConsumUploadPictureController controller = new ConsumUploadPictureController();
 
        Test.startTest();
        controller.init();
        controller.caesd.Picture1__c = 'aaa';
        controller.caesd.Picture2__c = 'bbb';
        controller.save();
        Test.stopTest();
 
        caesdList = [SELECT Picture1__c, Picture2__c, Has_Picture__c FROM Consum_Apply_Equipment_Set_Detail__c];
        System.assertEquals(null, caesdList[0].Picture1__c);
        System.assertEquals(null, caesdList[0].Picture2__c);
        System.assertEquals(false, caesdList[0].Has_Picture__c);
    }
}