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.WebDriverLegacyITBase;
021    
022    import org.junit.Assert;
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 ConfigurationTestViewLegacyIT extends WebDriverLegacyITBase {
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            
043        /**
044         * test for text input field label - style setting and refreshWhenChanged for components not in collection
045         */
046        @Test
047            public void testConfigurationTestView() throws Exception {
048            openConfigurationTestView();
049    
050            selectFrame("iframeportlet");
051            // testing for https://groups.google.com/a/kuali.org/group/rice.usergroup.krad/browse_thread/thread/1e501d07c1141aad#
052            String styleValue = getAttributeByXpath("//span[@id='" + idPrefix + "TextInputField_label_span']","style");
053            // log.info("styleValue is " + styleValue);
054            Assert.assertTrue(idPrefix + "textInputField label does not contain expected style", styleValue.replace(" ", "").contains(
055                    "color:red"));
056    
057            // get current list of options
058            String refreshTextSelectLocator = "//select[@id='" + idPrefix + "RefreshTextField_control']";
059            String[] options1 = getSelectOptionsByXpath(refreshTextSelectLocator);
060            String dropDownSelectLocator = "//select[@id='" + idPrefix + "DropDown_control']";
061            selectByXpath(dropDownSelectLocator, "Vegetables");        
062            Thread.sleep(3000);
063            //get list of options after change
064            String[] options2 = getSelectOptionsByXpath(refreshTextSelectLocator);
065            //verify that the change has occurred
066            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]));
067            //confirm that control gets disabled
068            selectByXpath(dropDownSelectLocator, "None");
069            Thread.sleep(3000);
070            assertEquals("true", getAttributeByXpath(refreshTextSelectLocator, "disabled"));
071            passed();
072            }
073    
074        /**
075         * open the configuration test view page
076         */
077        private void openConfigurationTestView() throws InterruptedException {
078            waitAndClickByLinkText("KRAD");
079            waitAndClickByLinkText("Configuration Test View");
080            waitForPageToLoad();
081        }
082    
083        /**
084         * test adding a line to a collection which uses an add line that has spring expressions that are evaluated on refresh
085         * a specific time is set
086         */
087        @Test    
088        public void testAddLineWithSpecificTime() throws Exception{
089            openConfigurationTestView();
090            
091            selectFrame("iframeportlet");
092            
093            confirmAddLineControlsPresent();
094            
095            String startTimeId = "//*[@id='" +idPrefix + "StartTime" + addLineIdSuffix + "']";      
096    
097            String inputTime = "7:06";
098            waitAndTypeByXpath(startTimeId, inputTime);
099            String amPmSelectLocator = "//*[@id='" + idPrefix + "StartTimeAmPm" + addLineIdSuffix + "']";
100    
101            selectByXpath(amPmSelectLocator, "PM");
102            assertEquals("PM", getAttributeByXpath(amPmSelectLocator, "value"));
103            Thread.sleep(5000); //allow for ajax refresh        
104            waitAndClickByXpath("//button");
105            Thread.sleep(5000); //allow for line to be added
106            //confirm that line has been added
107            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", isElementPresentByXpath("//input[@value='7:06']"));
108            passed();
109        }
110    
111        /**
112         * test adding a line to a collection which has the property refreshWhenChangedPropertyNames set
113         * on more than one component.
114         */
115        @Test
116        public void testAddLineWithAllDay() throws Exception {
117            openConfigurationTestView();
118    
119            selectFrame("iframeportlet");
120    
121            confirmAddLineControlsPresent();
122    
123            String startTimeId = "//*[@id='" + idPrefix + "StartTime" + addLineIdSuffix + "']";
124    
125            String inputTime = "5:20";
126            waitAndTypeByXpath(startTimeId, inputTime);
127    
128            String allDaySelector = "//*[@id='" + idPrefix + "AllDay" + addLineIdSuffix + "']";
129    
130            Thread.sleep(5000); //allow for ajax refresh
131            waitAndClickByXpath(allDaySelector);
132    
133            Thread.sleep(5000); //allow for ajax refresh
134            waitAndClick("div#ConfigurationTestView-ProgressiveRender-TimeInfoSection button");
135            Thread.sleep(5000); //allow for line to be added           
136            passed();
137        }
138    
139        /**
140         * verify that add line controls are present
141         */
142        private void confirmAddLineControlsPresent() {
143            String[] addLineIds = {"StartTime", "StartTimeAmPm", "AllDay"};
144    
145            for (String id: addLineIds) {
146               String tagId = "//*[@id='" + idPrefix + id + addLineIdSuffix + "']";
147               assertTrue("Did not find id " + tagId, isElementPresentByXpath(tagId));
148            }
149        }
150    
151        /**
152         * test adding a line to a collection which uses an add line that has spring expressions that are evaluated on refresh
153         * a specific time is set
154         */
155        @Test  
156        public void testAddLineAllDay() throws Exception{
157            openConfigurationTestView();
158            
159            selectFrame("iframeportlet");
160            
161            confirmAddLineControlsPresent();
162    
163            //store number of rows before adding the lines
164            String cssCountRows = "div#ConfigurationTestView-ProgressiveRender-TimeInfoSection.uif-group div#ConfigurationTestView-ProgressiveRender-TimeInfoSection_disclosureContent.uif-disclosureContent table tbody tr";
165            int rowCount = (getCssCount(cssCountRows));
166    
167            String allDayId = "//*[@id='" + idPrefix + "AllDay" + addLineIdSuffix + "']";        
168            Thread.sleep(5000); //allow for ajax refresh
169            waitAndClickByXpath(allDayId);
170            waitAndClick("div#ConfigurationTestView-ProgressiveRender-TimeInfoSection button");
171            Thread.sleep(5000); //allow for line to be added
172    
173            //confirm that line has been added (by checking for the new delete button)
174            assertEquals("line was not added", rowCount + 1, (getCssCount(cssCountRows)));
175            passed();
176        }
177    }