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
@isTest
private class ConsumApplyCancelControllerTest {
    // 造出选择完明细的申请
    @testSetup static void setupTestData(){
        ConsumTestDataFactory factory = new ConsumTestDataFactory();
        factory.setupTestData();
    }
    static testMethod void testSaveCancel() {
        Consum_Apply__c ca = [SELECT Id FROM Consum_Apply__c LIMIT 1];
        PageReference ref = new PageReference('/apex/ConsumApplyCancel?objId=' + ca.Id);
        Test.setCurrentPage(ref);
        ConsumApplyCancelController controller = new ConsumApplyCancelController();
        controller.init();
        Test.startTest();
        // 不填取消理由,取消不成功
        controller.ra.Loaner_cancel_request__c = '取消备注';
        controller.saveCancel();
        ca = [SELECT Id, RA_Status__c FROM Consum_Apply__c LIMIT 1];
        System.assertNotEquals('取消', ca.RA_Status__c);
        System.assertEquals('ng', controller.saveStatus);
 
        // 填写理由,取消成功
        controller.ra.Cancel_Reason__c = '主动取消';
        controller.saveCancel();
        ca = [SELECT Id, RA_Status__c FROM Consum_Apply__c LIMIT 1];
        System.assertEquals('取消', ca.RA_Status__c);
        System.assertEquals('ok', controller.saveStatus);
        Test.stopTest();
    }
}