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

Commit

Permalink
add functional test for gettext plural push and pull
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Huang committed Feb 10, 2014
1 parent 30c0f4d commit 1fc5dcf
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 9 deletions.
Expand Up @@ -236,6 +236,104 @@ public WebElement apply(WebDriver input) {
return new EditorPage(getDriver());
}

public EditorPage setSyntaxHighlighting(boolean option) {
openConfigurationPanel();
if (getDriver().findElement(By.id("gwt-uid-144")).isSelected() != option) {
getDriver().findElement(By.id("gwt-uid-144")).click();
}
return new EditorPage(getDriver());
}

private Boolean openConfigurationPanel() {
getDriver().findElement(By.className("icon-cog")).click();
return waitForTenSec().until(new Function<WebDriver, Boolean>() {
@Override
public Boolean apply(WebDriver input) {
return input.findElement(
By.className("gwt-TabLayoutPanelContentContainer"))
.isDisplayed();
}
});

}

public String getBasicTranslationTargetAtRowIndex(final int rowIndex) {
return getContentAtRowIndex(rowIndex, TARGET_ID_FMT, SINGULAR);
}

/**
* Get content from a target using the non-CodeMirror configuration
* @param rowIndex
* @return row target content
*/
private String getContentAtRowIndex(final long rowIndex,
final String idFormat,
final int pluralIndex) {
return waitForTenSec().until(new Function<WebDriver, String>() {
@Override
public String apply(WebDriver input) {
return input.findElement(By.id(String.format(idFormat, rowIndex, pluralIndex))).getAttribute("value");
}
});
}

/**
* Translate a target using the non-CodeMirror field
* @param rowIndex
* @param text
* @return updated EditorPage
*/
public EditorPage translateTargetAtRowIndex(final int rowIndex, String text) {
setTargetContent(rowIndex, text, TARGET_ID_FMT, SINGULAR);
return new EditorPage(getDriver());
}

private void setTargetContent(final long rowIndex, final String text,
final String idFormat, final int pluralIndex) {
WebElement we = waitForTenSec().until(new Function<WebDriver, WebElement>() {
@Override
public WebElement apply(WebDriver input) {
return input.findElement(
By.id(String.format(idFormat, rowIndex, pluralIndex)));
}
});
we.click();
we.clear();
we.sendKeys(text);
}

/**
* Press the Approve button for the currently selected translation row
* @return new Editor page object
*/
public EditorPage approveSelectedTranslation() {
WebElement approve = waitForTenSec().until(new Function<WebDriver, WebElement>() {
@Override
public WebElement apply(WebDriver input) {
return input.findElement(By.className("selected"))
.findElement(By.className("icon-install"));
}
});
approve.click();
return new EditorPage(getDriver());
}

/**
* Press the Save as Fuzzy button for the currently selected translation row
* @return new Editor page object
*/
public EditorPage saveAsFuzzySelectedTranslation() {
WebElement approve = waitForTenSec().until(new Function<WebDriver, WebElement>() {
@Override
public WebElement apply(WebDriver input) {
return input.findElement(By.className("selected"))
.findElement(By.className("icon-flag-1"));
}
});
approve.click();
return new EditorPage(getDriver());
}

public String getMessageTargetAtRowIndex(int rowIndex, int pluralIndex) {
Preconditions.checkArgument(pluralIndex >= 0 && pluralIndex <= 6,
"plural index must be in range [0,6]");
Expand Down
Expand Up @@ -14,7 +14,7 @@
import org.xml.sax.InputSource;
import org.zanata.adapter.po.PoReader2;
import org.zanata.common.LocaleId;
import org.zanata.feature.BasicAcceptanceTest;
import org.zanata.feature.DetailedTest;
import org.zanata.page.webtrans.EditorPage;
import org.zanata.rest.dto.resource.TextFlow;
import org.zanata.rest.dto.resource.TextFlowTarget;
Expand All @@ -35,7 +35,7 @@
* @author Patrick Huang <a
* href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
*/
@Category(BasicAcceptanceTest.class)
@Category(DetailedTest.class)
public class GettextPluralSupportTest {
@Rule
public SampleProjectRule sampleProjectRule = new SampleProjectRule();
Expand Down Expand Up @@ -102,16 +102,22 @@ public void canPushAndPullPlural() throws IOException {
getTextFlowTargets(new File(pullDir + "/pl/test.po"));
assertThat(pulledTargets, Matchers.equalTo(originalTargets));

// TODO translate some text in UI and then pull and compare
// translate on web UI and pull again
editorPage.setSyntaxHighlighting(false)
.translateTargetAtRowIndex(0, "one aoeuaouaou")
.saveAsFuzzySelectedTranslation();


client.callWithTimeout(tempDir, command);
List<String> newContents =
getTextFlowTargets(new File(pullDir + "/pl/test.po")).get(0)
.getContents();
assertThat(newContents, Matchers.hasItem("one aoeuaouaou"));

}

private static EditorPage verifyPluralPushedToEditor() {
// first message
// msgid "One file removed"
// msgid_plural "%d files removed"
// msgstr[0] "1 aoeuaouaou"
// msgstr[1] "%d aoeuaouao"

// verify first message
new LoginWorkFlow().signIn("admin", "admin");
EditorPage editorPage =
new BasicWorkFlow().goToPage(String.format(
Expand Down

0 comments on commit 1fc5dcf

Please sign in to comment.