/**
 * UI login for the customer portal (seeded demo user).
 * Form: apps/edr-freight-web/portal/src/pages/accounts/LoginPage.tsx.
 * Portal is a different origin (port 5373), so specs visit it via absolute
 * URL — each test here stays on that single origin, no cy.origin needed.
 */
const portal = () => Cypress.env("portalUrl") as string;

describe("portal: UI login", () => {
  it("logs in via the form", () => {
    cy.clearCookies();
    cy.visit(`${portal()}/login`);
    cy.get('input[placeholder="name@company.com or 09XXXXXXXX"]').type("user@gmail.com");
    cy.get('input[placeholder="Enter your password"]').type(
      Cypress.env("demoPassword"),
      { log: false },
    );
    cy.get('button[type="submit"]').click();

    cy.location("pathname", { timeout: 20000 }).should("not.eq", "/login");
    cy.getCookie("auth-token").should("exist");
  });

  it("rejects wrong credentials", () => {
    cy.clearCookies();
    cy.visit(`${portal()}/login`);
    cy.get('input[placeholder="name@company.com or 09XXXXXXXX"]').type("user@gmail.com");
    cy.get('input[placeholder="Enter your password"]').type("definitely-wrong");
    cy.get('button[type="submit"]').click();

    cy.location("pathname").should("eq", "/login");
    cy.getCookie("auth-token").should("not.exist");
  });
});

export {};
