<commit_before>/*
 * Copyright 2006-2012 The Kuali Foundation
 *
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.opensource.org/licenses/ecl2.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package edu.samplu.travel.krad.test;

import edu.samplu.common.ITUtil;
import edu.samplu.common.UpgradedSeleniumITBase;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;

import static junit.framework.Assert.*;

/**
 * test that configuration test view items work as expected
 *
 * @author K<NAME> (<EMAIL>)
 */
public class ConfigurationTestViewIT extends UpgradedSeleniumITBase {
    @Override
    public String getTestUrl() {
        return ITUtil.PORTAL;
    }
    /** bean id prefix in used in view */
    private String idPrefix = "ConfigurationTestView-ProgressiveRender-";
    /** bean id suffix for add line controls */
    String addLineIdSuffix = "InputField_add_control";

	@Test
    /**
     * test for text input field label - style setting and refreshWhenChanged for components not in collection
     */
	public void testConfigurationTestView() throws Exception {
        openConfigurationTestView();

        // testing for https://groups.google.com/a/kuali.org/group/rice.usergroup.krad/browse_thread/thread/1e501d07c1141aad#
        String styleValue = getAttribute("//span[@id='" + idPrefix + "TextInputField_label_span']@style");
        // log.info("styleValue is " + styleValue);
        Assert.assertTrue(idPrefix + "textInputField label does not contain expected style", styleValue.replace(" ", "").contains(
                "color:red"));

        // testing for refreshWhenChanged when using spel expressions
        selectFrame("iframeportlet");
        // get current list of options
        String refreshTextSelectLocator = "id=" + idPrefix + "RefreshTextField_control";
        String[] options1 = selenium.getSelectOptions(refreshTextSelectLocator);
        String dropDownSelectLocator = "id=" + idPrefix + "DropDown_control";
        select(dropDownSelectLocator, "label=Vegetables");
        waitAndClick("//option[@value='Vegetables']");
        Thread.sleep(3000);
        //get list of options after change
        String[] options2 = selenium.getSelectOptions(refreshTextSelectLocator);
        //verify that the change has occurred
        assertFalse(options1[options1.length - 1].equalsIgnoreCase(options2[options2.length - 1]));
        //confirm that control gets disabled
        select(dropDownSelectLocator, "label=None");
        Thread.sleep(3000);
        assertEquals("true", getAttribute(refreshTextSelectLocator+ "@disabled"));

	}

    /**
     * open the configuration test view page
     */
    private void openConfigurationTestView() throws InterruptedException {
        waitAndClick("link=KRAD");
        waitAndClick("link=Configuration Test View");
        waitForPageToLoad();
    }

    /**
     * test adding a line to a collection which uses an add line that has spring expressions that are evaluated on refresh
     * a specific time is set
     */
    @Test
    public void testAddLineWithSpecificTime() throws Exception{
        openConfigurationTestView();
        confirmAddLineControlsPresent();
        
        String startTimeId = "id=" +idPrefix + "StartTime" + addLineIdSuffix;
        selectFrame("iframeportlet");
        focus(startTimeId);
        String inputTime = "7:06";
        waitAndType(startTimeId, inputTime);
        String amPmSelectLocator = "id=" + idPrefix + "StartTimeAmPm" + addLineIdSuffix;
       // waitAndClick(amPmSelectLocator);
        select(amPmSelectLocator, "label=PM");
        assertEquals("PM", selenium.getSelectedLabel(amPmSelectLocator));
        Thread.sleep(5000); //allow for ajax refresh        
        waitAndClick("//button");
        Thread.sleep(5000); //allow for line to be added
        //confirm that line has been added
        assertTrue("line (//input[@value='7:06'])is not present", isElementPresent("//input[@value='7:06']"));
        
    }

