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.labs.kitchensink;
17  
18  import org.junit.Test;
19  import org.kuali.rice.testtools.selenium.WebDriverUtils;
20  
21  import static org.junit.Assert.assertNotSame;
22  
23  /**
24   * @author Kuali Rice Team (rice.collab@kuali.org)
25   */
26  
27  public class LabsCollectionsAft extends LabsKitchenSinkBase {
28  
29      public static final String BOOKMARK_URL = "/kr-krad/uicomponents?viewId=UifCompView&formKey=ab7fa92d-a2a0-4b94-b349-c00eb81de311&cacheKey=endwmf7mxaohx3lxynk6sm&pageId=UifCompView-Page7#UifCompView-Page7";
30  
31      public static final String FIELD_ELEMENT_NAME = "list4[0].subList[0].field1";
32  
33      @Override
34      protected String getBookmarkUrl() {
35          return BOOKMARK_URL;
36      }
37  
38  	@Override
39  	protected void navigate() throws Exception {
40  		navigateToKitchenSink("Collections");
41  	}
42  	
43  	@Test
44      public void testCollectionsBookmark() throws Exception {
45          testCollections();
46          testSubCollectionSize();
47          testDeleteSubCollectionLine();
48          passed();
49      }
50  
51      @Test
52      public void testCollectionsNav() throws Exception {
53          testCollections();
54          testSubCollectionSize();
55          testDeleteSubCollectionLine();
56          passed();
57      }
58      
59      protected void testCollections() throws InterruptedException {
60          // Wait for page to load
61          waitForTextPresent("Collection Group rendered as a List ", WebDriverUtils.configuredImplicityWait() * 10);
62  
63      	//Collection Group 1 - CollectionGroupTableLayout
64      	waitForElementPresentByXpath("//table[@class='table table-condensed table-bordered uif-tableCollectionLayout uif-hasAddLine dataTable']/tbody/tr[@class='uif-collectionAddItem odd']",
65                  "https://jira.kuali.org/browse/RICEQA-274 AFT Failure update LabsCollectionsAft");
66      	assertElementPresentByXpath("//table[@class='table table-condensed table-bordered uif-tableCollectionLayout uif-hasAddLine dataTable']/tbody/tr/td[@class='uif-collection-column-action ']");
67      
68      	//Collection Group 2 - CollectionGroupTableLayout with jQuery table features on
69      	assertElementPresentByXpath("//div[@id='collection2_disclosureContent']/div/table[@class='table table-condensed table-bordered uif-tableCollectionLayout uif-hasAddLine dataTable']/tbody/tr[@class='uif-collectionAddItem odd']");
70      	assertElementPresentByXpath("//div[@id='collection2_disclosureContent']/div/div[@class='dataTables_length']/label/select");
71      	assertElementPresentByXpath("//div[@id='collection2_disclosureContent']/div/table[@class='table table-condensed table-bordered uif-tableCollectionLayout uif-hasAddLine dataTable']/tbody/tr/td[1]/div/fieldset/div/button");
72      	
73      	//Collection Group 6 - CollectionGroupTableLayout with jQuery table features on
74      	assertElementPresentByXpath("//section[@class='uif-collectionItem uif-tableCollectionItem uif-collectionAddItem']/table[@class='table table-condensed table-bordered uif-gridLayout uif-table-fixed']");
75      	assertElementPresentByXpath("//div[@class='dataTables_scrollBody']/table[@class='table table-condensed table-bordered uif-tableCollectionLayout dataTable']/tbody/tr/td[@class='uif-collection-column-action ']");
76      	
77      	//Collection Group 3 - Stacked
78      	assertElementPresentByXpath("//div[@id='collection3_disclosureContent']/section/table");
79      	
80      	//Collection Group 4 - Stacked Collection with a Table subcollection
81      	assertElementPresentByXpath("//div[@id='collection4_disclosureContent']/section/table");
82      	assertElementPresentByXpath("//div[@id='subCollection1_line0_disclosureContent']");
83      	
84      	//Collection Group 5 - Stacked Collection with a Stacked subcollection
85      	assertElementPresentByXpath("//ul/li/div[@data-parent='UifCompView-CollectionList']");
86      }
87  
88      protected void testSubCollectionSize() throws Exception {
89          // wait for collections page to load by checking the presence of a sub collection line item
90          for (int second = 0;; second++) {
91              if (second >= waitSeconds)
92                  jiraAwareFail(TIMEOUT_MESSAGE
93                          + " looking for "
94                          + SUB_COLLECTION_UIF_DISCLOSURE_SPAN_UIF_HEADER_TEXT_SPAN_XPATH);
95              try {
96                  if (isElementPresentByXpath("//span[@class='uif-headerText-span' and contains(text(),'SubCollection - (3 lines)')]"))
97                  {
98                      break;
99                  }
100             } catch (Exception e) {}
101             Thread.sleep(1000);
102         }
103 
104         // verify that sub collection sizes are displayed as expected
105         waitForElementPresentByXpath("//section[@id='subCollection1_line0']/header/div/label/a/span[contains(text(),'SubCollection - (3 lines)')]]");
106         waitForElementPresentByXpath("//a[@id='subCollection1_line1_toggle']/span");
107     }
108 
109     protected void testDeleteSubCollectionLine() throws Exception {
110         // wait for collections page to load by checking the presence of a sub collection line item
111         waitForElementPresentByName(FIELD_ELEMENT_NAME);
112 
113         // change a value in the line to be deleted
114         waitAndTypeByName(FIELD_ELEMENT_NAME, "selenium");
115 
116         // click the delete button
117         waitAndClickById("subCollection1_line0_del_line0_line0");
118         Thread.sleep(2000);
119 
120         // confirm that the input box containing the modified value is not present
121         for (int second = 0;; second++) {
122             if (second >= waitSeconds)fail(TIMEOUT_MESSAGE);
123 
124             try {
125                 if (!"selenium".equals(waitAndGetAttributeByName(FIELD_ELEMENT_NAME, "value")))
126                     break;
127             } catch (Exception e) {}
128 
129             Thread.sleep(1000);
130         }
131 
132         // verify that the value has changed for the input box in the line that has replaced the deleted one
133         assertNotSame("selenium", waitAndGetAttributeByName(FIELD_ELEMENT_NAME, "value"));
134     }
135 }