package com.intland.codebeamer.functionaltest.test.tracker.configuration.workflow;

import com.codeborne.selenide.testng.ScreenShooter;
import com.intland.codebeamer.functionaltest.helper.Helper;
import com.intland.codebeamer.functionaltest.page.mystart.MyStartPage;
import com.intland.codebeamer.functionaltest.page.ProjectAdminSettingsPage;
import com.intland.codebeamer.functionaltest.page.wiki.ProjectWikiPage;
import com.intland.codebeamer.functionaltest.page.projects.ProjectsPage;
import com.intland.codebeamer.functionaltest.test.BaseTest;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

@Listeners(ScreenShooter.class)
public class WorkflowActionsTests extends BaseTest {

	String testProjectNamePrefix = "tp testWfActions";

	@DataProvider(name = "testParametersProviderWorkflowActionsUpdateItemPropertiesChoiceField")
	public static Object[][] testParamtersArray1() {
		return new Object[][] {
			{ "Bugs", "Start", "Set", "Priority", "Low" },
			{ "Tasks", "Resolve", "Clear", "Severity", "--"},
			{ "Change Requests", "Approve", "Set", "CustomChoiceField1", "Option1" },
			{ "Risks", "Verify", "Clear", "CustomChoiceField1", "--" }
		};
	}

	@Test(dataProvider = "testParametersProviderWorkflowActionsUpdateItemPropertiesChoiceField")
    public void testWorkflowActionsUpdateItemPropertiesChoiceField(String trackerName, String transitionName, String action, String propName, String actionValue) {
		WorkflowActionsUpdateItemPropertiesChoiceFieldTests testClass = new WorkflowActionsUpdateItemPropertiesChoiceFieldTests();
		testClass.testWorkflowActionsUpdateItemPropertiesChoiceField(trackerName, transitionName, action, propName, actionValue);
    }

	@DataProvider(name = "testParametersProviderWorkflowActionsUpdateItemPropertiesDateField")
	public static Object[][] testParamtersArray2() {
		return new Object[][] {
			{ "Tasks", "Start", "Set to", "End Date", "Tomorrow" },
			{ "Tasks", "Start", "Clear", "End Date", "--"},
			{ "Change Requests", "Approve", "Set to", "CustomDateField1", "Tomorrow" },
			{ "Risks", "Verify", "Clear", "CustomDateField1", "--" }
		};
	}

	@Test(dataProvider = "testParametersProviderWorkflowActionsUpdateItemPropertiesDateField")
    public void testWorkflowActionsUpdateItemPropertiesDateField(String trackerName, String transitionName, String action, String propName, String actionValue) {
		WorkflowActionsUpdateItemPropertiesDateFieldTests testClass = new WorkflowActionsUpdateItemPropertiesDateFieldTests();
		testClass.testWorkflowActionsUpdateItemPropertiesDateField(trackerName, transitionName, action, propName, actionValue);
    }

	@DataProvider(name = "testParametersProviderWorkflowActionsUpdateItemPropertiesIntegerField")
	public static Object[][] testParamtersArray3() {
		return new Object[][] {
			{ "Tasks", "Start", "Set to", "Story Points", "10" },
			{ "Bugs", "Verify", "Clear", "Story Points", "--" },
			{ "Tasks", "Start", "Increase by", "Story Points", "10" },
			{ "Bugs", "Verify", "Decrease by", "Story Points", "3" },
			{ "User Stories", "Start", "Set to", "CustomIntegerField1", "8" },
			{ "Risks", "Verify", "Clear", "CustomIntegerField1", "--" },
			{ "User Stories", "Start", "Increase by", "CustomIntegerField1", "3" },
			{ "Risks", "Verify", "Decrease by", "CustomIntegerField1", "2" },
		};
	}

