1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 CAL_TYPES_REQUIRED = "Calendar Types (Calendar Types) is a required field.";
36 private static final String FLSA_DAY_REQUIRED = "FLSA Begin Day is a required field.";
37 private static final String FLSA_TIME_REQUIRED = "FLSA Begin Time is a required field.";
38
39 @Test
40 public void testDisplayCalendarTypeRadioOptions() throws Exception {
41
42
43 HtmlPage calendarPage = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.CALENDAR_MAINT_URL);
44 HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(calendarPage, "search");
45 HtmlUnitUtil.createTempFile(resultPage);
46 Assert.assertTrue("Lookup page contains:\n" + "The both radio button is not present", resultPage.asText().contains("Both"));
47
48
49 HtmlPage calendarMaintPage = HtmlUnitUtil.clickAnchorContainingText(resultPage, "edit");
50 HtmlUnitUtil.createTempFile(calendarMaintPage);
51 Assert.assertFalse("Maintenance page contains:\n" + "The both radio button is present", calendarMaintPage.asText().contains("Both"));
52
53 }
54
55 @Test
56 public void testRequiredFields() throws Exception {
57 String baseUrl = TkTestConstants.Urls.CALENDAR_MAINT_NEW_URL;
58 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(baseUrl);
59 Assert.assertNotNull(page);
60
61 HtmlForm form = page.getFormByName("KualiForm");
62 Assert.assertNotNull("Search form was missing from page.", form);
63
64 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
65 Assert.assertNotNull("Could not locate submit button", input);
66
67 HtmlElement element = page.getElementByName("methodToCall.route");
68 page = element.click();
69 Assert.assertFalse("page text contains: Incident Report", page.asText().contains("Incident Report"));
70 Assert.assertTrue("page text does not contain:\n" + CAL_NAME_REQUIRED, page.asText().contains(CAL_NAME_REQUIRED));
71 Assert.assertTrue("page text does not contain:\n" + CAL_DESP_REQUIRED, page.asText().contains(CAL_DESP_REQUIRED));
72 Assert.assertTrue("page text does not contain:\n" + CAL_TYPES_REQUIRED, page.asText().contains(CAL_TYPES_REQUIRED));
73 Assert.assertFalse("page text contains:\n" + FLSA_DAY_REQUIRED, page.asText().contains(FLSA_DAY_REQUIRED));
74 Assert.assertFalse("page text contains:\n" + FLSA_TIME_REQUIRED, page.asText().contains(FLSA_TIME_REQUIRED));
75
76 setFieldValue(page, "document.newMaintainableObject.calendarName", "testCal");
77 setFieldValue(page, "document.newMaintainableObject.calendarDescriptions", "testDes");
78
79 setFieldValue(page, "document.newMaintainableObject.calendarTypesLeave", "on");
80 page = page.getElementByName("methodToCall.route").click();
81 Assert.assertFalse("page text contains:\n" + FLSA_DAY_REQUIRED, page.asText().contains(FLSA_DAY_REQUIRED));
82 Assert.assertFalse("page text contains:\n" + FLSA_TIME_REQUIRED, page.asText().contains(FLSA_TIME_REQUIRED));
83
84
85 setFieldValue(page, "document.newMaintainableObject.calendarTypesPay", "on");
86 page = page.getElementByName("methodToCall.route").click();
87 Assert.assertTrue("page text does not contain:\n" + FLSA_DAY_REQUIRED, page.asText().contains(FLSA_DAY_REQUIRED));
88 Assert.assertTrue("page text does not contain:\n" + FLSA_TIME_REQUIRED, page.asText().contains(FLSA_TIME_REQUIRED));
89 }
90 }