<commit_before>/*
 * Copyright (c) 2012-2018 Red Hat, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Red Hat, Inc. - initial API and implementation
 */
package org.eclipse.che.selenium.preferences;

import static org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants.Assistant.ASSISTANT;
import static org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants.Assistant.ToolWindows.CONTRIBUTE_TOOL_WIDOWS;
import static org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants.Assistant.ToolWindows.TOOL_WINDOWS;
import static org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants.Profile.PREFERENCES;
import static org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants.Profile.PROFILE_MENU;
import static org.eclipse.che.selenium.pageobject.PanelSelector.PanelTypes.LEFT_RIGHT_BOTTOM_ID;
import static org.eclipse.che.selenium.pageobject.Preferences.DropDownGitInformationMenu.CONTRIBUTE_PREFERENCES;
import static org.eclipse.che.selenium.pageobject.Wizard.TypeProject.MAVEN;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;

import com.google.inject.Inject;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.eclipse.che.selenium.core.client.TestGitHubRepository;
import org.eclipse.che.selenium.core.client.TestProjectServiceClient;
import org.eclipse.che.selenium.core.project.ProjectTemplates;
import org.eclipse.che.selenium.core.user.DefaultTestUser;
import org.eclipse.che.selenium.core.workspace.TestWorkspace;
import org.eclipse.che.selenium.pageobject.AskDialog;
import org.eclipse.che.selenium.pageobject.Ide;
import org.eclipse.che.selenium.pageobject.Menu;
import org.eclipse.che.selenium.pageobject.NotificationsPopupPanel;
import org.eclipse.che.selenium.pageobject.PanelSelector;
import org.eclipse.che.selenium.pageobject.Preferences;
import org.eclipse.che.selenium.pageobject.ProjectExplorer;
import org.eclipse.che.selenium.pageobject.PullRequestPanel;
import org.eclipse.che.selenium.pageobject.git.Git;
import org.eclipse.che.selenium.refactor.move.MoveItemsTest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

/** @author <NAME> */
public class ContributeTabTest {
  private static final Logger LOG = LoggerFactory.getLogger(MoveItemsTest.class);
  private static final String FIRST_PROJECT_NAME = "first-vcs-project";
  private static final String SECOND_PROJECT_NAME = "second-vcs-project";
  private static final String THIRD_PROJECT_NAME = "not-vcs-project";
  private static final String EXP_TEXT_NOT_VCS =
      "Project does not provide VCS, supported by contribution plugin.";
  private static final String NOTIFICATION_MESSAGE =
      "To activate Contribute Panel by clicking on a project go to Profile -> Preferences -> Git -> Contribute";

  private String firstProjectUrl;
  private String secondProjectUrl;

  @Inject private Ide ide;
  @Inject private Menu menu;
  @Inject private Git git;
  @Inject private DefaultTestUser user;
  @Inject private AskDialog askDialog;
  @Inject private Preferences preferences;
  @Inject private TestWorkspace testWorkspace;
  @Inject private TestGitHubRepository testRepo;
  @Inject private TestGitHubRepository testRepo2;
  @Inject private ProjectExplorer projectExplorer;
  @Inject private PullRequestPanel pullRequestPanel;
  @Inject private TestProjectServiceClient testProjectServiceClient;
  @Inject private NotificationsPopupPanel notificationsPopupPanel;
  @Inject private PanelSelector panelSelector;

  @BeforeClass
  public void setUp() throws Exception {
    Path entryPath =
        Paths.get(getClass().getResource("/projects/default-spring-project").getPath());
    testRepo.addContent(entryPath);
    testRepo2.addContent(entryPath);

    URL resource = getClass().getResource("/projects/guess-project");
    testProjectServiceClient.importProject(
        testWorkspace.getId(),
        Paths.get(resource.toURI()),
        THIRD_PROJECT_NAME,
        ProjectTemplates.MAVEN_SPRING);

    ide.open(testWorkspace);
  }

  @AfterMethod
  public void closeForm() {

    if (preferences.isPreferencesFormOpened()) {
      preferences.clickOnCloseButton();
    }

    if (askDialog.isOpened()) {
      askDialog.confirmAndWaitClosed();
    }

    preferences.waitPreferencesFormIsClosed();
  }

  @Test
  public void checkSettingContributeTab() {
    firstProjectUrl = testRepo.getHtmlUrl() + ".git";
    secondProjectUrl = testRepo2.getHtmlUrl() + ".git";

    projectExplorer.waitProjectExplorer();
    projectExplorer.waitItem(THIRD_PROJECT_NAME);

    // import the first and second projects
    git.importJavaApp(firstProjectUrl, FIRST_PROJECT_NAME, MAVEN);
    git.importJavaApp(secondProjectUrl, SECOND_PROJECT_NAME, MAVEN);

    // check opening the PR panel by select a project
    pullRequestPanel.waitClosePanel();
    projectExplorer.waitAndSelectItem(FIRST_PROJECT_NAME);
    pullRequestPanel.waitOpenPanel();

    // check the text when a project is not under VCS
    projectExplorer.waitAndSelectItem(THIRD_PROJECT_NAME);
    pullRequestPanel.waitTextNotVcsProject(EXP_TEXT_NOT_VCS);

    // check the 'Contribute' checkbox is true by default
    openContributeTab();
    preferences.waitContributeCheckboxIsSelected();
    preferences.closeForm();
  }