	@Test(dataProvider = "testParametersProviderWorkflowActionsUpdateItemPropertiesIntegerField")
    public void testWorkflowActionsUpdateItemPropertiesIntegerField(String trackerName, String transitionName, String action, String propName, String actionValue) {
		WorkflowActionsUpdateItemPropertiesIntegerFieldTests testClass = new WorkflowActionsUpdateItemPropertiesIntegerFieldTests();
		testClass.testWorkflowActionsUpdateItemPropertiesIntegerField(trackerName, transitionName, action, propName, actionValue);
    }

	@DataProvider(name = "testParametersProviderWorkflowActionsUpdateItemPropertiesMembersField")
	public static Object[][] testParamtersArray4() {
		return new Object[][] {
			{ "System Requirement Specifications", "Define", "Set to", "Assigned to", "Stakeholder" },
			{ "System Requirement Specifications", "Define", "Clear", "Assigned to", "--" },
			{ "System Requirement Specifications", "Approve", "Add", "Assigned to", "Stakeholder" },
			{ "System Requirement Specifications", "Approve", "Remove", "Assigned to", "Tester" },
			{ "System Requirement Specifications", "Approve", "Retain", "Assigned to", "Tester" }
//			{ "Bugs", "Start", "Set to", "CustomMemberField1", "Tester" },
//			{ "Bugs", "Verify", "Clear", "CustomMemberField1", "--" },
//			{ "Bugs", "Start", "Add", "CustomMemberField1", "Stakeholder" },
//			{ "Bugs", "Verify", "Remove", "CustomMemberField1", "Tester" },
//			{ "Bugs", "Verify", "Retain", "CustomMemberField1", "Tester" }
		};
	}

	@Test(dataProvider = "testParametersProviderWorkflowActionsUpdateItemPropertiesMembersField")
    public void testWorkflowActionsUpdateItemPropertiesMembersField(String trackerName, String transitionName, String action, String propName, String actionValue) {
		WorkflowActionsUpdateItemPropertiesMembersFieldTests testClass = new WorkflowActionsUpdateItemPropertiesMembersFieldTests();
		testClass.testWorkflowActionsUpdateItemPropertiesMembersField(trackerName, transitionName, action, propName, actionValue);
    }

	@DataProvider(name = "testParametersProviderWorkflowActionsUpdateItemPropertiesTextField")
	public static Object[][] testParamtersArray5() {
		return new Object[][] {
//			{ "Contacts", "Activate", "Set to", "City", "Stuttgart" },
//			{ "Contacts", "Activate", "Clear", "City", "--" },
//			{ "Contacts", "Activate", "Append", "City", "Beach" },
//			{ "Contacts", "Activate", "Prepend", "City", "West" },
			{ "User Stories", "Start", "Set to", "CustomTextField1", "Jerusalem" },
			{ "User Stories", "Start", "Clear", "CustomTextField1", "--" },
			{ "User Stories", "Start", "Append", "CustomTextField1", "Beach" },
			{ "User Stories", "Start", "Prepend", "CustomTextField1", "West" },
		};
	}

	@Test(dataProvider = "testParametersProviderWorkflowActionsUpdateItemPropertiesTextField")
    public void testWorkflowActionsUpdateItemPropertiesTextField(String trackerName, String transitionName, String action, String propName, String actionValue) {
		WorkflowActionsUpdateItemPropertiesTextFieldTests testClass = new WorkflowActionsUpdateItemPropertiesTextFieldTests();
		testClass.testWorkflowActionsUpdateItemPropertiesTextField(trackerName, transitionName, action, propName, actionValue);
    }

	@DataProvider(name = "testParametersProviderWorkflowActionsUpdateItemPropertiesWikiField")
	public static Object[][] testParamtersArray6() {
		return new Object[][] {
			{ "Risks", "Verify", "Set to", "Hazard", "Test text in wiki field" },
			{ "Risks", "Verify", "Clear", "Hazard", "--" },
			{ "Risks", "Verify", "Append", "Hazard", "Appended text" },
			{ "Risks", "Verify", "Prepend", "Hazard", "Prefix" },
			{ "Change Requests", "Define", "Set to", "CustomWikiField1", "Test text in wiki field" },
			{ "Change Requests", "Define", "Clear", "CustomWikiField1", "--" },
			{ "Change Requests", "Define", "Append", "CustomWikiField1", "Appended text" },
			{ "Change Requests", "Define", "Prepend", "CustomWikiField1", "Prefix" },
		};
	}

