001    /*
002     * Copyright 2006-2012 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    
017    package edu.samplu.travel.krad.test;
018    
019    import edu.samplu.common.UpgradedSeleniumITBase;
020    import org.junit.Assert;
021    import org.junit.Ignore;
022    import org.junit.Test;
023    
024    import static junit.framework.Assert.*;
025    
026    /**
027     * test that configuration test view items work as expected
028     *
029     * @author Kuali Rice Team (rice.collab@kuali.org)
030     */
031    public class ConfigurationTestViewIT extends UpgradedSeleniumITBase {
032        @Override
033        public String getTestUrl() {
034            return PORTAL;
035        }
036        /** bean id prefix in used in view */
037        private String idPrefix = "ConfigurationTestView-ProgressiveRender-";
038        /** bean id suffix for add line controls */
039        String addLineIdSuffix = "InputField_add_control";
040    
041            @Test
042        /**
043         * test for text input field label - style setting and refreshWhenChanged for components not in collection
044         */
045            public void testConfigurationTestView() throws Exception {
046            openConfigurationTestView();
047    
048            // testing for https://groups.google.com/a/kuali.org/group/rice.usergroup.krad/browse_thread/thread/1e501d07c1141aad#
049            String styleValue = selenium.getAttribute("//span[@id='" + idPrefix + "TextInputField_label_span']@style");
050            // log.info("styleValue is " + styleValue);
051            Assert.assertTrue(idPrefix + "textInputField label does not contain expected style", styleValue.replace(" ", "").contains(
052                    "color:red"));
053    
054            // testing for refreshWhenChanged when using spel expressions
055            selenium.selectFrame("iframeportlet");
056            // get current list of options
057            String refreshTextSelectLocator = "id=" + idPrefix + "RefreshTextField_control";
058            String[] options1 = selenium.getSelectOptions(refreshTextSelectLocator);
059            String dropDownSelectLocator = "id=" + idPrefix + "DropDown_control";
060            selenium.select(dropDownSelectLocator, "label=Vegetables");
061            selenium.click("//option[@value='Vegetables']");
062            Thread.sleep(3000);
063            //get list of options after change
064            String[] options2 = selenium.getSelectOptions(refreshTextSelectLocator);
065            //verify that the change has occurred
066            assertFalse(options1[options1.length - 1].equalsIgnoreCase(options2[options2.length - 1]));
067            //confirm that control gets disabled
068            selenium.select(dropDownSelectLocator, "label=None");
069            Thread.sleep(3000);
070            assertEquals("true", selenium.getAttribute(refreshTextSelectLocator+ "@disabled"));
071    
072            }
073    
074        /**
075         * open the configuration test view page
076         */
077        private void openConfigurationTestView() {
078            selenium.click("link=KRAD");
079            selenium.waitForPageToLoad("30000");
080            selenium.isElementPresent("link=Configuration Test View");
081            selenium.click("link=Configuration Test View");
082            selenium.waitForPageToLoad("30000");
083        }
084    
085        /**
086         * test adding a line to a collection which uses an add line that has spring expressions that are evaluated on refresh
087         * a specific time is set
088         */
089        @Test
090        public void testAddLineWithSpecificTime() throws Exception{
091            openConfigurationTestView();
092            confirmAddLineControlsPresent();
093    
094            String startTimeId = "id=" +idPrefix + "StartTime" + addLineIdSuffix;
095            selenium.focus(startTimeId);
096            String inputTime = "7:06";
097            selenium.type(startTimeId, inputTime);
098    
099            String amPmSelectLocator = "id=" + idPrefix + "StartTimeAmPm" + addLineIdSuffix;
100            selenium.click(amPmSelectLocator);
101            selenium.select(amPmSelectLocator, "label=PM");
102            assertEquals("PM", selenium.getSelectedLabel(amPmSelectLocator));
103    
104            Thread.sleep(5000); //allow for ajax refresh
105            selenium.click("css=div#ConfigurationTestView-ProgressiveRender-TimeInfoSection button");
106            Thread.sleep(5000); //allow for line to be added
107    
108            //confirm that line has been added
109            assertTrue("line is not present", selenium.isElementPresent("//input[@value='7:06']"));
110        }
111    
112        /**
113             * test adding a line to a collection which  has the property refreshWhenChangedPropertyNames
114             * set on more than one component.
115             */
116            @Test
117            public void testAddLineWithAllDay() throws Exception{
118                openConfigurationTestView();
119                confirmAddLineControlsPresent();
120    
121                String startTimeId = "id=" +idPrefix + "StartTime" + addLineIdSuffix;
122                selenium.focus(startTimeId);
123                String inputTime = "5:20";
124                selenium.type(startTimeId, inputTime);
125    
126                String allDaySelector = "id=" + idPrefix + "AllDay" + addLineIdSuffix;
127                selenium.focus(allDaySelector);
128                Thread.sleep(5000); //allow for ajax refresh
129                selenium.click(allDaySelector);
130    
131                String amPmSelectLocator = "id=" + idPrefix + "StartTimeAmPm" + addLineIdSuffix;
132                selenium.click(amPmSelectLocator);
133                selenium.select(amPmSelectLocator, "label=PM");
134                assertEquals("PM", selenium.getSelectedLabel(amPmSelectLocator));
135    
136                Thread.sleep(5000); //allow for ajax refresh
137                selenium.click("css=div#ConfigurationTestView-ProgressiveRender-TimeInfoSection button");
138                Thread.sleep(5000); //allow for line to be added
139    
140                //confirm that line has been added
141                assertTrue("line is not present", selenium.isElementPresent("//input[@value='5:20']"));
142            }
143    
144        /**
145         * verify that add line controls are present
146         */
147        private void confirmAddLineControlsPresent() {
148            String[] addLineIds = {"StartTime", "StartTimeAmPm", "AllDay"};
149    
150            for (String id: addLineIds) {
151                String tagId = "id=" + idPrefix + id + addLineIdSuffix;
152               assertTrue("Did not find id " + tagId, selenium.isElementPresent(tagId));
153            }
154        }
155    
156        /**
157         * test adding a line to a collection which uses an add line that has spring expressions that are evaluated on refresh
158         * a specific time is set
159         */
160        @Test
161        @Ignore("count rows through CSS or XPATH fails")
162        public void testAddLineAllDay() throws Exception{
163            openConfigurationTestView();
164            confirmAddLineControlsPresent();
165    
166            //store number of rows before adding the lines
167            String cssCountRows = "div#ConfigurationTestView-ProgressiveRender-TimeInfoSection.uif-group div#ConfigurationTestView-ProgressiveRender-TimeInfoSection_disclosureContent.uif-disclosureContent table tbody tr";
168            int rowCount = (selenium.getCssCount(cssCountRows)).intValue();
169    
170            String allDayId = "id=" + idPrefix + "AllDay" + addLineIdSuffix;
171            selenium.focus(allDayId);
172            Thread.sleep(5000); //allow for ajax refresh
173            selenium.click(allDayId);
174            selenium.click("css=div#ConfigurationTestView-ProgressiveRender-TimeInfoSection button");
175            Thread.sleep(5000); //allow for line to be added
176    
177            //confirm that line has been added (by checking for the new delete button)
178            assertEquals("line was not added", rowCount + 1, (selenium.getCssCount(cssCountRows)).intValue());
179        }
180    }