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.collections;
17  
18  import org.junit.Test;
19  
20  import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase;
21  import org.openqa.selenium.By;
22  
23  /**
24   * @author Kuali Rice Team (rice.collab@kuali.org)
25   */
26  public class LibraryCollectionFeaturesActionPlacementAft extends WebDriverLegacyITBase {
27  
28      /**
29       * /kr-krad/kradsampleapp?viewId=Demo-CollectionActionPlacementView
30       */
31      public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-CollectionActionPlacementView";
32  
33      @Override
34      protected String getBookmarkUrl() {
35          return BOOKMARK_URL;
36      }
37  
38      @Override
39      protected void navigate() throws Exception {
40          waitAndClickLibraryLink();
41          waitAndClickByLinkText("Collection Features");
42          waitAndClickByLinkText("Action Placement");
43      }
44  
45      /**
46       * Tests whether the buttons are showing up in the left column and that the sequence is showing up in the next
47       * column and is sequential.
48       *
49       * @throws Exception for any test errors
50       */
51      protected void testCollectionFeaturesActionPlacementLeft() throws Exception {
52          waitAndSelectByName("exampleShown", "Action in Left Column");
53  
54          String parent = "section[data-parent = 'Demo-CollectionActionPlacement-Example1']";
55  
56          // buttons should show up in the left column
57          waitForElementPresent(parent + " table tbody tr td:first-child button");
58  
59          // sequence should show up in the second column and be sequential
60          assertSequenceColumn(parent, 2);
61      }
62  
63      /**
64       * Tests whether the sequence is showing up in the first column and is sequential and that the buttons are showing
65       * up in the left column.
66       *
67       * @throws Exception for any test errors
68       */
69      protected void testCollectionFeaturesActionPlacementSecondColumn() throws Exception {
70          waitAndSelectByName("exampleShown", "Action in Second Column");
71  
72          String parent = "section[data-parent = 'Demo-CollectionActionPlacement-Example2']";
73  
74          // sequence should show up in the first column and be sequential
75          assertSequenceColumn(parent, 1);
76  
77          // buttons should show up in the second column
78          waitForElementPresent(parent + "table tbody tr td:nth-child(2) button");
79      }
80  
81      /**
82       * Asserts that the sequence column is in order.
83       *
84       * @param parent the parent css selector
85       * @param column the column number
86       *
87       * @throws Exception for any test errors
88       */
89      protected void assertSequenceColumn(String parent, int column) throws Exception {
90          int rowCount = getCssCount(By.cssSelector(parent + " table tbody tr"));
91  
92          for (int i = 1; i <= rowCount; i++) {
93              String text = getText(parent + " table tbody tr:nth-child(" + i + ") td:nth-child(" + column + ")");
94  
95              if (i == 1) {
96                  assertEquals("add", text);
97              } else {
98                  assertEquals(Integer.toString(i - 1), text);
99              }
100         }
101     }
102 
103     /**
104      * Tests all features.
105      *
106      * @throws Exception for any test errors
107      */
108     protected void testCollectionFeaturesActionPlacement() throws Exception {
109         testCollectionFeaturesActionPlacementLeft();
110         testCollectionFeaturesActionPlacementSecondColumn();
111     }
112     
113     @Test
114     public void testCollectionFeaturesActionPlacementBookmark() throws Exception {
115         testCollectionFeaturesActionPlacement();
116         passed();
117     }
118 
119     @Test
120     public void testCollectionFeaturesActionPlacementNav() throws Exception {
121         testCollectionFeaturesActionPlacement();
122         passed();
123     }
124 
125 }