From 8999358ec2098d89a82f992c98355d16661043d2 Mon Sep 17 00:00:00 2001 From: YevgeniyShunevych Date: Tue, 3 Dec 2019 10:31:25 +0200 Subject: [PATCH] #45 Add KendoDateInput control; #46 Add NgKendoDateInput control --- .../KendoDateInputTests.cs | 69 ++++++++----------- .../Extensions/IWebElementExtensions.cs | 14 ++++ src/Atata.KendoUI/KendoDateInput`1.cs | 12 ++-- src/Atata.KendoUI/NgKendoDateInput`1.cs | 11 +-- 4 files changed, 53 insertions(+), 53 deletions(-) create mode 100644 src/Atata.KendoUI/Extensions/IWebElementExtensions.cs diff --git a/src/Atata.KendoUI.Tests/KendoDateInputTests.cs b/src/Atata.KendoUI.Tests/KendoDateInputTests.cs index 1884037..cc7dff3 100644 --- a/src/Atata.KendoUI.Tests/KendoDateInputTests.cs +++ b/src/Atata.KendoUI.Tests/KendoDateInputTests.cs @@ -11,39 +11,23 @@ private static DateInputPage GoToTestPage() return Go.To(); } - [Test] - public void KendoDateInput_Regular() + [PlainTestCaseSource(KendoLibrary.JQuery, KendoLibrary.React, KendoLibrary.Vue)] + public void KendoDateInput(KendoLibrary library) { - var control = GoToTestPage().Regular; - - control.Should.BeNull(); + var control = GoToSnippetPage(library).Get>(); TestControl(control); } - private void TestControl(KendoDateInput control) - where TPage : PageObject + [Test] + [Explicit] + public void NgKendoDateInput() { - control.Should.BeEnabled(); - control.Should.Not.BeReadOnly(); - - DateTime value1 = new DateTime(2018, 7, 11); - control.Set(value1); - control.Should.Equal(value1); - - control.Owner.Press(Keys.Tab); - control.Should.Equal(value1); - - DateTime value2 = new DateTime(2019, 12, 31); - control.Set(value2); - control.Should.Equal(value2); - - DateTime value3 = new DateTime(1995, 5, 19); - control.Set(value3); - control.Should.Equal(value3); + var control = GoToSnippetPage(KendoLibrary.Angular, "dateinputs/dateinput"). + SwitchToFirstFrame(). + Get>(); - control.Set(null); - control.Should.BeNull(); + TestControl(control); } [Test] @@ -66,22 +50,29 @@ public void KendoDateInput_ReadOnly() control.Should.Equal(new DateTime(2005, 7, 20)); } - [PlainTestCaseSource(KendoLibrary.React, KendoLibrary.Vue)] - public void KendoDateInput(KendoLibrary library) + private void TestControl(KendoDateInput control) + where TPage : PageObject { - var control = GoToSnippetPage(library).Get>(); - TestControl(control); - } + control.Should.BeEnabled(); + control.Should.Not.BeReadOnly(); - [Test] - [Explicit] - public void NgKendoDateInput() - { - var control = GoToSnippetPage(KendoLibrary.Angular, "dateinputs/dateinput"). - SwitchToFirstFrame(). - Get>(); + DateTime value1 = new DateTime(2018, 7, 11); + control.Set(value1); + control.Should.Equal(value1); - TestControl(control); + AtataContext.Current.Driver.Perform(x => x.KeyDown(Keys.Shift).SendKeys(Keys.Tab).KeyUp(Keys.Shift)); + control.Should.Equal(value1); + + DateTime value2 = new DateTime(2019, 12, 31); + control.Set(value2); + control.Should.Equal(value2); + + DateTime value3 = new DateTime(1995, 5, 19); + control.Set(value3); + control.Should.Equal(value3); + + control.Set(null); + control.Should.BeNull(); } } } diff --git a/src/Atata.KendoUI/Extensions/IWebElementExtensions.cs b/src/Atata.KendoUI/Extensions/IWebElementExtensions.cs new file mode 100644 index 0000000..e76dd2e --- /dev/null +++ b/src/Atata.KendoUI/Extensions/IWebElementExtensions.cs @@ -0,0 +1,14 @@ +using OpenQA.Selenium; + +namespace Atata.KendoUI +{ + internal static class IWebElementExtensions + { + public static void ClearWithHomeShiftEndDelKeys(this IWebElement element) + { + element.SendKeys(Keys.Home); + AtataContext.Current.Driver.Perform(x => x.KeyDown(Keys.Shift).SendKeys(Keys.End).KeyUp(Keys.Shift)); + element.SendKeys(Keys.Delete); + } + } +} diff --git a/src/Atata.KendoUI/KendoDateInput`1.cs b/src/Atata.KendoUI/KendoDateInput`1.cs index 1d51e5e..6af702c 100644 --- a/src/Atata.KendoUI/KendoDateInput`1.cs +++ b/src/Atata.KendoUI/KendoDateInput`1.cs @@ -30,18 +30,22 @@ public class KendoDateInput : DateInput protected override void SetValue(DateTime? value) { - string valueAsString = ConvertValueToStringUsingSetFormat(value); - IWebElement scope = Scope; + OnClear(); - scope.Clear(); + string valueAsString = ConvertValueToStringUsingSetFormat(value); if (!string.IsNullOrEmpty(valueAsString)) { - scope.SendKeys(Keys.Home); + IWebElement scope = Scope; foreach (char item in valueAsString) scope.SendKeys(item.ToString()); } } + + protected override void OnClear() + { + Scope.ClearWithHomeShiftEndDelKeys(); + } } } diff --git a/src/Atata.KendoUI/NgKendoDateInput`1.cs b/src/Atata.KendoUI/NgKendoDateInput`1.cs index acab125..f7a3ba7 100644 --- a/src/Atata.KendoUI/NgKendoDateInput`1.cs +++ b/src/Atata.KendoUI/NgKendoDateInput`1.cs @@ -1,5 +1,4 @@ -using System; -using OpenQA.Selenium; +using OpenQA.Selenium; namespace Atata.KendoUI { @@ -16,14 +15,6 @@ namespace Atata.KendoUI public class NgKendoDateInput : KendoDateInput where TOwner : PageObject { - protected override void SetValue(DateTime? value) - { - if (value == null) - OnClear(); - else - base.SetValue(value); - } - protected override void OnClear() { Driver.Perform(x => x.KeyDown(Scope, Keys.Control).SendKeys("a").KeyUp(Keys.Control).SendKeys(Keys.Delete));