View Javadoc

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