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