This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
/
VersionLanguagesTab.java
155 lines (135 loc) · 5.58 KB
/
VersionLanguagesTab.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* 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.page.projectversion.versionsettings;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.collect.Lists;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.zanata.page.projectversion.VersionBasePage;
import org.zanata.util.WebElementUtil;
import java.util.List;
/**
* This class represents the project version settings tab for languages.
*
* @author Damian Jansen
* <a href="mailto:djansen@redhat.com">djansen@redhat.com</a>
*/
public class VersionLanguagesTab extends VersionBasePage {
@FindBy(id = "languageAutocomplete-autocomplete__input")
private WebElement addNewLanguageField;
public VersionLanguagesTab(WebDriver driver) {
super(driver);
}
/**
* Get a list of locales enabled in this version
*
* @return String list of language/locale names
*/
public List<String> getEnabledLocaleList() {
List<String> rows =Lists.transform(getEnabledLocaleListElement(),
new Function<WebElement, String>() {
@Override
public String apply(WebElement li) {
return li.getText();
}
});
return rows;
}
private List<WebElement> getEnabledLocaleListElement() {
return getDriver().findElement(By.id("settings-languages-form"))
.findElements(By.xpath(".//ul/li[@class='reveal--list-item']"));
}
public void waitForLanguagesContains(String language) {
waitForLanguageEntryExpected(language, true);
}
public void waitForLanguagesNotContains(String language) {
waitForLanguageEntryExpected(language, false);
}
private void waitForLanguageEntryExpected(final String language,
final boolean exists) {
waitForTenSec().until(new Function<WebDriver, Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
return getEnabledLocaleList().contains(language) == exists;
}
});
}
public VersionLanguagesTab enterSearchLanguage(String localeQuery) {
WebElementUtil.searchAutocomplete(getDriver(), "languageAutocomplete",
localeQuery);
return new VersionLanguagesTab(getDriver());
}
public VersionLanguagesTab removeLocale(final String localeId) {
boolean removedLocale = false;
for (WebElement localeLi : getEnabledLocaleListElement()) {
String displayedLocaleId =
localeLi.findElement(By.xpath(".//span")).getText()
.replace("[", "").replace("]", "");
if (displayedLocaleId.equals(localeId)) {
localeLi.findElement(By.tagName("a")).click();
removedLocale = true;
break;
}
}
Preconditions.checkState(removedLocale, "can not remove locale: %s",
localeId);
refreshPageUntil(this, new Predicate<WebDriver>() {
@Override
public boolean apply(WebDriver driver) {
return !getEnabledLocaleList().contains(localeId);
}
});
return new VersionLanguagesTab(getDriver());
}
public VersionLanguagesTab addLocale(final String localeId) {
waitForTenSec().until(new Function<WebDriver, List<WebElement>>() {
@Override
public List<WebElement> apply(WebDriver driver) {
return WebElementUtil.getSearchAutocompleteResults(driver,
"settings-languages-form", "languageAutocomplete");
}
});
List<WebElement> searchResults =
WebElementUtil.getSearchAutocompleteResults(getDriver(),
"settings-languages-form", "languageAutocomplete");
boolean clickedLocale = false;
for (WebElement searchResult : searchResults) {
if (searchResult.getText().contains(localeId)) {
searchResult.click();
clickedLocale = true;
break;
}
}
Preconditions.checkState(clickedLocale, "can not find locale - %s",
localeId);
refreshPageUntil(this, new Predicate<WebDriver>() {
@Override
public boolean apply(WebDriver driver) {
return getEnabledLocaleList().contains(localeId);
}
});
return new VersionLanguagesTab(getDriver());
}
}