package it.com.atlassian.stash;

import com.atlassian.pageobjects.PageBinder;
import com.atlassian.pageobjects.elements.query.Poller;
import com.atlassian.pageobjects.elements.timeout.TimeoutType;
import com.atlassian.webdriver.bitbucket.element.KeyboardShortcutsDialog;
import com.atlassian.webdriver.bitbucket.page.BitbucketHomePage;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;

import static org.junit.Assert.assertEquals;

public class KeyboardShortcutsTest extends BaseBrowserFuncTest {

    private BitbucketHomePage homePage;

    @Test
    public void showAndHideKeyboardShortcutsDialog() {
        homePage = loginAsRegularUser(BitbucketHomePage.class);

        WebDriver driver = BITBUCKET.getTester().getDriver();
        PageBinder pageBinder = BITBUCKET.getPageBinder();


        driver.findElement(By.tagName("body")).sendKeys("?");
        KeyboardShortcutsDialog keyboardShortcutsDialog = pageBinder.bind(KeyboardShortcutsDialog.class, By.id("keyboard-shortcut-dialog"), TimeoutType.DIALOG_LOAD);

        Poller.waitUntilTrue("Keyboard shortcuts help dialog is shown", keyboardShortcutsDialog.isOpen());
        assertEquals("Keyboard shortcuts", keyboardShortcutsDialog.getTitleText());

        driver.findElement(By.tagName("body")).sendKeys(Keys.ESCAPE);
        Poller.waitUntilFalse("Keyboard shortcuts help dialog is closed", keyboardShortcutsDialog.isOpen());
    }

}
