Skip to content

Commit d47c80f

Browse files
committed
mob
1 parent c869121 commit d47c80f

21 files changed

+2145
-0
lines changed

Plugins.sln

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Community.PowerToys.Run.Plu
2323
EndProject
2424
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Community.PowerToys.Run.Plugin.DenCode.UnitTests", "src\Community.PowerToys.Run.Plugin.DenCode.UnitTests\Community.PowerToys.Run.Plugin.DenCode.UnitTests.csproj", "{BA33AC73-DB36-49E9-9FA9-C309BA818E8F}"
2525
EndProject
26+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Community.PowerToys.Run.Plugin.MobTimer", "src\Community.PowerToys.Run.Plugin.MobTimer\Community.PowerToys.Run.Plugin.MobTimer.csproj", "{956C4880-6C53-87C5-B3F9-E339C319EB65}"
27+
EndProject
28+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Community.PowerToys.Run.Plugin.MobTimer.UnitTests", "src\Community.PowerToys.Run.Plugin.MobTimer.UnitTests\Community.PowerToys.Run.Plugin.MobTimer.UnitTests.csproj", "{10886CC4-8E0E-9661-F25E-F15F1544302F}"
29+
EndProject
2630
Global
2731
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2832
Debug|ARM64 = Debug|ARM64
@@ -111,6 +115,22 @@ Global
111115
{BA33AC73-DB36-49E9-9FA9-C309BA818E8F}.Release|ARM64.Build.0 = Release|ARM64
112116
{BA33AC73-DB36-49E9-9FA9-C309BA818E8F}.Release|x64.ActiveCfg = Release|x64
113117
{BA33AC73-DB36-49E9-9FA9-C309BA818E8F}.Release|x64.Build.0 = Release|x64
118+
{956C4880-6C53-87C5-B3F9-E339C319EB65}.Debug|ARM64.ActiveCfg = Debug|ARM64
119+
{956C4880-6C53-87C5-B3F9-E339C319EB65}.Debug|ARM64.Build.0 = Debug|ARM64
120+
{956C4880-6C53-87C5-B3F9-E339C319EB65}.Debug|x64.ActiveCfg = Debug|x64
121+
{956C4880-6C53-87C5-B3F9-E339C319EB65}.Debug|x64.Build.0 = Debug|x64
122+
{956C4880-6C53-87C5-B3F9-E339C319EB65}.Release|ARM64.ActiveCfg = Release|ARM64
123+
{956C4880-6C53-87C5-B3F9-E339C319EB65}.Release|ARM64.Build.0 = Release|ARM64
124+
{956C4880-6C53-87C5-B3F9-E339C319EB65}.Release|x64.ActiveCfg = Release|x64
125+
{956C4880-6C53-87C5-B3F9-E339C319EB65}.Release|x64.Build.0 = Release|x64
126+
{10886CC4-8E0E-9661-F25E-F15F1544302F}.Debug|ARM64.ActiveCfg = Debug|ARM64
127+
{10886CC4-8E0E-9661-F25E-F15F1544302F}.Debug|ARM64.Build.0 = Debug|ARM64
128+
{10886CC4-8E0E-9661-F25E-F15F1544302F}.Debug|x64.ActiveCfg = Debug|x64
129+
{10886CC4-8E0E-9661-F25E-F15F1544302F}.Debug|x64.Build.0 = Debug|x64
130+
{10886CC4-8E0E-9661-F25E-F15F1544302F}.Release|ARM64.ActiveCfg = Release|ARM64
131+
{10886CC4-8E0E-9661-F25E-F15F1544302F}.Release|ARM64.Build.0 = Release|ARM64
132+
{10886CC4-8E0E-9661-F25E-F15F1544302F}.Release|x64.ActiveCfg = Release|x64
133+
{10886CC4-8E0E-9661-F25E-F15F1544302F}.Release|x64.Build.0 = Release|x64
114134
EndGlobalSection
115135
GlobalSection(SolutionProperties) = preSolution
116136
HideSolutionNode = FALSE

docs/mobtimer.png

