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 java.util.Calendar;
019
020 import junit.framework.Assert;
021
022 import org.junit.After;
023 import org.junit.Before;
024 import org.junit.Test;
025 import org.kuali.hr.test.KPMETestCase;
026 import org.kuali.hr.time.test.HtmlUnitUtil;
027 import org.kuali.hr.time.test.TkTestConstants;
028 import org.kuali.hr.time.util.TKUtils;
029
030 import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
031 import com.gargoylesoftware.htmlunit.WebClient;
032 import com.gargoylesoftware.htmlunit.html.HtmlButton;
033 import com.gargoylesoftware.htmlunit.html.HtmlPage;
034
035 public class LeaveBlockDisplayWebTest extends KPMETestCase {
036
037 @Before
038 public void setUp() throws Exception {
039 super.setUp();
040 }
041
042 @After
043 public void tearDown() throws Exception {
044 super.tearDown();
045 }
046
047 public void updateWebClient() {
048 WebClient webClient = getWebClient();
049 webClient.setJavaScriptEnabled(true);
050 webClient.setThrowExceptionOnScriptError(true);
051 webClient.setAjaxController(new NicelyResynchronizingAjaxController());
052 webClient.waitForBackgroundJavaScript(10000);
053 }
054
055 @Test
056 public void testLeaveBlockDisplayPage() throws Exception {
057 // get the page and Login
058 Calendar currentCalendar = Calendar.getInstance();
059 HtmlPage leaveBlockDisplayPage = HtmlUnitUtil
060 .gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.LEAVE_BLOCK_DISPLAY_URL);
061 Assert.assertNotNull("Leave Request page not found" + leaveBlockDisplayPage);
062
063 updateWebClient();
064
065 // check page contains the current year
066 Assert.assertTrue("Page is not current year ",
067 leaveBlockDisplayPage.asText().contains(Integer.toString(currentCalendar.get(Calendar.YEAR))));
068
069 // Check Main section
070 // depends on injection of test data for current year.
071 Assert.assertTrue("Page does not contain planned leave ",
072 leaveBlockDisplayPage.asText().contains("Send for Approval"));
073
074 // check Days Removed in correction section
075 Assert.assertTrue("Page does not contain approved leaves ",
076 leaveBlockDisplayPage.asText().contains("Updated by others"));
077
078 // check Inactive Leave entries
079 Assert.assertTrue("Page does not contain approved leaves ",
080 leaveBlockDisplayPage.asText().contains("Updated by self"));
081
082 // check page contains Document Status column
083 Assert.assertTrue("Page does not contain Document Status ",
084 leaveBlockDisplayPage.asText().contains("Document Status"));
085 Assert.assertTrue("Page does not contain 'FINAL' Document Status ",
086 leaveBlockDisplayPage.asText().contains("FINAL"));
087
088 // check page contains Planning Status column
089 Assert.assertTrue("Page does not contain Planning Status ",
090 leaveBlockDisplayPage.asText().contains("Planning Status"));
091
092 // Check for next year
093 HtmlButton nextButton = (HtmlButton) leaveBlockDisplayPage
094 .getElementById("nav_lb_next");
095 leaveBlockDisplayPage = nextButton.click();
096
097 // check page contains the next year
098 Assert.assertTrue("Page does not contain next year ",
099 leaveBlockDisplayPage.asText().contains(Integer.toString(currentCalendar.get(Calendar.YEAR)+1)));
100 }
101
102 }