Skip to content

Commit e5759a1

Browse files
Added tests
1 parent b82c5af commit e5759a1

1 file changed

Lines changed: 67 additions & 2 deletions

File tree

tests/adapters_unit_tests/controllers/settings_controller_tests.cpp

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ TEST_F(ASettingsController, SuceedsInitialisingPropertyMaps)
194194
};
195195

196196
// Act
197-
// This calls a slot on the settings controller which causes the property
198-
// maps to be
197+
// This calls a slot on the settings controller that causes the property
198+
// maps to be stored
199199
emit settingsServiceMock.settingsLoaded(settings);
200200

201201

@@ -212,5 +212,70 @@ TEST_F(ASettingsController, SuceedsInitialisingPropertyMaps)
212212
EXPECT_EQ(upKeyValue, shortcutsMap->value("MoveUp").toString());
213213
}
214214

215+
TEST_F(ASettingsController, SucceedsCheckingIfAShortcutIsAlreadyInUse)
216+
{
217+
// Arrange
218+
QString shortcutToCheck = "Ctrl+A";
219+
auto shortcut1 = utility::getNameForEnumValue(SettingKeys::AddBook);
220+
auto shortcut1Value = QVariant::fromValue(shortcutToCheck);
221+
222+
auto shortcut2 = utility::getNameForEnumValue(SettingKeys::ZoomIn);
223+
auto shortcut2Value = QVariant::fromValue(QString("Ctrl+B"));
224+
225+
// App settings sent to initalize the QQmlPropertymaps with
226+
ApplicationSettings settings {
227+
{},
228+
{},
229+
{
230+
{ shortcut1, shortcut1Value },
231+
{ shortcut2, shortcut2Value },
232+
},
233+
};
234+
235+
// Make sure the are stored
236+
emit settingsServiceMock.settingsLoaded(settings);
237+
238+
QString expectedResult = shortcut1;
239+
240+
241+
// Act
242+
auto result = settingsController->checkIfShortcutIsInUse(shortcutToCheck);
243+
244+
// Assert
245+
EXPECT_EQ(expectedResult, result);
246+
}
247+
248+
TEST_F(ASettingsController, FailsCheckingIfAShortcutIsAlreadyInUseIfItIsntUsed)
249+
{
250+
// Arrange
251+
QString unusedShortcut = "Ctrl+C";
252+
auto shortcut1 = utility::getNameForEnumValue(SettingKeys::AddBook);
253+
auto shortcut1Value = QVariant::fromValue(QString("Ctrl+A"));
254+
255+
auto shortcut2 = utility::getNameForEnumValue(SettingKeys::ZoomIn);
256+
auto shortcut2Value = QVariant::fromValue(QString("Ctrl+B"));
257+
258+
// App settings sent to initalize the QQmlPropertymaps with
259+
ApplicationSettings settings {
260+
{},
261+
{},
262+
{
263+
{ shortcut1, shortcut1Value },
264+
{ shortcut2, shortcut2Value },
265+
},
266+
};
267+
268+
// Make sure the are stored
269+
emit settingsServiceMock.settingsLoaded(settings);
270+
271+
QString expectedResult = "";
272+
273+
274+
// Act
275+
auto result = settingsController->checkIfShortcutIsInUse(unusedShortcut);
276+
277+
// Assert
278+
EXPECT_EQ(expectedResult, result);
279+
}
215280

216281
} // namespace tests::adapters

0 commit comments

Comments
 (0)