From 284b3904e6e811c03f865be16d58b52a8598a0bb Mon Sep 17 00:00:00 2001 From: Jon Kafton <939376+jonkafton@users.noreply.github.com> Date: Thu, 8 May 2025 17:04:24 +0200 Subject: [PATCH 1/2] Remove onboarding finish navigation from next param --- .../OnboardingPage/OnboardingPage.test.tsx | 38 ++----------------- .../OnboardingPage/OnboardingPage.tsx | 8 ---- 2 files changed, 3 insertions(+), 43 deletions(-) diff --git a/frontends/main/src/app-pages/OnboardingPage/OnboardingPage.test.tsx b/frontends/main/src/app-pages/OnboardingPage/OnboardingPage.test.tsx index dc624f4000..3b40667b6d 100644 --- a/frontends/main/src/app-pages/OnboardingPage/OnboardingPage.test.tsx +++ b/frontends/main/src/app-pages/OnboardingPage/OnboardingPage.test.tsx @@ -4,6 +4,7 @@ import { merge, times } from "lodash" import { renderWithProviders, screen, + waitFor, setMockResponse, user, } from "../../test-utils" @@ -18,32 +19,8 @@ import { type Profile, } from "api/v0" -import { waitFor } from "@testing-library/react" - import OnboardingPage from "./OnboardingPage" -const oldWindowLocation = window.location - -beforeAll(() => { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - delete (window as any).location - - window.location = Object.defineProperties( - {} as unknown as string & Location, - { - ...Object.getOwnPropertyDescriptors(oldWindowLocation), - assign: { - configurable: true, - value: jest.fn(), - }, - }, - ) -}) - -afterAll(() => { - window.location = oldWindowLocation as unknown as string & Location -}) - const STEPS_DATA: Partial[] = [ { topic_interests: [factories.learningResources.topic()], @@ -91,9 +68,7 @@ const setup = async (profile: Profile) => { ...req, })) - renderWithProviders(, { - url: "/onboarding?next=http%3A%2F%2Flearn.mit.edu", - }) + renderWithProviders() } // this function sets up the test and progresses the UI to the designated step @@ -132,15 +107,8 @@ describe("OnboardingPage", () => { const nextStep = step + 1 await setupAndProgressToStep(step) if (step === STEP_TITLES.length - 1) { - const finishButton = await findFinishButton() - + await findFinishButton() expect(queryBackButton()).not.toBeNil() - - await user.click(finishButton) - await waitFor(() => { - expect(window.location).toBe("http://learn.mit.edu") - }) - return } diff --git a/frontends/main/src/app-pages/OnboardingPage/OnboardingPage.tsx b/frontends/main/src/app-pages/OnboardingPage/OnboardingPage.tsx index 0f8e53cf51..499cebb1ac 100644 --- a/frontends/main/src/app-pages/OnboardingPage/OnboardingPage.tsx +++ b/frontends/main/src/app-pages/OnboardingPage/OnboardingPage.tsx @@ -27,8 +27,6 @@ import { DASHBOARD_HOME } from "@/common/urls" import { useFormik } from "formik" import { useLearningResourceTopics } from "api/hooks/learningResources" import { useUserMe } from "api/hooks/user" - -import { useSearchParams } from "next/navigation" import { CERTIFICATE_CHOICES, EDUCATION_LEVEL_OPTIONS, @@ -158,8 +156,6 @@ const OnboardingPage: React.FC = () => { const { isLoading: userLoading, data: user } = useUserMe() const [activeStep, setActiveStep] = React.useState(0) const router = useRouter() - const searchParams = useSearchParams() - const nextUrl = searchParams.get("next") const formik = useFormik({ enableReinitialize: true, @@ -175,10 +171,6 @@ const OnboardingPage: React.FC = () => { if (activeStep < NUM_STEPS - 1) { setActiveStep((prevActiveStep) => prevActiveStep + 1) } else { - if (nextUrl) { - ;(window as Window).location = nextUrl - return null - } router.push(DASHBOARD_HOME) } }, From 2dcdf4ad4120e6f6071d4fafce8c8d6c45abdf55 Mon Sep 17 00:00:00 2001 From: Jon Kafton <939376+jonkafton@users.noreply.github.com> Date: Thu, 8 May 2025 18:09:04 +0200 Subject: [PATCH 2/2] Remove param in test --- authentication/views.py | 5 ++--- authentication/views_test.py | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/authentication/views.py b/authentication/views.py index d052d20593..8e7f92c780 100644 --- a/authentication/views.py +++ b/authentication/views.py @@ -4,7 +4,7 @@ from django.contrib.auth import logout from django.shortcuts import redirect -from django.utils.http import url_has_allowed_host_and_scheme, urlencode +from django.utils.http import url_has_allowed_host_and_scheme from django.views import View from main import settings @@ -80,8 +80,7 @@ def get( not profile.completed_onboarding and request.GET.get("skip_onboarding", "0") == "0" ): - params = urlencode({"next": redirect_url}) - redirect_url = f"{settings.MITOL_NEW_USER_LOGIN_URL}?{params}" + redirect_url = settings.MITOL_NEW_USER_LOGIN_URL profile.completed_onboarding = True profile.save() return redirect(redirect_url) diff --git a/authentication/views_test.py b/authentication/views_test.py index 53be67ebe6..9333c006e6 100644 --- a/authentication/views_test.py +++ b/authentication/views_test.py @@ -120,7 +120,6 @@ def test_custom_login_view_authenticated_user_with_onboarding(mocker): request.user = MagicMock(is_anonymous=False) request.user.profile = MagicMock(completed_onboarding=False) mocker.patch("authentication.views.get_redirect_url", return_value="/dashboard") - mocker.patch("authentication.views.urlencode", return_value="next=/dashboard") mocker.patch( "authentication.views.settings.MITOL_NEW_USER_LOGIN_URL", "/onboarding" ) @@ -128,7 +127,7 @@ def test_custom_login_view_authenticated_user_with_onboarding(mocker): response = CustomLoginView().get(request) assert response.status_code == 302 - assert response.url == "/onboarding?next=/dashboard" + assert response.url == "/onboarding" def test_custom_login_view_authenticated_user_skip_onboarding(mocker):