	@Test(dataProvider = "testParametersProviderWorkflowActionsUpdateItemPropertiesWikiField")
    public void testWorkflowActionsUpdateItemPropertiesWikiField(String trackerName, String transitionName, String action, String propName, String actionValue) {
		WorkflowActionsUpdateItemPropertiesWikiFieldTests testClass = new WorkflowActionsUpdateItemPropertiesWikiFieldTests();
		testClass.testWorkflowActionsUpdateItemPropertiesWikiField(trackerName, transitionName, action, propName, actionValue);
    }

	@DataProvider(name = "testParametersProviderWorkflowActionsUpdateItemPropertiesWorkItemField")
	public static Object[][] testParamtersArray7() {
		return new Object[][] {
			{ "System Requirement Specifications", "Define", "Set to", "Subject", "test custreq 1" },
			{ "System Requirement Specifications", "Define", "Clear", "Subject", "--" },
			{ "System Requirement Specifications", "Approve", "Add", "Subject", "test custreq 3" },
			{ "System Requirement Specifications", "Approve", "Remove", "Subject", "test custreq 1" },
			{ "System Requirement Specifications", "Approve", "Retain", "Subject", "test custreq 1" }
		};
	}

	@Test(dataProvider = "testParametersProviderWorkflowActionsUpdateItemPropertiesWorkItemField")
    public void testWorkflowActionsUpdateItemPropertiesWorkItemField(String trackerName, String transitionName, String action, String propName, String actionValue) {
		WorkflowActionsUpdateItemPropertiesWorkItemFieldTests testClass = new WorkflowActionsUpdateItemPropertiesWorkItemFieldTests();
		testClass.testWorkflowActionsUpdateItemPropertiesWorkItemField(trackerName, transitionName, action, propName, actionValue);
    }

	@DataProvider(name = "testParametersProviderWorkflowActionsCreateNewSequentialNumber")
	public static Object[][] testParamtersArray8() {
		return new Object[][] {
			{ "Bugs", "Verify", "Story Points", "Value", "" },
			{ "Bugs", "Verify", "Summary", "Value", "AAA" },
			{ "Bugs", "Verify", "Summary", "Copy from", "Summary" },
			{ "Bugs", "Verify", "Summary", "Compute as", "Summary" },
			{ "Bugs", "Verify", "CustomIntegerField1", "Value", "" }
		};
	}

	@Test(dataProvider = "testParametersProviderWorkflowActionsCreateNewSequentialNumber")
    public void testWorkflowActionsCreateNewSequentialNumber(String trackerName, String transitionName, String fieldName, String prefixType, String prefixValue) {
		WorkflowActionsCreateNewSequentialNumberTests testClass = new WorkflowActionsCreateNewSequentialNumberTests();
		testClass.testWorkflowActionsCreateNewSequentialNumber(trackerName, transitionName, fieldName, prefixType, prefixValue);
    }

	@AfterMethod
	public void tearDown() {
		boolean success = false;
		for (int i=0;i<3;i++) {
			try {
				if (!success) {
					// Login as system admin
					MyStartPage myStartPage = Helper.loginWithSystemAdmin();
					// Finding and removing test project
					ProjectsPage projectsPage = myStartPage.clickOnProjects();
					projectsPage.clickOnCompactList();
					ProjectWikiPage projectWikiPage = projectsPage.clickOnProject(testProjectNamePrefix);
					ProjectAdminSettingsPage projectAdminSettingsPage = projectWikiPage.clickOnAdmin();
					projectAdminSettingsPage.clickOnRemoveProject();
					projectAdminSettingsPage.confirmRemoveProject();
					projectAdminSettingsPage.clickOnDeleteProject();
					projectAdminSettingsPage.confirmDeleteProject();
					success = true;
				}
			} catch (Exception e) {
			}
		}
	}

}