    /**
         * test adding a line to a collection which  has the property refreshWhenChangedPropertyNames
         * set on more than one component.
         */
        @Test
        public void testAddLineWithAllDay() throws Exception{
            openConfigurationTestView();
            confirmAddLineControlsPresent();

            String startTimeId = "id=" +idPrefix + "StartTime" + addLineIdSuffix;
            selectFrame("iframeportlet");
            focus(startTimeId);
            String inputTime = "5:20";
            waitAndType(startTimeId, inputTime);

            String allDaySelector = "id=" + idPrefix + "AllDay" + addLineIdSuffix;
            focus(allDaySelector);
            Thread.sleep(5000); //allow for ajax refresh
            waitAndClick(allDaySelector);
            
            //Since All Day checkbox is selected, asserting PM with default AM would fails the test. Commenting out.
            //Or Else put the commented piece of code before selecting the checkbox. 
            /*
            String amPmSelectLocator = "id=" + idPrefix + "StartTimeAmPm" + addLineIdSuffix;
            waitAndClick(amPmSelectLocator);<commit_msg>KULRICE-7723 : Fix failing smoke tests - add liras to failure messages<commit_after>/*
 * Copyright 2006-2012 The Kuali Foundation
 *
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.opensource.org/licenses/ecl2.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package edu.samplu.travel.krad.test;

import edu.samplu.common.ITUtil;
import edu.samplu.common.UpgradedSeleniumITBase;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;

import static junit.framework.Assert.*;

/**
 * test that configuration test view items work as expected
 *
 * @author <NAME> (<EMAIL>)
 */
public class ConfigurationTestViewIT extends UpgradedSeleniumITBase {
    @Override
    public String getTestUrl() {
        return ITUtil.PORTAL;
    }
    /** bean id prefix in used in view */
    private String idPrefix = "ConfigurationTestView-ProgressiveRender-";
    /** bean id suffix for add line controls */
    String addLineIdSuffix = "InputField_add_control";

	@Test
    /**
     * test for text input field label - style setting and refreshWhenChanged for components not in collection
     */
	public void testConfigurationTestView() throws Exception {
        openConfigurationTestView();

        // testing for https://groups.google.com/a/kuali.org/group/rice.usergroup.krad/browse_thread/thread/1e501d07c1141aad#
        String styleValue = getAttribute("//span[@id='" + idPrefix + "TextInputField_label_span']@style");
        // log.info("styleValue is " + styleValue);
        Assert.assertTrue(idPrefix + "textInputField label does not contain expected style", styleValue.replace(" ", "").contains(
                "color:red"));

        // testing for refreshWhenChanged when using spel expressions
        selectFrame("iframeportlet");
        // get current list of options
        String refreshTextSelectLocator = "id=" + idPrefix + "RefreshTextField_control";
        String[] options1 = selenium.getSelectOptions(refreshTextSelectLocator);
        String dropDownSelectLocator = "id=" + idPrefix + "DropDown_control";
        select(dropDownSelectLocator, "label=Vegetables");
        waitAndClick("//option[@value='Vegetables']");
        Thread.sleep(3000);
        //get list of options after change
        String[] options2 = selenium.getSelectOptions(refreshTextSelectLocator);
        //verify that the change has occurred
        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]));
        //confirm that control gets disabled
        select(dropDownSelectLocator, "label=None");
        Thread.sleep(3000);
        assertEquals("true", getAttribute(refreshTextSelectLocator+ "@disabled"));

	}

    /**
     * open the configuration test view page
     */
    private void openConfigurationTestView() throws InterruptedException {
        waitAndClick("link=KRAD");
        waitAndClick("link=Configuration Test View");
        waitForPageToLoad();
    }

    /**
     * test adding a line to a collection which uses an add line that has spring expressions that are evaluated on refresh
     * a specific time is set
     */
    @Test
    public void testAddLineWithSpecificTime() throws Exception{
        openConfigurationTestView();
        confirmAddLineControlsPresent();
        
        String startTimeId = "id=" +idPrefix + "StartTime" + addLineIdSuffix;
        selectFrame("iframeportlet");
        focus(startTimeId);
        String inputTime = "7:06";
        waitAndType(startTimeId, inputTime);
        String amPmSelectLocator = "id=" + idPrefix + "StartTimeAmPm" + addLineIdSuffix;
       // waitAndClick(amPmSelectLocator);
        select(amPmSelectLocator, "label=PM");
        assertEquals("PM", selenium.getSelectedLabel(amPmSelectLocator));
        Thread.sleep(5000); //allow for ajax refresh        
        waitAndClick("//button");
        Thread.sleep(5000); //allow for line to be added
        //confirm that line has been added
        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']"));
        
    }

    /**
         * test adding a line to a collection which  has the property refreshWhenChangedPropertyNames
         * set on more than one component.
         */
        @Test
        public void testAddLineWithAllDay() throws Exception{
            openConfigurationTestView();
            confirmAddLineControlsPresent();

            String startTimeId = "id=" +idPrefix + "StartTime" + addLineIdSuffix;
            selectFrame("iframeportlet");
            focus(startTimeId);
            String inputTime = "5:20";
            waitAndType(startTimeId, inputTime);

            String allDaySelector = "id=" + idPrefix + "AllDay" + addLineIdSuffix;
            focus(allDaySelector);
            Thread.sleep(5000); //allow for ajax refresh
            waitAndClick(allDaySelector);
            
            //Since All Day checkbox is selected, asserting PM with default AM would fails the test. Commenting out.
            //Or Else put the commented piece of code before selecting the checkbox. 
            /*
            String amPmSelectLocator = "id=" + idPrefix + "StartTimeAmPm" + addLineIdSuffix;
            waitAndClick(amPmSelectLocator);
{'fraction_non_alphanumeric': 0.09659581821323657, 'fraction_numerical': 0.011923276308968377, 'mean_word_length': 3.0190972222222223, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6650494', 'n_tokens_mistral': 3144, 'n_tokens_neox': 2997, 'n_words': 910}