44.5 KB
Loading
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<Import Project="../../UnitTests.props" />
4+
5+
<ItemGroup>
6+
<ProjectReference Include="..\Community.PowerToys.Run.Plugin.MobTimer\Community.PowerToys.Run.Plugin.MobTimer.csproj" />
7+
</ItemGroup>
8+
9+
</Project>
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
using Community.PowerToys.Run.Plugin.MobTimer.Models;
2+
using FluentAssertions;
3+
4+
namespace Community.PowerToys.Run.Plugin.MobTimer.UnitTests;
5+
6+
[TestClass]
7+
public class ExtensionsTests
8+
{
9+
[TestMethod]
10+
public void Clean_should_remove_Backspace()
11+
{
12+
$"{Extensions.Backspace} 25".Clean().Should().Be("25");
13+
}
14+
15+
[TestMethod]
16+
public void IsExport_should_check_query()
17+
{
18+
"export".IsExport().Should().BeTrue();
19+
"import".IsExport().Should().BeFalse();
20+
}
21+
22+
[TestMethod]
23+
public void IsImport_should_check_query()
24+
{
25+
"import {}".IsImport().Should().BeTrue();
26+
"export".IsImport().Should().BeFalse();
27+
}
28+
29+
[TestMethod]
30+
public void TryGetDuration_should_parse_int()
31+
{
32+
"25".TryGetDuration(out int duration).Should().BeTrue();
33+
duration.Should().Be(25);
34+
35+
"25a".TryGetDuration(out duration).Should().BeFalse();
36+
duration.Should().Be(0);
37+
}
38+
39+
[TestMethod]
40+
public void TryGetBreaks_should_parse_int()
41+
{
42+
"3".TryGetBreaks(out int breaks).Should().BeTrue();
43+
breaks.Should().Be(3);
44+
45+
"3a".TryGetBreaks(out breaks).Should().BeFalse();
46+
breaks.Should().Be(0);
47+
}
48+
49+
[TestMethod]
50+
public void TryGetParticipant_should_parse_string()
51+
{
52+
"Dave".TryGetParticipant(out string name).Should().BeTrue();
53+
name.Should().Be("Dave");
54+
55+
"".TryGetParticipant(out name).Should().BeFalse();
56+
name.Should().Be("");
57+
}
58+
59+
[TestMethod]
60+
public void IsValid_Duration_should_validate_duration()
61+
{
62+
new Duration(25).IsValid().Should().BeTrue();
63+
new Duration(0).IsValid().Should().BeFalse();
64+
}
65+
66+
[TestMethod]
67+
public void IsValid_Breaks_should_validate_breaks()
68+
{
69+
new Breaks(3).IsValid().Should().BeTrue();
70+
new Breaks(0).IsValid().Should().BeFalse();
71+
}
72+
73+
[TestMethod]
74+
public void IsValid_Participant_should_validate_name()
75+
{
76+
new Participant("Dave").IsValid().Should().BeTrue();
77+
new Participant("").IsValid().Should().BeFalse();
78+
}
79+
80+
[TestMethod]
81+
public void IsValid_string_should_validate()
82+
{
83+
"Dave".IsValid().Should().BeTrue();
84+
"".IsValid().Should().BeFalse();
85+
}
86+
87+
[TestMethod]
88+
public void Format_double_should_format_time()
89+
{
90+
25.0.Format().Should().Be("25 minutes");
91+
1.0.Format().Should().Be("1 minute");
92+
}
93+
94+
[TestMethod]
95+
public void Format_Duration_should_format_time()
96+
{
97+
new Duration(25).Format().Should().Be("25 minutes");
98+
new Duration(1).Format().Should().Be("1 minute");
99+
}
100+
101+
[TestMethod]
102+
public void Format_int_should_format_periodicity()
103+
{
104+
3.Format().Should().Be("every 3 rotations");
105+
1.Format().Should().Be("after 1 rotation");
106+
}
107+
108+
[TestMethod]
109+
public void Format_Breaks_should_format_periodicity()
110+
{
111+
new Breaks(3).Format().Should().Be("every 3 rotations");
112+
new Breaks(1).Format().Should().Be("after 1 rotation");
113+
}
114+
115+
[TestMethod]
116+
public void RotationsPerDay_double_should_calculate()
117+
{
118+
25.0.RotationsPerDay().Should().Be(14);
119+
}
120+
121+
[TestMethod]
122+
public void RotationsPerDay_Duration_should_calculate()
123+
{
124+
new Duration(25).RotationsPerDay().Should().Be(14);
125+
}
126+
127+
[TestMethod]
128+
public void BreaksPerDay_int_should_calculate()
129+
{
130+
3.BreaksPerDay(new Duration(25)).Should().Be(4);
131+
}
132+
133+
[TestMethod]
134+
public void BreaksPerDay_Breaks_should_calculate()
135+
{
136+
new Breaks(3).BreaksPerDay(new Duration(25)).Should().Be(4);
137+
}
138+
139+
[TestMethod]
140+
public void IsPlural_double_should_evaluate()
141+
{
142+
2.0.IsPlural().Should().BeTrue();
143+
1.0.IsPlural().Should().BeFalse();
144+
}
145+
146+
[TestMethod]
147+
public void IsPlural_int_should_evaluate()
148+
{
149+
2.IsPlural().Should().BeTrue();
150+
1.IsPlural().Should().BeFalse();
151+
}
152+
153+
[TestMethod]
154+
public void IsExpired_Rotation_should_evaluate_End()
155+
{
156+
var subject = new Rotation(new(1));
157+
subject.IsExpired().Should().BeFalse();
158+
159+
subject.End = DateTime.Now;
160+
subject.IsExpired().Should().BeFalse();
161+
162+
subject.End = DateTime.Now.AddDays(-1);
163+
subject.IsExpired().Should().BeTrue();
164+
}
165+
}
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
using Community.PowerToys.Run.Plugin.MobTimer.Models;
2+
using FluentAssertions;
3+
using Moq;
4+
using Wox.Plugin;
5+
using Timer = Community.PowerToys.Run.Plugin.MobTimer.Models.Timer;
6+
7+
namespace Community.PowerToys.Run.Plugin.MobTimer.UnitTests;
8+
9+
[TestClass]
10+
public class MainTests
11+
{
12+
private Mock<IMobTimerService> _mock = null!;
13+
private Main _subject = null!;
14+
15+
[TestInitialize]
16+
public void TestInitialize()
17+
{
18+
var settings = new MobTimerSettings();
19+
var session = new MobTimerSession();
20+
_mock = new Mock<IMobTimerService>();
21+
22+
_subject = new Main(settings, session, _mock.Object);
23+
}
24+
25+
[TestMethod]
26+
public void Query_export()
27+
{
28+
_subject.Query(new("export"))
29+
.Should().BeEquivalentTo(
30+
[
31+
new Result { Title = "Export", SubTitle = "Export mob session", IcoPath = @"Images\mobtimer.png" },
32+
]);
33+
}
34+
35+
[TestMethod]
36+
public void Query_import()
37+
{
38+
_subject.Query(new("import {}"))
39+
.Should().BeEquivalentTo(
40+
[
41+
new Result { Title = "Import", SubTitle = "Import mob session", IcoPath = @"Images\mobtimer.png" },
42+
]);
43+
}
44+
45+
[TestMethod]
46+
public void Query_()
47+
{
48+
_subject.Query(new(""))
49+
.Should().BeEquivalentTo(
50+
[
51+
new Result { Title = "Start timer", SubTitle = "Start timer for new rotation", IcoPath = @"Images\mobtimer.png" },
52+
new Result { Title = "Duration: 20 minutes", SubTitle = "Duration in minutes for each rotation", IcoPath = @"Images\mobtimer.png" },
53+
new Result { Title = "Break: every 2 rotations", SubTitle = "Take a break after completing a number of rotations", IcoPath = @"Images\mobtimer.png" },
54+
new Result { Title = "Alice", SubTitle = "Participant of mob session", IcoPath = @"Images\mobtimer.png" },
55+
new Result { Title = "Bob", SubTitle = "Participant of mob session", IcoPath = @"Images\mobtimer.png" },
56+
new Result { Title = "Charlie", SubTitle = "Participant of mob session", IcoPath = @"Images\mobtimer.png" },
57+
]);
58+
}
59+
60+
[TestMethod]
61+
public void Query_int()
62+
{
63+
_subject.Query(new("3"))
64+
.Should().ContainEquivalentOf(
65+
new Result { Title = "Set duration: 3 minutes", SubTitle = "Duration in minutes for each rotation", IcoPath = @"Images\mobtimer.png" }
66+
)
67+
.And.ContainEquivalentOf(
68+
new Result { Title = "Set break: every 3 rotations", SubTitle = "Take a break after completing a number of rotations", IcoPath = @"Images\mobtimer.png" }
69+
);
70+
}
71+
72+
[TestMethod]
73+
public void Query_string()
74+
{
75+
_subject.Query(new("Dave"))
76+
.Should().ContainEquivalentOf(
77+
new Result { Title = "Dave", SubTitle = "Add participant to mob session", IcoPath = @"Images\mobtimer.png" }
78+
);
79+
}
80+
81+
[TestMethod]
82+
public void LoadContextMenus_Start()
83+
{
84+
var result = new Result { ContextData = new Start(new(1)) };
85+
_subject.LoadContextMenus(result)
86+
.Should().HaveCount(1)
87+
.And.Contain(x => x.Title == "Start (Enter)");
88+
}
89+
90+
[TestMethod]
91+
public void LoadContextMenus_Timer_IsRunning()
92+
{
93+
_mock.Setup(x => x.IsRunning).Returns(true);
94+
var result = new Result { ContextData = new Timer() };
95+
_subject.LoadContextMenus(result)
96+
.Should().HaveCount(2)
97+
.And.Contain(x => x.Title == "Pause (Enter)")
98+
.And.Contain(x => x.Title == "Clear (Delete)");
99+
}
100+
101+
[TestMethod]
102+
public void LoadContextMenus_Timer_IsNotRunning()
103+
{
104+
_mock.Setup(x => x.IsRunning).Returns(false);
105+
var result = new Result { ContextData = new Timer() };
106+
_subject.LoadContextMenus(result)
107+
.Should().HaveCount(2)
108+
.And.Contain(x => x.Title == "Resume (Enter)")
109+
.And.Contain(x => x.Title == "Clear (Delete)");
110+
}
111+
112+
[TestMethod]
113+
public void LoadContextMenus_Duration()
114+
{
115+
var result = new Result { ContextData = new Duration(1) };
116+
_subject.LoadContextMenus(result)
117+
.Should().HaveCount(1)
118+
.And.Contain(x => x.Title == "Reset to default (Delete)");
119+
}
120+
121+
[TestMethod]
122+
public void LoadContextMenus_Breaks()
123+
{
124+
var result = new Result { ContextData = new Breaks(1) };
125+
_subject.LoadContextMenus(result)
126+
.Should().HaveCount(1)
127+
.And.Contain(x => x.Title == "Reset to default (Delete)");
128+
}
129+
130+
[TestMethod]
131+
public void LoadContextMenus_Participant()
132+
{
133+
var result = new Result { ContextData = new Participant("A") };
134+
_subject.LoadContextMenus(result)
135+
.Should().HaveCount(4)
136+
.And.Contain(x => x.Title == "Select as driver (Enter)")
137+
.And.Contain(x => x.Title == "Move up (Alt + Up)")
138+
.And.Contain(x => x.Title == "Move down (Alt + Down)")
139+
.And.Contain(x => x.Title == "Remove (Delete)");
140+
}
141+
142+
[TestMethod]
143+
public void LoadContextMenus_Set_Duration()
144+
{
145+
var result = new Result { ContextData = new Set<Duration>(new(1)) };
146+
_subject.LoadContextMenus(result)
147+
.Should().HaveCount(1)
148+
.And.Contain(x => x.Title == "Set duration (Enter)");
149+
}
150+
151+
[TestMethod]
152+
public void LoadContextMenus_Set_Breaks()
153+
{
154+
var result = new Result { ContextData = new Set<Breaks>(new(1)) };
155+
_subject.LoadContextMenus(result)
156+
.Should().HaveCount(1)
157+
.And.Contain(x => x.Title == "Set break (Enter)");
158+
}
159+
160+
[TestMethod]
161+
public void LoadContextMenus_Add_Participant()
162+
{
163+
var result = new Result { ContextData = new Add<Participant>(new("A")) };
164+
_subject.LoadContextMenus(result)
165+
.Should().HaveCount(1)
166+
.And.Contain(x => x.Title == "Add participant (Enter)");
167+
}
168+
169+
[TestMethod]
170+
public void LoadContextMenus_Export()
171+
{
172+
var result = new Result { ContextData = new Export() };
173+
_subject.LoadContextMenus(result)
174+
.Should().HaveCount(1)
175+
.And.Contain(x => x.Title == "Export (Enter)");
176+
}
177+
178+
[TestMethod]
179+
public void LoadContextMenus_Import()
180+
{
181+
var result = new Result { ContextData = new Import("import {}") };
182+
_subject.LoadContextMenus(result)
183+
.Should().HaveCount(1)
184+
.And.Contain(x => x.Title == "Import (Enter)");
185+
}
186+
}

0 commit comments

Comments
 (0)