@isTest
private class NewLoanerUserControllerTest {
    
    @TestSetup
    static void setup(){
        TestDataUtility.CreatePIPolicyConfigurations(new string[]{'loaner_user__c','Contact'});
    }
    
	static void setupTestData() {
                OlympusCalendar__c oc1 = new OlympusCalendar__c(Date__c = Date.today().addDays(1), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
                OlympusCalendar__c oc2 = new OlympusCalendar__c(Date__c = Date.today().addDays(2), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
                OlympusCalendar__c oc3 = new OlympusCalendar__c(Date__c = Date.today().addDays(3), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
                OlympusCalendar__c oc4 = new OlympusCalendar__c(Date__c = Date.today().addDays(4), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
                OlympusCalendar__c oc5 = new OlympusCalendar__c(Date__c = Date.today().addDays(5), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
                OlympusCalendar__c oc6 = new OlympusCalendar__c(Date__c = Date.today().addDays(6), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
                OlympusCalendar__c oc7 = new OlympusCalendar__c(Date__c = Date.today().addDays(7), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
                OlympusCalendar__c oc8 = new OlympusCalendar__c(Date__c = Date.today().addDays(8), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
                OlympusCalendar__c oc9 = new OlympusCalendar__c(Date__c = Date.today().addDays(9), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
                OlympusCalendar__c oc10 = new OlympusCalendar__c(Date__c = Date.today().addDays(10), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
                OlympusCalendar__c oc11 = new OlympusCalendar__c(Date__c = Date.today().addDays(11), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
                OlympusCalendar__c oc12 = new OlympusCalendar__c(Date__c = Date.today().addDays(12), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
                OlympusCalendar__c oc13 = new OlympusCalendar__c(Date__c = Date.today().addDays(-1), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
                OlympusCalendar__c oc14 = new OlympusCalendar__c(Date__c = Date.today().addDays(-2), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
                OlympusCalendar__c oc15 = new OlympusCalendar__c(Date__c = Date.today().addDays(-3), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
                OlympusCalendar__c oc16 = new OlympusCalendar__c(Date__c = Date.today().addDays(-4), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
                OlympusCalendar__c oc17 = new OlympusCalendar__c(Date__c = Date.today().addDays(-5), ChangeToHoliday__c=false, ChangeToWorkday__c=true);

                insert new OlympusCalendar__c[] {oc1,oc2,oc3,oc4,oc5,oc6,oc7,oc8,oc9,oc10,oc11,oc12,oc13,oc14,oc15,oc16,oc17};
            }
	@isTest static void test_method_one() {
		setupTestData();
		// Implement test code
		List<RecordType> rectLo = [select Id from RecordType where IsActive = true and SobjectType = 'loaner_application__c' and Name = 'BS'];

		List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];

		// 新建备品借出申请
		loaner_application__c loaner = new loaner_application__c();
		loaner.Name = 'TEST';
		loaner.RecordTypeId = rectLo[0].id;
		loaner.EC_CODE_1__C = 'DV2-CAMELEONS-CUBE';
		loaner.Request_shipping_Date__c = Date.today();
		loaner.Request_return_Date__c = Date.today();
		loaner.Status__c = '已出库指示';
		loaner.Return_Track_Company__c = '物流公司';
		insert loaner;

		// 新建 客户
		Account acc = new Account();
		acc.RecordTypeId = rectCo[0].Id;
		acc.Name         = '客户テスト1';
		acc.DivisionName__c = 'DivisionName__c';
		acc.FacilityName__c = 'FacilityName__c';
		acc.PostCode__c = '000000';
		insert acc;

		// 新建 客户2
		Account acc2 = new Account();
		acc2.RecordTypeId = rectCo[0].Id;
		acc2.Name         = '客户テスト2';
		acc2.DivisionName__c = 'DivisionName__c';
		acc2.FacilityName__c = 'FFFF';
		acc2.Phone = '123456789';
		acc2.PostCode__c = '000000';
		insert acc2;

		// 新建 联系人
		Contact con = new Contact();
		con.LastName = 'test1';
		con.AccountId = acc.Id;
		con.Address1__c = 'Address1D__c';
		con.Postcode__c = '100111';
		con.Phone = '123456789';
		con.ContactStatus__c = 'ContactStatusD__c';
		con.StatusD__c = 'Pass';

		insert con;

		// 新建 联系人2
		Contact con2 = new Contact();
		con2.LastName = 'test2';
		con2.AccountId = acc.Id;
		con2.Address1__c = 'Address1D__c';
		con2.Postcode__c = '100111';
		con2.ContactStatus__c = 'ContactStatusD__c';
		con2.StatusD__c = 'Pass';

        insert con2;

		// 借用客户
		loaner_user__c lu = new loaner_user__c();
		lu.Customer__c = acc.id;
		lu.Contact__c = con.id;
		lu.loaner_application__c = loaner.id;
		lu.Remarks__c = '123';
		insert lu;

		//
		PageReference page = new PageReference('/apex/NewLoanerUserController?headId=' + loaner.Id );
		System.Test.setCurrentPage(page);
		NewLoanerUserController  controller = new NewLoanerUserController(new ApexPages.StandardController(lu));

		controller.init();

		controller.dataLines[0].Remarks__c = '备注';
		controller.dataLines[0].Contact__c = con2.id;
		controller.dataLines[0].Customer__c = acc2.id;

		controller.updateUser();

		List<loaner_user__c> luNew = [select Id, Remarks__c, Contact__r.name, Customer__r.name, ContactNumber__c from loaner_user__c];
		List<loaner_application__c> laNew = [select Loaner_receive_staff__c, Loaner_receive_staff_phone__c, direct_shippment_address__c, Post_Code__c from loaner_application__c];

		//system.assertEquals('备注', luNew[0].Remarks__c);
		//system.assertEquals('test2', luNew[0].Contact__r.name);
		//system.assertEquals('test2', laNew[0].Loaner_receive_staff__c);
		//system.assertEquals('Address1D__c', laNew[0].direct_shippment_address__c);
		//system.assertEquals('100111', laNew[0].Post_Code__c);

		controller.cancelBtn();
	}
	
	@isTest static void test_method_two() {
		// Implement test code
	}
	
}