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