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