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 */
016package org.kuali.hr.time.util;
017
018import org.junit.After;
019import org.junit.Before;
020import org.junit.Ignore;
021import org.junit.Test;
022import org.kuali.kpme.core.FunctionalTest;
023
024import com.thoughtworks.selenium.DefaultSelenium;
025import com.thoughtworks.selenium.SeleneseTestCase;
026
027@Ignore
028@FunctionalTest
029public class UICalendarTest extends SeleneseTestCase {
030    @Before
031    public void setUp() throws Exception {
032        selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://ci.kpme.kuali.org:9080/");
033//        selenium = new DefaultSelenium("localhost", 4444, "*firefox /Applications/Firefox.app/Contents/MacOS/firefox-bin", "http://ci.kpme.kuali.org:9080/");
034        // set speed to 1 sec between each action. this is mainly for the ajax call to get the earn code.
035        selenium.setSpeed("1000");
036        try {
037            selenium.start();
038        } catch (Exception e) {
039
040        }
041    }
042
043    /**
044     * Test adding and deleting a timeblock
045     *
046     * @throws Exception
047     */
048    @Test
049    public void testAddAndDeleteTimeBlock() throws Exception {
050        openPageAndLogin("/tk-dev/TimeDetail.do");
051        selenium.waitForPageToLoad("5000");
052        selenium.click("id=day_9");
053        selenium.select("id=assignment", "value=1_1234_1");
054        selenium.type("id=beginTimeField", "08:00 AM");
055        selenium.type("id=endTimeField", "05:00 PM");
056        selenium.click("//button[@type='button']");
057        selenium.waitForPageToLoad("5000");
058        selenium.click("class=event-delete");
059        selenium.waitForPageToLoad("3000");
060        verifyFalse(selenium.isTextPresent("08:00 AM"));
061        verifyFalse(selenium.isTextPresent("05:00 PM"));
062    }
063
064    /**
065     * This is to test that the entry fields for time / hours / amount should be correspondent with the selected earn code
066     *
067     * @throws Exception
068     */
069    @Test
070    public void testTestEarnCodeSwitch() throws Exception {
071        openPageAndLogin("/tk-dev/TimeDetail.do");
072        selenium.click("id=day_10");
073        selenium.select("id=assignment", "label=work area description : $0.00 Rcd 1 TEST-DEPT");
074        // verify the time entry fields are presented when the earn code type is "TIME"
075        verifyTrue(selenium.isTextPresent("exact:In:"));
076        verifyTrue(selenium.isTextPresent("exact:Out:"));
077        verifyTrue(selenium.isTextPresent("RGH : REGULAR"));
078        // verify the time entry fields are presented when the earn code type is "HOURS"
079        selenium.select("id=earnCode", "label=SCK : SICK");
080        verifyTrue(selenium.isTextPresent("exact:Hours:"));
081        // verify the time entry fields are presented when the earn code type is "AMOUNT"
082        selenium.select("id=earnCode", "label=TIP : Tips");
083        verifyTrue(selenium.isTextPresent("exact:Amount:"));
084    }
085
086    /**
087     * Test clocking in and out
088     *
089     * @throws Exception
090     */
091    @Test
092    public void testTestClockInAndOut() throws Exception {
093        openPageAndLogin("/tk-dev/Clock.do");
094        selenium.waitForPageToLoad("3000");
095        selenium.select("id=assignment", "label=work area description : $0.00 Rcd 1 TEST-DEPT");
096        // clock in
097        selenium.click("id=clock-button");
098        selenium.waitForPageToLoad("3000");
099        // verify the clock out button is presented
100        verifyEquals("Clock Out", selenium.getValue("id=clock-button"));
101        // clock out
102        selenium.click("id=clock-button");
103        // go to the time detail page and make sure clocking in/out is successful
104        selenium.click("link=Time Detail");
105        selenium.waitForPageToLoad("3000");
106        verifyTrue(selenium.isTextPresent("exact:RGN: REGULAR"));
107    }
108
109    @After
110    public void tearDown() throws Exception {
111        selenium.stop();
112    }
113
114    private void openPageAndLogin(String pageLink) {
115        selenium.open(pageLink);
116        selenium.type("__login_user", "admin");
117        selenium.click("//input[@name='login']");
118        selenium.waitForPageToLoad("2000");
119    }
120}
121
122