李彤
2022-04-02 2f1466af31796c1a963f26e86038ddc84471ed2e
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/**
 * This class contains unit tests for validating the behavior of Apex classes
 * and triggers.
 *
 * Unit tests are class methods that verify whether a particular piece
 * of code is working properly. Unit test methods take no arguments,
 * commit no data to the database, and are flagged with the testMethod
 * keyword in the method definition.
 *
 * All test methods in an organization are executed whenever Apex code is deployed
 * to a production organization to confirm correctness, ensure code
 * coverage, and prevent regressions. All Apex classes are
 * required to have at least 75% code coverage in order to be deployed
 * to a production organization. In addition, all triggers must have some code coverage.
 * 
 * The @isTest class annotation indicates this class only contains test
 * methods. Classes defined with the @isTest annotation do not count against
 * the organization size limit for all Apex scripts.
 *
 * See the Apex Language Reference for more information about Testing and Code Coverage.
 */
@isTest
private class SetPersonalTargetControllerTest {
 
    static testMethod void myUnitTest() {
        
        RecordType rt = [select Id from RecordType where SobjectType = 'Opportunity' and IsActive = true and DeveloperName = 'Target'];
        
        // システム管理者
        User u3 = new User();
        u3.LastName = '_サンブリッジ00';
        u3.FirstName = 'う';
        u3.Alias = 'う';
        u3.Email = 'olympusTest03@sunbridge.com';
        u3.Username = 'olympusTest03@sunbridge.com';
        u3.CommunityNickname = 'う';
        u3.IsActive = true;
        u3.EmailEncodingKey = 'ISO-2022-JP';
        u3.TimeZoneSidKey = 'Asia/Tokyo';
        u3.LocaleSidKey = 'ja_JP';
        u3.LanguageLocaleKey = 'ja';
        u3.ProfileId = System.Label.ProfileId_SystemAdmin;
        u3.Job_Category__c = '销售推广';
        u3.Province__c = '上海市';
        u3.Use_Start_Date__c = Date.today().addMonths(-6);
        insert u3;
        
        System.runAs(u3) {
//            // 5.华南销售本部に変更
//            List<User> us = [select Id from User where IsActive = true and Id != :u3.Id];
//            for (User u : us) {
//                u.Province__c = '湖北省';
//            }
//            update us;
 
            // 102_销售产品推广
            User u1 = new User();
            u1.LastName = '_サンブリッジ01';
            u1.FirstName = 'あ1';
            u1.Alias = 'あ9';
            u1.Email = 'olympusTest01@sunbridge.com';
            u1.Username = 'olympusTest09@sunbridge.com';
            u1.CommunityNickname = 'あ9';
            u1.IsActive = true;
            u1.EmailEncodingKey = 'ISO-2022-JP';
            u1.TimeZoneSidKey = 'Asia/Tokyo';
            u1.LocaleSidKey = 'ja_JP';
            u1.LanguageLocaleKey = 'ja';
            u1.ProfileId = System.Label.ProfileId_SystemAdmin;
            u1.Job_Category__c = '销售推广';
            u1.Province__c = '河北省';
            u1.Post__c = '一般';
            u1.Sales_Speciality__c = '医院担当';
            u1.Use_Start_Date__c = Date.today().addYears(-1);
            insert u1;
            
            User u2 = new User();
            u2.LastName = '四洋';
            u2.FirstName = '张';
            u2.Alias = '张四洋';
            u2.Email = 'olympusTest02@sunbridge.com';
            u2.Username = 'olympusTest02@sunbridge.com';
            u2.CommunityNickname = '张四洋';
            u2.IsActive = true;
            u2.EmailEncodingKey = 'ISO-2022-JP';
            u2.TimeZoneSidKey = 'Asia/Tokyo';
            u2.LocaleSidKey = 'ja_JP';
            u2.LanguageLocaleKey = 'ja';
            u2.ProfileId = System.Label.ProfileId_SystemAdmin;
            u2.Job_Category__c = '销售推广';
            u2.Province__c = '上海市';
            u2.Post__c = '主管';
            u2.Sales_Speciality__c = '医院担当';
            u2.Use_Start_Date__c = Date.today().addYears(-1);
            insert u2;
            // 现在时间
            Date dateNow = Date.today();
            Integer year = dateNow.year();
            Integer month = dateNow.month();
            if (month < 4) {
                year -= 1;
            }
            Amount_Major_Product__c amp=new Amount_Major_Product__c();
            amp.key__c=U2.id+'_GI';
            amp.Amount__c=200.0;
            amp.user_Alias__c=U2.Alias;
            amp.Is_Processing__c=true;
            amp.iYear__c=year;
            amp.SAP_Province__c = U2.Province__c;
            amp.Use_Start_Date__c = U2.Use_Start_Date__c;
 
            insert amp;
 
            SetPersonalTargetController odc = new SetPersonalTargetController();
            // 初期表示
            odc.init();
            //System.assertEquals(1, odc.getUserSize());
            //System.assertEquals(7, odc.getPSize());
            //System.assertEquals(1, odc.dataBeans.size());
            
            //wangweipeng      SWAG-C6V8W5        2021/09/16     start
            odc.saveFlg = true;
            odc.searchByFilter();
            //wangweipeng      SWAG-C6V8W5        2021/09/16     end
        
        
            // 検索
            // 3.西北销售本部
            odc.salesDpt = '3.西北销售本部_Dummy';
            odc.searchByDpt();
            System.assertEquals(0, odc.dataBeans.size());
            
            // 上海市
            odc.loginUser.Province__c = '上海市';
            odc.searchByProvince();
            //System.assertEquals(1, odc.dataBeans.size());
            
            // 职位:一般
            odc.plist[0].check = true;
            odc.plist[1].check = false;
            odc.plist[2].check = false;
            odc.plist[3].check = false;
            odc.plist[4].check = false;
            // odc.plist[5].check = false;
            // odc.plist[6].check = false;
            //odc.searchByFilter();
            //System.assertEquals(1, odc.dataBeans.size());
            //导出
            odc.exportBycsv();
 
            //odc.csvFileBody = Blob.valueOf('本部,省,角色,担当,职位,负责产品分类,GI,ET,BF,GS,URO,GYN,ENT,ENG \n,5.华东,上海市,上海GI组,张四洋,主管,GI,2000,2345,123,1200,400,500,40,55');
            odc.csvAsString = '本部,省,角色,担当,职位,负责产品分类(主),负责产品分类(兼),GI,ET,BF,GS,URO,GYN,ENT,ENG\n5.华东,上海市,上海GI组,张四洋,主管,GI,,2000,2345,123,1200,400,500,40,55';
            //test read csv file
            odc.importCSVFile();
            
 
            // 保存
            //odc.dataBeans[0].amount[0].Amount = 100;
            //odc.dataBeans[0].isChanged = '1';
            odc.saveBtn();
            
            /*List<Opportunity> opps = [select SAP_Province__c, Amount from Opportunity where RecordTypeId = :rt.Id];
            System.assertEquals('上海市上海市', opps[0].SAP_Province__c);
            System.assertEquals(100, opps[0].Amount);*/
            
            // 上年度
            odc.previous();
            //System.assertEquals(false, odc.previousRendered);
            
            // 下年度
            odc.next();
            //System.assertEquals(null, odc.dataBeans[0].amount[0].Amount);
            
            // 返回
            odc.backBtn();
        }
    }
}