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.junit.Test;
19  import org.kuali.rice.krad.demo.uif.library.DemoLibraryBase;
20  import org.openqa.selenium.By;
21  import org.openqa.selenium.WebElement;
22  
23  /**
24   * @author Kuali Rice Team (rice.collab@kuali.org)
25   */
26  public class DemoFieldsImageAft extends DemoLibraryBase {
27  
28      /**
29       * /kr-krad/kradsampleapp?viewId=Demo-ImageFieldView&methodToCall=start
30       */
31      public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-ImageFieldView&methodToCall=start";
32  
33      @Override
34      public String getBookmarkUrl() {
35          return BOOKMARK_URL;
36      }
37  
38      @Override
39      protected void navigate() throws Exception {
40          navigateToLibraryDemo("Fields", "Image Field");
41      }
42  
43      protected void testImageFieldDefault() throws Exception {
44          WebElement exampleDiv = navigateToExample("Demo-ImageField-Example1");
45          WebElement field = findElement(By.cssSelector("div[data-label='ImageField 1']"), exampleDiv);
46  
47          String fieldId = field.getAttribute("id");
48  
49          assertIsVisible("#" + fieldId);
50          assertIsVisible("label[data-label_for='" + fieldId + "']");
51          WebElement label = findElement(By.cssSelector("label[data-label_for='" + fieldId + "']"), field);
52          if (!label.getText().contains("ImageField 1:")) {
53              fail("Label text does not match");
54          }
55  
56          String imgId = label.getAttribute("for");
57  
58          assertIsVisible("#" + imgId + "[src='/krad/images/pdf.png']");
59          assertIsVisible("#" + imgId + "[alt='']");
60  
61          // validate that the image comes after the label
62          findElement(By.cssSelector("label[data-label_for='" + fieldId + "'] + img[src='/krad/images/pdf.png']"),
63                  exampleDiv);
64      }
65  
66      protected void testImageFieldAlternateText() throws Exception {
67          WebElement exampleDiv = navigateToExample("Demo-ImageField-Example2");
68          WebElement field = findElement(By.cssSelector("div[data-label='ImageField 1']"), exampleDiv);
69  
70          String fieldId = field.getAttribute("id");
71  
72          WebElement label = findElement(By.cssSelector("label[data-label_for='" + fieldId + "']"), field);
73  
74          String imgId = label.getAttribute("for");
75  
76          assertIsVisible("#" + imgId + "[src='/krad/images/pdf_ne.png']");
77          assertIsVisible("#" + imgId + "[alt='pdf']");
78      }
79  
80      protected void testImageFieldExamples() throws Exception {
81          testImageFieldDefault();
82          testImageFieldAlternateText();
83      }
84  
85      @Test
86      public void testImageFieldExamplesBookmark() throws Exception {
87          testImageFieldExamples();
88          passed();
89      }
90  
91      @Test
92      public void testImageFieldExamplesNav() throws Exception {
93          testImageFieldExamples();
94          passed();
95      }
96  
97      @Test
98      public void testImageFieldDefaultBookmark() throws Exception {
99          testImageFieldDefault();
100         passed();
101     }
102 
103     @Test
104     public void testImageFieldDefaultNav() throws Exception {
105         testImageFieldDefault();
106         passed();
107     }
108 
109     @Test
110     public void testImageFieldAlternateTextBookmark() throws Exception {
111         testImageFieldAlternateText();
112         passed();
113     }
114 
115     @Test
116     public void testImageFieldAlternateTextNav() throws Exception {
117         testImageFieldAlternateText();
118         passed();
119     }
120 }