  @Test(priority = 1)
  public void checkRefreshAndSaveButton() {
    openContributeTab();

    preferences.setContributeCheckbox(true);
    preferences.clickOnOkBtn();

    assertFalse(preferences.isSaveButtonIsEnabled());

    // check the 'Refresh button
    preferences.clickOnContributeCheckbox();
    preferences.waitContributeCheckboxIsNotSelected();

    assertTrue(preferences.isSaveButtonIsEnabled());

    preferences.clickRefreshButton();
    preferences.waitContributeCheckboxIsSelected();

    assertFalse(
        preferences.isSaveButtonIsEnabled(),
        "Known issue https://github.com/eclipse/che/issues/9959");

    preferences.closeForm();
  }

  @Test(priority = 1)
  public void checkSwitchProjectsWhenContributeIsFalse() {
    openContributeTab();
    setStateContributeChecboxAndCloseForm(true);

    projectExplorer.waitAndSelectItem(FIRST_PROJECT_NAME);
    pullRequestPanel.waitOpenPanel();

    openContributeTab();
    setStateContributeChecboxAndCloseForm(false);

    // switch between projects
    projectExplorer.waitAndSelectItem(FIRST_PROJECT_NAME);
    pullRequestPanel.waitRepoUrl(firstProjectUrl);
    pullRequestPanel.waitProjectName(FIRST_PROJECT_NAME);

    projectExplorer.waitAndSelectItem(SECOND_PROJECT_NAME);
    pullRequestPanel.waitRepoUrl(secondProjectUrl);
    pullRequestPanel.waitProjectName(SECOND_PROJECT_NAME);

    projectExplorer.waitAndSelectItem(THIRD_PROJECT_NAME);
    pullRequestPanel.waitTextNotVcsProject(EXP_TEXT_NOT_VCS);
  }

