001/**
002 * Copyright 2005-2016 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.rice.krad.demo.uif.library.elements;
017
018import org.junit.Test;
019import org.kuali.rice.krad.demo.uif.library.LibraryBase;
020import org.openqa.selenium.By;
021
022/**
023 * @author Kuali Rice Team (rice.collab@kuali.org)
024 */
025public class LibraryElementsActionAft extends LibraryBase {
026
027    /**
028     * /kr-krad/kradsampleapp?viewId=Demo-ActionView&methodToCall=start
029     */
030    public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-ActionView&methodToCall=start";
031
032    @Override
033    public String getBookmarkUrl() {
034        return BOOKMARK_URL;
035    }
036
037    @Override
038    protected void navigate() throws Exception {
039        waitAndClickLibraryLink();
040        waitAndClickByLinkText("Elements");
041        waitAndClickByLinkText("Action");
042    }
043
044    protected void testActionDefault() throws Exception {
045        waitForElementPresentByClassName("uif-headerText-span");
046        assertTextPresent("Default");
047        assertTrue(getTextByClassName("uif-instructionalMessage").contains(
048                "Action with action script"));
049        assertElementPresentByLinkText("Action Link");
050        waitAndClickByLinkText("Action Link");
051        acceptAlert();
052    }
053
054    protected void testActionPresubmit() throws Exception {
055        waitAndClickByLinkText("Presubmit");
056        waitForElementPresentByClassName("uif-headerText-span");
057        assertTextPresent("Presubmit");
058        assertTextPresent("ActionLinkField with presubmit script");
059        assertElementPresentByLinkText("Pre submit returning true Link");
060        assertElementPresentByLinkText("Pre submit returning false Link");
061
062        waitAndClickByLinkText("Pre submit returning true Link");
063        assertTrue(driver.switchTo().alert().getText().contains("Pre submit call was invoked, returning true"));
064        driver.switchTo().alert().accept();
065
066        waitAndClickLinkContainingText("Pre submit returning false Link");
067        assertTrue(driver.switchTo().alert().getText().contains("Pre submit call was invoked, returning false"));
068        driver.switchTo().alert().accept();
069    }
070
071    protected void testActionSuccessCallback() throws Exception {
072        waitAndClickByLinkText("Success Callback");
073        waitForElementPresentByClassName("uif-headerText-span");
074        assertTextPresent("Action Field with a success callback script");
075        assertElementPresentByLinkText("Action Link success callback");
076
077        waitAndClickByLinkText("Action Link success callback");
078        Thread.sleep(1500); // give the alert time to get triggered via callback
079        assertTrue(driver.switchTo().alert().getText().contains("Refresh called successfully"));
080        driver.switchTo().alert().accept();
081    }
082
083    protected void testActionValidation() throws Exception {
084        waitForElementPresentByClassName("uif-page"); // make sure the page is there before we use the driver
085        findElement(By.className("uif-page")).findElement(By.linkText("Validation")).click();
086
087        waitForElementPresentByClassName("uif-headerText-span");
088        assertTextPresent("Action Field with client side validation");
089        assertTextPresent("InputField 1");
090        assertIsNotVisibleByXpath("//a[contains(text(),'Required')]");
091
092        waitAndClickByLinkText("Action Field with client side required validation");
093        assertIsVisibleByXpath("//a[contains(text(),'Required')]", "");
094
095        waitAndTypeByName("inputField1", "some text");
096        waitAndClickByLinkText("Action Field with client side required validation");
097        assertIsNotVisibleByXpath("//a[contains(text(),'Required')]");
098    }
099
100    protected void testActionImages() throws Exception {
101        waitAndClickByLinkText("Images");
102        waitForElementPresentByClassName("uif-headerText-span");
103        assertTextPresent("Images");
104        assertTextPresent("Action Field with images");
105        findElement(By.partialLinkText("Action Link with left image")).findElement(By.className("leftActionImage"));
106        findElement(By.partialLinkText("Action Link with right image")).findElement(By.className("rightActionImage"));
107        waitAndClickByLinkText("Action Link with left image");
108        acceptAlert();
109        waitAndClickByLinkText("Action Link with right image");
110        acceptAlert();
111    }
112
113    protected void testActionButton() throws Exception {
114        waitAndClickByLinkText("Buttons");
115        waitForElementPresentByClassName("prettyprint");
116        assertTextPresent("Buttons");
117        assertTextPresent("Action Field buttons");
118
119        waitAndClickButtonByText("button");
120        assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
121        driver.switchTo().alert().accept();
122
123        waitAndClickButtonByText("Image BOTTOM");
124        assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
125        driver.switchTo().alert().accept();
126
127        waitAndClickById("ST-DemoButtonImageTop");
128        assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
129        driver.switchTo().alert().accept();
130
131        findElement(By.xpath("//span[contains(text(),'Image LEFT')]"));
132        findElement(By.id("ST-DemoButtonImageLeft")).click();
133        assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
134        driver.switchTo().alert().accept();
135
136        findElement(By.id("ST-DemoButtonImageRight")).click();
137        assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
138        driver.switchTo().alert().accept();
139
140        findElement(By.id("ST-DemoButtonImageOnly")).click();
141        assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
142        driver.switchTo().alert().accept();
143
144        findElement(By.xpath("//button[contains(text(),'Disabled Button') and @disabled]/preceding-sibling::button/img"));
145        findElement(By.xpath("//button/img[contains(@alt,'Image Only button')]"));
146
147        findElement(By.xpath("//button[contains(text(),'Disabled Button') and @disabled]"));
148    }
149    
150    protected void testActionStyleVarities() throws Exception {
151        waitAndClickByLinkText("Style Varieties");
152        
153        //Assertion of Large Buttons
154        waitForElementPresentByXpath("//button[@class='btn btn-primary btn-lg uif-action uif-boxLayoutVerticalItem pull-left clearfix']");
155        waitForElementPresentByXpath("//button[@class='btn btn-primary btn-lg uif-action uif-boxLayoutVerticalItem pull-left clearfix disabled' and @disabled]");
156        waitForElementPresentByXpath("//button[@class='btn btn-default btn-lg uif-action uif-boxLayoutVerticalItem pull-left clearfix']");
157        waitForElementPresentByXpath("//button[@class='btn btn-default btn-lg uif-action uif-boxLayoutVerticalItem pull-left clearfix disabled' and @disabled]");
158        
159        //Assertion of Small Buttons
160        waitForElementPresentByXpath("//button[@class='btn btn-primary btn-sm uif-action uif-boxLayoutVerticalItem pull-left clearfix']");
161        waitForElementPresentByXpath("//button[@class='btn btn-primary btn-sm uif-action uif-boxLayoutVerticalItem pull-left clearfix disabled' and @disabled]");
162        waitForElementPresentByXpath("//button[@class='btn btn-default btn-sm uif-action uif-boxLayoutVerticalItem pull-left clearfix']");
163        waitForElementPresentByXpath("//button[@class='btn btn-default btn-sm uif-action uif-boxLayoutVerticalItem pull-left clearfix disabled' and @disabled]");
164        
165        //Assertion of Mini Buttons
166        waitForElementPresentByXpath("//button[@class='btn btn-primary btn-xs uif-action uif-boxLayoutVerticalItem pull-left clearfix']");
167        waitForElementPresentByXpath("//button[@class='btn btn-primary btn-xs uif-action uif-boxLayoutVerticalItem pull-left clearfix disabled' and @disabled]");
168        waitForElementPresentByXpath("//button[@class='btn btn-default btn-xs uif-action uif-boxLayoutVerticalItem pull-left clearfix']");
169        waitForElementPresentByXpath("//button[@class='btn btn-default btn-xs uif-action uif-boxLayoutVerticalItem pull-left clearfix disabled' and @disabled]");
170        
171        //ICON Examples
172        waitForElementPresentByXpath("//button[@class='btn btn-primary btn-lg uif-action uif-boxLayoutVerticalItem pull-left clearfix']/span[@class='icon-ok']");
173        waitForElementPresentByXpath("//button[@class='btn btn-primary uif-action uif-boxLayoutVerticalItem pull-left clearfix']/span[@class='icon-ok']");
174        waitForElementPresentByXpath("//button[@class='btn btn-primary btn-sm uif-action uif-boxLayoutVerticalItem pull-left clearfix']/span[@class='icon-ok']");
175        waitForElementPresentByXpath("//button[@class='btn btn-primary btn-xs uif-action uif-boxLayoutVerticalItem pull-left clearfix']/span[@class='icon-ok']");
176        waitForElementPresentByXpath("//button[@class='btn btn-primary btn-lg uif-action uif-boxLayoutVerticalItem pull-left clearfix icon-ok']");
177        waitForElementPresentByXpath("//button[@class='btn btn-primary uif-action uif-boxLayoutVerticalItem pull-left clearfix icon-ok']");
178        waitForElementPresentByXpath("//button[@class='btn btn-primary btn-sm uif-action uif-boxLayoutVerticalItem pull-left clearfix icon-ok']");
179        waitForElementPresentByXpath("//button[@class='btn btn-primary btn-xs uif-action uif-boxLayoutVerticalItem pull-left clearfix icon-ok']");
180    }
181
182    protected void testActionIcons() throws Exception {
183        waitAndClickByXpath("//a[@href='#Demo-Action-Example6_tabPanel' and contains(text(),'Icons')]");
184        waitForElementPresentByXpath("//button[@class='btn btn-primary uif-action uif-boxLayoutVerticalItem pull-left clearfix']/span[@class='icon-office']");
185        waitForElementPresentByXpath("//button[@class='btn btn-primary uif-action uif-boxLayoutVerticalItem pull-left clearfix icon-office']");
186    }
187    
188    private void testAllActionTabs() throws Exception {
189//        testActionDefault();
190//        testActionSuccessCallback();
191//        testActionValidation();
192//        testActionImages();
193//        testActionButton();
194//        testActionStyleVarities();
195//        testActionIcons();
196        testActionPresubmit(); // last because it is failing https://jira.kuali.org/browse/KULRICE-10961 Library Action Presubmit Pre submit returning true Link redirects to Library Action Default
197    }
198
199    @Test
200    public void testActionBookmark() throws Exception {
201        testAllActionTabs();
202        passed();
203    }
204
205    @Test
206    public void testActionNav() throws Exception {
207        testAllActionTabs();
208        passed();
209    }
210}