高章伟
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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
@isTest
private class AgencyHospitalLinkControllerTest
{
    static Account agency1;
    static Account agency2;
    static void initAgencyHospital() {
        //医院
        RecordType hospitP = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name='病院' limit 1];
        //销售商
        RecordType agencyP = [select Id from RecordType where IsActive = true and SobjectType= 'Account' and Name = '販売店' limit 1];
        //省
        Address_Level__c alc1 = new Address_Level__c(
            Name = '安徽省'
        );
        Address_Level__c alc2 = new Address_Level__c(
            Name = '河南省'
        );
        insert new Address_Level__c[] {alc1,alc2};
 
        Address_Level2__c alc11 = new Address_Level2__c(
            Name = '黄山市',Address_Level__c = alc1.Id,Level1_Name__c='安徽省'
        );
        Address_Level2__c alc12 = new Address_Level2__c(
            Name = '合肥市',Address_Level__c = alc1.Id,Level1_Name__c='安徽省'
        );
 
        Address_Level2__c alc21 = new Address_Level2__c(
            Name = '郑州市',Address_Level__c = alc2.Id,Level1_Name__c='河南省'
        );
        insert new Address_Level2__c[] {alc11,alc12,alc21};
 
 
        //安徽
        Account hospital1 = new Account();
        hospital1.Name = 'test hospital1';
        hospital1.RecordTypeId = hospitP.id; 
        hospital1.State_Master__c = alc1.id; 
        hospital1.OCM_Category__c = 'SLTV'; 
        hospital1.City_Master__c = alc11.id;
        hospital1.Is_Active__c = '有効';
        
        Account hospital2 = new Account();
        hospital2.Name = 'test hospital2';
        hospital2.RecordTypeId = hospitP.id;
        hospital2.State_Master__c = alc1.id; 
        hospital2.OCM_Category__c = 'LTV'; 
        hospital2.City_Master__c = alc12.id;
        hospital2.Is_Active__c = '有効';
        
        //河南
        Account hospital3 = new Account();
        hospital3.Name = 'test hospital3';
        hospital3.RecordTypeId = hospitP.id; 
        hospital3.State_Master__c = alc2.id; 
        hospital3.OCM_Category__c = 'SLTV'; 
        hospital3.City_Master__c = alc21.id;
        hospital3.Is_Active__c = '有効';
        
        Account hospital4 = new Account();
        hospital4.Name = 'test hospital4';
        hospital4.RecordTypeId = hospitP.id; 
        hospital4.State_Master__c = alc2.id; 
        hospital4.OCM_Category__c = 'SLTV'; 
        hospital4.City_Master__c = alc21.id;
        hospital4.Is_Active__c = '有効';
        
