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