View Javadoc

1   /*
2    * Copyright 2005-2013 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 edu.samplu.krad.demo.uif.library;
17  
18  import edu.samplu.common.Failable;
19  import org.junit.Test;
20  import org.kuali.rice.krad.uif.UifConstants;
21  import org.openqa.selenium.By;
22  import org.openqa.selenium.WebElement;
23  
24  /**
25   * @author Kuali Rice Team (rice.collab@kuali.org)
26   */
27  public class DemoLibraryDataFieldSmokeTest extends DemoLibraryBase {
28  
29      /**
30       * /kr-krad/kradsampleapp?viewId=Demo-DataField-View&methodToCall=start
31       */
32      public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-DataField-View&methodToCall=start";
33  
34      @Override
35      public String getBookmarkUrl() {
36          return BOOKMARK_URL;
37      }
38  
39      @Override
40      protected void navigate() throws Exception {
41          navigateToLibraryDemo("Fields", "Data Field");
42      }
43  
44      protected void testDataFieldDefault() throws Exception {
45          WebElement exampleDiv = navigateToExample("Demo-DataField-Example1");
46          WebElement field = exampleDiv.findElement(By.cssSelector("div[data-label='DataField 1']"));
47  
48          String fieldId = field.getAttribute("id");
49          String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
50  
51          assertIsVisible("#" + fieldId);
52          assertIsVisible("label[for='" + controlId + "']");
53  
54          WebElement label = field.findElement(By.cssSelector("label[for='" + controlId + "']"));
55          if(!label.getText().contains("DataField 1:")){
56              fail("Label text does not match");
57          }
58  
59          assertIsVisible("#" + controlId);
60  
61          assertTextPresent("1001", "#" + controlId, "DataField value not correct");
62      }
63  
64      protected void testDataFieldLabelTop() throws Exception {
65          WebElement exampleDiv = navigateToExample("Demo-DataField-Example2");
66          WebElement field = exampleDiv.findElement(By.cssSelector("div[data-label='DataField 1']"));
67  
68          String fieldId = field.getAttribute("id");
69          String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
70  
71          assertIsVisible("#" + fieldId);
72          assertIsVisible("label[for='" + controlId + "']");
73  
74          WebElement label = field.findElement(By.cssSelector("label[for='" + controlId + "']"));
75          if(!label.getText().contains("DataField 1:")){
76              fail("Label text does not match");
77          }
78  
79          WebElement labelspan = field.findElement(By.cssSelector("span[data-label_for='" + fieldId + "']"));
80          if(!labelspan.getAttribute("class").contains("uif-labelBlock")){
81              fail("Label span does not contain the appropriate class expected");
82          }
83  
84          assertIsVisible("#" + controlId);
85      }
86  
87      protected void testDataFieldExamples() throws Exception{
88          testDataFieldDefault();
89          testDataFieldLabelTop();
90      }
91  
92      public void testDataFieldNav(Failable failable) throws Exception{
93          testDataFieldExamples();
94          passed();
95      }
96  
97      public void testDataFieldBookmark(Failable failable) throws Exception{
98          testDataFieldExamples();
99          passed();
100     }
101 
102     @Test
103     public void testDataFieldBookmark() throws Exception {
104         testDataFieldBookmark(this);
105     }
106 
107     @Test
108     public void testDataFieldNav() throws Exception {
109         testDataFieldNav(this);
110     }
111 }