parent
a62c6cd22b
commit
7128e873a4
|
@ -47,6 +47,7 @@ namespace TerminalAppLocalTests
|
||||||
TEST_METHOD(TestReorderingWithoutGuid);
|
TEST_METHOD(TestReorderingWithoutGuid);
|
||||||
TEST_METHOD(TestLayeringNameOnlyProfiles);
|
TEST_METHOD(TestLayeringNameOnlyProfiles);
|
||||||
TEST_METHOD(TestExplodingNameOnlyProfiles);
|
TEST_METHOD(TestExplodingNameOnlyProfiles);
|
||||||
|
TEST_METHOD(TestHideAllProfiles);
|
||||||
|
|
||||||
TEST_CLASS_SETUP(ClassSetup)
|
TEST_CLASS_SETUP(ClassSetup)
|
||||||
{
|
{
|
||||||
|
@ -1125,4 +1126,69 @@ namespace TerminalAppLocalTests
|
||||||
VERIFY_ARE_EQUAL(L"Windows PowerShell", settings._profiles.at(3)._name);
|
VERIFY_ARE_EQUAL(L"Windows PowerShell", settings._profiles.at(3)._name);
|
||||||
VERIFY_ARE_EQUAL(L"cmd", settings._profiles.at(4)._name);
|
VERIFY_ARE_EQUAL(L"cmd", settings._profiles.at(4)._name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SettingsTests::TestHideAllProfiles()
|
||||||
|
{
|
||||||
|
const std::string settingsWithProfiles{ R"(
|
||||||
|
{
|
||||||
|
"profiles": [
|
||||||
|
{
|
||||||
|
"name" : "profile0",
|
||||||
|
"hidden": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "profile1",
|
||||||
|
"hidden": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})" };
|
||||||
|
|
||||||
|
const std::string settingsWithoutProfiles{ R"(
|
||||||
|
{
|
||||||
|
"profiles": [
|
||||||
|
{
|
||||||
|
"name" : "profile0",
|
||||||
|
"hidden": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "profile1",
|
||||||
|
"hidden": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})" };
|
||||||
|
|
||||||
|
VerifyParseSucceeded(settingsWithProfiles);
|
||||||
|
VerifyParseSucceeded(settingsWithoutProfiles);
|
||||||
|
|
||||||
|
{
|
||||||
|
// Case 1: Good settings
|
||||||
|
CascadiaSettings settings;
|
||||||
|
settings._ParseJsonString(settingsWithProfiles, false);
|
||||||
|
settings.LayerJson(settings._userSettings);
|
||||||
|
|
||||||
|
settings._RemoveHiddenProfiles();
|
||||||
|
Log::Comment(NoThrowString().Format(
|
||||||
|
L"settingsWithProfiles successfully parsed and validated"));
|
||||||
|
VERIFY_ARE_EQUAL(1u, settings._profiles.size());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// Case 2: Bad settings
|
||||||
|
|
||||||
|
CascadiaSettings settings;
|
||||||
|
settings._ParseJsonString(settingsWithoutProfiles, false);
|
||||||
|
settings.LayerJson(settings._userSettings);
|
||||||
|
|
||||||
|
bool caughtExpectedException = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
settings._RemoveHiddenProfiles();
|
||||||
|
}
|
||||||
|
catch (const ::TerminalApp::SettingsException& ex)
|
||||||
|
{
|
||||||
|
VERIFY_IS_TRUE(ex.Error() == ::TerminalApp::SettingsLoadErrors::AllProfilesHidden);
|
||||||
|
caughtExpectedException = true;
|
||||||
|
}
|
||||||
|
VERIFY_IS_TRUE(caughtExpectedException);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,9 @@ static const std::array<std::wstring_view, 2> settingsLoadWarningsLabels {
|
||||||
L"MissingDefaultProfileText",
|
L"MissingDefaultProfileText",
|
||||||
L"DuplicateProfileText"
|
L"DuplicateProfileText"
|
||||||
};
|
};
|
||||||
static const std::array<std::wstring_view, 1> settingsLoadErrorsLabels {
|
static const std::array<std::wstring_view, 2> settingsLoadErrorsLabels {
|
||||||
L"NoProfilesText"
|
L"NoProfilesText",
|
||||||
|
L"AllProfilesHiddenText"
|
||||||
};
|
};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
|
|
|
@ -355,4 +355,14 @@ void CascadiaSettings::_RemoveHiddenProfiles()
|
||||||
_profiles.end(),
|
_profiles.end(),
|
||||||
[](auto&& profile) { return profile.IsHidden(); }),
|
[](auto&& profile) { return profile.IsHidden(); }),
|
||||||
_profiles.end());
|
_profiles.end());
|
||||||
|
|
||||||
|
// Ensure that we still have some profiles here. If we don't, then throw an
|
||||||
|
// exception, so the app can use the defaults.
|
||||||
|
const bool hasProfiles = !_profiles.empty();
|
||||||
|
if (!hasProfiles)
|
||||||
|
{
|
||||||
|
// Throw an exception. This is an invalid state, and we want the app to
|
||||||
|
// be able to gracefully use the default settings.
|
||||||
|
throw ::TerminalApp::SettingsException(::TerminalApp::SettingsLoadErrors::AllProfilesHidden);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,6 +131,10 @@
|
||||||
</data>
|
</data>
|
||||||
<data name="NoProfilesText" xml:space="preserve">
|
<data name="NoProfilesText" xml:space="preserve">
|
||||||
<value>No profiles were found in your settings.
|
<value>No profiles were found in your settings.
|
||||||
|
</value>
|
||||||
|
</data>
|
||||||
|
<data name="AllProfilesHiddenText" xml:space="preserve">
|
||||||
|
<value>All profiles were hidden in your settings. You must have at least one non-hidden profile.
|
||||||
</value>
|
</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="ReloadJsonParseErrorText" xml:space="preserve">
|
<data name="ReloadJsonParseErrorText" xml:space="preserve">
|
||||||
|
|
|
@ -29,7 +29,8 @@ namespace TerminalApp
|
||||||
// that we could not recover from.
|
// that we could not recover from.
|
||||||
enum class SettingsLoadErrors : uint32_t
|
enum class SettingsLoadErrors : uint32_t
|
||||||
{
|
{
|
||||||
NoProfiles = 0
|
NoProfiles = 0,
|
||||||
|
AllProfilesHidden = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
// This is a helper class to wrap up a SettingsLoadErrors into a proper
|
// This is a helper class to wrap up a SettingsLoadErrors into a proper
|
||||||
|
|
Loading…
Reference in a new issue