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.containers;
017
018import org.junit.Ignore;
019import org.junit.Test;
020
021import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase;
022import org.openqa.selenium.By;
023import org.openqa.selenium.NoSuchElementException;
024import org.openqa.selenium.WebElement;
025
026/**
027 * @author Kuali Rice Team (rice.collab@kuali.org)
028 */
029public class LibraryContainerDialogGroupAft extends WebDriverLegacyITBase {
030
031    /**
032     * /kr-krad/dialog?viewId=Demo-DialogGroupView
033     */
034    public static final String BOOKMARK_URL = "/kr-krad/dialog?viewId=Demo-DialogGroupView";
035    
036    @Override
037    protected String getBookmarkUrl() {
038        return BOOKMARK_URL;
039    }
040
041    @Override
042    protected void navigate() throws Exception {
043        waitAndClickLibraryLink();
044        waitAndClickByLinkText("Containers");
045        waitAndClickByLinkText("Dialog Group");
046    }
047    
048    protected void testContainerDialogGroupConfirmAction() throws Exception {
049        waitAndClickByXpath("//section[@id='Demo-DialogGroup-Example1']/button");
050        waitAndClickByXpath("//section[@id='Uif-DialogGroup-YesNotmp']/div/div/div[@data-parent='Uif-DialogGroup-YesNo']/button[contains(text(),'No')]");
051    }
052
053    protected void testContainerDialogGroupConfirmWithExplaination() throws Exception {
054        waitAndClickByLinkText("Confirm with Explanation");
055        waitAndClickByXpath("//section[@id='Demo-DialogGroup-Example2']/button");
056        waitForElementPresentByXpath("//section[@id='Demo-DialogEx2']/div/div/div[@class='modal-body']/div/div/textarea");
057        waitAndClickByXpath("//section[@id='Demo-DialogEx2']/div/div/div[@data-parent='Demo-DialogEx2']/button[contains(text(),'OK')]");
058        waitForElementPresentByXpath("//a[contains(text(),'Required')]");
059        waitAndClickByXpath("//section[@id='Demo-DialogEx2']/div/div/div[@data-parent='Demo-DialogEx2']/button[contains(text(),'Cancel')]");
060    }
061    
062    protected void testContainerDialogGroupGetDialogResponse1() throws Exception {
063        waitAndClickByLinkText("Get Dialog Response Ex. 1");
064        waitAndClickByXpath("//section[@id='Demo-DialogGroup-Example3']/button");
065        waitAndClickByXpath("//section[@id='Demo-DialogGroup-DialogResponse1']/div/div/div[@data-parent='Demo-DialogGroup-DialogResponse1']/button[contains(text(),'OK')]");
066        acceptAlertIfPresent();
067        waitAndClickByXpath("//section[@id='Demo-DialogGroup-Example3']/button");
068        waitAndClickByXpath("//section[@id='Demo-DialogGroup-DialogResponse1']/div/div/div[@data-parent='Demo-DialogGroup-DialogResponse1']/button[contains(text(),'Cancel')]");
069        acceptAlertIfPresent();
070    }
071
072    protected void testContainerDialogGroupGetDialogResponse2() throws Exception {
073        waitAndClickByLinkText("Get Dialog Response Ex. 2");
074        waitAndClickByXpath("//section[@id='Demo-DialogGroup-Example4']/button");
075        waitAndClickByXpath("//section[@id='Demo-DialogGroup-DialogResponse2']/div/div/div[@data-parent='Demo-DialogGroup-DialogResponse2']/button[contains(text(),'Green Eggs and Ham')]");
076        acceptAlertIfPresent();
077        waitAndClickByXpath("//section[@id='Demo-DialogGroup-Example4']/button");
078        waitAndClickByXpath("//section[@id='Demo-DialogGroup-DialogResponse2']/div/div/div[@data-parent='Demo-DialogGroup-DialogResponse2']/button[contains(text(),'Cat in the Hat')]");
079        acceptAlertIfPresent();
080        waitAndClickByXpath("//section[@id='Demo-DialogGroup-Example4']/button");
081        waitAndClickByXpath("//section[@id='Demo-DialogGroup-DialogResponse2']/div/div/div[@data-parent='Demo-DialogGroup-DialogResponse2']/button[contains(text(),'The Grinch')]");
082        acceptAlertIfPresent();
083    }
084    
085    protected void testContainerDialogGroupShowDialog1() throws Exception {
086        waitAndClickByLinkText("Show Dialog Ex. 1");
087        waitAndClickByXpath("//section[@id='Demo-DialogGroup-Example5']/a[contains(text(),'Show Dialog')]");
088        waitForElementPresentByXpath("//input[@name='inputField1']");
089        waitForElementPresentByXpath("//input[@name='inputField2']");
090        waitForElementPresentByXpath("//input[@name='inputField3']");
091        waitForElementPresentByXpath("//input[@name='inputField4']");
092        waitForElementPresentByXpath("//input[@name='inputField5']");
093        waitAndClickByXpath("//section[@id='Demo-DialogGroup-ShowDialog1']/div/div/div[@data-parent='Demo-DialogGroup-ShowDialog1']/button[contains(text(),'Continue')]");
094    }
095
096    protected void testContainerDialogGroupShowDialog2() throws Exception {
097        waitAndClickByLinkText("Show Dialog Ex. 2");
098        waitAndClickByXpath("//section[@id='Demo-DialogGroup-Example6']/a[contains(text(),'Show Dialog')]");
099        waitForElementPresentByXpath("//section[@id='Demo-DialogGroup-ShowDialog2Refresh' and @style='display: none; background-color: rgba(255, 248, 198, 0);']");
100        waitAndClickByXpath("//input[@name='inputField6' and @value='show']");
101        waitForElementPresentByXpath("//section[@id='Demo-DialogGroup-ShowDialog2Refresh' and @style='display: block; background-color: rgba(255, 248, 198, 0);']");
102        waitAndClickByXpath("//section[@id='Demo-DialogGroup-ShowDialog2']/div/div/div[@data-parent='Demo-DialogGroup-ShowDialog2']/button[contains(text(),'OK')]");
103    }
104    
105    protected void testContainerDialogGroupDialogEvents() throws Exception {
106        waitAndClickByLinkText("Dialog Events");
107        waitAndClickByXpath("//section[@id='Demo-DialogGroup-Example7']/button");
108        waitAndClickByXpath("//section[@id='Demo-DialogGroup-DialogEvents']/div/div/div[@data-parent='Demo-DialogGroup-DialogEvents']/button[contains(text(),'Continue')]");
109        acceptAlertIfPresent();
110        acceptAlertIfPresent();
111        waitAndClickByXpath("//section[@id='Demo-DialogGroup-Example7']/button");
112        waitAndClickByXpath("//section[@id='Demo-DialogGroup-DialogEvents']/div/div/div[@data-parent='Demo-DialogGroup-DialogEvents']/button[contains(text(),'Log out')]");
113        acceptAlertIfPresent();
114        acceptAlertIfPresent();
115    }
116    
117    protected void testContainerDialogGroupServerDialog1() throws Exception {
118        waitAndClickByLinkText("Server Dialog Ex. 1");
119        waitAndClickByXpath("//section[@id='Demo-DialogGroup-Example8']/button");
120        waitForProgressLoading();
121        waitAndClickByXpath(
122                "//section[@id='Demo-DialogGroup-ServerResponse1']/div/div/div[@data-parent='Demo-DialogGroup-ServerResponse1']/button[contains(text(),'Yes')]");
123        waitForElementPresentByXpath("//div[@id='Demo-DialogGroup-Example8_messages']/ul/li[contains(text(), 'Save was completed.')]");
124    }
125    
126    protected void testContainerDialogGroupServerDialog2() throws Exception {
127        waitAndClickByLinkText("Server Dialog Ex. 2");
128        waitAndClickByXpath("//section[@id='Demo-DialogGroup-Example9']/button");
129        waitForProgressLoading();
130        waitAndClickByXpath("//section[@id='Demo-DialogGroup-ServerResponse2']/div/div/div[@data-parent='Demo-DialogGroup-ServerResponse2']/button[contains(text(),'OK')]");
131        waitForElementPresentByXpath("//a[contains(text(),'Required')]");
132        waitIsVisible(By.xpath("//section[@id='Demo-DialogGroup-ServerResponse2']/div/div/div[@data-parent='Demo-DialogGroup-ServerResponse2']/button[contains(text(),'Cancel')]"));
133        waitAndClickByXpath("//section[@id='Demo-DialogGroup-ServerResponse2']/div/div/div[@data-parent='Demo-DialogGroup-ServerResponse2']/button[contains(text(),'Cancel')]");
134    }
135
136    protected void testContainerDialogGroupAjaxRetrieval() throws Exception {
137        waitAndClickByLinkText("Ajax Retrieval");
138        //Needs to fix the functionality.
139    }
140    
141    protected void testContainerDialogGroupValidationInDialog() throws Exception {
142        waitAndClickByLinkText("Validation in Dialog");
143        waitAndClickByLinkText("Show Dialog");
144        waitAndClickByXpath("//section[@id='Demo-DialogGroup-ShowDialog11']/div/div/div[@data-parent='Demo-DialogGroup-ShowDialog11']/button[contains(text(),'Continue')]");
145        waitForElementPresentByXpath("//a[contains(text(),'Field 1: Required')]");
146        waitForElementPresentByXpath("//a[contains(text(),'Field 2: Required')]");
147        waitForElementPresentByXpath("//a[contains(text(),'Field 3: Required')]");
148        waitForElementPresentByXpath("//a[contains(text(),'Field 4: Required')]");
149        waitForElementPresentByXpath("//a[contains(text(),'Field 5: Required')]");
150        waitAndClickByXpath("//section[@id='Demo-DialogGroup-ShowDialog11']/div/div/header/button");
151    }
152
153    protected void testContainerDialogGroupDialogReuse() throws Exception {
154        Thread.sleep(1000); // try to avoid cache problem
155        waitAndClickByLinkText("Dialog Reuse");
156
157        // assert first row data
158        assertEquals("1", waitForElementVisibleBy(By.name("collection2[1].field1")).getAttribute("value"));
159        assertEquals("2", waitForElementVisibleBy(By.name("collection2[1].field2")).getAttribute("value"));
160        assertEquals("3", waitForElementVisibleBy(By.name("collection2[1].field3")).getAttribute("value"));
161
162        jGrowl("Click Delete");
163        // First row is del_line1, noting this here as the second row is del_line0
164        waitAndClickByXpath("//button[@id='Demo-DialogGroup-WizardStep2_del_line1']");
165        jGrowl("Cancel Delete");
166        waitForTextPresent("Are you sure you wish to delete line: 1?");
167        waitAndClickByXpath("//section[@id='Uif-DialogGroup-YesNotmp']/div/div/div[@data-parent='Uif-DialogGroup-YesNo']/button[contains(text(),'No')]");
168
169        // assert first row data not deleted
170        assertEquals("1", waitForElementVisibleBy(By.name("collection2[1].field1")).getAttribute("value"));
171        assertEquals("2", waitForElementVisibleBy(By.name("collection2[1].field2")).getAttribute("value"));
172        assertEquals("3", waitForElementVisibleBy(By.name("collection2[1].field3")).getAttribute("value"));
173
174        jGrowl("Click Delete");
175        waitAndClickByXpath("//button[@id='Demo-DialogGroup-WizardStep2_del_line0']");
176        waitForTextPresent("Are you sure you wish to delete line: A?");
177        jGrowl("Confirm Delete");
178        waitAndClickByXpath("//section[@id='Uif-DialogGroup-YesNotmp']/div/div/div[@data-parent='Uif-DialogGroup-YesNo']/button[contains(text(),'Yes')]");
179        waitForProgressDeletingLine();
180
181        // assert new second row data
182        assertEquals("a", waitForElementVisibleBy(By.name("collection2[2].field1")).getAttribute("value"));
183        assertEquals("b", waitForElementVisibleBy(By.name("collection2[2].field2")).getAttribute("value"));
184        assertEquals("c", waitForElementVisibleBy(By.name("collection2[2].field3")).getAttribute("value"));
185    }
186    
187    protected void testContainerDialogGroupSmallDialog() throws Exception {
188        waitAndClickByLinkText("Small Dialog");
189        waitAndClickByXpath("//section[@id='Demo-DialogGroup-Example13']/a");
190        waitAndClickByXpath("//section[@id='Demo-DialogGroup-ShowSmallDialog']/div/div/div[@data-parent='Demo-DialogGroup-ShowSmallDialog']/button[contains(text(),'OK')]");
191    }
192    
193    protected void testContainerDialogGroupLargeDialog() throws Exception {
194        waitAndClickByLinkText("Large Dialog");
195        waitAndClickByXpath("//section[@id='Demo-DialogGroup-Example14']/a");
196        waitAndClickByXpath("//section[@id='Demo-DialogGroup-ShowLargeDialog']/div/div/div[@data-parent='Demo-DialogGroup-ShowLargeDialog']/button[contains(text(),'OK')]");
197    }
198
199    protected void testContainerDialogGroupDestroyDialogOnHidden() throws Exception {
200        WebElement exampleAnchorElement = findElement(By.cssSelector("a[id^='Demo-DialogGroup-Example15']"));
201        exampleAnchorElement.click();
202        WebElement dialog = findElement(By.cssSelector(
203                "section[id='Demo-DialogGroup-DestroyDialogOnHidden'] > div.modal-dialog"));
204        assertTrue("Dialog should not be visisble on page load.", !dialog.isDisplayed());
205        WebElement dialogLink = findElement(By.cssSelector("section[id='Demo-DialogGroup-Example15'] > a"));
206        dialogLink.click();
207        waitForProgressLoading();
208        dialog = waitForElementVisibleBy(By.cssSelector("section[id='Demo-DialogGroup-DestroyDialogOnHidden']"));
209        WebElement anyButton = dialog.findElement(By.cssSelector("button:first-of-type"));
210        anyButton.click();
211        try {
212            dialog = waitAndGetElementByAttributeValue("id", "Demo-DialogGroup-DestroyDialogOnHidden");
213            assertFalse("Dialog should not be present.", dialog.isDisplayed());
214        } catch (NoSuchElementException exception) {
215        }
216    }
217    
218    protected void testContainerDialogGroupAll() throws Exception {
219        testContainerDialogGroupConfirmAction();
220        testContainerDialogGroupGetDialogResponse1();
221        testContainerDialogGroupGetDialogResponse2();
222        testContainerDialogGroupShowDialog1();
223        testContainerDialogGroupShowDialog2();
224        testContainerDialogGroupServerDialog1();
225//      testContainerDialogGroupServerDialog2(); // fails when run with others, test below
226        testContainerDialogGroupAjaxRetrieval();
227//      testContainerDialogGroupValidationInDialog(); // fails when run with others, test below
228        testContainerDialogGroupDialogReuse();
229//      testContainerDialogGroupSmallDialog(); // fails when run with others, test below
230//      testContainerDialogGroupLargeDialog(); // run below
231//        testContainerDialogGroupDestroyDialogOnHidden(); // run below
232        testContainerDialogGroupDialogEvents(); // run last as it logs out via dialog
233    }
234
235    @Test
236    public void testContainerDialogGroupBookmark() throws Exception {
237        testContainerDialogGroupAll();
238        passed();
239    }
240
241    @Test
242    public void testContainerDialogGroupNav() throws Exception {
243        testContainerDialogGroupAll();
244        passed();
245    }
246
247    @Test
248    public void testContainerDialogGroupLargeDialogBookmark() throws Exception {
249        testContainerDialogGroupLargeDialog();
250        passed();
251    }
252
253    @Test
254    public void testContainerDialogGroupLargeDialogNav() throws Exception {
255        testContainerDialogGroupLargeDialog();
256        passed();
257    }
258
259    @Test
260    public void testContainerDialogGroupServerDialog2Bookmark() throws Exception {
261        testContainerDialogGroupServerDialog2();
262        passed();
263    }
264
265    @Test
266    public void testContainerDialogGroupServerDialog2Nav() throws Exception {
267        testContainerDialogGroupServerDialog2();
268        passed();
269    }
270
271    @Test
272    public void testContainerDialogGroupValidationInDialogBookmark() throws Exception {
273        testContainerDialogGroupValidationInDialog();
274        passed();
275    }
276
277    @Test
278    public void testContainerDialogGroupValidationInDialogNav() throws Exception {
279        testContainerDialogGroupValidationInDialog();
280        passed();
281    }
282
283    @Test
284    public void testContainerDialogGroupSmallDialogBookmark() throws Exception {
285        testContainerDialogGroupSmallDialog();
286        passed();
287    }
288
289    @Test
290    public void testContainerDialogGroupSmallDialogNav() throws Exception {
291        testContainerDialogGroupSmallDialog();
292        passed();
293    }
294
295    @Test
296    public void testContainerDialogGroupDestroyDialogOnHiddenBookmark() throws Exception {
297        testContainerDialogGroupDestroyDialogOnHidden();
298        passed();
299    }
300
301    @Test
302    public void testContainerDialogGroupDestroyDialogOnHiddenNav() throws Exception {
303        testContainerDialogGroupDestroyDialogOnHidden();
304        passed();
305    }
306}