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 LibraryFieldsGroupLinkAft extends LibraryFieldsKimLinkBase {
29  
30      /**
31       * /kr-krad/kradsampleapp?viewId=Demo-GroupLinkFieldView&methodToCall=start
32       */
33      public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-GroupLinkFieldView&methodToCall=start";
34  
35      public static final String GROUP_ID1 = "2005";
36      public static final String GROUP_ID2 = "2001";
37      public static final String GROUP_ID3 = "2000";
38      public static final String GROUP_ID4 = "2005";
39      public static final String GROUP_ID5 = "2005";
40      public static final String GROUP_NAMESPACECODE1 = "KUALI";
41      public static final String GROUP_NAMESPACECODE1_DROPDOWN = "KKKKKKKKKKKK";
42      public static final String GROUP_NAMESPACECODE2 = "KUALI";
43      public static final String GROUP_NAMESPACECODE3 = "KR-WKFLW";
44      public static final String GROUP_NAMESPACECODE4 = "KUALI";
45      public static final String GROUP_NAMESPACECODE5 = "KUALI";
46      public static final String GROUP_NAME1 = "Group1";
47      public static final String GROUP_NAME2 = "TestGroup1";
48      public static final String GROUP_NAME3 = "NotificationAdmin";
49      public static final String GROUP_NAME4 = "Group1";
50      public static final String GROUP_NAME5 = "Group1";
51      public static final String GROUP_LINKTEXT1 = "KUALI Group1";
52      public static final String GROUP_LINKTEXT2 = "KUALI TestGroup1";
53      public static final String GROUP_LINKTEXT3 = "KR-WKFLW NotificationAdmin";
54      public static final String GROUP_LINKTEXT4 = "KUALI Group1";
55      public static final String GROUP_LINKTEXT5 = "KUALI Group1";
56      public static final String GROUP_INQUIRY_KEY_ID1 = "id=2005";
57      public static final String GROUP_INQUIRY_KEY_ID2 = "id=2001";
58      public static final String GROUP_INQUIRY_KEY_ID3 = "id=2000";
59      public static final String GROUP_INQUIRY_KEY_ID4 = "id=2005";
60      public static final String GROUP_INQUIRY_KEY_ID5 = "id=2005";
61      public static final String GROUP_INQUIRY_KEY_NAME1 = "name=Group1";
62      public static final String GROUP_INQUIRY_KEY_NAME2 = "name=TestGroup1";
63      public static final String GROUP_INQUIRY_KEY_NAME3 = "name=NotificationAdmin";
64      public static final String GROUP_INQUIRY_KEY_NAME4 = "name=Group1";
65      public static final String GROUP_INQUIRY_KEY_NAME5 = "name=Group1";
66      public static final String GROUP_INQUIRY_KEY_NAMESPACECODE1 = "namespaceCode=KUALI";
67      public static final String GROUP_INQUIRY_KEY_NAMESPACECODE2 = "namespaceCode=KUALI";
68      public static final String GROUP_INQUIRY_KEY_NAMESPACECODE3 = "namespaceCode=KR-WKFLW";
69      public static final String GROUP_INQUIRY_KEY_NAMESPACECODE4 = "namespaceCode=KUALI";
70      public static final String GROUP_INQUIRY_KEY_NAMESPACECODE5 = "namespaceCode=KUALI";
71  
72      public static final String GROUP_ICON_CLASSNAME = "icon-users";
73      public static final String LABEL_GROUP_NAME = "Group Name";
74      public static final String LABEL_NAME = "Name";
75      public static final String LABEL_GROUP_LINK = "Group Link";
76      public static final String LABEL_GROUP_LINK1 = "Group Link1";
77      public static final String LABEL_GROUP_LINK2 = "Group Link2";
78      public static final String LABEL_NAMESPACECODE = "NamespaceCode";
79      public static final String LABEL_GROUPNAME = "GroupName";
80      public static final String LABEL_DISABLED_GROUP_LINK = "Disabled Group Link";
81      public static final String LABEL_GROUP_ID = "Group Id";
82  
83      public static final String DEMO_PAGE_ID1 = "Demo-GroupLinkField-Example1";
84      public static final String DEMO_PAGE_ID2 = "Demo-GroupLinkField-Example2";
85      public static final String DEMO_PAGE_ID3 = "Demo-GroupLinkField-Example3";
86      public static final String DEMO_PAGE_ID4 = "Demo-GroupLinkField-Example4";
87      public static final String DEMO_PAGE_ID5 = "Demo-GroupLinkField-Example5";
88      public static final String DEMO_PAGE_ID6 = "Demo-GroupLinkField-Example6";
89      public static final String DEMO_PAGE_ID7 = "Demo-GroupLinkField-Example7";
90      public static final String DEMO_PAGE_ID8 = "Demo-GroupLinkField-Example8";
91      public static final String DEMO_PAGE_HEADER1 = "Default";
92      public static final String DEMO_PAGE_HEADER2 = "Group Link Field with Label";
93      public static final String DEMO_PAGE_HEADER3 = "Group Link Field with Link Disabled";
94      public static final String DEMO_PAGE_HEADER4 = "Inquiry without Lightbox";
95      public static final String DEMO_PAGE_HEADER5 = "Group Link refreshed by Field changes";
96      public static final String DEMO_PAGE_HEADER6 = "Group Link as Input Field Addon";
97      public static final String DEMO_PAGE_HEADER7 = "Group Link as Icon";
98      public static final String DEMO_PAGE_HEADER8 = "Group 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", "Group 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", "Group Link Field");
114         return super.navigateToExample(exampleId);
115     }
116 
117     protected void testGroupLinkFieldDefault() throws Exception {
118         jGrowl("-- testGroupLinkFieldDefault");
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 group 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, GROUP_INQUIRY_KEY_ID1) ||
133                     (StringUtils.contains(href, GROUP_INQUIRY_KEY_NAMESPACECODE2) &&
134                      StringUtils.contains(href, GROUP_INQUIRY_KEY_NAME2)))) {
135                 fail("Group inquiry keys not found in href.");
136             }
137 
138             String linkText = link.getText();
139             if ( !(StringUtils.contains(linkText, GROUP_LINKTEXT1) ||
140                    StringUtils.contains(linkText, GROUP_LINKTEXT2))) {
141                 fail("Group names in linkText not found");
142             }
143         }
144 
145         field = findElement(By.linkText(GROUP_LINKTEXT1), exampleDiv);
146         verifyLinkDataItem(field, LABEL_GROUP_NAME, GROUP_NAME1);
147 
148         field = findElement(By.linkText(GROUP_LINKTEXT2), exampleDiv);
149         verifyLinkDataItem(field, LABEL_GROUP_NAME, GROUP_NAME2);
150     }
151 
152     protected void testGroupLinkFieldLabel() throws Exception {
153         jGrowl("-- testGroupLinkFieldLabel");
154         WebElement exampleDiv = navigateToExample(DEMO_PAGE_ID2);
155         assertTextPresent(DEMO_PAGE_HEADER2);
156 
157         assertLabelWithTextPresent(LABEL_GROUP_LINK1);
158         assertLabelWithTextPresent(LABEL_GROUP_LINK2);
159 
160         WebElement field = findElement(By.linkText(GROUP_LINKTEXT1), exampleDiv);
161         verifyLinkIsInquiry(field);
162         verifyKeyInInquiryHref(field, GROUP_INQUIRY_KEY_ID1);
163         verifyLinkText(field, GROUP_LINKTEXT1);
164         verifyLinkDataItem(field, LABEL_GROUP_NAME, GROUP_NAME1);
165 
166         field = findElement(By.linkText(GROUP_LINKTEXT2),exampleDiv);
167         verifyLinkIsInquiry(field);
168         verifyKeyInInquiryHref(field, GROUP_INQUIRY_KEY_NAMESPACECODE2);
169         verifyKeyInInquiryHref(field, GROUP_INQUIRY_KEY_NAME2);
170         verifyLinkText(field, GROUP_LINKTEXT2);
171         verifyLinkDataItem(field, LABEL_GROUP_NAME, GROUP_NAME2);
172     }
173 
174     protected void testGroupLinkFieldLinkDisabled() throws Exception {
175         jGrowl("-- testGroupLinkFieldLinkDisabled");
176         WebElement exampleDiv = navigateToExample(DEMO_PAGE_ID3);
177         assertTextPresent(DEMO_PAGE_HEADER3);
178 
179         assertLabelWithTextPresent(LABEL_GROUP_LINK1);
180         assertLabelWithTextPresent(LABEL_GROUP_LINK2);
181 
182         WebElement disabledLink = findElement(By.xpath("//span[contains( text(),'" + GROUP_LINKTEXT1 + "')]"), exampleDiv);
183         assertEquals("Disabled Link text not found", GROUP_LINKTEXT1, disabledLink.getText());
184 
185         disabledLink = findElement(By.xpath("//span[contains( text(),'" + GROUP_LINKTEXT2 + "')]"), exampleDiv);
186         assertEquals("Disabled Link text not found", GROUP_LINKTEXT2, disabledLink.getText());
187     }
188 
189     protected void testGroupLinkFieldNoLightbox() throws Exception {
190         jGrowl("-- testGroupLinkFieldNoLightbox");
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, GROUP_INQUIRY_KEY_ID1);
198         verifyLinkText(field, GROUP_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 testGroupLinkFieldRefresh() throws Exception {
210         jGrowl("-- testGroupLinkFieldRefresh");
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_GROUP_LINK);
216         verifyLinkIsInquiry(field);
217         verifyKeyInInquiryHref(field, GROUP_INQUIRY_KEY_NAMESPACECODE3);
218         verifyKeyInInquiryHref(field, GROUP_INQUIRY_KEY_NAME3);
219         verifyLinkText(field, GROUP_LINKTEXT3);
220         verifyLinkDataItem(field, LABEL_GROUP_NAME, GROUP_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]", GROUP_NAMESPACECODE1_DROPDOWN);
227         waitAndTypeByName("lookupCriteria[name]", GROUP_NAME1);
228         // alternate Search parameter with same results
229         //waitAndTypeByName("lookupCriteria[id]", GROUP_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, GROUP_LINKTEXT1);
237         verifyKeyInInquiryHref(field, GROUP_INQUIRY_KEY_NAMESPACECODE1);
238         verifyKeyInInquiryHref(field, GROUP_INQUIRY_KEY_NAME1);
239 
240         exampleDiv = waitForExampleElementById(DEMO_PAGE_ID5);
241         field = findElement(By.cssSelector(UIF_LINK_CSS_SELECTOR), exampleDiv);
242         verifyLinkDataItem(field, LABEL_GROUP_NAME, GROUP_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 testGroupLinkFieldAddon() throws Exception {
251         jGrowl("-- testGroupLinkFieldAddon");
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, GROUP_INQUIRY_KEY_NAMESPACECODE4);
258         verifyKeyInInquiryHref(field, GROUP_INQUIRY_KEY_NAME4);
259         verifyLinkText(field, GROUP_LINKTEXT4);
260 
261         clearTextByName("testGroupName4");
262         waitAndTypeByName("testGroupName4",GROUP_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_GROUP_NAME, GROUP_NAME2);
269 
270         // clean up change page alert for next test navigation
271         waitAndClickLibraryLink();
272         acceptAlertIfPresent();
273     }
274 
275     protected void testGroupLinkFieldIconLinks() throws Exception {
276         jGrowl("-- testGroupLinkFieldIconLinks");
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_GROUP_LINK1 + "']/a"), exampleDiv);
282         verifyKeyInInquiryHref(field, GROUP_INQUIRY_KEY_ID5);
283         verifyLinkIcon(field, GROUP_ICON_CLASSNAME);
284         verifyLinkDataItem(field, LABEL_GROUP_NAME, GROUP_NAME5);
285 
286         exampleDiv = waitForExampleElementById(DEMO_PAGE_ID7);
287         field = findElement(By.xpath("//section[@id='" + DEMO_PAGE_ID7 + "']/div[@data-label='" +
288                 LABEL_GROUP_LINK2 + "']/span"), exampleDiv);
289         verifyLinkIcon(field, GROUP_ICON_CLASSNAME);
290     }
291 
292     protected void testGroupLinkFieldRefreshIconLinks() throws Exception {
293         jGrowl("-- testGroupLinkFieldRefreshIconLinks");
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_GROUPNAME + "']/div/div/div/a[contains(@class,'" + GROUP_ICON_CLASSNAME + "')]"), exampleDiv);
299         verifyLinkIsInquiry(field);
300         verifyLinkDataItem(field, LABEL_GROUP_NAME, GROUP_NAME5);
301 
302         clearTextByName("testGroupNamespaceCode5");
303         waitAndTypeByName("testGroupNamespaceCode5", GROUP_NAMESPACECODE3);
304         typeTab();
305         clearTextByName("testGroupName5");
306         waitAndTypeByName("testGroupName5", GROUP_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_GROUPNAME +
312                 "']/div/div/div/a[contains(@class,'" + GROUP_ICON_CLASSNAME + "')]"), exampleDiv);
313         verifyLinkDataItem(field, LABEL_GROUP_NAME, GROUP_NAME3);
314 
315         // clean up change page alert for next test navigation
316         waitAndClickLibraryLink();
317         acceptAlertIfPresent();
318     }
319 
320     protected void testGroupLinkFieldSuppressedNcLink() throws Exception {
321         jGrowl("-- testGroupLinkFieldSuppressedNcLink");
322         WebElement exampleDiv = navigateToExample(DEMO_PAGE_ID8);
323         assertTextPresent(DEMO_PAGE_HEADER8);
324 
325         WebElement field = findElement(By.linkText(GROUP_NAME1), exampleDiv);
326         assertLabelWithTextPresent(LABEL_GROUP_LINK1);
327         verifyLinkIsInquiry(field);
328         verifyKeyInInquiryHref(field, GROUP_INQUIRY_KEY_ID1);
329         verifyLinkDataItem(field, LABEL_GROUP_NAME, GROUP_NAME1);
330 
331         exampleDiv = waitForExampleElementById(DEMO_PAGE_ID8);
332         field = findElement(By.linkText(GROUP_NAME2), exampleDiv);
333         assertLabelWithTextPresent(LABEL_GROUP_LINK2);
334         verifyLinkIsInquiry(field);
335         verifyKeyInInquiryHref(field, GROUP_INQUIRY_KEY_NAME2);
336         verifyLinkDataItem(field, LABEL_GROUP_NAME, GROUP_NAME2);
337     }
338 
339     protected void testGroupLinkFieldExamples() throws Exception {
340         testGroupLinkFieldDefault();
341         testGroupLinkFieldLabel();
342         testGroupLinkFieldLinkDisabled();
343         testGroupLinkFieldNoLightbox();
344         testGroupLinkFieldRefresh();
345         testGroupLinkFieldIconLinks();
346         testGroupLinkFieldSuppressedNcLink();
347     }
348 
349     @Test
350     public void testGroupLinkFieldExamplesBookmark() throws Exception {
351         testGroupLinkFieldExamples();
352         passed();
353     }
354 
355     @Test
356     public void testGroupLinkFieldRefreshExamplesBookmark() throws Exception {
357         testGroupLinkFieldAddon();
358         testGroupLinkFieldRefreshIconLinks();
359         passed();
360     }
361 
362     @Test
363     public void testGroupLinkFieldExamplesNav() throws Exception {
364         testGroupLinkFieldExamples();
365         passed();
366     }
367 
368     @Test
369     public void testGroupLinkFieldRefreshExamplesNav() throws Exception {
370         testGroupLinkFieldAddon();
371         testGroupLinkFieldRefreshIconLinks();
372         passed();
373     }
374 }