This repository has been archived by the owner on Jan 21, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
LineEditDriver.cs
78 lines (68 loc) · 2.45 KB
/
LineEditDriver.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Threading.Tasks;
using Godot;
using GodotTestDriver.Util;
using JetBrains.Annotations;
namespace GodotTestDriver.Drivers
{
/// <summary>
/// Driver for the <see cref="LineEdit"/> control.
/// </summary>
[PublicAPI]
public partial class LineEditDriver<T> : ControlDriver<T> where T:LineEdit
{
public LineEditDriver(Func<T> producer, string description = "") : base(producer, description)
{
}
/// <summary>
/// The current text of the line edit.
/// </summary>
public string Text => PresentRoot.Text;
/// <summary>
/// Whether the line edit is currently editable.
/// </summary>
public bool Editable => PresentRoot.Editable;
/// <summary>
/// Types the given text into the line edit. Existing text will be overwritten.
/// </summary>
public async Task Type(string text)
{
if (!Editable)
{
throw new InvalidOperationException(ErrorMessage("Cannot type text into LineEdit because it is not editable."));
}
var edit = VisibleRoot;
await edit.GetTree().NextFrame();
await ClickCenter();
edit.Text = text;
edit.EmitSignal(LineEdit.SignalName.TextChanged, text);
await edit.GetTree().WaitForEvents();
}
/// <summary>
/// Types the given text into the line edit. Existing text will be overwritten. Presses "enter" afterwards.
/// </summary>
public async Task Submit(string text)
{
if (!Editable)
{
throw new InvalidOperationException(ErrorMessage("Cannot type text into LineEdit because it is not editable."));
}
var edit = VisibleRoot;
// first type the text, so the text change events are triggered
await Type(text);
// then send the "TextSubmitted" event
edit.EmitSignal(LineEdit.SignalName.TextSubmitted, text);
await edit.GetTree().WaitForEvents();
}
}
/// <summary>
/// Driver for the <see cref="LineEdit"/> control.
/// </summary>
[PublicAPI]
public sealed class LineEditDriver : LineEditDriver<LineEdit>
{
public LineEditDriver(Func<LineEdit> producer, string description = "") : base(producer, description)
{
}
}
}