@isTest
public with sharing class BmeWorkControllerTest {
	//-----------------------------------------------------------------------------------------------------------
	@TestSetup static void init() {
		//insert p
		Profile p = [select Id from Profile where id = :System.Label.ProfileId_SystemAdmin];
		//insert comOwner
		User comOwner = new User(Test_staff__c = true, LastName = 'com', FirstName = 'owner', Alias = 'com', CommunityNickname = 'comOwner', Email = 'olympus_comowner@sunbridge.com', Username = 'olympus_comowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
		insert comOwner;
		//insert rectHp
		List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
		//insert Account
		Account myAccount1 = new Account(name = 'testaccount001', RecordTypeId = rectHp[0].Id );
		insert myAccount1;
		//insert Campaign
		Campaign cam = new Campaign();
		cam.Name = 'cam';
		cam.Name2__c = '1234';
		cam.status = '公开中';
		cam.StartDate = Date.today().addDays(15);
		cam.EndDate = Date.today().addDays(18);
		cam.Mailflg_after45__c = true;
		cam.Mailflg_cancel__c = true;
		cam.Mailflg_before15__c = true;
		cam.Mailflg_before7__c = true;
		cam.Mailflg_after3__c = true;
		insert cam;
		//insert Contact
		Contact core = new Contact(
		    firstname = 'Joe',
		    lastname = 'Plumber',
		    Campaign__c = cam.Id,
		    Ownerid = comOwner.Id,
		    MedicalStaff_Full_name__c = '张三',
		    accountid = myAccount1.Id,
		    OnJobState__c = '离岗',
		    IsEndoscope__c = '是',
		    Follow_state__c = '普通跟进'
		);
		insert core;
		//insert MeetingManagement__c
		MeetingManagement__c memat = new MeetingManagement__c(
		    Contact__c = core.Id,
		    MaintenanceReportTime__c = 1,
		    InspectTime__c = 1,
		    InspectEquipmentTime__c = 1,
		    VisitTime__c = 1,
		    pollingTime__c = 1,
		    TeachingTime__c = 1,
            CreatedDate__c = Date.toDay()
		);
		insert memat;
	}
	//------------------------------------------------------检索-------------------------------------------------------------
	static testMethod void chickNumtextA1() {
		//医院科室
		PageReference page = new PageReference('/apex/BmeWork');
		System.Test.setCurrentPage(page);
		BmeWorkController controller = new BmeWorkController();
		controller.init();
		controller.numtextA1 = 'Account.Name';
		controller.numtextA2 = '=';
		controller.numtextA = '宣武区椿树医院 耳鼻喉科 耳鼻喉科';
		controller.chick();
		controller.numtextA1 = 'Account.Name';
		controller.numtextA2 = '<>';
		controller.numtextA = '北京妇产医院 妇科 妇科';
		controller.chick();
	}
	static testMethod void chickNumtextB1() {
		//学会培训名称
		PageReference page = new PageReference('/apex/BmeWork');
		System.Test.setCurrentPage(page);
		BmeWorkController controller = new BmeWorkController();
		controller.init();
		controller.numtextB1 = 'Campaign__r.Name';
		controller.numtextB2 = '=';
		controller.numtextB = '151P北京内镜临床工程师培养班（12月）';
		controller.chick();
		controller.numtextB1 = 'Campaign__r.Name';
		controller.numtextB2 = '<>';
		controller.numtextB = '151P北京内镜临床工程师培养班（12月）';
		controller.chick();
	}
	static testMethod void chickNumtextC1() {
		//学会培训主担当
		PageReference page = new PageReference('/apex/BmeWork');
		System.Test.setCurrentPage(page);
		BmeWorkController controller = new BmeWorkController();
		controller.init();
		controller.numtextC1 = 'Owner.Alias__c';
		controller.numtextC2 = '=';
		controller.numtextC = '精琢技术';
		controller.chick();
		controller.numtextC1 = 'Owner.Alias__c';
		controller.numtextC2 = '<>';
		controller.numtextC = '精琢技术';
		controller.chick();
	}
	static testMethod void chickNumtextD1() {
		//拜访人姓名
		PageReference page = new PageReference('/apex/BmeWork');
		System.Test.setCurrentPage(page);
		BmeWorkController controller = new BmeWorkController();
		controller.init();
		controller.numtextD1 = 'MedicalStaff_Full_name__c';
		controller.numtextD2 = '=';
		controller.numtextD = '李四';
		controller.chick();
		controller.numtextD1 = 'MedicalStaff_Full_name__c';
		controller.numtextD2 = '<>';
		controller.numtextD = '李四';
		controller.chick();
	}
	//---------------------------------------------makeSQL----------------------------------------------------------------
	static testMethod void makeSQL1() {
		PageReference page = new PageReference('/apex/BmeWork');
		System.Test.setCurrentPage(page);
		BmeWorkController controller = new BmeWorkController();
		controller.init();
		controller.numtextA1 = 'Account.Name';
		controller.numtextA2 = 'contains';
		controller.numtextA = '耳鼻 喉科, 北 京';
		controller.numtextB1 = 'Campaign__r.Name';
		controller.numtextB2 = 'starts with';
		controller.numtextB = '151P北京内镜临床工程师培养班（12月）';
		controller.numtextC1 = 'Owner.Alias__c';
		controller.numtextC2 = '=';
		controller.numtextC = '精琢技术,奥林巴斯';
		controller.numtextD1 = 'MedicalStaff_Full_name__c';
		controller.numtextD2 = 'contains';
		controller.numtextD = '李四 张三';
		controller.chick();
	}
	static testMethod void makeSQL2() {
		PageReference page = new PageReference('/apex/BmeWork');
		System.Test.setCurrentPage(page);
		BmeWorkController controller = new BmeWorkController();
		controller.init();
		controller.numtextA1 = 'Account.Name';
		controller.numtextA2 = 'notcontains';
		controller.numtextA = '耳鼻喉科';
		controller.numtextB1 = 'MedicalStaff_Full_name__c';
		controller.numtextB2 = 'starts with';
		controller.numtextB = '李四 张三';
		controller.numtextC1 = 'Owner.Alias__c';
		controller.numtextC2 = '<>';
		controller.numtextC = '精琢技术,奥林巴斯';
		controller.numtextD1 = 'MedicalStaff_Full_name__c';
		controller.numtextD2 = '=';
		controller.numtextD = '李四 张三';
		controller.chick();
	}
	//----------------------------------------------------------------------------------------------------------------------
	static testMethod void sortKeyIsNull() {
		PageReference page = new PageReference('/apex/BmeWork');
		System.Test.setCurrentPage(page);
		BmeWorkController controller = new BmeWorkController();
		controller.sortKey = '2';
		//controller.sortTable();
		controller.init();
	}
	static testMethod void sortKeyIsNull2() {
		PageReference page = new PageReference('/apex/BmeWork');
		System.Test.setCurrentPage(page);
		BmeWorkController controller = new BmeWorkController();
		controller.sortKey = '1';
		controller.init();
	}
	//----------------------------------------------------------------------------------------------------------------------
	static testMethod void save() {
		PageReference page = new PageReference('/apex/BmeWork');
		System.Test.setCurrentPage(page);
		BmeWorkController controller = new BmeWorkController();
		controller.init();
		controller.oppRecords[0].changeFlg = '1';
		controller.save();
	}
	//----------------------------------------------------------------------------------------------------------------------
	static testMethod void myUnitTestTime_LimitsAndOppCount() {
		PageReference page = new PageReference('/apex/BmeWork');
		System.Test.setCurrentPage(page);
		BmeWorkController controller = new BmeWorkController();
		controller.init();
		controller.limits = '10';
		controller.searchOppInner();
		controller.oppCount = 1000;
		controller.init();
	}
}