        insert new Account[] {hospital1,hospital2,hospital3,hospital4};
        //安徽
        agency1 = new Account();
        agency1.Name = 'test agency1'; 
        agency1.State_Master__c = alc1.id; 
        agency1.RecordTypeId = agencyP.id; 
        insert agency1;
        agency1 = [select Id from Account where Id = :agency1.Id];
        //河南
        agency2 = new Account();
        agency2.Name = 'test agency2'; 
        agency2.State_Master__c = alc2.id; 
        agency2.RecordTypeId = agencyP.id;
        insert agency2;
        agency2 = [select Id from Account where Id = :agency2.Id];
    }
 
 
    @isTest
    static void testSearch() {
        initAgencyHospital();
        PageReference page = new PageReference('/apex/AgencyHospitalLink?userid=' + agency1.Id);
        System.Test.setCurrentPage(page);
        AgencyHospitalLinkController controllTest = new AgencyHospitalLinkController();
        controllTest.init();
        controllTest.allSave = false;
        controllTest.refreshPageSize();
        controllTest.searchHospital();
        System.assertEquals(4, controllTest.hospitalInfoRecordsview.size());
 
        controllTest.moveToNext();
        List<SelectOption> cityOpts1 = new List<SelectOption>();
        cityOpts1.add(new SelectOption('', '--无--'));
        cityOpts1.add(new SelectOption('黄山市', '黄山市'));
        cityOpts1.add(new SelectOption('合肥市', '合肥市'));
 
        
        controllTest.area ='安徽省';
        controllTest.cityload();
        System.assertEquals(cityOpts1, controllTest.cityOpts);
        controllTest.city ='黄山市';
        controllTest.searchHospital();
        System.assertEquals(1, controllTest.hospitalInfoRecoedsviewCount);
        System.assertEquals(1, controllTest.hospitalInfoRecordsview.size());
        System.assertEquals('test hospital1', controllTest.hospitalInfoRecordsview[0].acc1.Name);
        controllTest.allSave = false;
        controllTest.refreshPageSize();
 
        controllTest.init();
        controllTest.searchHospital();
        controllTest.category1 = 'test';
        controllTest.searchHospital();
        System.assertEquals(1, controllTest.hospitalInfoRecordsview.size());
        //System.assertEquals('test hospital1', controllTest.hospitalInfoRecordsview[0].acc1.Name);
        
        
 
    }
 
 
 
    @isTest
    static void testinit()
    {
        initAgencyHospital();
        PageReference page = new PageReference('/apex/AgencyHospitalLink?userid=' + agency1.Id);
        System.Test.setCurrentPage(page);
        AgencyHospitalLinkController controllTest = new AgencyHospitalLinkController();
        controllTest.init();
 
 
        System.assertEquals(2, controllTest.hospitalInfoRecordsview.size());
        //System.assertEquals('test hospital1', controllTest.hospitalInfoRecordsview[0].acc1.Name);
        //System.assertEquals('test hospital2', controllTest.hospitalInfoRecordsview[1].acc1.Name);
 
        controllTest.searchHospital();
        System.assertEquals(4, controllTest.hospitalInfoRecordsview.size());
        //System.assertEquals('test hospital2', controllTest.hospitalInfoRecordsview[0].acc1.Name);
        //System.assertEquals('test hospital1', controllTest.hospitalInfoRecordsview[1].acc1.Name);
        //System.assertEquals('test hospital3', controllTest.hospitalInfoRecordsview[2].acc1.Name);
        //System.assertEquals('test hospital4', controllTest.hospitalInfoRecordsview[3].acc1.Name);
        
        controllTest.area ='河南省';
        controllTest.cityload();
        controllTest.searchHospital();
        System.assertEquals(2, controllTest.hospitalInfoRecordsview.size());
        //System.assertEquals('test hospital3', controllTest.hospitalInfoRecordsview[0].acc1.Name);
        //System.assertEquals('test hospital4', controllTest.hospitalInfoRecordsview[1].acc1.Name);
        controllTest.hospitalInfoRecordsview[0].check= true;
        controllTest.allSave = false;
        controllTest.CheckHospitalInfo();
        //System.assertEquals(0, controllTest.delAgencyLinkSize);
        controllTest.save();
        List<Agency_Hospital_Link__c> ahlList = [select Id,Name,Hospital__c,Hospital__r.Id,Hospital__r.Name,Hospital__r.Management_Code__c,Agency__c
                                                from Agency_Hospital_Link__c
                                                WHERE Agency__c = :agency1.Id];
        System.assertEquals(1, ahlList.size());
        System.assertEquals('test hospital4', ahlList[0].Hospital__r.Name);
 
        page = new PageReference('/apex/AgencyHospitalLink?userid=' + agency1.Id);
        System.Test.setCurrentPage(page);
        controllTest.init();
 
        controllTest.refreshPageSize(); 
        System.assertEquals(2, controllTest.hospitalInfoRecordsview.size());
        controllTest.searchHospital();
        System.assertEquals(4, controllTest.hospitalInfoRecordsview.size());
        controllTest.hospitalInfoRecordsview[0].check= false;
        controllTest.hospitalInfoRecordsview[1].check= true;
        controllTest.allSave = true;
        controllTest.CheckHospitalInfo();
        //System.assertEquals(0, controllTest.delAgencyLinkSize);
        controllTest.save();
        controllTest.refreshPageSize();
        controllTest.area ='河南省';
        controllTest.searchHospital();
        System.assertEquals(2, controllTest.hospitalInfoRecordsview.size());
        controllTest.ToPage();
    }
 
    @isTest
    static void testSave() {
        initAgencyHospital();
        PageReference page = new PageReference('/apex/AgencyHospitalLink?userid=' + agency2.Id);
        System.Test.setCurrentPage(page);
        
        AgencyHospitalLinkController controller = new AgencyHospitalLinkController();
        //初始化、
        controller.init();
        System.assertEquals(2, controller.hospitalInfoRecordsview.size());
        //System.assertEquals('test hospital3', controller.hospitalInfoRecordsview[0].acc1.Name);
        //System.assertEquals('test hospital4', controller.hospitalInfoRecordsview[1].acc1.Name);
        controller.searchHospital();
        System.assertEquals(4, controller.hospitalInfoRecordsview.size());
        //System.assertEquals('test hospital1', controller.hospitalInfoRecordsview[0].acc1.Name);
        //System.assertEquals('test hospital2', controller.hospitalInfoRecordsview[1].acc1.Name);
        //System.assertEquals('test hospital3', controller.hospitalInfoRecordsview[2].acc1.Name);
        //System.assertEquals('test hospital4', controller.hospitalInfoRecordsview[3].acc1.Name);
        controller.hospitalInfoRecordsview[0].check= true;
        controller.hospitalInfoRecordsview[2].check= true;
        controller.allSave = false;
        controller.CheckHospitalInfo();
        //System.assertEquals(0, controller.delAgencyLinkSize);
        controller.save();
        
        controller.init();
        controller.searchHospital();
        controller.makepagerecords();
        System.assertEquals(4, controller.hospitalInfoRecordsview.size());
        //System.assertEquals('test hospital1', controller.hospitalInfoRecordsview[0].esd.Hospital__r.Name);
        //System.assertEquals('test hospital3', controller.hospitalInfoRecordsview[1].esd.Hospital__r.Name);
        //System.assertEquals('test hospital2', controller.hospitalInfoRecordsview[2].acc1.Name);
        //System.assertEquals('test hospital4', controller.hospitalInfoRecordsview[3].acc1.Name);
        
        List<Agency_Hospital_Link__c> ahlList = [select Id,Name,Hospital__c,Hospital__r.Id,Hospital__r.Name,Hospital__r.Management_Code__c,Agency__c
                                                from Agency_Hospital_Link__c
                                                WHERE Agency__c = :agency2.Id];
        System.assertEquals(2, ahlList.size());
        //System.assertEquals('test hospital2', ahlList[0].Hospital__r.Name);
 
 
        PageReference page1 = new PageReference('/apex/AgencyHospitalLink?userid=' + agency1.Id);
        System.Test.setCurrentPage(page1);
        
        AgencyHospitalLinkController controller1 = new AgencyHospitalLinkController();
        //初始化、
        controller1.init();
        AgencyHospitalLinkController.getAreaOpts();
        AgencyHospitalLinkController.getOcmOpts();
        System.assertEquals(2, controller1.hospitalInfoRecordsview.size());
        
        //System.assertEquals('test hospital1', controller1.hospitalInfoRecordsview[0].acc1.Name);
        //System.assertEquals('test hospital2', controller1.hospitalInfoRecordsview[1].acc1.Name);
 
        controller1.searchHospital();
        controller1.hospitalInfoRecordsview[2].check= true;
        controller1.allSave = false;
        controller1.CheckHospitalInfo();
        //System.assertEquals(1, controller1.delAgencyLinkSize);
        controller1.save();
 
        List<Agency_Hospital_Link__c> ahlcList1 = [select Id,Name,Hospital__c,Hospital__r.Id,Hospital__r.Name,Hospital__r.Management_Code__c,Agency__c
                                                from Agency_Hospital_Link__c
                                                WHERE Agency__c = :agency1.Id];
        System.assertEquals(1, ahlcList1.size());
 
        /*List<Agency_Hospital_Link__c> ahlcList2 = [select Id,Name,Hospital__c,Hospital__r.Id,Hospital__r.Name,Hospital__r.Management_Code__c,Agency__c
                                                from Agency_Hospital_Link__c
                                                WHERE Agency__c = :agency2.Id];
        System.assertEquals(1, ahlcList2.size());*/
    }
}