Repository: microsoft/terminal (language: cpp)

Issue:
TerminalAppLocalTests::TabTests are failing
### Windows Terminal version

Commit c3fd26a393bd00664a3527f3c973e2cec2344e06

### Windows build number

10.0.19041.1415

### Other Software

_No response_

### Steps to reproduce

1. Checkout the latest code.
2. Build. 
3. Run the `TerminalAppLocalTests` unit tests.

### Expected Behavior

Tests should pass.

### Actual Behavior

Two tests are failing:

    TerminalAppLocalTests::TabTests::TestPreviewCommitScheme [Failed]
    TerminalAppLocalTests::TabTests::TestPreviewDismissScheme [Failed]

As far as I can tell, these first stopped working in commit c3fd26a393bd00664a3527f3c973e2cec2344e06.


Discussion / hints:
That sounds like something I screwed up. Welp. I'll take a look. Thanks ~CI~ @j4james!
3 tests failing for me:
```
TerminalAppLocalTests::TabTests::VerifyCommandPaletteTabSwitcherOrder [Failed]
TerminalAppLocalTests::TabTests::TestPreviewCommitScheme [Failed]
TerminalAppLocalTests::TabTests::TestPreviewDismissScheme [Failed]
```

Fix patch:
diff --git a/src/cascadia/LocalTests_TerminalApp/TabTests.cpp b/src/cascadia/LocalTests_TerminalApp/TabTests.cpp
index ae7f646395a..6fe34c2eb68 100644
--- a/src/cascadia/LocalTests_TerminalApp/TabTests.cpp
+++ b/src/cascadia/LocalTests_TerminalApp/TabTests.cpp
@@ -681,6 +681,10 @@ namespace TerminalAppLocalTests
 
     void TabTests::TryZoomPane()
     {
+        BEGIN_TEST_METHOD_PROPERTIES()
+            TEST_METHOD_PROPERTY(L"IsolationLevel", L"Method")
+        END_TEST_METHOD_PROPERTIES()
+
         auto page = _commonSetup();
 
         Log::Comment(L"Create a second pane");
@@ -1312,7 +1316,8 @@ namespace TerminalAppLocalTests
         TestOnUIThread([&page]() {
             Log::Comment(L"Emulate previewing the SetColorScheme action");
             SetColorSchemeArgs args{ L"Vintage" };
-            page->_PreviewColorScheme(args);
+            ActionAndArgs actionAndArgs{ ShortcutAction::SetColorScheme, args };
+            page->_PreviewAction(actionAndArgs);
         });
 
         TestOnUIThread([&page]() {
@@ -1379,7 +1384,8 @@ namespace TerminalAppLocalTests
         TestOnUIThread([&page]() {
             Log::Comment(L"Emulate previewing the SetColorScheme action");
             SetColorSchemeArgs args{ L"Vintage" };
-            page->_PreviewColorScheme(args);
+            ActionAndArgs actionAndArgs{ ShortcutAction::SetColorScheme, args };
+            page->_PreviewAction(actionAndArgs);
         });
 
         TestOnUIThread([&page]() {
diff --git a/src/cascadia/TerminalApp/ActionPreviewHandlers.cpp b/src/cascadia/TerminalApp/ActionPreviewHandlers.cpp
index 84aba407f74..67212bbbe43 100644
--- a/src/cascadia/TerminalApp/ActionPreviewHandlers.cpp
+++ b/src/cascadia/TerminalApp/ActionPreviewHandlers.cpp
@@ -35,18 +35,18 @@ namespace winrt::TerminalApp::implementation
     // Method Description:
     // - Stop previewing the currently previewed action. We can use this to
     //   clean up any state from that action's preview.
-    // - We use _lastPreviewedCommand to determine what type of action to clean up.
+    // - We use _lastPreviewedAction to determine what type of action to clean up.
     // Arguments:
     // - <none>
     // Return Value:
     // - <none>
     void TerminalPage::_EndPreview()
     {
-        if (_lastPreviewedCommand == nullptr || _lastPreviewedCommand.ActionAndArgs() == nullptr)
+        if (_lastPreviewedAction == nullptr)
         {
             return;
         }
-        switch (_lastPreviewedCommand.ActionAndArgs().Action())
+        switch (_lastPreviewedAction.Action())
         {
         case ShortcutAction::SetColorScheme:
         case ShortcutAction::AdjustOpacity:
@@ -55,7 +55,7 @@ namespace winrt::TerminalApp::implementation
             break;
         }
         }
-        _lastPreviewedCommand = nullptr;
+        _lastPreviewedAction = nullptr;
     }
 
     // Method Description:
@@ -140,6 +140,29 @@ namespace winrt::TerminalApp::implementation
         });
     }
 
+    void TerminalPage::_PreviewAction(const Settings::Model::ActionAndArgs& args)
+    {
+        switch (args.Action())
+        {
+        case ShortcutAction::SetColorScheme:
+            _PreviewColorScheme(args.Args().try_as<SetColorSchemeArgs>());
+            break;
+        case ShortcutAction::AdjustOpacity:
+            _PreviewAdjustOpacity(args.Args().try_as<AdjustOpacityArgs>());
+            break;
+        }
+
+        // GH#9818 Other ideas for actions that could be preview-able:
+        // * Set Font size
+        // * Set acrylic true/false/opacity?
+        // * SetPixelShaderPath?
+        // * SetWindowTheme (light/dark/system/<some theme from #3327>)?
+
+        // Stash this action, so we know what to do when we're done
+        // previewing.
+        _lastPreviewedAction = args;
+    }
+
     // Method Description:
     // - Handler for the CommandPalette::PreviewAction event. The Command
     //   Palette will raise this even when an action is selected, but _not_
@@ -164,29 +187,7 @@ namespace winrt::TerminalApp::implementation
         }
         else
         {
-            switch (args.ActionAndArgs().Action())
-            {
-            case ShortcutAction::SetColorScheme:
-            {
-                _PreviewColorScheme(args.ActionAndArgs().Args().try_as<SetColorSchemeArgs>());
-                break;
-            }
-            case ShortcutAction::AdjustOpacity:
-            {
-                _PreviewAdjustOpacity(args.ActionAndArgs().Args().try_as<AdjustOpacityArgs>());
-                break;
-            }
-            }
-
-            // GH#9818 Other ideas for actions that could be preview-able:
-            // * Set Font size
-            // * Set acrylic true/false/opacity?
-            // * SetPixelShaderPath?
-            // * SetWindowTheme (light/dark/system/<some theme from #3327>)?
-
-            // Stash this action, so we know what to do when we're done
-            // previewing.
-            _lastPreviewedCommand = args;
+            _PreviewAction(args.ActionAndArgs());
         }
     }
 }
diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp
index 2d0078c3747..68010c6c73a 100644
--- a/src/cascadia/TerminalApp/TerminalPage.cpp
+++ b/src/cascadia/TerminalApp/TerminalPage.cpp
@@ -3380,6 +3380,12 @@ namespace winrt::TerminalApp::implementation
     // - Displays a info popup guiding the user into setting their default terminal.
     void TerminalPage::ShowSetAsDefaultInfoBar() const
     {
+        if (::winrt::Windows::UI::Xaml::Application::Current().try_as<::winrt::TerminalApp::App>() == nullptr)
+        {
+            // Just ignore this in the tests (where the Application::Current()
+            // is not a TerminalApp::App)
+            return;
+        }
         if (!CascadiaSettings::IsDefaultTerminalAvailable() || _IsMessageDismissed(InfoBarMessage::SetAsDefault))
         {
             return;
diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h
index 55021a1e896..310910f5228 100644
--- a/src/cascadia/TerminalApp/TerminalPage.h
+++ b/src/cascadia/TerminalApp/TerminalPage.h
@@ -409,12 +409,13 @@ namespace winrt::TerminalApp::implementation
         void _HidePointerCursorHandler(const IInspectable& sender, const IInspectable& eventArgs);
         void _RestorePointerCursorHandler(const IInspectable& sender, const IInspectable& eventArgs);
 
+        void _PreviewAction(const Microsoft::Terminal::Settings::Model::ActionAndArgs& args);
         void _PreviewActionHandler(const IInspectable& sender, const Microsoft::Terminal::Settings::Model::Command& args);
         void _EndPreview();
         void _RunRestorePreviews();
         void _PreviewColorScheme(const Microsoft::Terminal::Settings::Model::SetColorSchemeArgs& args);
         void _PreviewAdjustOpacity(const Microsoft::Terminal::Settings::Model::AdjustOpacityArgs& args);
-        winrt::Microsoft::Terminal::Settings::Model::Command _lastPreviewedCommand{ nullptr };
+        winrt::Microsoft::Terminal::Settings::Model::ActionAndArgs _lastPreviewedAction{ nullptr };
         std::vector<std::function<void()>> _restorePreviewFuncs{};
 
         HRESULT _OnNewConnection(const winrt::Microsoft::Terminal::TerminalConnection::ConptyConnection& connection);


Test patch: