<commit_before>﻿// Copyright Naked Objects Group Ltd, 45 Station Road, Henley on Thames, UK, RG9 1AT
// Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0.
// 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.

using System;
using System.Linq;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;

namespace NakedObjects.Selenium {
    /// <summary>
    /// Tests for the detailed operation of dialogs, including parameter rendering,
    /// choices, auto-complete, default values, formatting, and validation
    /// </summary>
    public abstract class DialogTestsRoot : AWTest {
        public virtual void PasswordParam() {
            GeminiUrl("object?i1=View&o1=___1.Person--11656&as1=open&d1=ChangePassword&f1_oldPassword=%22%22&f1_newPassword=%22%22&f1_confirm=%22%22");
            //Check that params marked with DataType.Password show up as input type="password" for browser to obscure
            wait.Until(dr => dr.FindElements(By.CssSelector("input")).Count(el => el.GetAttribute("type") == "password") == 3);
        }

        public virtual void ScalarChoicesParm() {
            Url(OrdersMenuUrl);
            OpenActionDialog("Orders By Value");
            SelectDropDownOnField("#ordering1", "Descending");
            Click(OKButton());
            WaitForView(Pane.Single, PaneType.List, "Orders By Value");
            AssertTopItemInListIs("SO51131");
        }

        public virtual void TestCancelDialog() {
            Url(OrdersMenuUrl);
            OpenActionDialog("Orders By Value");
            CancelDialog();
            WaitUntilElementDoesNotExist(".dialog");
        }

        public virtual void FieldsRetainedWhenNavigatingAwayAndBack() {
            GeminiUrl("home?m1=CustomerRepository&d1=FindIndividualCustomerByName");
            ClearFieldThenType("#firstname1", "arthur");
            ClearFieldThenType("#lastname1", "brent");
            //1. Navigating away and back retains values
            ClickRecentButton();
            WaitForView(Pane.Single, PaneType.Recent);
            ClickBackButton();
            WaitForView(Pane.Single, PaneType.Home);
            wait.Until(d => d.FindElement(By.CssSelector("#firstname1")).GetAttribute("value") == "arthur");
            wait.Until(d => d.FindElement(By.CssSelector("#lastname1")).GetAttribute("value") == "brent");
        }

        public virtual void ReopeningADialogThatWasntCancelledDoesNotRetainFields() {
            ClickRecentButton();
            WaitForView(Pane.Single, PaneType.Recent);
            Click(HomeIcon());
            WaitForView(Pane.Single, PaneType.Home);
            GoToMenuFromHomePage("Customers");
            OpenSubMenu("Individuals");
            OpenActionDialog("Find Individual Customer By Name");
            wait.Until(d => d.FindElement(By.CssSelector("#firstname1")).GetAttribute("value") == "");
            wait.Until(d => d.FindElement(By.CssSelector("#lastname1")).GetAttribute("value") == "");
        }

        public virtual void ScalarParmShowsDefaultValue() {
            Url(CustomersMenuUrl);
            GetObjectActions(CustomerServiceActions);
            OpenActionDialog("Find Customer By Account Number");
            var input = WaitForCss(".value input");
            Assert.AreEqual("AW", input.GetAttribute("value"));
        }

        public virtual void DateTimeParmKeepsValue() {
            GeminiUrl("object?o1=___1.Customer--29923&as1=open");
            OpenSubMenu("Orders");
            OpenActionDialog("Search For Orders");
            var fromDate = WaitForCss("#fromdate1");
            Assert.AreEqual("2000-01-01", fromDate.GetAttribute("value")); //Default field value
            ClearFieldThenType("#fromdate1", "01 09 2007");
            //CancelDatePicker("#fromdate1");
            ClearFieldThenType("#todate1", "01 04 2008");
            //CancelDatePicker("#todate1");
            Click(OKButton());
            WaitForView(Pane.Single, PaneType.List, "Search For Orders");
            var details = WaitForCss(".summary .details");
            Assert.AreEqual("Page 1 of 1; viewing 2 of 2 items", details.Text);
        }

        public virtual void TimeSpanParm() {
            GeminiUrl("object?i1=View&o1=___1.Shift--1&as1=open");
            OpenActionDialog("Change Times");
            var rand = new Random();
            var start = new TimeSpan(rand.Next(23), rand.Next(59), 0).ToString(@"hh\:mm");
            ClearFieldThenType("#starttime1", start);
            var end = new TimeSpan(rand.Next(23), rand.Next(59), 0).ToString(@"hh\:mm");
            ClearFieldThenType("#endtime1", end);
            Click(OKButton());
            WaitForTextEquals(".property", 2, "Start Time:\r\n" + start);
            WaitForTextEquals(".property", 3, "End Time:\r\n" + end);
        }

