Skip to content

πŸ™Œ OpenHands: AI-Driven Development

refactor(frontend): remove auth modal and related tests (#12307)

Hiep Le6475aa34872b
diff --git a/frontend/__tests__/components/features/auth-modal.test.tsx b/frontend/__tests__/components/features/auth-modal.test.tsx
deleted file mode 100644
index 30550f7106..0000000000
--- a/frontend/__tests__/components/features/auth-modal.test.tsx
+++ /dev/null
@@ -1,217 +0,0 @@
-import { render, screen } from "@testing-library/react";
-import { it, describe, expect, vi, beforeEach, afterEach } from "vitest";
-import userEvent from "@testing-library/user-event";
-import { MemoryRouter } from "react-router";
-import { AuthModal } from "#/components/features/waitlist/auth-modal";
-
-// Mock the useAuthUrl hook
-vi.mock("#/hooks/use-auth-url", () => ({
- useAuthUrl: () => "https://gitlab.com/oauth/authorize",
-}));
-
-// Mock the useTracking hook
-vi.mock("#/hooks/use-tracking", () => ({
- useTracking: () => ({
- trackLoginButtonClick: vi.fn(),
- }),
-}));
-
-describe("AuthModal", () => {
- beforeEach(() => {
- vi.stubGlobal("location", { href: "" });
- });
-
- afterEach(() => {
- vi.unstubAllGlobals();
- vi.resetAllMocks();
- });
-
- it("should render the GitHub and GitLab buttons", () => {
- render(
- <MemoryRouter>
- <AuthModal
- githubAuthUrl="mock-url"
- appMode="saas"
- providersConfigured={["github", "gitlab"]}
- />
- </MemoryRouter>,
- );
-
- const githubButton = screen.getByRole("button", {
- name: "GITHUB$CONNECT_TO_GITHUB",
- });
- const gitlabButton = screen.getByRole("button", {
- name: "GITLAB$CONNECT_TO_GITLAB",
- });
-
- expect(githubButton).toBeInTheDocument();
- expect(gitlabButton).toBeInTheDocument();
- });
-
- it("should redirect to GitHub auth URL when GitHub button is clicked", async () => {
- const user = userEvent.setup();
- const mockUrl = "https://github.com/login/oauth/authorize";
- render(
- <MemoryRouter>
- <AuthModal
- githubAuthUrl={mockUrl}
- appMode="saas"
- providersConfigured={["github"]}
- />
- </MemoryRouter>,
- );
-
- const githubButton = screen.getByRole("button", {
- name: "GITHUB$CONNECT_TO_GITHUB",
- });
- await user.click(githubButton);
-
- expect(window.location.href).toBe(mockUrl);
- });
-
- it("should render Terms of Service and Privacy Policy text with correct links", () => {
- render(
- <MemoryRouter>
- <AuthModal githubAuthUrl="mock-url" appMode="saas" />
- </MemoryRouter>,
- );
-
- // Find the terms of service section using data-testid
- const termsSection = screen.getByTestId("terms-and-privacy-notice");
- expect(termsSection).toBeInTheDocument();
-
- // Check that all text content is present in the paragraph
- expect(termsSection).toHaveTextContent(
- "AUTH$BY_SIGNING_UP_YOU_AGREE_TO_OUR",
- );
- expect(termsSection).toHaveTextContent("COMMON$TERMS_OF_SERVICE");
- expect(termsSection).toHaveTextContent("COMMON$AND");
- expect(termsSection).toHaveTextContent("COMMON$PRIVACY_POLICY");
-
- // Check Terms of Service link
- const tosLink = screen.getByRole("link", {
- name: "COMMON$TERMS_OF_SERVICE",
- });
- expect(tosLink).toBeInTheDocument();
- expect(tosLink).toHaveAttribute("href", "https://www.all-hands.dev/tos");
- expect(tosLink).toHaveAttribute("target", "_blank");
- expect(tosLink).toHaveClass("underline", "hover:text-primary");
-
- // Check Privacy Policy link
- const privacyLink = screen.getByRole("link", {
- name: "COMMON$PRIVACY_POLICY",
- });
- expect(privacyLink).toBeInTheDocument();
- expect(privacyLink).toHaveAttribute(
- "href",
- "https://www.all-hands.dev/privacy",
- );
- expect(privacyLink).toHaveAttribute("target", "_blank");
- expect(privacyLink).toHaveClass("underline", "hover:text-primary");
-
- // Verify that both links are within the terms section
- expect(termsSection).toContainElement(tosLink);
- expect(termsSection).toContainElement(privacyLink);
- });
-
- it("should display email verified message when emailVerified prop is true", () => {
- render(
- <MemoryRouter>
- <AuthModal
- githubAuthUrl="mock-url"
- appMode="saas"
- emailVerified={true}
- />
- </MemoryRouter>,
- );
-
- expect(
- screen.getByText("AUTH$EMAIL_VERIFIED_PLEASE_LOGIN"),
- ).toBeInTheDocument();
- });
-
- it("should not display email verified message when emailVerified prop is false", () => {
- render(
- <MemoryRouter>
- <AuthModal
- githubAuthUrl="mock-url"
- appMode="saas"
- emailVerified={false}
- />
- </MemoryRouter>,
- );
-
- expect(
- screen.queryByText("AUTH$EMAIL_VERIFIED_PLEASE_LOGIN"),
- ).not.toBeInTheDocument();
- });
-
- it("should open Terms of Service link in new tab", () => {
- render(
- <MemoryRouter>
- <AuthModal githubAuthUrl="mock-url" appMode="saas" />
- </MemoryRouter>,
- );
-
- const tosLink = screen.getByRole("link", {
- name: "COMMON$TERMS_OF_SERVICE",
- });
- expect(tosLink).toHaveAttribute("target", "_blank");
- });
-
- it("should open Privacy Policy link in new tab", () => {
- render(
- <MemoryRouter>
- <AuthModal githubAuthUrl="mock-url" appMode="saas" />
- </MemoryRouter>,
- );
-
- const privacyLink = screen.getByRole("link", {
- name: "COMMON$PRIVACY_POLICY",
- });
- expect(privacyLink).toHaveAttribute("target", "_blank");
- });
-
- describe("Duplicate email error message", () => {
- const renderAuthModalWithRouter = (initialEntries: string[]) => {
- const hasDuplicatedEmail = initialEntries.includes(
- "/?duplicated_email=true",
- );
-
- return render(
- <MemoryRouter initialEntries={initialEntries}>
- <AuthModal
- githubAuthUrl="mock-url"
- appMode="saas"
- providersConfigured={["github"]}
- hasDuplicatedEmail={hasDuplicatedEmail}
- />
- </MemoryRouter>,
- );
- };
-
- it("should display error message when duplicated_email query parameter is true", () => {
- // Arrange
- const initialEntries = ["/?duplicated_email=true"];
-
- // Act
- renderAuthModalWithRouter(initialEntries);
-
- // Assert
- const errorMessage = screen.getByText("AUTH$DUPLICATE_EMAIL_ERROR");
- expect(errorMessage).toBeInTheDocument();
- });
-
- it("should not display error message when duplicated_email query parameter is missing", () => {
- // Arrange
- const initialEntries = ["/"];
-
- // Act
- renderAuthModalWithRouter(initialEntries);
-
- // Assert
- const errorMessage = screen.queryByText("AUTH$DUPLICATE_EMAIL_ERROR");
- expect(errorMessage).not.toBeInTheDocument();
- });
- });
-});
diff --git a/frontend/src/components/features/waitlist/auth-modal.tsx b/frontend/src/components/features/waitlist/auth-modal.tsx
deleted file mode 100644
index 6d92cb4dfc..0000000000
--- a/frontend/src/components/features/waitlist/auth-modal.tsx
+++ /dev/null
@@ -1,222 +0,0 @@
-import React from "react";
-import { useTranslation } from "react-i18next";
-import { I18nKey } from "#/i18n/declaration";
-import OpenHandsLogo from "#/assets/branding/openhands-logo.svg?react";
-import { ModalBackdrop } from "#/components/shared/modals/modal-backdrop";
-import { ModalBody } from "#/components/shared/modals/modal-body";
-import { BrandButton } from "../settings/brand-button";
-import GitHubLogo from "#/assets/branding/github-logo.svg?react";
-import GitLabLogo from "#/assets/branding/gitlab-logo.svg?react";
-import BitbucketLogo from "#/assets/branding/bitbucket-logo.svg?react";
-import AzureDevOpsLogo from "#/assets/branding/azure-devops-logo.svg?react";
-import { useAuthUrl } from "#/hooks/use-auth-url";
-import { GetConfigResponse } from "#/api/option-service/option.types";
-import { Provider } from "#/types/settings";
-import { useTracking } from "#/hooks/use-tracking";
-import { TermsAndPrivacyNotice } from "#/components/shared/terms-and-privacy-notice";
-
-interface AuthModalProps {
- githubAuthUrl: string | null;
- appMode?: GetConfigResponse["APP_MODE"] | null;
- authUrl?: GetConfigResponse["AUTH_URL"];
- providersConfigured?: Provider[];
- emailVerified?: boolean;
- hasDuplicatedEmail?: boolean;
-}
-
-export function AuthModal({
- githubAuthUrl,
- appMode,
- authUrl,
- providersConfigured,
- emailVerified = false,
- hasDuplicatedEmail = false,
-}: AuthModalProps) {
- const { t } = useTranslation();
- const { trackLoginButtonClick } = useTracking();
-
- const gitlabAuthUrl = useAuthUrl({
- appMode: appMode || null,
- identityProvider: "gitlab",
- authUrl,
- });
-
- const bitbucketAuthUrl = useAuthUrl({
- appMode: appMode || null,
- identityProvider: "bitbucket",
- authUrl,
- });
-
- const azureDevOpsAuthUrl = useAuthUrl({
- appMode: appMode || null,
- identityProvider: "azure_devops",
- authUrl,
- });
-
- const enterpriseSsoUrl = useAuthUrl({
- appMode: appMode || null,
- identityProvider: "enterprise_sso",
- authUrl,
- });
-
- const handleGitHubAuth = () => {
- if (githubAuthUrl) {
- trackLoginButtonClick({ provider: "github" });
- // Always start the OIDC flow, let the backend handle TOS check
- window.location.href = githubAuthUrl;
- }
- };
-
- const handleGitLabAuth = () => {
- if (gitlabAuthUrl) {
- trackLoginButtonClick({ provider: "gitlab" });
- // Always start the OIDC flow, let the backend handle TOS check
- window.location.href = gitlabAuthUrl;
- }
- };
-
- const handleBitbucketAuth = () => {
- if (bitbucketAuthUrl) {
- trackLoginButtonClick({ provider: "bitbucket" });
- // Always start the OIDC flow, let the backend handle TOS check
- window.location.href = bitbucketAuthUrl;
- }
- };
-
- const handleAzureDevOpsAuth = () => {
- if (azureDevOpsAuthUrl) {
- // Always start the OIDC flow, let the backend handle TOS check
- window.location.href = azureDevOpsAuthUrl;
- }
- };
-
- const handleEnterpriseSsoAuth = () => {
- if (enterpriseSsoUrl) {
- trackLoginButtonClick({ provider: "enterprise_sso" });
- // Always start the OIDC flow, let the backend handle TOS check
- window.location.href = enterpriseSsoUrl;
- }
- };
-
- // Only show buttons if providers are configured and include the specific provider
- const showGithub =
- providersConfigured &&
- providersConfigured.length > 0 &&
- providersConfigured.includes("github");
- const showGitlab =
- providersConfigured &&
- providersConfigured.length > 0 &&
- providersConfigured.includes("gitlab");
- const showBitbucket =
- providersConfigured &&
- providersConfigured.length > 0 &&
- providersConfigured.includes("bitbucket");
- const showAzureDevOps =
- providersConfigured &&
- providersConfigured.length > 0 &&
- providersConfigured.includes("azure_devops");
- const showEnterpriseSso =
- providersConfigured &&
- providersConfigured.length > 0 &&
- providersConfigured.includes("enterprise_sso");
-
- // Check if no providers are configured
- const noProvidersConfigured =
- !providersConfigured || providersConfigured.length === 0;
-
- return (
- <ModalBackdrop>
- <ModalBody className="border border-tertiary">
- <OpenHandsLogo width={68} height={46} />
- {emailVerified && (
- <div className="flex flex-col gap-2 w-full items-center text-center">
- <p className="text-sm text-muted-foreground">
- {t(I18nKey.AUTH$EMAIL_VERIFIED_PLEASE_LOGIN)}
- </p>
- </div>
- )}
- {hasDuplicatedEmail && (
- <div className="text-center text-danger text-sm mt-2 mb-2">
- {t(I18nKey.AUTH$DUPLICATE_EMAIL_ERROR)}
- </div>
- )}
- <div className="flex flex-col gap-2 w-full items-center text-center">
- <h1 className="text-2xl font-bold">
- {t(I18nKey.AUTH$SIGN_IN_WITH_IDENTITY_PROVIDER)}
- </h1>
- </div>
-
- <div className="flex flex-col gap-3 w-full">
- {noProvidersConfigured ? (
- <div className="text-center p-4 text-muted-foreground">
- {t(I18nKey.AUTH$NO_PROVIDERS_CONFIGURED)}
- </div>
- ) : (
- <>
- {showGithub && (
- <BrandButton
- type="button"
- variant="primary"
- onClick={handleGitHubAuth}
- className="w-full font-semibold"
- startContent={<GitHubLogo width={20} height={20} />}
- >
- {t(I18nKey.GITHUB$CONNECT_TO_GITHUB)}
- </BrandButton>
- )}
-
- {showGitlab && (
- <BrandButton
- type="button"
- variant="primary"
- onClick={handleGitLabAuth}
- className="w-full font-semibold"
- startContent={<GitLabLogo width={20} height={20} />}
- >
- {t(I18nKey.GITLAB$CONNECT_TO_GITLAB)}
- </BrandButton>
- )}
-
- {showBitbucket && (
- <BrandButton
- type="button"
- variant="primary"
- onClick={handleBitbucketAuth}
- className="w-full font-semibold"
- startContent={<BitbucketLogo width={20} height={20} />}
- >
- {t(I18nKey.BITBUCKET$CONNECT_TO_BITBUCKET)}
- </BrandButton>
- )}
-
- {showAzureDevOps && (
- <BrandButton
- type="button"
- variant="primary"
- onClick={handleAzureDevOpsAuth}
- className="w-full font-semibold"
- startContent={<AzureDevOpsLogo width={20} height={20} />}
- >
- {t(I18nKey.AZURE_DEVOPS$CONNECT_ACCOUNT)}
- </BrandButton>
- )}
-
- {showEnterpriseSso && (
- <BrandButton
- type="button"
- variant="primary"
- onClick={handleEnterpriseSsoAuth}
- className="w-full font-semibold"
- >
- {t(I18nKey.ENTERPRISE_SSO$CONNECT_TO_ENTERPRISE_SSO)}
- </BrandButton>
- )}
- </>
- )}
- </div>
-
- <TermsAndPrivacyNotice />
- </ModalBody>
- </ModalBackdrop>
- );
-}