@isTest
private class addInitTaskBatchTest {
	@TestSetup
	public static void setup(){
		OlympusCalendar__c oc = new OlympusCalendar__c();
        oc.Date__c = System.Today();
        oc.Before_1_WorkDay__c = oc.Date__c.addDays(-1);
        insert oc;

        Daily_Report__c dr1 = new Daily_Report__c();
        dr1.Reporter__c = UserInfo.getUserId();
        dr1.Reported_Date__c = date.today().addDays(-2);
        dr1.Status__c = '申請中';
        Daily_Report__c dr2 = new Daily_Report__c();
        dr2.Reporter__c = UserInfo.getUserId();
        dr2.Reported_Date__c = date.today().addDays(2);
        dr2.Status__c = '申請中';
        Daily_Report__c dr3 = new Daily_Report__c();
        dr3.Reporter__c = UserInfo.getUserId();
        dr3.Reported_Date__c = date.today().addDays(4);
        dr3.Status__c = '申請中';
        insert new list<Daily_Report__c>{dr1,dr2,dr3};

        Event__c event = new Event__c();
        event.ActivityDate__c = date.today().addDays(-2);
        event.Daily_Report__c = dr1.Id;
        event.StartDateTime__c = Datetime.newInstance(2021, 8, 17, 10, 0, 0);
        event.EndDateTime__c = Datetime.newInstance(2021, 8, 17, 17, 0, 0);

        Event__c event2 = new Event__c();
        event2.ActivityDate__c = date.today().addDays(-2);
        event2.Daily_Report__c = dr1.Id;
        event2.StartDateTime__c = Datetime.newInstance(2021, 8, 17, 10, 0, 0);
        event2.EndDateTime__c = Datetime.newInstance(2021, 8, 17, 17, 0, 0);

        Event__c event3 = new Event__c();
        event3.ActivityDate__c = date.today().addDays(-2);
        event3.Daily_Report__c = dr2.Id;
        event3.StartDateTime__c = Datetime.newInstance(2021, 8, 17, 10, 0, 0);
        event3.EndDateTime__c = Datetime.newInstance(2021, 8, 17, 17, 0, 0);

        Event__c event4 = new Event__c();
        event4.ActivityDate__c = date.today().addDays(-2);
        event4.Daily_Report__c = dr3.Id;
        event4.StartDateTime__c = Datetime.newInstance(2021, 8, 20, 10, 0, 0);
        event4.EndDateTime__c = Datetime.newInstance(2021, 8, 21, 17, 0, 0);
        insert new list<Event__c>{event,event2,event3,event4};

        List<task__c> tasks = new List<task__c>();
        task__c t1 = new task__c();
        t1.Name = 'test1';
        t1.taskDifferent__c = '主动任务';
        t1.taskStatus__c = '02 接受';
        t1.assignee__c = Userinfo.getUserId();
        t1.Event__c = event.Id;
        t1.Daily_Report__c = dr1.Id;
        t1.Activity_Date__c = Date.newInstance(2021, 7, 17);
        tasks.add(t1);

        task__c t2 = new task__c();
        t2.Name = 'test2';
        t2.taskDifferent__c = '主动任务';
        t2.taskStatus__c = '02 接受';
        t2.assignee__c = Userinfo.getUserId();
        t2.Event__c = event2.Id;
        t2.Daily_Report__c = dr2.Id;
        t2.Activity_Date__c = Date.newInstance(2021, 8, 17);
        tasks.add(t2);

        task__c t3 = new task__c();
        t3.Name = 'test3';
        t3.taskDifferent__c = '主动任务';
        t3.taskStatus__c = '02 接受';
        t3.assignee__c = Userinfo.getUserId();
        t3.Daily_Report__c = dr3.Id;
        t3.Event__c = event4.Id;
        t3.Activity_Date__c = Date.newInstance(2021, 8, 20);
        tasks.add(t3);
        insert tasks;

        t1.delayTask__c = t2.id;
        t2.delayTask__c = t3.id;
        t2.delayTaskP__c = t1.id;
        t3.delayTaskP__c = t2.id;
        update new list<task__c> {t1,t2,t3};
	}

	@isTest
    public static void testMethod1() {
    	list<task__c> tlist = 
    		[SELECT Id,Name,delayTask__c, Daily_Report__c , Event__c 
    			FROM task__c
    			where name = 'test2'];
    	Test.StartTest();
        Database.executeBatch( new addInitTaskBatch(tlist[0].id),1);
        Test.stopTest();

    }

	@isTest
    public static void testMethod2() {
    	list<task__c> tlist = 
    		[SELECT Id,Name,delayTask__c, Daily_Report__c , Event__c ,delayTaskP__c
    			FROM task__c
    			where name = 'test2'];
    	addInitTaskBatch controller = new addInitTaskBatch();
    	controller.main( tlist);
    	Test.StartTest();
        Database.executeBatch( new modifyInitTaskBatch(tlist[0].id),1);
        Test.stopTest();

    }
}