        public virtual void RefChoicesParmKeepsValue() {
            Url(ProductServiceUrl);
            OpenActionDialog("List Products By Sub Category");
            Thread.Sleep(500);
            SelectDropDownOnField("#subcategory1", "Forks");
            Click(OKButton());
            WaitForView(Pane.Single, PaneType.List, "List Products By Sub Category");
            wait.Until(dr => dr.FindElements(By.CssSelector("td.reference"))[0].Text == "HL Fork");
        }<commit_msg>fix test<commit_after>﻿// Copyright Naked Objects Group Ltd, 45 Station Road, Henley on Thames, UK, RG9 1AT
// Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0.
// 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.

using System;
using System.Linq;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;

namespace NakedObjects.Selenium {
    /// <summary>
    /// Tests for the detailed operation of dialogs, including parameter rendering,
    /// choices, auto-complete, default values, formatting, and validation
    /// </summary>
    public abstract class DialogTestsRoot : AWTest {
        public virtual void PasswordParam() {
            GeminiUrl("object?i1=View&o1=___1.Person--11656&as1=open&d1=ChangePassword&f1_oldPassword=%22%22&f1_newPassword=%22%22&f1_confirm=%22%22");
            //Check that params marked with DataType.Password show up as input type="password" for browser to obscure
            wait.Until(dr => dr.FindElements(By.CssSelector("input")).Count(el => el.GetAttribute("type") == "password") == 3);
        }

        public virtual void ScalarChoicesParm() {
            Url(OrdersMenuUrl);
            OpenActionDialog("Orders By Value");
            SelectDropDownOnField("#ordering1", "Descending");
            Click(OKButton());
            WaitForView(Pane.Single, PaneType.List, "Orders By Value");
            AssertTopItemInListIs("SO51131");
        }

        public virtual void TestCancelDialog() {
            Url(OrdersMenuUrl);
            OpenActionDialog("Orders By Value");
            CancelDialog();
            WaitUntilElementDoesNotExist(".dialog");
        }

        public virtual void FieldsRetainedWhenNavigatingAwayAndBack() {
            GeminiUrl("home?m1=CustomerRepository&d1=FindIndividualCustomerByName");
            ClearFieldThenType("#firstname1", "arthur");
            ClearFieldThenType("#lastname1", "brent");
            //1. Navigating away and back retains values
            ClickRecentButton();
            WaitForView(Pane.Single, PaneType.Recent);
            ClickBackButton();
            WaitForView(Pane.Single, PaneType.Home);
            wait.Until(d => d.FindElement(By.CssSelector("#firstname1")).GetAttribute("value") == "arthur");
            wait.Until(d => d.FindElement(By.CssSelector("#lastname1")).GetAttribute("value") == "brent");
        }

        public virtual void ReopeningADialogThatWasntCancelledDoesNotRetainFields() {
            ClickRecentButton();
            WaitForView(Pane.Single, PaneType.Recent);
            Click(HomeIcon());
            WaitForView(Pane.Single, PaneType.Home);
            GoToMenuFromHomePage("Customers");
            OpenSubMenu("Individuals");
            OpenActionDialog("Find Individual Customer By Name");
            wait.Until(d => d.FindElement(By.CssSelector("#firstname1")).GetAttribute("value") == "");
            wait.Until(d => d.FindElement(By.CssSelector("#lastname1")).GetAttribute("value") == "");
        }

        public virtual void ScalarParmShowsDefaultValue() {
            Url(CustomersMenuUrl);
            GetObjectActions(CustomerServiceActions);
            OpenActionDialog("Find Customer By Account Number");
            var input = WaitForCss(".value input");
            Assert.AreEqual("AW", input.GetAttribute("value"));
        }

        public virtual void DateTimeParmKeepsValue() {
            GeminiUrl("object?o1=___1.Customer--29923&as1=open");
            OpenSubMenu("Orders");
            OpenActionDialog("Search For Orders");
            var fromDate = WaitForCss("#fromdate1");
            Assert.AreEqual("1 Jan 2000", fromDate.GetAttribute("value")); //Default field value
            ClearFieldThenType("#fromdate1", "01/09/2007");
            //CancelDatePicker("#fromdate1");
            ClearFieldThenType("#todate1", "01/04/2008");
            //CancelDatePicker("#todate1");
            Thread.Sleep(1000);
            Click(OKButton());
            WaitForView(Pane.Single, PaneType.List, "Search For Orders");
            var details = WaitForCss(".summary .details");
            Assert.AreEqual("Page 1 of 1; viewing 2 of 2 items", details.Text);
        }

        public virtual void TimeSpanParm() {
            GeminiUrl("object?i1=View&o1=___1.Shift--1&as1=open");
            OpenActionDialog("Change Times");
            var rand = new Random();
            var start = new TimeSpan(rand.Next(23), rand.Next(59), 0).ToString(@"hh\:mm");
            ClearFieldThenType("#starttime1", start);
            var end = new TimeSpan(rand.Next(23), rand.Next(59), 0).ToString(@"hh\:mm");
            ClearFieldThenType("#endtime1", end);
            Click(OKButton());
            WaitForTextEquals(".property", 2, "Start Time:\r\n" + start);
            WaitForTextEquals(".property", 3, "End Time:\r\n" + end);
        }

        public virtual void RefChoicesParmKeepsValue() {
            Url(ProductServiceUrl);
            OpenActionDialog("List Products By Sub Category");
            Thread.Sleep(500);
            SelectDropDownOnField("#subcategory1", "Forks");
            Click(OKButton());
            WaitForView(Pane.Single, PaneType.List, "List Products By Sub Category");
            wait.Until(dr => dr.FindElements(By.CssSelector("td.reference"))[0].Text == "HL Fork");
        }
{'fraction_non_alphanumeric': 0.12595979639375376, 'fraction_numerical': 0.01975670779052713, 'mean_word_length': 2.7734375, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, 'https://': 0, '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': '369971', 'n_tokens_mistral': 3267, 'n_tokens_neox': 3090, 'n_words': 718}