package com.intland.codebeamer.functionaltest.test;

import com.intland.codebeamer.functionaltest.helper.Helper;
import com.intland.codebeamer.functionaltest.page.wiki.ProjectWikiPage;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import static com.codeborne.selenide.Selenide.open;

// TODO party completed: https://codebeamer.com/cb/issue/921542
public class EditorViewTests extends BaseTest {

    @DataProvider(name = "EditorModeProvider")
    public static Object[][] editorModes() {
        return new Object[][]{
                {"wiki", "markup", "wysiwyg"}
        };
    }

    @Test(dataProvider = "EditorModeProvider")
    public void testAddWikiEditor(String contentType, String defaultMode, String targetMode) {
        Helper.loginWithSystemAdmin();
        ProjectWikiPage projectWikiPage = open("/project/Selenium", ProjectWikiPage.class);
        setEditorDefaultMode(defaultMode, projectWikiPage);
    }

    private void setEditorDefaultMode(String defaultMode, ProjectWikiPage projectWikiPage) {
        /*
		 * Clicking on Agile Dashboard subpage
		 */
        projectWikiPage.centerPane.clickOnWikiPage("Agile Dashboard");
		/*
		 * Clicking the Edit link of wiki page
		 */
		projectWikiPage.centerPane.clickOnEdit();
        /*
		 * Switching to Edit wiki popup window
		 */
//        projectWikiPage.switchToWikiEditor();
//
//        projectWikiPage.clickOnWysiwyg();
		/*
		 * Determining if the target mode is default or not
		 */
//        WebElement targetModeTab = driver.findElement(By.id("wiki-" + targetMode + "-tab"));
//        boolean targetModeIsDefault = targetModeTab.getAttribute("class").contains("ditch-focused");
//		/*
//		 * If target mode is not the default, changing to it, and making it
//		 * default
//		 */
//        if (!targetModeIsDefault) {
//			/*
//			 * Clicking on tab of target mode
//			 */
//            executor.executeScript("arguments[0].click();", targetModeTab);
//            if (targetMode.equals("wysiwyg")) {
//                Time.waitForElementsToBeVisible(driver, By.className("mce-toolbar"));
//            }
//			/*
//			 * Clicking on make default link
//			 */
//            Time.waitForElementToBeClickable(driver, By.className("editorModeLink")).click();
//			/*
//			 * Accepting the alert
//			 */
//            driver.switchTo().alert().accept();
//        }
//		/*
//		 * Canceling wiki eddit popup
//		 */
//        Time.waitForElementToBeClickable(driver, By.id("cancelBtn")).click();
//		/*
//		 * Switching back to display wiki page
//		 */
//        Time.waitForWindow(driver, "/cb/wiki/", getVeryShortTime());
    }
}
