@isTest
private class AssessmentReportControllerTest {

	@TestSetup 
    
    static void init() {
		RecordType rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Hp'];
		List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName IN ('Department_GI', 'Department_BF') order by DeveloperName desc];

		Account acc = new Account();
		acc.RecordTypeId = rectCo.Id;
		acc.Name = 'HP test1';
		insert acc;

		List<Account> dept = [select Id, Name from Account where ParentId = :acc.Id and Department_Class_Label__c IN ('消化科', '呼吸科') order by Department_Class_Label__c];

		Account depart1 = new Account();
		depart1.RecordTypeId = rectDpt[0].Id;
		depart1.Name         = '*';
		depart1.Department_Name__c  = 'Gastoro Intestin Test';
		depart1.ParentId            = dept[0].Id;
		depart1.Department_Class__c = dept[0].Id;
		depart1.Hospital__c         = acc.Id;

		Account depart2 = new Account();
		depart2.RecordTypeId = rectDpt[1].Id;
		depart2.Name         = '*';
		depart2.Department_Name__c  = '診療科2';
		depart2.ParentId            = dept[1].Id;
		depart2.Department_Class__c = dept[1].Id;
		depart2.Hospital__c         = acc.Id;
		insert new Account[] {depart1, depart2};

		Contact con = new Contact();
		con.LastName = 'lastname2';
		con.FirstName = 'firstname2';
		con.Email = 'olympustest033@sunbridge.com';
		con.MobilePhone = '99999999';
		con.Work_Location_manual__c = 'location2';
		con.Post_picklist__c = '部长';
		con.Job_Category_picklist__c = '销售推广';
		con.Hire_date_text__c = Date.today().addMonths(-6);
		con.Gender_text__c = '男';
		con.dept__c = '服务本部';
		con.Pregnant_Rest__c = true;
		insert con;

		/*RecordType rectCam =
		    [select Id from RecordType
		     where IsActive = true and SobjectType = 'Campaign'
		                      and DeveloperName = 'ServiceEngineerTraining'];*/

		Campaign cam = new Campaign();
		cam.Name = 'cam';
		cam.Name2__c = '1234';
		//cam.RecordTypeId = rectCam.Id;
		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;
		cam.HostName__c = '111';
		cam.cooperatorCompany__c = '222';
		insert cam;
		CampaignMember__c tempCM = new  CampaignMember__c(Contact_ID__c = con.id, Campaign__c = cam.id);
		insert tempCM;

		AssessmentReport__C temAR = new AssessmentReport__C();
		temAR.Campaign__c = cam.id;
		temAR.Status__c	 = '草案中';
		temAR.Name = cam.Name + '第' + 1 + '次报告';
		temAR.Type__c = '授课';
		insert temAR;
		AssessmentReportStaff__c tempARS =  new AssessmentReportStaff__c();
		tempARS.CampaignMember__c = tempCM.id;
		tempARS.Contact__c       = con.id;
		tempARS.AssessmentReport__c = temAR.id;
		tempARS.Department__c = depart2.id ;
		insert tempARS;

	}

	@isTest static void test_init() {
		// Implement test code

		list<Campaign> camlist = [select id from Campaign];
		Campaign cam = camlist[0];
		PageReference page = new PageReference('/apex/AssessmentReport?camid=' + cam.Id);
		System.Test.setCurrentPage(page);
		AssessmentReportController cmc = new AssessmentReportController();
		cmc.init();
		AssessmentReport__C temAR = [select id from AssessmentReport__C];
		page = new PageReference('/apex/AssessmentReport?id=' + temAR.Id);
		System.Test.setCurrentPage(page);
		cmc = new AssessmentReportController();
		cmc.init();


	}
	@isTest static void test_CheckSaveInput() {
		AssessmentReport__C temAR = [select id from AssessmentReport__C];
		PageReference page = new PageReference('/apex/AssessmentReport?id=' + temAR.Id);
		System.Test.setCurrentPage(page);
		AssessmentReportController cmc = new AssessmentReportController();
		cmc.init();
		cmc.CheckSaveInput();
		cmc.AssessmentReport.TeachingHourSelect__c = '其他';
		cmc.AssessmentReport.Type__c = '';
		cmc.CheckSaveInput();
	}
	@isTest static void test_Save_Submit() {
		list<Campaign> camlist = [select id from Campaign];
		Campaign cam = camlist[0];
		PageReference page = new PageReference('/apex/AssessmentReport?camid=' + cam.Id);
		System.Test.setCurrentPage(page);
		AssessmentReportController cmc = new AssessmentReportController();
		cmc.init();

		cmc.save();
		cmc.saveAndCancel();
		cmc.Submit();
		cmc.AssessmentReport.Type__c = '授课';
		cmc.AssessmentReport.TeachingHourSelect__c = '4';
		cmc.AssessmentReport.TrainedStaffFeedback__c = '4';
		cmc.AssessmentReport.HomeworkFeedback__c = '4';
		cmc.AssessmentReport.TeacherFeedback__c = '4';
		cmc.AssessmentReport.LectureFeedback__c = '4';
		cmc.AssessmentReport.GoodExample__c = '4';


		cmc.AssessmentReport.TrainingLecturer1__c = null;
		cmc.save();
		cmc.saveAndCancel();
		cmc.Submit();

		Test.startTest();
		for (AssessmentReportController.AssessmentReportStaffInfo tempARS : cmc.ARSInfoList) {
			tempARS.ARS.AttendStatus__c = '出勤';
			tempARS.ARS.AttendRate__c = '优秀';
			tempARS.ARS.HomeworkFeedback__c = '优秀';
		}
		cmc.AssessmentReport.TrainingLecturer1__c = UserInfo.getUserId();
 		
		cmc.save();
		cmc.saveAndCancel();
		cmc.Submit();
		
		Test.stopTest();

	}

	@isTest static void test_unitTest() {
		AssessmentReport__C temAR = [select id from AssessmentReport__C];
		PageReference page = new PageReference('/apex/AssessmentReport?id=' + temAR.Id);
		System.Test.setCurrentPage(page);
		AssessmentReportController cmc = new AssessmentReportController();
		cmc.init();
		cmc.EditRecord();
		cmc.getInputdisabled();
		cmc.cancel();


	}

}