View Javadoc
1   /**
2    * Copyright 2004-2015 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.hr.core.calendar;
17  
18  
19  import org.junit.Assert;
20  import org.junit.Test;
21  import org.kuali.hr.KPMEWebTestCase;
22  import org.kuali.hr.util.HtmlUnitUtil;
23  import org.kuali.kpme.core.FunctionalTest;
24  import org.kuali.kpme.core.util.HrTestConstants;
25  
26  import com.gargoylesoftware.htmlunit.html.HtmlElement;
27  import com.gargoylesoftware.htmlunit.html.HtmlForm;
28  import com.gargoylesoftware.htmlunit.html.HtmlInput;
29  import com.gargoylesoftware.htmlunit.html.HtmlPage;
30  
31  @FunctionalTest
32  public class CalendarMaintTest extends KPMEWebTestCase {
33  
34  	public static final String TEST_USER = "admin";
35  	private static final String CAL_NAME_REQUIRED = "Calendar Name (Calendar Name) is a required field.";
36  	private static final String CAL_DESP_REQUIRED = "Calendar Description (Calendar Description) is a required field.";
37  	private static final String CAL_TYPES_REQUIRED = "Calendar Type (Calendar Type) is a required field.";
38  	private static final String FLSA_DAY_REQUIRED = "FLSA Begin Day is a required field.";
39  	private static final String FLSA_TIME_REQUIRED = "FLSA Begin Time is a required field.";
40  	
41  	@Test
42  	public void testDisplayCalendarTypeRadioOptions() throws Exception {
43  		/*
44  		//verify the lookup page doesn't contain the both radio button
45  		HtmlPage calendarPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), HrTestConstants.Urls.CALENDAR_MAINT_URL);
46  		HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(calendarPage, "search");
47  		HtmlUnitUtil.createTempFile(resultPage);
48  		Assert.assertTrue("Lookup page contains:\n" + "The both radio button is not present", resultPage.asText().contains("Both"));
49  		
50  		//verify the lookup page doesn't contain the both radio button
51  		HtmlPage calendarMaintPage = HtmlUnitUtil.clickAnchorContainingText(resultPage, "edit"); //click on the first result
52  		HtmlUnitUtil.createTempFile(calendarMaintPage);
53  		Assert.assertFalse("Maintenance page contains:\n" + "The both radio button is present", calendarMaintPage.asText().contains("Both"));
54  		
55  	}
56  	
57  	@Test
58  	public void testRequiredFields() throws Exception {
59  	  	String baseUrl = HrTestConstants.Urls.CALENDAR_MAINT_NEW_URL;
60  	  	HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
61  	  	Assert.assertNotNull(page);
62  	 
63  	  	HtmlForm form = page.getFormByName("KualiForm");
64  	  	Assert.assertNotNull("Search form was missing from page.", form);
65  	  	
66  	  	HtmlInput  input  = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
67  	  	Assert.assertNotNull("Could not locate submit button", input);
68  	  	
69  	  	HtmlElement element = page.getElementByName("methodToCall.route");
70  	  	page = element.click();
71  	  	Assert.assertFalse("page text contains: Incident Report", page.asText().contains("Incident Report"));
72  	  	Assert.assertTrue("page text does not contain:\n" + CAL_NAME_REQUIRED, page.asText().contains(CAL_NAME_REQUIRED));
73  	  	Assert.assertTrue("page text does not contain:\n" + CAL_DESP_REQUIRED, page.asText().contains(CAL_DESP_REQUIRED));
74  	  	Assert.assertTrue("page text does not contain:\n" + CAL_TYPES_REQUIRED, page.asText().contains(CAL_TYPES_REQUIRED));
75  	  	Assert.assertFalse("page text contains:\n" + FLSA_DAY_REQUIRED, page.asText().contains(FLSA_DAY_REQUIRED));
76  	  	Assert.assertFalse("page text contains:\n" + FLSA_TIME_REQUIRED, page.asText().contains(FLSA_TIME_REQUIRED));
77  	    
78  	    HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.calendarName", "testCal");
79  	    HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.calendarDescriptions", "testDes");
80  	    // when calendar type is leave, flsa day and time are NOT required
81  	    HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.calendarTypesLeave", "on");
82  	  	page = ((HtmlElement)page.getElementByName("methodToCall.route")).click();
83  	  	Assert.assertFalse("page text contains:\n" + FLSA_DAY_REQUIRED, page.asText().contains(FLSA_DAY_REQUIRED));
84  	  	Assert.assertFalse("page text contains:\n" + FLSA_TIME_REQUIRED, page.asText().contains(FLSA_TIME_REQUIRED));
85  	    
86  	    // when calendar type is Pay, flsa day and time are required
87  	    HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.calendarTypesPay", "on");
88  	    page = ((HtmlElement)page.getElementByName("methodToCall.route")).click();
89  	    Assert.assertTrue("page text does not contain:\n" + FLSA_DAY_REQUIRED, page.asText().contains(FLSA_DAY_REQUIRED));
90  	    Assert.assertTrue("page text does not contain:\n" + FLSA_TIME_REQUIRED, page.asText().contains(FLSA_TIME_REQUIRED));
91  	    */
92  	}
93  }