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.lm.leave.web;
017    
018    import junit.framework.Assert;
019    
020    import org.junit.After;
021    import org.junit.Before;
022    import org.junit.Ignore;
023    import org.junit.Test;
024    import org.kuali.hr.test.KPMETestCase;
025    import org.kuali.hr.time.test.HtmlUnitUtil;
026    import org.kuali.hr.time.test.TkTestConstants;
027    
028    import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
029    import com.gargoylesoftware.htmlunit.WebClient;
030    import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput;
031    import com.gargoylesoftware.htmlunit.html.HtmlElement;
032    import com.gargoylesoftware.htmlunit.html.HtmlPage;
033    
034    public class LeaveRequestWebTest extends KPMETestCase {
035    
036            @Before
037            public void setUp() throws Exception {
038                    super.setUp();
039            }
040    
041            @After
042            public void tearDown() throws Exception {
043                    super.tearDown();
044            }
045    
046            public void setWebClient(WebClient webClient) {
047                    webClient.setJavaScriptEnabled(true);
048                    webClient.setThrowExceptionOnScriptError(true);
049                    webClient.setAjaxController(new NicelyResynchronizingAjaxController());
050                    webClient.waitForBackgroundJavaScript(10000);
051            }
052    
053            @Test
054        @Ignore
055            public void testLeaveRequestPage() throws Exception {
056                    // get the page and Login
057                    HtmlPage leaveRequestPage = HtmlUnitUtil
058                                    .gotoPageAndLogin(TkTestConstants.Urls.LEAVE_REQUEST_PAGE_URL);
059                    Assert.assertNotNull("Leave Request page not found" + leaveRequestPage);
060    
061                    // Check planned requests
062                    Assert.assertTrue("Page does not contain planned leave ", leaveRequestPage
063                                    .asText().contains("Send for Approval"));
064    
065                    // check Approved Leaves
066                    Assert.assertTrue("Page does not contain approved leaves ", leaveRequestPage
067                                    .asText().contains("Approved Leave"));
068    
069                    // check disapproved Leaves
070                    Assert.assertTrue("Page does not contain approved leaves ", leaveRequestPage
071                                    .asText().contains("Disapprove"));
072    
073                    HtmlCheckBoxInput htmlElement = (HtmlCheckBoxInput) leaveRequestPage
074                                    .getElementByName("plannedLeaves[0].submit");
075                    leaveRequestPage = (HtmlPage) htmlElement.setValueAttribute("true");
076    
077                    HtmlCheckBoxInput checkbox = (HtmlCheckBoxInput) HtmlUnitUtil
078                                    .getInputContainingText(leaveRequestPage,
079                                                    "plannedLeaves[0].submit");
080                    checkbox.setChecked(true);
081    
082                    HtmlElement elementSubmit = leaveRequestPage.getElementByName("Submit");
083                    Assert.assertNotNull(elementSubmit);
084    
085                    HtmlUnitUtil.createTempFile(leaveRequestPage);
086    
087                    HtmlPage leaveRequestPage1 = elementSubmit.click();
088    
089                    HtmlUnitUtil.createTempFile(leaveRequestPage1);
090    
091                    // check if submitted pending leave comes in the section of Requested
092                    // leave
093                    Assert.assertTrue("Page does not contain Pending leave ", leaveRequestPage1
094                                    .asText().contains("Send for Approval"));
095    
096            }
097    
098    }