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( - - - , - ); - - 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( - - - , - ); - - 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( - - - , - ); - - // 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( - - - , - ); - - expect( - screen.getByText("AUTH$EMAIL_VERIFIED_PLEASE_LOGIN"), - ).toBeInTheDocument(); - }); - - it("should not display email verified message when emailVerified prop is false", () => { - render( - - - , - ); - - expect( - screen.queryByText("AUTH$EMAIL_VERIFIED_PLEASE_LOGIN"), - ).not.toBeInTheDocument(); - }); - - it("should open Terms of Service link in new tab", () => { - render( - - - , - ); - - 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( - - - , - ); - - 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( - - - , - ); - }; - - 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 ( - - - - {emailVerified && ( -
-

- {t(I18nKey.AUTH$EMAIL_VERIFIED_PLEASE_LOGIN)} -

-
- )} - {hasDuplicatedEmail && ( -
- {t(I18nKey.AUTH$DUPLICATE_EMAIL_ERROR)} -
- )} -
-

- {t(I18nKey.AUTH$SIGN_IN_WITH_IDENTITY_PROVIDER)} -

-
- -
- {noProvidersConfigured ? ( -
- {t(I18nKey.AUTH$NO_PROVIDERS_CONFIGURED)} -
- ) : ( - <> - {showGithub && ( - } - > - {t(I18nKey.GITHUB$CONNECT_TO_GITHUB)} - - )} - - {showGitlab && ( - } - > - {t(I18nKey.GITLAB$CONNECT_TO_GITLAB)} - - )} - - {showBitbucket && ( - } - > - {t(I18nKey.BITBUCKET$CONNECT_TO_BITBUCKET)} - - )} - - {showAzureDevOps && ( - } - > - {t(I18nKey.AZURE_DEVOPS$CONNECT_ACCOUNT)} - - )} - - {showEnterpriseSso && ( - - {t(I18nKey.ENTERPRISE_SSO$CONNECT_TO_ENTERPRISE_SSO)} - - )} - - )} -
- - -
-
- ); -}