buli
2022-05-13 2f4492ee18f90274582fcc2bb06f5e9bf64136e8
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
@isTest
private class NewLoanerApplicationControllerTest {
    static void setupTestData() {
                OlympusCalendar__c oc1 = new OlympusCalendar__c(Date__c = Date.today().addDays(1), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
                OlympusCalendar__c oc2 = new OlympusCalendar__c(Date__c = Date.today().addDays(2), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
                OlympusCalendar__c oc3 = new OlympusCalendar__c(Date__c = Date.today().addDays(3), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
                OlympusCalendar__c oc4 = new OlympusCalendar__c(Date__c = Date.today().addDays(4), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
                OlympusCalendar__c oc5 = new OlympusCalendar__c(Date__c = Date.today().addDays(5), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
                OlympusCalendar__c oc6 = new OlympusCalendar__c(Date__c = Date.today().addDays(6), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
                OlympusCalendar__c oc7 = new OlympusCalendar__c(Date__c = Date.today().addDays(7), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
                OlympusCalendar__c oc8 = new OlympusCalendar__c(Date__c = Date.today().addDays(8), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
                OlympusCalendar__c oc9 = new OlympusCalendar__c(Date__c = Date.today().addDays(9), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
                OlympusCalendar__c oc10 = new OlympusCalendar__c(Date__c = Date.today().addDays(10), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
                OlympusCalendar__c oc11 = new OlympusCalendar__c(Date__c = Date.today().addDays(11), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
                OlympusCalendar__c oc12 = new OlympusCalendar__c(Date__c = Date.today().addDays(12), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
                OlympusCalendar__c oc13 = new OlympusCalendar__c(Date__c = Date.today().addDays(-1), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
                OlympusCalendar__c oc14 = new OlympusCalendar__c(Date__c = Date.today().addDays(-2), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
                OlympusCalendar__c oc15 = new OlympusCalendar__c(Date__c = Date.today().addDays(-3), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
                OlympusCalendar__c oc16 = new OlympusCalendar__c(Date__c = Date.today().addDays(-4), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
                OlympusCalendar__c oc17 = new OlympusCalendar__c(Date__c = Date.today().addDays(-5), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
 
                insert new OlympusCalendar__c[] {oc1,oc2,oc3,oc4,oc5,oc6,oc7,oc8,oc9,oc10,oc11,oc12,oc13,oc14,oc15,oc16,oc17};
            }
    @isTest static void test_method_one() {
        setupTestData();
        // Implement test code
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
 
        // 新建 客户
        Account acc = new Account();
        acc.RecordTypeId = rectCo[0].Id;
        acc.Name         = '客户テスト1';
        acc.DivisionName__c = 'DivTEST';
        acc.FacilityName__c = 'FacTEST    ';
        acc.PostCode__c = '000000';
        insert acc;
 
        // 新建 联系人
        Contact con = new Contact();
        con.LastName = 'test1';
        con.AccountId = acc.Id;
        con.Address1__c = 'Address1D__c';
        con.Postcode__c = '100111';
        con.ContactStatus__c = 'ContactStatusD__c';
        con.StatusD__c = 'Pass';
        insert con;
 
        // 新建用户
        User user = new User();
        user.LastName = 'test';
        user.FirstName = 'test';
        user.Alias = 'test';
        user.Email = 'test@test.com';
        user.Username = 'test111@test222.com';
        user.CommunityNickname = 'test';
        user.IsActive = true;
        user.EmailEncodingKey = 'ISO-2022-JP';
        user.TimeZoneSidKey = 'Asia/Tokyo';
        user.LocaleSidKey = 'ja_JP';
        user.LanguageLocaleKey = 'ja';
        user.ProfileId = System.Label.SystemAdmin;
        insert user;
 
        //PageReference page = new PageReference('/apex/NewLoanerApplicationController?accid=' + acc.Id );
        PageReference page = new PageReference('/apex/NewLoanerApplicationController?accid=' + acc.Id + '&ConId=' + con.id);
        System.Test.setCurrentPage(page);
        NewLoanerApplicationController  controller = new NewLoanerApplicationController();
 
        controller.init();
 
        List<RecordType> rectLo = [select Id from RecordType where IsActive = true and SobjectType = 'loaner_application__c' and Name = 'IE'];
 
        controller.la.name = '申请1';
        controller.la.Demo_purpose__c = '展会';
        controller.la.RecordTypeId = rectLo[0].id;
        controller.la.Loaner_Ser__c = '借用担当';
        controller.la.Request_shipping_Date__c = Date.today();
        controller.la.Request_return_Date__c = Date.today().addDays(2);
        controller.la.Approver__c = user.id;
 
        controller.saveBtn();
 
        List<loaner_user__c> luNew = [select Id, Remarks__c, Contact__r.name, Customer__c, ContactNumber__c from loaner_user__c];
        List<loaner_application__c> laNew = [select name from loaner_application__c];
 
        system.assertEquals('申请1', laNew[0].name);
        system.assertEquals(acc.id, luNew[0].Customer__c);
 
 
        controller.cancelBtn();
    }
    
    @isTest static void test_method_two() {
        // Implement test code
    }
    
}