001 /** 002 * Copyright 2005-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package edu.samplu.krad.library.collections; 017 018 import org.kuali.rice.testtools.selenium.JiraAwareFailureUtil; 019 import org.kuali.rice.testtools.selenium.SmokeTestBase; 020 import org.apache.commons.lang.StringUtils; 021 import org.junit.Test; 022 import org.openqa.selenium.By; 023 024 /** 025 * @author Kuali Rice Team (rice.collab@kuali.org) 026 */ 027 public class DemoLibraryCollectionFeaturesColumnCalculationsSmokeTest extends SmokeTestBase { 028 029 /** 030 * /kr-krad/kradsampleapp?viewId=Demo-TableLayoutTotaling-View&methodToCall=start 031 */ 032 public static final String BOOKMARK_URL = 033 "/kr-krad/kradsampleapp?viewId=Demo-TableLayoutTotaling-View&methodToCall=start"; 034 035 @Override 036 protected String getBookmarkUrl() { 037 return BOOKMARK_URL; 038 } 039 040 @Override 041 protected void navigate() throws Exception { 042 waitAndClickById("Demo-LibraryLink", ""); 043 waitAndClickByLinkText("Collection Features"); 044 waitAndClickByLinkText("Column Calculations"); 045 } 046 047 protected void testCollectionFeaturesColumnCalculations() throws Exception { 048 String preValueString = waitAndGetText(By.xpath( 049 "//div[@id='Demo-TableLayoutTotaling-Section1']/div/table/tfoot/tr/th[2]/div/fieldset/div/div[@class='uif-verticalBoxLayout']/div/span[@data-role]"))[0]; 050 if (StringUtils.isBlank(preValueString)) { 051 JiraAwareFailureUtil.fail("calculation column contains no text", this); 052 } 053 Integer preValue = Integer.parseInt(preValueString); 054 clearTextByName("collection1[0].field1"); 055 waitAndTypeByName("collection1[0].field1", "0"); 056 waitAndTypeByName("newCollectionLines['collection1'].field1", ""); 057 Integer postValue = Integer.parseInt(getTextByXpath( 058 "//div[@id='Demo-TableLayoutTotaling-Section1']/div/table/tfoot/tr/th[2]/div/fieldset/div/div[@class='uif-verticalBoxLayout']/div/span[@data-role]")); 059 060 if (postValue >= preValue) { 061 fail("Calculation Error !"); 062 } 063 } 064 065 protected void testCollectionFeaturesColumnCalculationsOnKeyUp() throws Exception { 066 selectByName("exampleShown", "On Key Up"); 067 Integer preValue = Integer.parseInt(waitAndGetText(By.xpath( 068 "//div[@id='Demo-TableLayoutTotaling-Section2']/div/table/tfoot/tr/th[2]/div/fieldset/div/div[@class='uif-verticalBoxLayout']/div/span[@data-role]"))[0]); 069 clearTextByName("collection1_2[0].field1"); 070 waitAndTypeByName("collection1_2[0].field1", "0"); 071 Thread.sleep(2000); 072 Integer postValue = Integer.parseInt(getTextByXpath( 073 "//div[@id='Demo-TableLayoutTotaling-Section2']/div/table/tfoot/tr/th[2]/div/fieldset/div/div[@class='uif-verticalBoxLayout']/div/span[@data-role]")); 074 if (postValue >= preValue) { 075 fail("Calculation Error !"); 076 077 } 078 } 079 080 protected void testCollectionFeaturesColumnCalculationsSomeColumns() throws Exception { 081 selectByName("exampleShown", "Some Columns"); 082 Integer preValue = Integer.parseInt(waitAndGetText(By.xpath( 083 "//div[@id='Demo-TableLayoutTotaling-Section3']/div/table/tfoot/tr/th[3]/div/fieldset/div/div[@class='uif-verticalBoxLayout']/div/span[@data-role]"))[0]); 084 clearTextByName("collection1_3[0].field2"); 085 waitAndTypeByName("collection1_3[0].field2", "0"); 086 waitAndTypeByName("newCollectionLines['collection1_3'].field2", ""); 087 Integer postValue = Integer.parseInt(getTextByXpath( 088 "//div[@id='Demo-TableLayoutTotaling-Section3']/div/table/tfoot/tr/th[3]/div/fieldset/div/div[@class='uif-verticalBoxLayout']/div/span[@data-role]")); 089 if (postValue >= preValue) { 090 fail("Calculation Error !"); 091 092 } 093 } 094 095 protected void testCollectionFeaturesColumnCalculationsLeftLabel() throws Exception { 096 selectByName("exampleShown", "Left Label"); 097 assertElementPresentByXpath( 098 "//div[@id='Demo-TableLayoutTotaling-Section4']/div/table/tfoot/tr/th/div/div[@class='uif-verticalBoxLayout clearfix']/span/label"); 099 } 100 101 protected void testCollectionFeaturesColumnCalculationsMultipleOptions() throws Exception { 102 selectByName("exampleShown", "Multiple Options"); 103 assertElementPresentByXpath( 104 "//div[@id='Demo-TableLayoutTotaling-Section5']/div/table/tfoot/tr/th/div/fieldset/div/div[@class='uif-verticalBoxLayout']/div/span[@data-role]"); 105 assertElementPresentByXpath( 106 "//div[@id='Demo-TableLayoutTotaling-Section5']/div/table/tfoot/tr/th/div/fieldset/div/div[@class='uif-verticalBoxLayout']/div/span/label"); 107 if (isElementPresentByXpath( 108 "//div[@id='Demo-TableLayoutTotaling-Section5']/div/table/tfoot/tr/th[2]/div/fieldset/div/div[@class='uif-verticalBoxLayout']/div/span/label")) { 109 fail("Multiple Options Failure !"); 110 } 111 } 112 113 protected void testCollectionFeaturesColumnCalculationsMultipleCalculations() throws Exception { 114 selectByName("exampleShown", "Multiple Calculations"); 115 assertElementPresentByXpath( 116 "//div[@id='Demo-TableLayoutTotaling-Section6']/div/table/tfoot/tr/th[5]/div/div[@class='uif-verticalBoxLayout clearfix']/div/fieldset/div/div[@class='uif-verticalBoxLayout']/div/span[@data-role]"); 117 assertElementPresentByXpath( 118 "//div[@id='Demo-TableLayoutTotaling-Section6']/div/table/tfoot/tr/th[5]/div/div[@class='uif-verticalBoxLayout clearfix']/div[2]/fieldset/div/div[@class='uif-verticalBoxLayout']/div/span[@data-role]"); 119 assertElementPresentByXpath( 120 "//div[@id='Demo-TableLayoutTotaling-Section6']/div/table/tfoot/tr/th[5]/div/div[@class='uif-verticalBoxLayout clearfix']/div[3]/fieldset/div/div[@class='uif-verticalBoxLayout']/div/span[@data-role]"); 121 assertElementPresentByXpath( 122 "//div[@id='Demo-TableLayoutTotaling-Section6']/div/table/tfoot/tr/th[5]/div/div[@class='uif-verticalBoxLayout clearfix']/div[4]/fieldset/div/div[@class='uif-verticalBoxLayout']/div/span[@data-role]"); 123 if (isElementPresentByXpath( 124 "//div[@id='Demo-TableLayoutTotaling-Section6']/div/table/tfoot/tr/th[2]/div/div[@class='uif-verticalBoxLayout clearfix']/div/fieldset/div/div[@class='uif-verticalBoxLayout']/div/span[@data-role]")) { 125 fail("Multiple Calculations Failure !"); 126 } 127 } 128 129 protected void testCollectionFeaturesColumnCalculationsGroupingCalculations() throws Exception { 130 selectByName("exampleShown", "Grouping Calculations"); 131 assertElementPresentByXpath( 132 "//div[@id='Demo-TableLayoutTotaling-Section7']/div/table/tbody/tr[7]/td/div/span[@data-role]"); 133 assertElementPresentByXpath( 134 "//div[@id='Demo-TableLayoutTotaling-Section7']/div/table/tbody/tr[7]/td[2]/div/span[@data-role]"); 135 assertElementPresentByXpath( 136 "//div[@id='Demo-TableLayoutTotaling-Section7']/div/table/tbody/tr[7]/td[3]/div/span[@data-role]"); 137 } 138 139 protected void testCollectionFeaturesColumnCalculationsNonClientSide() throws Exception { 140 selectByName("exampleShown", "Non Client-side"); 141 assertElementPresentByXpath( 142 "//div[@id='Demo-TableLayoutTotaling-Section8']/div/table/tfoot/tr/th[3]/div/fieldset/div/div[@class='uif-verticalBoxLayout']/div/span[@data-role]"); 143 } 144 145 protected void testCollectionFeaturesColumnCalculationsCustomCalculation() throws Exception { 146 selectByName("exampleShown", "Custom Calculation"); 147 assertTextPresent("Subtracted:"); 148 } 149 150 @Test 151 public void testCollectionFeaturesColumnCalculationsBookmark() throws Exception { 152 testCollectionFeaturesColumnCalculations(); 153 testCollectionFeaturesColumnCalculationsOnKeyUp(); 154 testCollectionFeaturesColumnCalculationsSomeColumns(); 155 testCollectionFeaturesColumnCalculationsLeftLabel(); 156 testCollectionFeaturesColumnCalculationsMultipleOptions(); 157 testCollectionFeaturesColumnCalculationsMultipleCalculations(); 158 testCollectionFeaturesColumnCalculationsGroupingCalculations(); 159 testCollectionFeaturesColumnCalculationsNonClientSide(); 160 testCollectionFeaturesColumnCalculationsCustomCalculation(); 161 passed(); 162 } 163 164 @Test 165 public void testCollectionFeaturesColumnCalculationsNav() throws Exception { 166 testCollectionFeaturesColumnCalculations(); 167 testCollectionFeaturesColumnCalculationsOnKeyUp(); 168 testCollectionFeaturesColumnCalculationsSomeColumns(); 169 testCollectionFeaturesColumnCalculationsLeftLabel(); 170 testCollectionFeaturesColumnCalculationsMultipleOptions(); 171 testCollectionFeaturesColumnCalculationsMultipleCalculations(); 172 testCollectionFeaturesColumnCalculationsGroupingCalculations(); 173 testCollectionFeaturesColumnCalculationsNonClientSide(); 174 testCollectionFeaturesColumnCalculationsCustomCalculation(); 175 passed(); 176 } 177 }