001    /**
002     * Copyright 2005-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 edu.samplu.krad.demo.uif.library;
017    
018    import org.junit.Test;
019    import org.openqa.selenium.By;
020    import org.openqa.selenium.WebElement;
021    
022    import java.text.SimpleDateFormat;
023    import java.util.Date;
024    
025    /**
026     * @author Kuali Rice Team (rice.collab@kuali.org)
027     */
028    public class DemoLibraryWidgetsDatePickerSmokeTest extends DemoLibraryBase {
029    
030        /**
031         * /kr-krad/kradsampleapp?viewId=Demo-DatePicker-View&methodToCall=start
032         */
033        public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-DatePicker-View&methodToCall=start";
034    
035        @Override
036        protected String getBookmarkUrl() {
037            return BOOKMARK_URL;
038        }
039    
040        @Override
041        protected void navigate() throws Exception {
042            navigateToExample("Widgets");
043            waitAndClickByLinkText("DatePicker");
044        }
045    
046        protected void testWidgetsDatePickerDefault() throws Exception {
047    
048            //click on datepicker
049            waitAndClick(By.cssSelector("img.ui-datepicker-trigger"));
050    
051            //select today
052            waitAndClick(By.cssSelector(".ui-datepicker-current"));
053    
054            //make sure today is populated
055            String today = new SimpleDateFormat("MM/dd/yyyy").format(new Date());
056            String populatedDate = driver.findElement(By.id("u100085_control")).getAttribute("value");
057            if (!populatedDate.equals(today)) {
058                fail("DatePicker did not populate correct value.");
059            }
060    
061        }
062    
063        protected void testWidgetsDatePickerWidget() throws Exception {
064            waitAndClickByLinkText(">> Open Library Navigation");
065            waitAndClickByLinkText("Suggest");
066            waitAndClickByLinkText("Tooltip");
067            select(By.id("Demo-LargeExampleDropdown_control"), "Tooltip On Focus");
068    
069            //focus label
070            fireMouseOverEvent(By.id("u100101_label"));
071            Thread.sleep(1000);
072            WebElement tooltipFocusLabel = driver.findElement(By.xpath("//div[@data-for=\"u100101_label\"]")).findElement(
073                    By.className("jquerybubblepopup-innerHtml"));
074            if (!tooltipFocusLabel.isDisplayed()) {
075                fail("Tooltip help for label not displayed.");
076            }
077            if (!tooltipFocusLabel.getText().equals("Click on the text box for a tool tip")) {
078                fail("Incorrect inner html text for label focus tooltip.");
079            }
080    
081            //focus control
082            waitAndClickById("u100101_control");
083            Thread.sleep(1000);
084            WebElement tooltipFocusControl = driver.findElement(By.xpath("//div[@data-for=\"u100101_control\"]"))
085                    .findElement(By.className("jquerybubblepopup-innerHtml"));
086            if (!tooltipFocusControl.isDisplayed()) {
087                fail("Tooltip help for control not displayed.");
088            }
089            if (!tooltipFocusControl.getText().equals("This tooltip appears when the field receives focus")) {
090                fail("Incorrect inner html text for tooltip focus control.");
091            }
092        }
093    
094        @Test
095        public void testWidgetsDatePickerBookmark() throws Exception {
096            testWidgetsDatePickerDefault();
097            driver.close();
098            passed();
099        }
100    
101        @Test
102        public void testWidgetsDatePickerNav() throws Exception {
103            testWidgetsDatePickerDefault();
104            driver.close();
105            passed();
106        }
107    }