View Javadoc
1   /**
2    * Copyright 2005-2014 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 LibraryFieldsRoleLinkAft extends LibraryFieldsKimLinkBase {
29  
30      /**
31       * /kr-krad/kradsampleapp?viewId=Demo-RoleLinkFieldView&methodToCall=start
32       */
33      public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-RoleLinkFieldView&methodToCall=start";
34  
35      public static final String ROLE_ID1 = "KRSAP10005";
36      public static final String ROLE_ID2 = "KR1000";
37      public static final String ROLE_ID3 = "67";
38      public static final String ROLE_ID4 = "KR1000";
39      public static final String ROLE_ID5 = "KR1000";
40      public static final String ROLE_NAMESPACECODE1 = "KR-SAP";
41      public static final String ROLE_NAMESPACECODE1_DROPDOWN = "KKKKKKKKK";
42      public static final String ROLE_NAMESPACECODE2 = "KUALI";
43      public static final String ROLE_NAMESPACECODE3 = "KR-WKFLW";
44      public static final String ROLE_NAMESPACECODE4 = "KUALI";
45      public static final String ROLE_NAMESPACECODE5 = "KUALI";
46      public static final String ROLE_NAME1 = "Travel Approver";
47      public static final String ROLE_NAME2 = "GuestRole";
48      public static final String ROLE_NAME3 = "Router";
49      public static final String ROLE_NAME4 = "GuestRole";
50      public static final String ROLE_NAME5 = "GuestRole";
51      public static final String ROLE_LINKTEXT1 = "KR-SAP Travel Approver";
52      public static final String ROLE_LINKTEXT2 = "KUALI GuestRole";
53      public static final String ROLE_LINKTEXT3 = "KR-WKFLW Router";
54      public static final String ROLE_LINKTEXT4 = "KUALI GuestRole";
55      public static final String ROLE_LINKTEXT5 = "KUALI GuestRole";
56      public static final String ROLE_INQUIRY_KEY_ID1 = "id=KRSAP10005";
57      public static final String ROLE_INQUIRY_KEY_ID2 = "id=KR1000";
58      public static final String ROLE_INQUIRY_KEY_ID3 = "id=67";
59      public static final String ROLE_INQUIRY_KEY_ID4 = "id=KR1000";
60      public static final String ROLE_INQUIRY_KEY_ID5 = "id=KR1000";
61      public static final String ROLE_INQUIRY_KEY_NAME1 = "name=Travel+Approver";
62      public static final String ROLE_INQUIRY_KEY_NAME2 = "name=GuestRole";
63      public static final String ROLE_INQUIRY_KEY_NAME3 = "name=Router";
64      public static final String ROLE_INQUIRY_KEY_NAME4 = "name=GuestRole";
65      public static final String ROLE_INQUIRY_KEY_NAME5 = "name=GuestRole";
66      public static final String ROLE_INQUIRY_KEY_NAMESPACECODE1 = "namespaceCode=KR-SAP";
67      public static final String ROLE_INQUIRY_KEY_NAMESPACECODE2 = "namespaceCode=KUALI";
68      public static final String ROLE_INQUIRY_KEY_NAMESPACECODE3 = "namespaceCode=KR-WKFLW";
69      public static final String ROLE_INQUIRY_KEY_NAMESPACECODE4 = "namespaceCode=KUALI";
70      public static final String ROLE_INQUIRY_KEY_NAMESPACECODE5 = "namespaceCode=KUALI";
71  
72      public static final String ROLE_ICON_CLASSNAME = "icon-stack";
73      public static final String LABEL_ROLE_NAME = "Role Name";
74      public static final String LABEL_NAME = "Name";
75      public static final String LABEL_ROLE_LINK = "Role Link";
76      public static final String LABEL_ROLE_LINK1 = "Role Link1";
77      public static final String LABEL_ROLE_LINK2 = "Role Link2";
78      public static final String LABEL_NAMESPACECODE = "NamespaceCode";
79      public static final String LABEL_ROLENAME = "RoleName";
80      public static final String LABEL_DISABLED_ROLE_LINK = "Disabled Role Link";
81      public static final String LABEL_ROLE_ID = "Role Id";
82  
83      public static final String DEMO_PAGE_ID1 = "Demo-RoleLinkField-Example1";
84      public static final String DEMO_PAGE_ID2 = "Demo-RoleLinkField-Example2";
85      public static final String DEMO_PAGE_ID3 = "Demo-RoleLinkField-Example3";
86      public static final String DEMO_PAGE_ID4 = "Demo-RoleLinkField-Example4";
87      public static final String DEMO_PAGE_ID5 = "Demo-RoleLinkField-Example5";
88      public static final String DEMO_PAGE_ID6 = "Demo-RoleLinkField-Example6";
89      public static final String DEMO_PAGE_ID7 = "Demo-RoleLinkField-Example7";
90      public static final String DEMO_PAGE_ID8 = "Demo-RoleLinkField-Example8";
91      public static final String DEMO_PAGE_HEADER1 = "Default";
92      public static final String DEMO_PAGE_HEADER2 = "Role Link Field with Label";
93      public static final String DEMO_PAGE_HEADER3 = "Role Link Field with Link Disabled";
94      public static final String DEMO_PAGE_HEADER4 = "Inquiry without Lightbox";
95      public static final String DEMO_PAGE_HEADER5 = "Role Link refreshed by Field changes";
96      public static final String DEMO_PAGE_HEADER6 = "Role Link as Input Field Addon";
97      public static final String DEMO_PAGE_HEADER7 = "Role Link as Icon";
98      public static final String DEMO_PAGE_HEADER8 = "Role Link with LinkText namespaceCode suppressed";
99  
100     @Override
101     public String getBookmarkUrl() {
102         return BOOKMARK_URL;
103     }
104 
105     @Override
106     protected void navigate() throws Exception {
107         navigateToLibraryDemo("Fields", "Role Link Field");
108     }
109 
110     @Override
111     public WebElement navigateToExample(String exampleId) throws Exception {
112         //navigate to base page ensures starting point for each navigateToExample
113         navigateToLibraryDemo("Fields", "Role Link Field");
114         return super.navigateToExample(exampleId);
115     }
116 
117     protected void testRoleLinkFieldDefault() throws Exception {
118         jGrowl("-- testRoleLinkFieldDefault");
119         WebElement exampleDiv = navigateToExample(DEMO_PAGE_ID1);
120         assertTextPresent(DEMO_PAGE_HEADER1);
121 
122         WebElement field = findElement(By.cssSelector(UIF_LINK_CSS_SELECTOR), exampleDiv);
123         List<WebElement> links = exampleDiv.findElements(By.className(UIF_LINK_CLASSNAME));
124         assertEquals("Number of expected role field links not found on page.", 2, links.size());
125 
126         for ( WebElement link : links) {
127             String href =  link.getAttribute(HREF_ATTRIBUTE);
128             if ( !StringUtils.contains(href, INQUIRY)) {
129                 fail("Inquiry not found in link.");
130             }
131 
132             if ( !(StringUtils.contains(href, ROLE_INQUIRY_KEY_ID1) ||
133                     (StringUtils.contains(href, ROLE_INQUIRY_KEY_NAMESPACECODE2) &&
134                             StringUtils.contains(href, ROLE_INQUIRY_KEY_NAME2)))) {
135                 fail("Role inquiry keys not found in href.");
136             }
137 
138             String linkText = link.getText();
139             if ( !(StringUtils.contains(linkText, ROLE_LINKTEXT1) ||
140                    StringUtils.contains(linkText, ROLE_LINKTEXT2))) {
141                 fail("Role names in linkText not found");
142             }
143         }
144 
145         field = findElement(By.linkText(ROLE_LINKTEXT1), exampleDiv);
146         verifyLinkDataItem(field, LABEL_ROLE_NAME, ROLE_NAME1);
147 
148         field = findElement(By.linkText(ROLE_LINKTEXT2), exampleDiv);
149         verifyLinkDataItem(field, LABEL_ROLE_NAME, ROLE_NAME2);
150     }
151 
152     protected void testRoleLinkFieldLabel() throws Exception {
153         jGrowl("-- testRoleLinkFieldLabel");
154         WebElement exampleDiv = navigateToExample(DEMO_PAGE_ID2);
155         assertTextPresent(DEMO_PAGE_HEADER2);
156 
157         assertLabelWithTextPresent(LABEL_ROLE_LINK1);
158         assertLabelWithTextPresent(LABEL_ROLE_LINK2);
159 
160         WebElement field = findElement(By.linkText(ROLE_LINKTEXT1), exampleDiv);
161         verifyLinkIsInquiry(field);
162         verifyKeyInInquiryHref(field, ROLE_INQUIRY_KEY_ID1);
163         verifyLinkText(field, ROLE_LINKTEXT1);
164         verifyLinkDataItem(field, LABEL_ROLE_NAME, ROLE_NAME1);
165 
166         field = findElement(By.linkText(ROLE_LINKTEXT2),exampleDiv);
167         verifyLinkIsInquiry(field);
168         verifyKeyInInquiryHref(field, ROLE_INQUIRY_KEY_NAMESPACECODE2);
169         verifyKeyInInquiryHref(field, ROLE_INQUIRY_KEY_NAME2);
170         verifyLinkText(field, ROLE_LINKTEXT2);
171         verifyLinkDataItem(field, LABEL_ROLE_NAME, ROLE_NAME2);
172     }
173 
174     protected void testRoleLinkFieldLinkDisabled() throws Exception {
175         jGrowl("-- testRoleLinkFieldLinkDisabled");
176         WebElement exampleDiv = navigateToExample(DEMO_PAGE_ID3);
177         assertTextPresent(DEMO_PAGE_HEADER3);
178 
179         assertLabelWithTextPresent(LABEL_ROLE_LINK1);
180         assertLabelWithTextPresent(LABEL_ROLE_LINK2);
181 
182         WebElement disabledLink = findElement(By.xpath("//span[contains( text(),'" + ROLE_LINKTEXT1 + "')]"), exampleDiv);
183         assertEquals("Disabled Link text not found", ROLE_LINKTEXT1, disabledLink.getText());
184 
185         disabledLink = findElement(By.xpath("//span[contains( text(),'" + ROLE_LINKTEXT2 + "')]"), exampleDiv);
186         assertEquals("Disabled Link text not found", ROLE_LINKTEXT2, disabledLink.getText());
187     }
188 
189     protected void testRoleLinkFieldNoLightbox() throws Exception {
190         jGrowl("-- testRoleLinkFieldNoLightbox");
191         WebElement exampleDiv = navigateToExample(DEMO_PAGE_ID4);
192         assertTextPresent(DEMO_PAGE_HEADER4);
193 
194         WebElement field = findElement(By.cssSelector(UIF_LINK_CSS_SELECTOR), exampleDiv);
195 
196         verifyLinkIsInquiry(field);
197         verifyKeyInInquiryHref(field, ROLE_INQUIRY_KEY_ID1);
198         verifyLinkText(field, ROLE_LINKTEXT1);
199 
200         String dataOnClickScript = field.getAttribute("data-onclick");
201         if ( StringUtils.contains(dataOnClickScript,"openLinkInDialog(jQuery(this), \"\");")) {
202             fail("Lightbox not suppressed for Inquiry.");
203         }
204 
205         waitAndClickByLinkText(field.getText());
206         waitAndClickButtonByText("Back", "Unable to find Back button");
207     }
208 
209     protected void testRoleLinkFieldRefresh() throws Exception {
210         jGrowl("-- testRoleLinkFieldRefresh");
211         WebElement exampleDiv = navigateToExample(DEMO_PAGE_ID5);
212         assertTextPresent(DEMO_PAGE_HEADER5);
213 
214         WebElement field = findElement(By.cssSelector(UIF_LINK_CSS_SELECTOR), exampleDiv);
215         assertLabelWithTextPresent(LABEL_ROLE_LINK);
216         verifyLinkIsInquiry(field);
217         verifyKeyInInquiryHref(field, ROLE_INQUIRY_KEY_NAMESPACECODE3);
218         verifyKeyInInquiryHref(field, ROLE_INQUIRY_KEY_NAME3);
219         verifyLinkText(field, ROLE_LINKTEXT3);
220         verifyLinkDataItem(field, LABEL_ROLE_NAME, ROLE_NAME3);
221 
222         waitForExampleElementById(DEMO_PAGE_ID5);
223         waitAndClickQuickFinderButton("QuickFinder not found.");
224         gotoLightBox();
225         // brittle test due to the fact if number of namespaces changez dropdown key strokes change
226         waitAndTypeByName("lookupCriteria[namespaceCode]", ROLE_NAMESPACECODE1_DROPDOWN);
227         waitAndTypeByName("lookupCriteria[name]", ROLE_NAME1);
228         // alternate Search parameter with same results
229         //waitAndTypeByName("lookupCriteria[id]", ROLE_ID1);
230 
231         waitAndClickButtonByExactText("Search");
232         waitAndClickByLinkText("return value");
233 
234         exampleDiv = waitForExampleElementById(DEMO_PAGE_ID5);
235         field = findElement(By.cssSelector(UIF_LINK_CSS_SELECTOR), exampleDiv);
236         verifyLinkText(field, ROLE_LINKTEXT1);
237         verifyKeyInInquiryHref(field, ROLE_INQUIRY_KEY_NAMESPACECODE1);
238         verifyKeyInInquiryHref(field, ROLE_INQUIRY_KEY_NAME1);
239 
240         exampleDiv = waitForExampleElementById(DEMO_PAGE_ID5);
241         field = findElement(By.cssSelector(UIF_LINK_CSS_SELECTOR), exampleDiv);
242         verifyLinkDataItem(field, LABEL_ROLE_NAME, ROLE_NAME1);
243         waitForExampleElementById(DEMO_PAGE_ID5);
244 
245         // clean up change page alert for next test navigation
246         waitAndClickLibraryLink();
247         acceptAlertIfPresent();
248     }
249 
250     protected void testRoleLinkFieldAddon() throws Exception {
251         jGrowl("-- testRoleLinkFieldAddon");
252         WebElement exampleDiv = navigateToExample(DEMO_PAGE_ID6);
253         assertTextPresent(DEMO_PAGE_HEADER6);
254 
255         WebElement field = findElement(By.cssSelector(UIF_LINK_CSS_SELECTOR), exampleDiv);
256         verifyLinkIsInquiry(field);
257         verifyKeyInInquiryHref(field, ROLE_INQUIRY_KEY_NAMESPACECODE4);
258         verifyKeyInInquiryHref(field, ROLE_INQUIRY_KEY_NAME4);
259         verifyLinkText(field, ROLE_LINKTEXT4);
260 
261         clearTextByName("testRoleName4");
262         waitAndTypeByName("testRoleName4",ROLE_NAME2);
263         typeTab();
264         Thread.sleep(2000);
265 
266         exampleDiv = waitForExampleElementById(DEMO_PAGE_ID6);
267         field = findElement(By.className(UIF_LINK_CLASSNAME), exampleDiv);
268         verifyLinkDataItem(field, LABEL_ROLE_NAME, ROLE_NAME2);
269 
270         // clean up change page alert for next test navigation
271         waitAndClickLibraryLink();
272         acceptAlertIfPresent();
273     }
274 
275     protected void testRoleLinkFieldIconLinks() throws Exception {
276         jGrowl("-- testRoleLinkFieldIconLinks");
277         WebElement exampleDiv = navigateToExample(DEMO_PAGE_ID7);
278         assertTextPresent(DEMO_PAGE_HEADER7);
279 
280         WebElement field = findElement(By.xpath("//section[@id='" + DEMO_PAGE_ID7 + "']/div[@data-label='" +
281                 LABEL_ROLE_LINK1 + "']/a"), exampleDiv);
282         verifyKeyInInquiryHref(field, ROLE_INQUIRY_KEY_ID5);
283         verifyLinkIcon(field, ROLE_ICON_CLASSNAME);
284         verifyLinkDataItem(field, LABEL_ROLE_NAME, ROLE_NAME5);
285 
286         exampleDiv = waitForExampleElementById(DEMO_PAGE_ID7);
287         field = findElement(By.xpath("//section[@id='" + DEMO_PAGE_ID7 + "']/div[@data-label='" +
288                 LABEL_ROLE_LINK2 + "']/span"), exampleDiv);
289         verifyLinkIcon(field, ROLE_ICON_CLASSNAME);
290     }
291 
292     protected void testRoleLinkFieldRefreshIconLinks() throws Exception {
293         jGrowl("-- testRoleLinkFieldRefreshIconLinks");
294         WebElement exampleDiv = navigateToExample(DEMO_PAGE_ID7);
295         assertTextPresent(DEMO_PAGE_HEADER7);
296 
297         WebElement field = findElement(By.xpath("//section[@id='" + DEMO_PAGE_ID7 + "']/div[@data-label='" +
298                 LABEL_ROLENAME + "']/div/div/div/a[contains(@class,'" + ROLE_ICON_CLASSNAME + "')]"), exampleDiv);
299         verifyLinkIsInquiry(field);
300         verifyLinkDataItem(field, LABEL_ROLE_NAME, ROLE_NAME5);
301 
302         clearTextByName("testRoleNamespaceCode5");
303         waitAndTypeByName("testRoleNamespaceCode5", ROLE_NAMESPACECODE3);
304         typeTab();
305         clearTextByName("testRoleName5");
306         waitAndTypeByName("testRoleName5", ROLE_NAME3);
307         typeTab();
308         Thread.sleep(2000);
309 
310         exampleDiv = waitForExampleElementById(DEMO_PAGE_ID7);
311         field = findElement(By.xpath("//section[@id='" + DEMO_PAGE_ID7 + "']/div[@data-label='" + LABEL_ROLENAME +
312                 "']/div/div/div/a[contains(@class,'" + ROLE_ICON_CLASSNAME + "')]"), exampleDiv);
313         verifyLinkDataItem(field, LABEL_ROLE_NAME, ROLE_NAME3);
314 
315         // clean up change page alert for next test navigation
316         waitAndClickLibraryLink();
317         acceptAlertIfPresent();
318     }
319 
320     protected void testRoleLinkFieldSuppressedNcLink() throws Exception {
321         jGrowl("-- testRoleLinkFieldSuppressedNcLink");
322         WebElement exampleDiv = navigateToExample(DEMO_PAGE_ID8);
323         assertTextPresent(DEMO_PAGE_HEADER8);
324 
325         WebElement field = findElement(By.linkText(ROLE_NAME1), exampleDiv);
326         assertLabelWithTextPresent(LABEL_ROLE_LINK1);
327         verifyLinkIsInquiry(field);
328         verifyKeyInInquiryHref(field, ROLE_INQUIRY_KEY_ID1);
329         verifyLinkDataItem(field, LABEL_ROLE_NAME, ROLE_NAME1);
330 
331         exampleDiv = waitForExampleElementById(DEMO_PAGE_ID8);
332         field = findElement(By.linkText(ROLE_NAME2), exampleDiv);
333         assertLabelWithTextPresent(LABEL_ROLE_LINK2);
334         verifyLinkIsInquiry(field);
335         verifyKeyInInquiryHref(field, ROLE_INQUIRY_KEY_NAME2);
336         verifyLinkDataItem(field, LABEL_ROLE_NAME, ROLE_NAME2);
337     }
338 
339     protected void testRoleLinkFieldExamples() throws Exception {
340         testRoleLinkFieldDefault();
341         testRoleLinkFieldLabel();
342         testRoleLinkFieldLinkDisabled();
343         testRoleLinkFieldNoLightbox();
344         testRoleLinkFieldRefresh();
345         testRoleLinkFieldIconLinks();
346         testRoleLinkFieldSuppressedNcLink();
347     }
348 
349     @Test
350     public void testRoleLinkFieldExamplesBookmark() throws Exception {
351         testRoleLinkFieldExamples();
352         passed();
353     }
354 
355     @Test
356     public void testRoleLinkFieldRefreshExamplesBookmark() throws Exception {
357         testRoleLinkFieldAddon();
358         testRoleLinkFieldRefreshIconLinks();
359         passed();
360     }
361 
362     @Test
363       public void testRoleLinkFieldExamplesNav() throws Exception {
364         testRoleLinkFieldExamples();
365         passed();
366     }
367 
368     @Test
369     public void testRoleLinkFieldRefreshExamplesNav() throws Exception {
370         testRoleLinkFieldAddon();
371         testRoleLinkFieldRefreshIconLinks();
372         passed();
373     }
374 }