  @Test(priority = 1)
  public void checkAutomaticChangeContributeToFalse() {<commit_msg>Add the 'Assert.fail()' to the 'ContributeTabTest' according to known issue #10019<commit_after>/*
 * Copyright (c) 2012-2018 Red Hat, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Red Hat, Inc. - initial API and implementation
 */
package org.eclipse.che.selenium.preferences;

import static org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants.Assistant.ASSISTANT;
import static org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants.Assistant.ToolWindows.CONTRIBUTE_TOOL_WIDOWS;
import static org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants.Assistant.ToolWindows.TOOL_WINDOWS;
import static org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants.Profile.PREFERENCES;
import static org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants.Profile.PROFILE_MENU;
import static org.eclipse.che.selenium.pageobject.PanelSelector.PanelTypes.LEFT_RIGHT_BOTTOM_ID;
import static org.eclipse.che.selenium.pageobject.Preferences.DropDownGitInformationMenu.CONTRIBUTE_PREFERENCES;
import static org.eclipse.che.selenium.pageobject.Wizard.TypeProject.MAVEN;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;

import com.google.inject.Inject;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.eclipse.che.selenium.core.client.TestGitHubRepository;
import org.eclipse.che.selenium.core.client.TestProjectServiceClient;
import org.eclipse.che.selenium.core.project.ProjectTemplates;
import org.eclipse.che.selenium.core.user.DefaultTestUser;
import org.eclipse.che.selenium.core.workspace.TestWorkspace;
import org.eclipse.che.selenium.pageobject.AskDialog;
import org.eclipse.che.selenium.pageobject.Ide;
import org.eclipse.che.selenium.pageobject.Menu;
import org.eclipse.che.selenium.pageobject.NotificationsPopupPanel;
import org.eclipse.che.selenium.pageobject.PanelSelector;
import org.eclipse.che.selenium.pageobject.Preferences;
import org.eclipse.che.selenium.pageobject.ProjectExplorer;
import org.eclipse.che.selenium.pageobject.PullRequestPanel;
import org.eclipse.che.selenium.pageobject.git.Git;
import org.eclipse.che.selenium.refactor.move.MoveItemsTest;
import org.openqa.selenium.WebDriverException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

/** @author Aleksandr Shmaraev */
public class ContributeTabTest {
  private static final Logger LOG = LoggerFactory.getLogger(MoveItemsTest.class);
  private static final String FIRST_PROJECT_NAME = "first-vcs-project";
  private static final String SECOND_PROJECT_NAME = "second-vcs-project";
  private static final String THIRD_PROJECT_NAME = "not-vcs-project";
  private static final String EXP_TEXT_NOT_VCS =
      "Project does not provide VCS, supported by contribution plugin.";
  private static final String NOTIFICATION_MESSAGE =
      "To activate Contribute Panel by clicking on a project go to Profile -> Preferences -> Git -> Contribute";

  private String firstProjectUrl;
  private String secondProjectUrl;

  @Inject private Ide ide;
  @Inject private Menu menu;
  @Inject private Git git;
  @Inject private DefaultTestUser user;
  @Inject private AskDialog askDialog;
  @Inject private Preferences preferences;
  @Inject private TestWorkspace testWorkspace;
  @Inject private TestGitHubRepository testRepo;
  @Inject private TestGitHubRepository testRepo2;
  @Inject private ProjectExplorer projectExplorer;
  @Inject private PullRequestPanel pullRequestPanel;
  @Inject private TestProjectServiceClient testProjectServiceClient;
  @Inject private NotificationsPopupPanel notificationsPopupPanel;
  @Inject private PanelSelector panelSelector;

  @BeforeClass
  public void setUp() throws Exception {
    Path entryPath =
        Paths.get(getClass().getResource("/projects/default-spring-project").getPath());
    testRepo.addContent(entryPath);
    testRepo2.addContent(entryPath);

    URL resource = getClass().getResource("/projects/guess-project");
    testProjectServiceClient.importProject(
        testWorkspace.getId(),
        Paths.get(resource.toURI()),
        THIRD_PROJECT_NAME,
        ProjectTemplates.MAVEN_SPRING);

    ide.open(testWorkspace);
  }

  @AfterMethod
  public void closeForm() {
    if (askDialog.isOpened()) {
      askDialog.confirmAndWaitClosed();
    }

    if (preferences.isPreferencesFormOpened()) {
      preferences.clickOnCloseButton();
    }

    preferences.waitPreferencesFormIsClosed();
  }

  @Test
  public void checkSettingContributeTab() {
    firstProjectUrl = testRepo.getHtmlUrl() + ".git";
    secondProjectUrl = testRepo2.getHtmlUrl() + ".git";

    projectExplorer.waitProjectExplorer();
    projectExplorer.waitItem(THIRD_PROJECT_NAME);

    // import the first and second projects
    git.importJavaApp(firstProjectUrl, FIRST_PROJECT_NAME, MAVEN);
    git.importJavaApp(secondProjectUrl, SECOND_PROJECT_NAME, MAVEN);

    // check opening the PR panel by select a project
    pullRequestPanel.waitClosePanel();
    projectExplorer.waitAndSelectItem(FIRST_PROJECT_NAME);
    pullRequestPanel.waitOpenPanel();

    // check the text when a project is not under VCS
    projectExplorer.waitAndSelectItem(THIRD_PROJECT_NAME);
    pullRequestPanel.waitTextNotVcsProject(EXP_TEXT_NOT_VCS);

    // check the 'Contribute' checkbox is true by default
    openContributeTab();
    preferences.waitContributeCheckboxIsSelected();
    preferences.closeForm();
  }

  @Test(priority = 1)
  public void checkRefreshAndSaveButton() {
    openContributeTab();

    preferences.setContributeCheckbox(true);
    preferences.clickOnOkBtn();

    assertFalse(preferences.isSaveButtonIsEnabled());

    // check the 'Refresh button
    preferences.clickOnContributeCheckbox();
    preferences.waitContributeCheckboxIsNotSelected();

    assertTrue(preferences.isSaveButtonIsEnabled());

    preferences.clickRefreshButton();
    preferences.waitContributeCheckboxIsSelected();

    assertFalse(
        preferences.isSaveButtonIsEnabled(),
        "Known issue https://github.com/eclipse/che/issues/9959");

    try {
      preferences.closeForm();
    } catch (WebDriverException ex) {
      // remove try-catch block after issue has been resolved
      fail("Known issue https://github.com/eclipse/che/issues/10019", ex);
    }
  }

  @Test(priority = 1)
  public void checkSwitchProjectsWhenContributeIsFalse() {
    openContributeTab();
    setStateContributeChecboxAndCloseForm(true);

    projectExplorer.waitAndSelectItem(FIRST_PROJECT_NAME);
    pullRequestPanel.waitOpenPanel();

    openContributeTab();
    setStateContributeChecboxAndCloseForm(false);

    // switch between projects
    projectExplorer.waitAndSelectItem(FIRST_PROJECT_NAME);
    pullRequestPanel.waitRepoUrl(firstProjectUrl);
    pullRequestPanel.waitProjectName(FIRST_PROJECT_NAME);

    projectExplorer.waitAndSelectItem(SECOND_PROJECT_NAME);
    pullRequestPanel.waitRepoUrl(secondProjectUrl);
    pullRequestPanel.waitProjectName(SECOND_PROJECT_NAME);

    projectExplorer.waitAndSelectItem(THIRD_PROJECT_NAME);
    pullRequestPanel.waitTextNotVcsProject(EXP_TEXT_NOT_VCS);
  }

  @Test(priority = 1)
  public void checkAutomaticChangeContributeToFalse() {
{'fraction_non_alphanumeric': 0.09012962462867945, 'fraction_numerical': 0.003915743991358358, 'mean_word_length': 5.197907949790795, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 10, 'https://': 3, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3878436', 'n_tokens_mistral': 4418, 'n_tokens_neox': 4289, 'n_words': 814}