import { expect } from "@wdio/globals";

describe("Application Launch", () => {
  it("should launch the application", async () => {
    // Wait for body element to appear
    const body = await $("body");
    await body.waitForDisplayed({ timeout: 15000 });

    // Verify app launched successfully
    expect(await body.isDisplayed()).toBe(true);
  });

  it("should render the main app container", async () => {
    // The app has a root div with specific classes
    const appContainer = await $("div.h-screen.bg-\\[var\\(--color-background\\)\\]");

    // Verify the main container exists
    expect(await appContainer.isExisting()).toBe(true);
    expect(await appContainer.isDisplayed()).toBe(true);
  });

  it("should show JellyTau branding", async () => {
    // The app should show JellyTau title on login page (default state)
    const title = await $("h1");
    await title.waitForDisplayed({ timeout: 10000 });

    const titleText = await title.getText();
    expect(titleText).toContain("JellyTau");
  });

  it("should redirect unauthenticated users to login", async () => {
    // Wait for login page elements to appear
    const serverUrlInput = await $("#server-url");
    await serverUrlInput.waitForDisplayed({ timeout: 10000 });

    // Verify we're on the login page
    expect(await serverUrlInput.isDisplayed()).toBe(true);
  });
});
