// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using Microsoft.CmdPal.Common.Helpers;
using Microsoft.CmdPal.Common.Text;
using Microsoft.CmdPal.UI.ViewModels.Commands;
using Microsoft.CmdPal.UI.ViewModels.MainPage;
using Microsoft.CommandPalette.Extensions;
using Microsoft.CommandPalette.Extensions.Toolkit;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Windows.Foundation;
namespace Microsoft.CmdPal.UI.ViewModels.UnitTests;
///
/// Guardrail tests for the "fast first paint" behavior of the main/root page.
///
/// The typing path renders deterministic in-proc results (top-level commands + installed
/// apps) immediately and folds in slow, out-of-proc fallback contributions asynchronously
/// as they resolve. These tests pin the two invariants that make that safe:
/// 1. Deterministic results are produced without any fallback contribution present, so
/// first paint never waits on a slow source.
/// 2. Late-arriving fallbacks are merged with a fresh score from the same ranker, always
/// at the FallbackFloor tier, so they can never leapfrog deterministic matches, and a
/// superseding query's snapshot replaces any stale one.
///
[TestClass]
public sealed partial class FastFirstPaintTests
{
private static readonly Separator _resultsSeparator = new("Results");
private static readonly Separator _fallbacksSeparator = new("Fallbacks");
// A list item whose Title can be mutated to simulate an extension resolving a dynamic
// fallback title asynchronously, after first paint.
private sealed partial class MutableListItem : IListItem
{
public string Title { get; set; } = string.Empty;
public string Subtitle { get; set; } = string.Empty;
public ICommand Command => new NoOpCommand();
public IDetails? Details => null;
public IIconInfo? Icon => null;
public string Section => string.Empty;
public ITag[] Tags => [];
public string TextToSuggest => string.Empty;
public IContextItem[] MoreCommands => [];
#pragma warning disable CS0067 // The event is never used
public event TypedEventHandler