Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Tests for viewing translation history
Browse files Browse the repository at this point in the history
Test the translation history view shows
Test two versions can be compared
  • Loading branch information
djansen-redhat committed Oct 10, 2014
1 parent e3a9f8e commit d95e8fe
Show file tree
Hide file tree
Showing 2 changed files with 222 additions and 0 deletions.
127 changes: 127 additions & 0 deletions functional-test/src/main/java/org/zanata/page/webtrans/EditorPage.java
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
waitForAMoment().until(new Predicate<WebDriver>() {
@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);
waitForAMoment().until(new Predicate<WebDriver>() {
@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();
waitForAMoment().until(new Predicate<WebDriver>() {
@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<String> getComparisonTextDiff() {
log.info("Query diff from history compare");
List<String> 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<WebElement> 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<WebElement> getCompareTabEntries() {
return getTranslationHistoryBox()
.findElements(By.className("gwt-TabLayoutPanelContent"))
.get(1) // Second tab
.findElements(By.className("textFlowEntry"));
}

}
@@ -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 <a href="mailto:djansen@redhat.com">djansen@redhat.com</a>
*/
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");
}
}

0 comments on commit d95e8fe

Please sign in to comment.