Skip to content

Commit

Permalink
#45 Add KendoDateInput<TOwner> control; #46 Add NgKendoDateInput<TOwn…
Browse files Browse the repository at this point in the history
…er> control
  • Loading branch information
YevgeniyShunevych committed Dec 3, 2019
1 parent 9b4f7ee commit 8999358
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 53 deletions.
69 changes: 30 additions & 39 deletions src/Atata.KendoUI.Tests/KendoDateInputTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,23 @@ private static DateInputPage GoToTestPage()
return Go.To<DateInputPage>();
}

[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<KendoDateInput<SnippetPage>>();

TestControl(control);
}

private void TestControl<TPage>(KendoDateInput<TPage> control)
where TPage : PageObject<TPage>
[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<NgKendoDateInput<SnippetPage>>();

control.Set(null);
control.Should.BeNull();
TestControl(control);
}

[Test]
Expand All @@ -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<TPage>(KendoDateInput<TPage> control)
where TPage : PageObject<TPage>
{
var control = GoToSnippetPage(library).Get<KendoDateInput<SnippetPage>>();
TestControl(control);
}
control.Should.BeEnabled();
control.Should.Not.BeReadOnly();

[Test]
[Explicit]
public void NgKendoDateInput()
{
var control = GoToSnippetPage(KendoLibrary.Angular, "dateinputs/dateinput").
SwitchToFirstFrame().
Get<NgKendoDateInput<SnippetPage>>();
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();
}
}
}
14 changes: 14 additions & 0 deletions src/Atata.KendoUI/Extensions/IWebElementExtensions.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
12 changes: 8 additions & 4 deletions src/Atata.KendoUI/KendoDateInput`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,22 @@ public class KendoDateInput<TOwner> : DateInput<TOwner>

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();
}
}
}
11 changes: 1 addition & 10 deletions src/Atata.KendoUI/NgKendoDateInput`1.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using OpenQA.Selenium;
using OpenQA.Selenium;

namespace Atata.KendoUI
{
Expand All @@ -16,14 +15,6 @@ namespace Atata.KendoUI
public class NgKendoDateInput<TOwner> : KendoDateInput<TOwner>
where TOwner : PageObject<TOwner>
{
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));
Expand Down

0 comments on commit 8999358

Please sign in to comment.