|
| 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