View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.demo.uif.library.fields;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.junit.Test;
20  import org.openqa.selenium.By;
21  import org.openqa.selenium.WebElement;
22  
23  import java.util.List;
24  
25  /**
26   * @author Kuali Rice Team (rice.collab@kuali.org)
27   */
28  public class LibraryFieldsUserLinkAft extends LibraryFieldsKimLinkBase {
29  
30      /**
31       * /kr-krad/kradsampleapp?viewId=Demo-UserLinkFieldView&methodToCall=start
32       */
33      public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-UserLinkFieldView&methodToCall=start";
34  
35      public static final String PRINCIPAL_ID1 = "eric";
36      public static final String PRINCIPAL_ID2 = "erin";
37      public static final String PRINCIPAL_ID3 = "test1";
38      public static final String PRINCIPAL_ID4 = "edna";
39      public static final String PRINCIPAL_NAME1 = "eric";
40      public static final String PRINCIPAL_NAME2 = "erin";
41      public static final String PRINCIPAL_NAME3 = "test1";
42      public static final String PRINCIPAL_NAME4 = "edna";
43      public static final String PRINCIPAL_LINKTEXT1 = "Employee, Eric";
44      public static final String PRINCIPAL_LINKTEXT2 = "Employee, Erin";
45      public static final String PRINCIPAL_LINKTEXT3 = "One, Tester";
46      public static final String PRINCIPAL_LINKTEXT4 = "Employee, Edna";
47      public static final String PRINCIPAL_INQUIRY_KEY_ID1 = "principalId=eric";
48      public static final String PRINCIPAL_INQUIRY_KEY_ID2 = "principalId=erin";
49      public static final String PRINCIPAL_INQUIRY_KEY_ID3 = "principalId=test1";
50      public static final String PRINCIPAL_INQUIRY_KEY_ID4 = "principalId=edna";
51      public static final String PRINCIPAL_INQUIRY_KEY_NAME1 = "principalName=eric";
52      public static final String PRINCIPAL_INQUIRY_KEY_NAME2 = "principalName=erin";
53      public static final String PRINCIPAL_INQUIRY_KEY_NAME3 = "principalName=test1";
54      public static final String PRINCIPAL_INQUIRY_KEY_NAME4 = "principalName=edna";
55  
56      public static final String USER_ICON_CLASSNAME = "icon-user3";
57      public static final String TEXT_PERSON_INQUIRY = "Person Inquiry";
58      public static final String LABEL_USER_NAME = "User Name";
59      public static final String LABEL_NAME = "Name";
60      public static final String LABEL_USER_LINK = "User Link";
61      public static final String LABEL_DISABLED_USER_LINK = "Disabled User Link";
62      public static final String LABEL_PRINCIPAL_ID = "Principal Id:";
63      public static final String DATA_LABEL_PRINCIPAL_ID = "Principal Id";
64  
65      public static final String DEMO_PAGE_ID1 = "Demo-UserLinkField-Example1";
66      public static final String DEMO_PAGE_ID2 = "Demo-UserLinkField-Example2";
67      public static final String DEMO_PAGE_ID3 = "Demo-UserLinkField-Example3";
68      public static final String DEMO_PAGE_ID4 = "Demo-UserLinkField-Example4";
69      public static final String DEMO_PAGE_ID5 = "Demo-UserLinkField-Example5";
70      public static final String DEMO_PAGE_ID6 = "Demo-UserLinkField-Example6";
71      public static final String DEMO_PAGE_ID7 = "Demo-UserLinkField-Example7";
72      public static final String DEMO_PAGE_HEADER1 = "Default";
73      public static final String DEMO_PAGE_HEADER2 = "User Link Field with Label";
74      public static final String DEMO_PAGE_HEADER3 = "User Link Field with Link Disabled";
75      public static final String DEMO_PAGE_HEADER4 = "User Link Field with Link Disabled";
76      public static final String DEMO_PAGE_HEADER5 = "User Link refreshed by Field changes";
77      public static final String DEMO_PAGE_HEADER6 = "User Link as Input Field Addon";
78      public static final String DEMO_PAGE_HEADER7 = "User Link as Icon";
79  
80      @Override
81      public String getBookmarkUrl() {
82          return BOOKMARK_URL;
83      }
84  
85      @Override
86      protected void navigate() throws Exception {
87          navigateToLibraryDemo("Fields", "User Link Field");
88      }
89  
90      @Override
91      public WebElement navigateToExample(String exampleId) throws Exception {
92          //navigate to base page ensures starting point for each navigateToExample
93          navigateToLibraryDemo("Fields", "User Link Field");
94          return super.navigateToExample(exampleId);
95      }
96  
97      protected void testUserLinkFieldDefault() throws Exception {
98          jGrowl("-- testUserLinkFieldDefault");
99          WebElement exampleDiv = navigateToExample(DEMO_PAGE_ID1);
100         assertTextPresent(DEMO_PAGE_HEADER1);
101 
102         WebElement field = findElement(By.cssSelector(UIF_LINK_CSS_SELECTOR), exampleDiv);
103         List<WebElement> links = exampleDiv.findElements(By.className(UIF_LINK_CLASSNAME));
104         assertEquals("Number of expected user field links not found on page.", 2, links.size());
105 
106         for ( WebElement link : links) {
107             String href =  link.getAttribute(HREF_ATTRIBUTE);
108             if ( !StringUtils.contains(href, INQUIRY)) {
109                 fail("Inquiry not found in link.");
110             }
111 
112             if ( !(StringUtils.contains(href,PRINCIPAL_INQUIRY_KEY_ID1) ||
113                     StringUtils.contains(href,PRINCIPAL_INQUIRY_KEY_NAME2))) {
114                 fail("User inquiry keys not found in href.");
115             }
116 
117             String linkText = link.getText();
118             if ( !(StringUtils.contains(linkText,PRINCIPAL_LINKTEXT1) ||
119                     StringUtils.contains(linkText,PRINCIPAL_LINKTEXT2))) {
120                 fail("User names in linkText not found");
121             }
122         }
123 
124         verifyLink(field, TEXT_PERSON_INQUIRY);
125     }
126 
127     protected void testUserLinkFieldLabel() throws Exception {
128         jGrowl("-- testUserLinkFieldLabel");
129         WebElement exampleDiv = navigateToExample(DEMO_PAGE_ID2);
130         assertTextPresent(DEMO_PAGE_HEADER2);
131 
132         WebElement field = findElement(By.cssSelector(UIF_LINK_CSS_SELECTOR), exampleDiv);
133         assertLabelWithTextPresent(LABEL_USER_NAME);
134         verifyLinkIsInquiry(field);
135         verifyKeyInInquiryHref(field, PRINCIPAL_INQUIRY_KEY_ID1);
136         verifyLinkText(field, PRINCIPAL_LINKTEXT1);
137 
138         verifyLink(field, TEXT_PERSON_INQUIRY);
139     }
140 
141     protected void testUserLinkFieldLinkDisabled() throws Exception {
142         jGrowl("-- testUserLinkFieldLinkDisabled");
143         WebElement exampleDiv = navigateToExample(DEMO_PAGE_ID3);
144         assertTextPresent(DEMO_PAGE_HEADER3);
145 
146         assertLabelWithTextPresent(LABEL_USER_NAME);
147         WebElement disabledLink = findElement(By.xpath("//span[contains( text(),'" + PRINCIPAL_LINKTEXT1 + "')]"), exampleDiv);
148         assertEquals("Disabled Link text not found", PRINCIPAL_LINKTEXT1, disabledLink.getText());
149     }
150 
151     protected void testUserLinkFieldNoLightbox() throws Exception {
152         jGrowl("-- testUserLinkFieldNoLightbox");
153         WebElement exampleDiv = navigateToExample(DEMO_PAGE_ID4);
154         assertTextPresent(DEMO_PAGE_HEADER4);
155 
156         WebElement field = findElement(By.cssSelector(UIF_LINK_CSS_SELECTOR), exampleDiv);
157 
158         verifyLinkIsInquiry(field);
159         verifyKeyInInquiryHref(field,PRINCIPAL_INQUIRY_KEY_ID1);
160         verifyLinkText(field, PRINCIPAL_LINKTEXT1);
161 
162         String dataOnClickScript = field.getAttribute("data-onclick");
163         if ( StringUtils.contains(dataOnClickScript,"openLinkInDialog(jQuery(this), \"\");")) {
164             fail("Lightbox not suppressed for Inquiry.");
165         }
166 
167         waitAndClickByLinkText(field.getText());
168         waitAndClickButtonByText("Back", "Unable to find Back button");
169     }
170 
171     protected void testUserLinkFieldRefresh() throws Exception {
172         jGrowl("-- testUserLinkFieldRefresh");
173         WebElement exampleDiv = navigateToExample(DEMO_PAGE_ID5);
174         assertTextPresent(DEMO_PAGE_HEADER5);
175 
176         WebElement field = findElement(By.cssSelector(UIF_LINK_CSS_SELECTOR), exampleDiv);
177         assertLabelWithTextPresent(LABEL_PRINCIPAL_ID);
178         verifyLinkIsInquiry(field);
179         verifyKeyInInquiryHref(field,PRINCIPAL_INQUIRY_KEY_ID2);
180         verifyLinkText(field, PRINCIPAL_LINKTEXT2);
181         verifyLinkDataItem(field, LABEL_NAME, PRINCIPAL_LINKTEXT2);
182 
183         waitForExampleElementById(DEMO_PAGE_ID5);
184         waitAndClickQuickFinderButton("QuickFinder not found.");
185         gotoLightBox();
186         waitAndTypeByName("lookupCriteria[principalName]", PRINCIPAL_ID1);
187         waitAndClickButtonByExactText("Search");
188         waitAndClickByLinkText("return value");
189 
190         exampleDiv = waitForExampleElementById(DEMO_PAGE_ID5);
191         field = findElement(By.cssSelector(UIF_LINK_CSS_SELECTOR), exampleDiv);
192         verifyLinkText(field, PRINCIPAL_LINKTEXT1);
193         verifyKeyInInquiryHref(field,PRINCIPAL_INQUIRY_KEY_ID1);
194         verifyLinkDataItem(field, LABEL_NAME, PRINCIPAL_LINKTEXT1);
195         waitForExampleElementById(DEMO_PAGE_ID5);
196 
197         // clean up change page alert for next test navigation
198         waitAndClickLibraryLink();
199         acceptAlertIfPresent();
200     }
201 
202     protected void testUserLinkFieldRefreshAddon() throws Exception {
203         jGrowl("-- testUserLinkFieldAddon");
204         WebElement exampleDiv = navigateToExample(DEMO_PAGE_ID6);
205         assertTextPresent(DEMO_PAGE_HEADER6);
206 
207         WebElement field = findElement(By.cssSelector(UIF_LINK_CSS_SELECTOR), exampleDiv);
208         assertLabelWithTextPresent(LABEL_PRINCIPAL_ID);
209         verifyLinkIsInquiry(field);
210         verifyKeyInInquiryHref(field, PRINCIPAL_INQUIRY_KEY_ID3);
211         verifyLinkText(field, PRINCIPAL_LINKTEXT3);
212         //String fieldId = field.getAttribute("id");
213 
214         clearTextByName("testPrincipalId3");
215         waitAndTypeByName("testPrincipalId3", PRINCIPAL_ID4);
216         typeTab();
217         Thread.sleep(2000);
218         waitAndClickByName("testPrincipalId3");
219 
220         exampleDiv = waitForExampleElementById(DEMO_PAGE_ID6);
221         try {
222             field = findElement(By.linkText(PRINCIPAL_LINKTEXT4), exampleDiv);
223         } catch (Exception e) {
224             fail("LINK did not update.");
225         }
226         verifyLinkDataItem(field, LABEL_NAME, PRINCIPAL_LINKTEXT4);
227 
228         // clean up change page alert for next test navigation
229         waitAndClickLibraryLink();
230         acceptAlertIfPresent();
231     }
232 
233     protected void testUserLinkFieldIconLinks() throws Exception {
234         jGrowl("-- testUserLinkFieldIconLinks");
235         WebElement exampleDiv = navigateToExample(DEMO_PAGE_ID7);
236         WebElement field = findElement(By.xpath("//section[@id='" + DEMO_PAGE_ID7 + "']/div[@data-label='" +
237                 LABEL_DISABLED_USER_LINK + "']/span"), exampleDiv);
238         verifyLinkIcon(field, USER_ICON_CLASSNAME);
239 
240         exampleDiv = waitForExampleElementById(DEMO_PAGE_ID7);
241         field = findElement(By.xpath("//section[@id='" + DEMO_PAGE_ID7 + "']/div[@data-label='" + LABEL_USER_LINK +
242                 "']/a"), exampleDiv);
243         verifyKeyInInquiryHref(field,PRINCIPAL_INQUIRY_KEY_ID1);
244         verifyLinkIcon(field,USER_ICON_CLASSNAME);
245         verifyLinkDataItem(field, LABEL_NAME, PRINCIPAL_LINKTEXT1);
246     }
247 
248     protected void testUserLinkFieldRefreshIconLinks() throws Exception {
249         jGrowl("-- testUserLinkFieldIconLinks");
250         WebElement exampleDiv = navigateToExample(DEMO_PAGE_ID7);
251         assertTextPresent(DEMO_PAGE_HEADER7);
252 
253         WebElement field = findElement(By.xpath("//section[@id='" + DEMO_PAGE_ID7 + "']/div[@data-label='" +
254                 DATA_LABEL_PRINCIPAL_ID + "']/div/div/div/a"), exampleDiv);
255         verifyLinkIsInquiry(field);
256         verifyKeyInInquiryHref(field, PRINCIPAL_INQUIRY_KEY_ID4);
257 
258         clearTextByName("testPrincipalId4");
259         waitAndTypeByName("testPrincipalId4", PRINCIPAL_ID1);
260         typeTab();
261         Thread.sleep(2000);
262         waitAndClickByName("testPrincipalId4");
263 
264         waitForProgressLoading();
265         exampleDiv = waitForExampleElementById(DEMO_PAGE_ID7);
266         try {
267             field = findElement(By.xpath("//section[@id='" + DEMO_PAGE_ID7 + "']/div[@data-label='" +
268                     DATA_LABEL_PRINCIPAL_ID + "']/div/div/div/a"), exampleDiv);
269         } catch (Exception e) {
270             fail("LINK did not update.");
271         }
272         verifyLinkDataItem(field, LABEL_NAME, PRINCIPAL_LINKTEXT1);
273 
274         // clean up change page alert for next test navigation
275         waitAndClickLibraryLink();
276         acceptAlertIfPresent();
277     }
278 
279     protected void testUserLinkFieldExamples() throws Exception {
280         testUserLinkFieldDefault();
281         testUserLinkFieldLabel();
282         testUserLinkFieldLinkDisabled();
283         testUserLinkFieldNoLightbox();
284         testUserLinkFieldRefresh();
285         testUserLinkFieldIconLinks();
286     }
287 
288     @Test
289     public void testUserLinkFieldExamplesBookmark() throws Exception {
290         testUserLinkFieldExamples();
291         passed();
292     }
293 
294     @Test
295     public void testUserLinkFieldAddonRefreshExamplesBookmark() throws Exception {
296         testUserLinkFieldRefreshAddon();
297         testUserLinkFieldRefreshIconLinks();
298         passed();
299     }
300 
301     @Test
302     public void testUserLinkFieldExamplesNav() throws Exception {
303         testUserLinkFieldExamples();
304         passed();
305     }
306 
307     @Test
308     public void testUserLinkFieldAddonRefreshExamplesNav() throws Exception {
309         testUserLinkFieldRefreshAddon();
310         testUserLinkFieldRefreshIconLinks();
311         passed();
312     }
313 }