001 /** 002 * Copyright 2004-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 org.kuali.hr.time.calendar; 017 018 019 import org.junit.Assert; 020 import org.junit.Test; 021 import org.kuali.hr.test.KPMETestCase; 022 import org.kuali.hr.time.test.HtmlUnitUtil; 023 import org.kuali.hr.time.test.TkTestConstants; 024 025 import com.gargoylesoftware.htmlunit.html.HtmlElement; 026 import com.gargoylesoftware.htmlunit.html.HtmlForm; 027 import com.gargoylesoftware.htmlunit.html.HtmlInput; 028 import com.gargoylesoftware.htmlunit.html.HtmlPage; 029 030 public class CalendarMaintTest extends KPMETestCase { 031 032 public static final String TEST_USER = "admin"; 033 private static final String CAL_NAME_REQUIRED = "Calendar Name (Calendar Name) is a required field."; 034 private static final String CAL_DESP_REQUIRED = "Calendar Descriptions (Calendar Descriptions) is a required field."; 035 private static final String CAL_TYPES_REQUIRED = "Calendar Types (Calendar Types) is a required field."; 036 private static final String FLSA_DAY_REQUIRED = "FLSA Begin Day is a required field."; 037 private static final String FLSA_TIME_REQUIRED = "FLSA Begin Time is a required field."; 038 039 @Test 040 public void testDisplayCalendarTypeRadioOptions() throws Exception { 041 042 //verify the lookup page doesn't contain the both radio button 043 HtmlPage calendarPage = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.CALENDAR_MAINT_URL); 044 HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(calendarPage, "search"); 045 HtmlUnitUtil.createTempFile(resultPage); 046 Assert.assertTrue("Lookup page contains:\n" + "The both radio button is not present", resultPage.asText().contains("Both")); 047 048 //verify the lookup page doesn't contain the both radio button 049 HtmlPage calendarMaintPage = HtmlUnitUtil.clickAnchorContainingText(resultPage, "edit"); //click on the first result 050 HtmlUnitUtil.createTempFile(calendarMaintPage); 051 Assert.assertFalse("Maintenance page contains:\n" + "The both radio button is present", calendarMaintPage.asText().contains("Both")); 052 053 } 054 055 @Test 056 public void testRequiredFields() throws Exception { 057 String baseUrl = TkTestConstants.Urls.CALENDAR_MAINT_NEW_URL; 058 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(baseUrl); 059 Assert.assertNotNull(page); 060 061 HtmlForm form = page.getFormByName("KualiForm"); 062 Assert.assertNotNull("Search form was missing from page.", form); 063 064 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route"); 065 Assert.assertNotNull("Could not locate submit button", input); 066 067 HtmlElement element = page.getElementByName("methodToCall.route"); 068 page = element.click(); 069 Assert.assertFalse("page text contains: Incident Report", page.asText().contains("Incident Report")); 070 Assert.assertTrue("page text does not contain:\n" + CAL_NAME_REQUIRED, page.asText().contains(CAL_NAME_REQUIRED)); 071 Assert.assertTrue("page text does not contain:\n" + CAL_DESP_REQUIRED, page.asText().contains(CAL_DESP_REQUIRED)); 072 Assert.assertTrue("page text does not contain:\n" + CAL_TYPES_REQUIRED, page.asText().contains(CAL_TYPES_REQUIRED)); 073 Assert.assertFalse("page text contains:\n" + FLSA_DAY_REQUIRED, page.asText().contains(FLSA_DAY_REQUIRED)); 074 Assert.assertFalse("page text contains:\n" + FLSA_TIME_REQUIRED, page.asText().contains(FLSA_TIME_REQUIRED)); 075 076 setFieldValue(page, "document.newMaintainableObject.calendarName", "testCal"); 077 setFieldValue(page, "document.newMaintainableObject.calendarDescriptions", "testDes"); 078 // when calendar type is leave, flsa day and time are NOT required 079 setFieldValue(page, "document.newMaintainableObject.calendarTypesLeave", "on"); 080 page = page.getElementByName("methodToCall.route").click(); 081 Assert.assertFalse("page text contains:\n" + FLSA_DAY_REQUIRED, page.asText().contains(FLSA_DAY_REQUIRED)); 082 Assert.assertFalse("page text contains:\n" + FLSA_TIME_REQUIRED, page.asText().contains(FLSA_TIME_REQUIRED)); 083 084 // when calendar type is Pay, flsa day and time are required 085 setFieldValue(page, "document.newMaintainableObject.calendarTypesPay", "on"); 086 page = page.getElementByName("methodToCall.route").click(); 087 Assert.assertTrue("page text does not contain:\n" + FLSA_DAY_REQUIRED, page.asText().contains(FLSA_DAY_REQUIRED)); 088 Assert.assertTrue("page text does not contain:\n" + FLSA_TIME_REQUIRED, page.asText().contains(FLSA_TIME_REQUIRED)); 089 } 090 }