/**
|
* 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 OFSHospitalLayoutControllerTest {
|
public class TestRepo {
|
public final Integer ASSETMAX = 8;
|
public Account hp { get; private set; }
|
public OFSHospitalLayout__c layout { get; private set; }
|
public List<Asset> assets { get; private set; }
|
TestRepo() {
|
assets = new List<Asset>();
|
createLayout();
|
createHospital();
|
}
|
public void createHospital() {
|
// 病院を作る
|
hp = new Account();
|
hp.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
|
hp.Name = 'test hospital';
|
insert hp;
|
}
|
private void createLayout() {
|
layout = new OFSHospitalLayout__c();
|
layout.Name = '医院';
|
layout.section1__c = '{"id":"001","title":"顾客信息","column":"2","showHeader":"true"}';
|
layout.field1__c = '{"sectionId":"001","api":"Name","right":"true"}';
|
layout.field2__c = '{"sectionId":"001","api":"Management_Code__c","right":"false"}';
|
|
layout.section2__c = '{"id":"002","title":"地址信息","column":"1","showHeader":"true"}';
|
layout.field3__c = '{"sectionId":"002","api":"Town__c"}';
|
layout.field4__c = '{"sectionId":"002", "api":{"columns":["OCM_Category__c", "Grade__c", "GI_Main__c", "SP_Main__c", "FSE_Main__c"], "lables":["OCM分类", "政府分级", "GI主担当", "SP主担当", "FSE主担当"]}, "lable":""}';
|
layout.recordType_devName__c = 'HP';
|
layout.relationList1__c = '{"object":"Asset", "condition_column":"Hospital__c", "field_set":"test"}';
|
layout.report1__c = '00O10000004ROGk';
|
layout.report1_Column__c = 'Event__c.AccountParentParentId__c';
|
layout.report1_Name__c = '每月拜访次数';
|
|
insert layout;
|
}
|
private Asset createAsset(String name, String serialNo) {
|
Asset asset = new Asset();
|
asset.Name = name;
|
asset.AccountId = hp.Id;
|
//asset.Department_Class__c = dcId;
|
asset.Hospital__c = hp.Id;
|
asset.SerialNumber = serialNo;
|
//asset.Product2Id = prId;
|
asset.InstallDate = Date.today();
|
return asset;
|
}
|
public void initAssets() {
|
for (Integer i= 0; i < ASSETMAX; i++) {
|
assets.add(createAsset('testAsset'+i, '0000'+i));
|
}
|
insert assets;
|
}
|
|
}
|
static testMethod void HospitalTest() {
|
Test.startTest();
|
TestRepo repo = new TestRepo();
|
Apexpages.currentPage().getParameters().put('id', repo.hp.Id); // FIXME yu why Id by katsu、こもじ id ですよ。
|
OFSHospitalLayoutController controller = new OFSHospitalLayoutController(new ApexPages.StandardController(repo.hp)); // FIXME yu StandardControllerのUnitTestだめですね。 by katsu。
|
// 初始化
|
controller.init();
|
system.assertEquals(2, controller.sectionList.size());
|
system.assertEquals('顾客信息', controller.sectionList[0].title);
|
system.assertEquals(1, controller.sectionList[1].column);
|
system.assertEquals(2, controller.sectionList[1].getSectionItemList().size()); // field3, field4
|
|
controller.prePage();
|
controller.nextPage();
|
controller.save();
|
|
controller.index = 1;
|
controller.showList();
|
controller.irCreate();
|
}
|
}
|