001 /* 002 * Copyright 2006-2012 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 017 package edu.samplu.krad.validationmessagesview; 018 019 import edu.samplu.common.UpgradedSeleniumITBase; 020 import junit.framework.Assert; 021 import org.junit.Test; 022 023 /** 024 * @author Kuali Rice Team (rice.collab@kuali.org) 025 */ 026 public class ClientErrorsIT extends UpgradedSeleniumITBase { 027 @Override 028 public String getTestUrl() { 029 return "/kr-krad/uicomponents?viewId=Demo-ValidationLayout&methodToCall=start"; 030 } 031 032 @Test 033 public void testClientErrors() throws Exception { 034 fireEvent("name=field1", "focus"); 035 waitAndType("name=field1", ""); 036 fireEvent("name=field1", "blur"); 037 Assert.assertEquals("true", getAttribute("name=field1@aria-invalid")); 038 Assert.assertTrue(getAttribute("name=field1@class").matches("^[\\s\\S]*error[\\s\\S]*$")); 039 Assert.assertTrue(isElementPresent("//textarea[@name='field1']/../../img[@alt='Error']")); 040 fireEvent("name=field1", "focus"); 041 for (int second = 0; ; second++) { 042 if (second >= 60) { 043 Assert.fail("timeout"); 044 } 045 try { 046 if (isVisible("css=.jquerybubblepopup-innerHtml")) { 047 break; 048 } 049 } catch (Exception e) { 050 } 051 Thread.sleep(1000); 052 } 053 054 Assert.assertTrue(isVisible( 055 "css=.jquerybubblepopup-innerHtml > .uif-clientMessageItems .uif-errorMessageItem-field")); 056 waitAndType("name=field1", "a"); 057 fireEvent("name=field1", "blur"); 058 fireEvent("name=field1", "focus"); 059 for (int second = 0; ; second++) { 060 if (second >= 60) { 061 Assert.fail("timeout"); 062 } 063 try { 064 if (!isVisible("css=.jquerybubblepopup-innerHtml")) { 065 break; 066 } 067 } catch (Exception e) { 068 } 069 Thread.sleep(1000); 070 } 071 072 Assert.assertFalse(isVisible("css=.jquerybubblepopup-innerHtml > .uif-clientMessageItems")); 073 fireEvent("name=field1", "blur"); 074 Assert.assertFalse(isElementPresent("name=field1@aria-invalid")); 075 Assert.assertTrue(getAttribute("name=field1@class").matches("^[\\s\\S]*valid[\\s\\S]*$")); 076 Assert.assertFalse(isElementPresent("//textarea[@name='field1']/../img[@alt='Error']")); 077 fireEvent("name=field2", "focus"); 078 waitAndType("name=field2", ""); 079 fireEvent("name=field2", "blur"); 080 Assert.assertEquals("true", getAttribute("name=field2@aria-invalid")); 081 Assert.assertTrue(getAttribute("name=field2@class").matches("^[\\s\\S]*error[\\s\\S]*$")); 082 Assert.assertTrue(isElementPresent("//input[@name='field2']/../img[@alt='Error']")); 083 fireEvent("name=field2", "focus"); 084 waitAndType("name=field2", "a"); 085 fireEvent("name=field2", "blur"); 086 Assert.assertFalse(isElementPresent("name=field2@aria-invalid")); 087 Assert.assertTrue(getAttribute("name=field2@class").matches("^[\\s\\S]*valid[\\s\\S]*$")); 088 Assert.assertFalse(isElementPresent("//textarea[@name='field2']/../img[@alt='Error']")); 089 fireEvent("name=field3", "focus"); 090 select("name=field3", ""); 091 fireEvent("name=field3", "blur"); 092 Assert.assertEquals("true", getAttribute("name=field3@aria-invalid")); 093 Assert.assertTrue(getAttribute("name=field3@class").matches("^[\\s\\S]*error[\\s\\S]*$")); 094 Assert.assertTrue(isElementPresent("//select[@name='field3']/../img[@alt='Error']")); 095 fireEvent("name=field3", "focus"); 096 select("name=field3", "Option 1"); 097 fireEvent("name=field3", "blur"); 098 Assert.assertFalse(isElementPresent("name=field3@aria-invalid")); 099 Assert.assertTrue(getAttribute("name=field3@class").matches("^[\\s\\S]*valid[\\s\\S]*$")); 100 Assert.assertFalse(isElementPresent("//select[@name='field3']/../img[@alt='Error']")); 101 fireEvent("name=field114", "focus"); 102 removeAllSelections("name=field114"); 103 fireEvent("name=field114", "blur"); 104 Assert.assertEquals("true", getAttribute("name=field114@aria-invalid")); 105 Assert.assertTrue(getAttribute("name=field114@class").matches("^[\\s\\S]*error[\\s\\S]*$")); 106 Assert.assertTrue(isElementPresent("//select[@name='field114']/../img[@alt='Error']")); 107 fireEvent("name=field114", "focus"); 108 select("name=field114", "Option 1"); 109 fireEvent("name=field114", "blur"); 110 Assert.assertFalse(isElementPresent("name=field114@aria-invalid")); 111 Assert.assertTrue(getAttribute("name=field114@class").matches("^[\\s\\S]*valid[\\s\\S]*$")); 112 Assert.assertFalse(isElementPresent("//select[@name='field114']/../img[@alt='Error']")); 113 fireEvent("name=field117 value=3", "focus"); 114 uncheck("name=field117 value=3"); 115 fireEvent("name=field117", "blur"); 116 for (int second = 0; ; second++) { 117 if (second >= 60) { 118 Assert.fail("timeout"); 119 } 120 try { 121 if (isElementPresent("//input[@name='field117']/../../../img[@alt='Error']")) { 122 break; 123 } 124 } catch (Exception e) { 125 } 126 Thread.sleep(1000); 127 } 128 129 Assert.assertEquals("true", getAttribute("name=field117 value=1@aria-invalid")); 130 Assert.assertTrue(getAttribute("name=field117 value=1@class").matches("^[\\s\\S]*error[\\s\\S]*$")); 131 Assert.assertTrue(isElementPresent("//input[@name='field117']/../../../img[@alt='Error']")); 132 fireEvent("name=field117 value=3", "focus"); 133 check("name=field117 value=3"); 134 fireEvent("name=field117 value=3", "blur"); 135 for (int second = 0; ; second++) { 136 if (second >= 60) { 137 Assert.fail("timeout"); 138 } 139 try { 140 if (!isElementPresent("//input[@name='field117']/../../../img[@alt='Error']")) { 141 break; 142 } 143 } catch (Exception e) { 144 } 145 Thread.sleep(1000); 146 } 147 148 Assert.assertFalse(isElementPresent("name=field117 value=1@aria-invalid")); 149 Assert.assertTrue(getAttribute("name=field117 value=3@class").matches("^[\\s\\S]*valid[\\s\\S]*$")); 150 Assert.assertFalse(isElementPresent("//input[@name='field117']/../../../img[@alt='Error']")); 151 fireEvent("name=bField1", "focus"); 152 uncheck("name=bField1"); 153 fireEvent("name=bField1", "blur"); 154 Assert.assertEquals("true", getAttribute("name=bField1@aria-invalid")); 155 Assert.assertTrue(getAttribute("name=bField1@class").matches("^[\\s\\S]*error[\\s\\S]*$")); 156 Assert.assertTrue(isElementPresent( 157 "//input[@name='bField1' and following-sibling::img[@alt='Error']]")); 158 fireEvent("name=bField1", "focus"); 159 check("name=bField1"); 160 fireEvent("name=bField1", "blur"); 161 Assert.assertFalse(isElementPresent("name=bField1@aria-invalid")); 162 Assert.assertTrue(getAttribute("name=bField1@class").matches("^[\\s\\S]*valid[\\s\\S]*$")); 163 Assert.assertFalse(isElementPresent( 164 "//input[@name='bField1' and following-sibling::img[@alt='Error']]")); 165 fireEvent("name=field115 value=3", "focus"); 166 uncheck("name=field115 value=3"); 167 uncheck("name=field115 value=4"); 168 fireEvent("name=field115", "blur"); 169 for (int second = 0; ; second++) { 170 if (second >= 60) { 171 Assert.fail("timeout"); 172 } 173 try { 174 if (isElementPresent("//input[@name='field115']/../../../img[@alt='Error']")) { 175 break; 176 } 177 } catch (Exception e) { 178 } 179 Thread.sleep(1000); 180 } 181 182 Assert.assertEquals("true", getAttribute("name=field115 value=1@aria-invalid")); 183 Assert.assertTrue(getAttribute("name=field115 value=1@class").matches("^[\\s\\S]*error[\\s\\S]*$")); 184 Assert.assertTrue(isElementPresent("//input[@name='field115']/../../../img[@alt='Error']")); 185 fireEvent("name=field115 value=3", "focus"); 186 check("name=field115 value=3"); 187 check("name=field115 value=4"); 188 fireEvent("name=field115", "blur"); 189 for (int second = 0; ; second++) { 190 if (second >= 60) { 191 Assert.fail("timeout"); 192 } 193 try { 194 if (!isElementPresent("//input[@name='field115']/../../../img[@alt='Error']")) { 195 break; 196 } 197 } catch (Exception e) { 198 } 199 Thread.sleep(1000); 200 } 201 202 Assert.assertFalse(isElementPresent("name=field115 value=1@aria-invalid")); 203 Assert.assertFalse(isElementPresent("//input[@name='field115']/../../../img[@alt='Error']")); 204 } 205 }