//<auto-generated />
// Auto generated header added to ignore this file from sonarcloud because test is not working anymore, see comments below.
//-----------------------------------------------------------------------
// <copyright file="BrowserWasmTests.cs" company="aliasvault">
// Copyright (c) aliasvault. All rights reserved.
// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
// </copyright>
//-----------------------------------------------------------------------

namespace AliasVault.E2ETests.Tests.Client.Shard3;

using Microsoft.Extensions.Configuration;
using Microsoft.Playwright;

/// <summary>
/// End-to-end tests for user two-factor authentication.
/// </summary>
[Parallelizable(ParallelScope.Self)]
[Category("ClientTests")]
[TestFixture]
public class BrowserWasmTests : ClientPlaywrightTest
{
    /// <summary>
    /// Test if setting up two-factor authentication and then logging in works.
    /// </summary>
    /// <returns>Async task.</returns>
    [Test]
    public async Task ShowsWarningWhenWebAssemblyNotSupported()
    {
        // NOTE: Disabling WebAssembly seems to not be (anymore) in the latest versions of Chrome since 133+.
        // The flags used below do not work. Check later if this bug is fixed in Chrome or if testing it this
        // way is not feasible anymore. If not feasible anymore, we should remove this test.
        await Task.Delay(1);
        Assert.Ignore("Disabling WebAssembly seems to not be (anymore) in the latest versions of Chrome since 133+.");

        // Store current browser context and page.
        /*var originalContext = Context;
        var originalPage = Page;

        try
        {
            // Create a new browser context and page with WebAssembly disabled to test the error message.
            var configuration = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                .AddJsonFile($"appsettings.Development.json", optional: true, reloadOnChange: true)
                .AddEnvironmentVariables()
                .Build();
            bool headless = configuration.GetValue("PlaywrightSettings:Headless", true);
            var playwright = await Playwright.CreateAsync();
            Browser = await playwright.Chromium.LaunchAsync(new()
            {
                Args = ["--js-flags=--noexpose-wasm"],
                Headless = headless,
            });
            Context = await Browser.NewContextAsync();
            Page = await Context.NewPageAsync();

            // Navigate to the app.
            await Page.GotoAsync(AppBaseUrl);

            // Wait for error message to appear.
            var errorMessage = Page.Locator("#error-message");
            await errorMessage.WaitForAsync(new LocatorWaitForOptions
            {
                State = WaitForSelectorState.Visible,
                Timeout = 5000,
            });

            // Verify the error message.
            var message = await errorMessage.TextContentAsync();
            Assert.That(message, Does.Contain("AliasVault requires WebAssembly"));
        }
        finally
        {
            // Clean up the test context and page.
            await Page.CloseAsync();
            await Context.CloseAsync();

            // Restore original context and page for further tests.
            Context = originalContext;
            Page = originalPage;
        }*/
    }
}
