Skip to content

Commit b6387e1

Browse files
test: reduce duplication (#203)
1 parent 2b59239 commit b6387e1

1 file changed

Lines changed: 20 additions & 27 deletions

File tree

tests/unit/app/client_state_test.cpp

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@
1414

1515
namespace {
1616

17+
/**
18+
* @brief Navigates from the initial hosts toolbar selection to the display settings options.
19+
*
20+
* @param state Client state to drive through the display settings commands.
21+
*/
22+
void open_display_settings_options(app::ClientState &state) {
23+
app::handle_command(state, input::UiCommand::move_left);
24+
app::handle_command(state, input::UiCommand::move_left);
25+
app::handle_command(state, input::UiCommand::activate);
26+
ASSERT_EQ(state.shell.activeScreen, app::ScreenId::settings);
27+
28+
app::handle_command(state, input::UiCommand::move_down);
29+
app::handle_command(state, input::UiCommand::activate);
30+
ASSERT_EQ(state.settings.selectedCategory, app::SettingsCategory::display);
31+
ASSERT_EQ(state.settings.focusArea, app::SettingsFocusArea::options);
32+
}
33+
1734
TEST(ClientStateTest, StartsOnTheHostsScreenWithTheToolbarSelected) {
1835
const app::ClientState state = app::create_initial_state();
1936

@@ -1018,15 +1035,7 @@ namespace {
10181035
state.settings.preferredVideoMode = state.settings.availableVideoModes.front();
10191036
state.settings.preferredVideoModeSet = true;
10201037

1021-
app::handle_command(state, input::UiCommand::move_left);
1022-
app::handle_command(state, input::UiCommand::move_left);
1023-
app::handle_command(state, input::UiCommand::activate);
1024-
ASSERT_EQ(state.shell.activeScreen, app::ScreenId::settings);
1025-
1026-
app::handle_command(state, input::UiCommand::move_down);
1027-
app::handle_command(state, input::UiCommand::activate);
1028-
ASSERT_EQ(state.settings.selectedCategory, app::SettingsCategory::display);
1029-
ASSERT_EQ(state.settings.focusArea, app::SettingsFocusArea::options);
1038+
ASSERT_NO_FATAL_FAILURE(open_display_settings_options(state));
10301039

10311040
const app::AppUpdate update = app::handle_command(state, input::UiCommand::activate);
10321041
EXPECT_EQ(update.navigation.activatedItemId, "cycle-stream-video-mode");
@@ -1039,15 +1048,7 @@ namespace {
10391048
TEST(ClientStateTest, DisplaySettingsCanCycleStreamFramerateThroughSixtyFps) {
10401049
app::ClientState state = app::create_initial_state();
10411050

1042-
app::handle_command(state, input::UiCommand::move_left);
1043-
app::handle_command(state, input::UiCommand::move_left);
1044-
app::handle_command(state, input::UiCommand::activate);
1045-
ASSERT_EQ(state.shell.activeScreen, app::ScreenId::settings);
1046-
1047-
app::handle_command(state, input::UiCommand::move_down);
1048-
app::handle_command(state, input::UiCommand::activate);
1049-
ASSERT_EQ(state.settings.selectedCategory, app::SettingsCategory::display);
1050-
ASSERT_EQ(state.settings.focusArea, app::SettingsFocusArea::options);
1051+
ASSERT_NO_FATAL_FAILURE(open_display_settings_options(state));
10511052

10521053
ASSERT_TRUE(state.detailMenu.select_item_by_id("cycle-stream-framerate"));
10531054
app::AppUpdate update = app::handle_command(state, input::UiCommand::activate);
@@ -1075,15 +1076,7 @@ namespace {
10751076
ASSERT_TRUE(state.settings.playAudioOnXbox);
10761077
ASSERT_FALSE(state.settings.showPerformanceStats);
10771078

1078-
app::handle_command(state, input::UiCommand::move_left);
1079-
app::handle_command(state, input::UiCommand::move_left);
1080-
app::handle_command(state, input::UiCommand::activate);
1081-
ASSERT_EQ(state.shell.activeScreen, app::ScreenId::settings);
1082-
1083-
app::handle_command(state, input::UiCommand::move_down);
1084-
app::handle_command(state, input::UiCommand::activate);
1085-
ASSERT_EQ(state.settings.selectedCategory, app::SettingsCategory::display);
1086-
ASSERT_EQ(state.settings.focusArea, app::SettingsFocusArea::options);
1079+
ASSERT_NO_FATAL_FAILURE(open_display_settings_options(state));
10871080

10881081
ASSERT_TRUE(state.detailMenu.select_item_by_id("toggle-play-audio-on-xbox"));
10891082
app::AppUpdate update = app::handle_command(state, input::UiCommand::activate);

0 commit comments

Comments
 (0)