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.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 LibraryCollectionFeaturesAddLineAft extends WebDriverLegacyITBase {
27  
28      /**
29       * /kr-krad/kradsampleapp?viewId=Demo-CollectionAddLineView
30       */
31      public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-CollectionAddLineView";
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("Add Line");
43      }
44  
45      protected void testCollectionFeaturesAddLine() throws Exception {
46          selectByName("exampleShown", "Collection Default Add Line");
47  
48          // add some values to the collection
49          waitAndTypeByName("newCollectionLines['collection1'].field1", "12");
50          waitAndTypeByName("newCollectionLines['collection1'].field2", "5");
51          jGrowl("Click Add button.");
52          waitAndClickByXpath("//section[@id = 'Demo-CollectionAddLine-Example1']//button[contains(text(), 'Add')]");
53  
54          // assert that the values have been added
55          waitForElementPresent("input[name = 'collection1[0].field1'][value = '12']");
56          waitForElementPresent("input[name = 'collection1[0].field2'][value = '5']");
57      }
58  
59      protected void testCollectionFeaturesAddLineWithDuplicatePropertyName() throws Exception {
60          selectByName("exampleShown", "Collection Add Line with duplicateLinePropertyNames");
61  
62          // attempt to add some values to the collection that have already been added
63          waitAndTypeByName("newCollectionLines['collection1_2'].field1", "13");
64          waitAndTypeByName("newCollectionLines['collection1_2'].field2", "14");
65          jGrowl("Click Add button.");
66          waitAndClickByXpath("//section[@id = 'Demo-CollectionAddLine-Example2']//button[contains(text(), 'Add')]");
67  
68          // assert that an error message is shown
69          waitForTextPresent("Duplicate Default Add Line with duplicateLinePropertyNames property configured");
70      }
71  
72      protected void testCollectionFeaturesAddLineWithDialog() throws Exception {
73          selectByName("exampleShown", "Collection Add Line with Dialog");
74  
75          // open the add line dialog
76          jGrowl("Click Add Line button.");
77          waitAndClickByXpath("//section[@id = 'Demo-CollectionAddLine-Example3']//button[contains(text(), 'Add Line')]");
78  
79          // attempt to enter an empty value via the dialog for the required field
80          waitForElementPresentByName("newCollectionLines['collection1_3'].field1");
81          jGrowl("Click Add button.");
82          waitAndClickByXpath("//div[@id = 'Uif-Dialogs']//button[contains(text(), 'Add')]");
83  
84          // assert that an error message is shown
85          waitIsVisible("div[data-label = 'Field 1'] li[class = 'uif-errorMessageItem-field']");
86  
87          // add some values to the collection via the dialog
88          waitAndTypeByName("newCollectionLines['collection1_3'].field1", "42");
89          waitAndTypeByName("newCollectionLines['collection1_3'].field2", "55");
90          jGrowl("Click Add button.");
91          waitAndClickByXpath("//div[@id = 'Uif-Dialogs']//button[contains(text(), 'Add')]");
92  
93          // assert that the values have been added
94          waitForElementPresent("input[name = 'collection1_3[0].field1'][value = '42']");
95          waitForElementPresent("input[name = 'collection1_3[0].field2'][value = '55']");
96      }
97  
98      protected void testCollectionFeaturesAddBlankLine() throws Exception {
99          selectByName("exampleShown", "Collection Add Blank Line");
100 
101         // click the add line button
102         jGrowl("Click Add Line button.");
103         waitAndClickByXpath("//section[@id = 'Demo-CollectionAddLine-Example4']//button[contains(text(), 'Add Line')]");
104 
105         // assert that the blank line has been added
106         waitForElementPresent("input[name = 'collection1_7[0].field1'][value = '']");
107         waitForElementPresent("input[name = 'collection1_7[0].field2'][value = '']");
108     }
109 
110     protected void testCollectionFeaturesAddLineWithCustomActions() throws Exception {
111         selectByName("exampleShown", "Collection Add Line with Custom Actions");
112 
113         // add some values to the collection via the dialog
114         waitAndTypeByName("newCollectionLines['collection1_8'].field1", "999");
115         waitAndTypeByName("newCollectionLines['collection1_8'].field2", "999");
116         jGrowl("Click Add button.");
117         waitAndClickByXpath("//section[@data-parent='Demo-CollectionAddLine-Example5']//button[contains(text(),'Add')]");
118 
119         // assert that the values have been added
120         waitForElementPresent("input[name = 'collection1_8[0].field1'][value = '999']");
121         waitForElementPresent("input[name = 'collection1_8[0].field2'][value = '999']");
122 
123         // delete the added line from the collection
124         jGrowl("Click Trash button.");
125         waitAndClick("#Demo-CollectionAddLine-Example5 button.icon-trash");
126 
127         // assert that the values have been deleted and that the message shows
128         waitForElementNotPresent(By.cssSelector("input[name = 'collection1_8[0].field1'][value = '999']"));
129         waitForElementNotPresent(By.cssSelector("input[name = 'collection1_8[0].field2'][value = '999']"));
130         waitForTextPresent("You have deleted an item from Project Income.");
131     }
132 
133     protected void testCollectionFeaturesAddLineWithDialogAndCustomActions() throws Exception {
134         selectByName("exampleShown", "Collection Add Line with Dialog and Custom Actions");
135 
136         // add some values to the dialog and cancel
137         waitAndClickByXpath("//section[@id = 'Demo-CollectionAddLine-Example6']//button/text()[contains(., 'Add Income')]/..");
138         waitAndTypeByName("newCollectionLines['collection1_9'].field1", "999");
139         waitAndTypeByName("newCollectionLines['collection1_9'].field2", "999");
140         waitAndClickByXpath("//section[@id = 'Demo-CollectionAddLine-Example6-AddLineDialog']//button[contains(text(),'Cancel')]");
141 
142         // assert that the values have not been added to the collection
143         waitForElementNotPresent(By.cssSelector("input[name = 'collection1_9[0].field1'][value = '999']"));
144         waitForElementNotPresent(By.cssSelector("input[name = 'collection1_9[0].field2'][value = '999']"));
145 
146         // add some values to the collection via the dialog
147         waitAndClickByXpath("//section[@id = 'Demo-CollectionAddLine-Example6']//button/text()[contains(., 'Add Income')]/..");
148         waitForElementPresentByName("newCollectionLines['collection1_9'].field1");
149         clearTextByName("newCollectionLines['collection1_9'].field1");
150         waitAndTypeByName("newCollectionLines['collection1_9'].field1", "999");
151         waitForElementPresentByName("newCollectionLines['collection1_9'].field2");
152         clearTextByName("newCollectionLines['collection1_9'].field2");
153         waitAndTypeByName("newCollectionLines['collection1_9'].field2", "999");
154         jGrowl("Click Add Income button.");
155         waitAndClickByXpath("//section[@id = 'Demo-CollectionAddLine-Example6-AddLineDialog']//button[contains(text(), 'Add Income')]");
156 
157         // assert that the values have been added
158         waitForElementPresent("input[name = 'collection1_9[0].field1'][value = '999']");
159         waitForElementPresent("input[name = 'collection1_9[0].field2'][value = '999']");
160 
161         // delete the added line from the collection
162         jGrowl("Click Trash button.");
163         waitAndClick("#Demo-CollectionAddLine-Example6 button.icon-trash");
164 
165         // assert that the values have been deleted and that the message shows
166         waitForElementNotPresent(By.cssSelector("input[name = 'collection1_9[0].field1'][value = '999']"));
167         waitForElementNotPresent(By.cssSelector("input[name = 'collection1_9[0].field2'][value = '999']"));
168         waitForTextPresent("You have deleted an item from Project Income.");
169     }
170 
171     protected void testCollectionFeaturesAddRefreshingDialog() throws Exception {
172         selectByName("exampleShown", "Collection Add Line with Refreshing Dialog");
173 
174         // open the add line dialog
175         jGrowl("Click Add Income button.");
176         waitAndClickByXpath("//section[@id = 'Demo-CollectionAddLine-Example7']//button/text()[contains(., 'Add Income')]/..");
177 
178         // assert that the button does not exist
179         waitForElementNotPresent(By.xpath("//section[@id = 'Demo-CollectionAddLine-Example7-AddLineDialog']//button[contains(text(), 'Add Income')]"));
180 
181         // enter the required value and trigger the change
182         waitAndTypeByName("newCollectionLines['collection1_10'].field1", "77");
183         waitAndTypeByName("newCollectionLines['collection1_10'].field2", "");
184         waitForProgressLoading();
185 
186         // assert that the button now exists
187         waitForElementPresent(By.xpath("//section[@id = 'Demo-CollectionAddLine-Example7-AddLineDialog']//button[contains(text(), 'Add Income')]"));
188     }
189 
190     @Test
191     public void testCollectionFeaturesAddLineBookmark() throws Exception {
192         testCollectionFeaturesAddLine();
193         testCollectionFeaturesAddLineWithDuplicatePropertyName();
194         testCollectionFeaturesAddLineWithDialog();
195         testCollectionFeaturesAddBlankLine();
196         testCollectionFeaturesAddLineWithCustomActions();
197         testCollectionFeaturesAddLineWithDialogAndCustomActions();
198         testCollectionFeaturesAddRefreshingDialog();
199         passed();
200     }
201 
202     @Test
203     public void testCollectionFeaturesAddLineNav() throws Exception {
204         testCollectionFeaturesAddLine();
205         testCollectionFeaturesAddLineWithDuplicatePropertyName();
206         testCollectionFeaturesAddLineWithDialog();
207         testCollectionFeaturesAddBlankLine();
208         testCollectionFeaturesAddLineWithCustomActions();
209         testCollectionFeaturesAddLineWithDialogAndCustomActions();
210         testCollectionFeaturesAddRefreshingDialog();
211         passed();
212     }
213 
214 }