From e59978a8b7490cff2ed5416252110495b1736f78 Mon Sep 17 00:00:00 2001 From: Damian Jansen Date: Wed, 17 Sep 2014 15:12:26 +1000 Subject: [PATCH] Tests for viewing translation history Test the translation history view shows Test two versions can be compared --- .../org/zanata/page/webtrans/EditorPage.java | 127 ++++++++++++++++++ .../editor/TranslationHistoryTest.java | 95 +++++++++++++ 2 files changed, 222 insertions(+) create mode 100644 functional-test/src/test/java/org/zanata/feature/editor/TranslationHistoryTest.java diff --git a/functional-test/src/main/java/org/zanata/page/webtrans/EditorPage.java b/functional-test/src/main/java/org/zanata/page/webtrans/EditorPage.java index 5277e469e5..67121f54fa 100644 --- a/functional-test/src/main/java/org/zanata/page/webtrans/EditorPage.java +++ b/functional-test/src/main/java/org/zanata/page/webtrans/EditorPage.java @@ -23,6 +23,7 @@ import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; +import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -504,15 +505,141 @@ public String getFilterQuery() { return editorFilterField.getAttribute("value"); } + // Find the right side column for the selected row private WebElement getTranslationTargetColumn() { return getDriver().findElement(By.className("selected")) .findElements(By.className("transUnitCol")) .get(1); // Right column } + // Find the validation messages / errors box private WebElement getTargetValidationBox() { return getTranslationTargetColumn() .findElement(By.className("gwt-DisclosurePanel")); } + // Click the History button for the selected row - row id must be known + public EditorPage clickShowHistoryForRow(int row) { + log.info("Click history button on row {}", row); + getTranslationTargetColumn() + .findElement(By.id("gwt-debug-target-" + row + "-history")) + .click(); + waitForTenSec().until(new Predicate() { + @Override + public boolean apply(WebDriver input) { + return getTranslationHistoryBox().isDisplayed(); + } + }); + return new EditorPage(getDriver()); + + } + + public String getHistoryEntryAuthor(int entry) { + log.info("Query author, action on history entry {}", entry); + return getTranslationHistoryList() + .get(entry) + .findElements(By.className("gwt-InlineHTML")) + .get(0) + .findElement(By.className("txt--meta")) + .getText(); + } + + public String getHistoryEntryContent(int entry) { + log.info("Query content on history entry {}", entry); + return getTranslationHistoryList() + .get(entry) + .findElements(By.className("gwt-InlineHTML")) + .get(1) + .findElement(By.className("cm-s-default")) + .getText(); + } + + public EditorPage clickCompareOn(final int entry) { + log.info("Click Compare on history entry {}", entry); + waitForTenSec().until(new Predicate() { + @Override + public boolean apply(WebDriver input) { + try { + return getTranslationHistoryList().get(entry) + .findElement(By.linkText("Compare")) + .isDisplayed(); + } catch(IndexOutOfBoundsException ioobe) { + return false; + } + } + }); + getTranslationHistoryList().get(entry) + .findElement(By.linkText("Compare")) + .click(); + slightPause(); + return new EditorPage(getDriver()); + } + + public String getTranslationHistoryCompareTabtext() { + log.info("Query history tab text"); + return getCompareTab().getText(); + } + + public EditorPage clickCompareVersionsTab() { + log.info("Click on Compare versions tab"); + getCompareTab().click(); + waitForTenSec().until(new Predicate() { + @Override + public boolean apply(WebDriver input) { + return getTranslationHistoryBox() + .findElement(By.className("html-face")) + .isDisplayed(); + } + }); + return new EditorPage(getDriver()); + } + + public String getComparisonTextInRow(int row) { + log.info("Query comparison text in row {}", row); + return getCompareTabEntries() + .get(row) + .findElement(By.tagName("pre")) + .getText(); + } + + public List getComparisonTextDiff() { + log.info("Query diff from history compare"); + List diffs = new ArrayList<>(); + for (WebElement element : getCompareTabEntries()) { + for (WebElement diffElement : element.findElements(By.className("diff-insert"))) { + diffs.add("++" + diffElement.getText()); + } + for (WebElement diffElement : element.findElements(By.className("diff-delete"))) { + diffs.add("--" + diffElement.getText()); + } + } + return diffs; + } + + private WebElement getTranslationHistoryBox() { + return getDriver().findElement(By.id("gwt-debug-transHistory")) + .findElement(By.id("gwt-debug-transHistoryTabPanel")); + } + + private List getTranslationHistoryList() { + return getTranslationHistoryBox() + .findElement(By.className("gwt-TabLayoutPanelContent")) + .findElement(By.className("list--slat")) + .findElements(By.className("l--pad-v-1")); + } + + private WebElement getCompareTab() { + return getTranslationHistoryBox() + .findElement(By.className("gwt-TabLayoutPanelTabs")) + .findElements(By.className("gwt-TabLayoutPanelTabInner")) + .get(1); + } + + private List getCompareTabEntries() { + return getTranslationHistoryBox() + .findElements(By.className("gwt-TabLayoutPanelContent")) + .get(1) // Second tab + .findElements(By.className("textFlowEntry")); + } + } diff --git a/functional-test/src/test/java/org/zanata/feature/editor/TranslationHistoryTest.java b/functional-test/src/test/java/org/zanata/feature/editor/TranslationHistoryTest.java new file mode 100644 index 0000000000..d1d9d90bae --- /dev/null +++ b/functional-test/src/test/java/org/zanata/feature/editor/TranslationHistoryTest.java @@ -0,0 +1,95 @@ +/* + * Copyright 2014, Red Hat, Inc. and individual contributors as indicated by the + * @author tags. See the copyright.txt file in the distribution for a full + * listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this software; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF + * site: http://www.fsf.org. + */ +package org.zanata.feature.editor; + +import org.junit.Rule; +import org.junit.Test; +import org.zanata.feature.testharness.ZanataTestCase; +import org.zanata.page.webtrans.EditorPage; +import org.zanata.util.RetryRule; +import org.zanata.util.SampleProjectRule; +import org.zanata.workflow.LoginWorkFlow; +import org.zanata.workflow.ProjectWorkFlow; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Damian Jansen djansen@redhat.com + */ +public class TranslationHistoryTest extends ZanataTestCase { + + @Rule + public RetryRule retryRule = new RetryRule(0); + + @Rule + public SampleProjectRule sampleProjectRule = new SampleProjectRule(); + + @Test + public void showTranslationHistory() { + new LoginWorkFlow().signIn("admin", "admin"); + EditorPage editorPage = new ProjectWorkFlow() + .goToProjectByName("about fedora") + .gotoVersion("master") + .translate("pl", "About_Fedora") + .translateTargetAtRowIndex(0, "historytest") + .saveAsFuzzyAtRow(0) + .clickShowHistoryForRow(0); + + assertThat(editorPage.getHistoryEntryAuthor(0)) + .startsWith("Administrator") + .as("The user is displayed"); + assertThat(editorPage.getHistoryEntryContent(0)) + .contains("historytest") + .as("The content change is displayed"); + } + + @Test + public void compareTranslationHistory() { + new LoginWorkFlow().signIn("admin", "admin"); + EditorPage editorPage = new ProjectWorkFlow() + .goToProjectByName("about fedora") + .gotoVersion("master") + .translate("pl", "About_Fedora") + .translateTargetAtRowIndex(0, "historytest") + .saveAsFuzzyAtRow(0) + .translateTargetAtRowIndex(0, "historytest2") + .approveTranslationAtRow(0) + .clickShowHistoryForRow(0) + .clickCompareOn(0) + .clickCompareOn(1); + + assertThat(editorPage.getTranslationHistoryCompareTabtext()) + .isEqualTo("Compare ver. 2 and 1") + .as("The tab displays compared versions"); + + editorPage = editorPage.clickCompareVersionsTab(); + + assertThat(editorPage.getComparisonTextInRow(0)) + .isEqualTo("historytest2") + .as("The new text is displayed"); + assertThat(editorPage.getComparisonTextInRow(1)) + .isEqualTo("historytest2") + .as("The old text is also displayed"); + assertThat(editorPage.getComparisonTextDiff()) + .contains("--2") + .as("The diff is displayed"); + } +}