Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update login pageName to include redirect #3801

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/layouts/Header/components/GuestHeader/GuestHeader.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { render, screen } from '@testing-library/react'
import qs from 'qs'
import React from 'react'
import { MemoryRouter, Route } from 'react-router-dom'

Expand Down Expand Up @@ -47,6 +48,7 @@ describe('GuestHeader', () => {
expect(link).toHaveAttribute('href', 'https://about.codecov.io')
})
})

describe('why test code link', () => {
it('directs user to what is code coverage page', async () => {
render(<GuestHeader />, {
Expand All @@ -61,6 +63,7 @@ describe('GuestHeader', () => {
)
})
})

describe('Get a demo link', () => {
it('directs user to demo page', async () => {
render(<GuestHeader />, {
Expand All @@ -72,6 +75,7 @@ describe('GuestHeader', () => {
expect(link).toHaveAttribute('href', 'https://about.codecov.io/demo')
})
})

describe('pricing link', () => {
it('directs user to pricing page', async () => {
render(<GuestHeader />, {
Expand All @@ -83,17 +87,20 @@ describe('GuestHeader', () => {
expect(link).toHaveAttribute('href', 'https://about.codecov.io/pricing')
})
})

describe('login link', () => {
it('directs user to login page', async () => {
it('directs user to login page with redirect to path', async () => {
render(<GuestHeader />, {
wrapper,
})

const queryString = qs.stringify({ to: '/gh' })
const link = await screen.findByTestId('login-link')
expect(link).toBeInTheDocument()
expect(link).toHaveAttribute('href', '/login')
expect(link).toHaveAttribute('href', `/login?${queryString}`)
})
})

describe('start trial link', () => {
it('directs user to start trial page', async () => {
render(<GuestHeader />, {
Expand Down Expand Up @@ -128,18 +135,21 @@ describe('GuestHeader', () => {
const pricing = screen.queryByText('Pricing')
expect(pricing).not.toBeInTheDocument()
})

it('does not render start free trial link', () => {
render(<GuestHeader />, { wrapper })

const startFreeTrial = screen.queryByText('Start Free Trial')
expect(startFreeTrial).not.toBeInTheDocument()
})
it('renders a login button', () => {

it('renders a login button with redirect to path', () => {
render(<GuestHeader />, { wrapper })

const queryString = qs.stringify({ to: '/gh' })
const login = screen.queryByText('Login')
expect(login).toBeInTheDocument()
expect(login).toHaveAttribute('href', '/')
expect(login).toHaveAttribute('href', `/?${queryString}`)
})
})
})
7 changes: 5 additions & 2 deletions src/layouts/Header/components/GuestHeader/GuestHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useLocation } from 'react-router'

import config from 'config'

import { CodecovIcon } from 'assets/svg/codecov'
Expand Down Expand Up @@ -26,6 +28,7 @@ const LogoButton = () => {

function GuestHeader() {
const isSelfHosted = config.IS_SELF_HOSTED
const location = useLocation()

return (
<div className="border-b">
Expand Down Expand Up @@ -69,7 +72,7 @@ function GuestHeader() {
<ThemeToggle />
{isSelfHosted ? (
<Button
to={{ pageName: 'login' }}
to={{ pageName: 'login', options: { to: location.pathname } }}
variant="primary"
activeClassName="hidden"
exact={true}
Expand All @@ -86,7 +89,7 @@ function GuestHeader() {
className="mx-2 flex items-center justify-between gap-4 md:mx-0"
>
<A
to={{ pageName: 'login' }}
to={{ pageName: 'login', options: { to: location.pathname } }}
variant="guestHeader"
activeClassName="hidden"
isExternal={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { render, screen, waitFor, within } from '@testing-library/react'
import { graphql, HttpResponse } from 'msw'
import { setupServer } from 'msw/node'
import qs from 'qs'
import { Suspense } from 'react'
import { MemoryRouter, Route } from 'react-router-dom'
import { type MockInstance } from 'vitest'
Expand Down Expand Up @@ -364,13 +365,16 @@ describe('CommitFileDiff', () => {
expect(errorMessage).toBeInTheDocument()
})

it('renders a login link', async () => {
it('renders a login link with redirect to path', async () => {
setup({ impactedFile: null })
render(<CommitFileDiff path={'random/path'} />, { wrapper })

const queryString = qs.stringify({
to: '/gh/codecov/gazebo/commit/123sha/folder/subfolder/file.js',
})
const link = await screen.findByText(/logging in/)
expect(link).toBeVisible()
expect(link).toHaveAttribute('href', '/login')
expect(link).toHaveAttribute('href', `/login?${queryString}`)
})
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery as useQueryV5 } from '@tanstack/react-queryV5'
import { Fragment, useMemo } from 'react'
import { useParams } from 'react-router-dom'
import { useLocation, useParams } from 'react-router-dom'

import { IgnoredIdsQueryOptions } from 'pages/CommitDetailPage/queries/IgnoredIdsQueryOptions'
import {
Expand Down Expand Up @@ -122,6 +122,8 @@ function DiffRenderer({
}

function ErrorDisplayMessage() {
const location = useLocation()

return (
<p className="border border-solid border-ds-gray-tertiary p-4">
There was a problem getting the source code from your provider. Unable to
Expand All @@ -132,6 +134,7 @@ function ErrorDisplayMessage() {
<A
to={{
pageName: 'login',
options: { to: location.pathname },
}}
hook={undefined}
isExternal={undefined}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { render, screen, waitFor, within } from '@testing-library/react'
import { graphql, HttpResponse } from 'msw'
import { setupServer } from 'msw/node'
import qs from 'qs'
import { Suspense } from 'react'
import { MemoryRouter, Route } from 'react-router-dom'
import { type MockInstance } from 'vitest'
Expand Down Expand Up @@ -357,9 +358,12 @@ describe('CommitFileDiff', () => {
setup({ impactedFile: null })
render(<CommitFileDiff path={'random/path'} />, { wrapper })

const queryString = qs.stringify({
to: '/gh/codecov/gazebo/commit/123sha/folder/subfolder/file.js',
})
const link = await screen.findByText(/logging in/)
expect(link).toBeVisible()
expect(link).toHaveAttribute('href', '/login')
expect(link).toHaveAttribute('href', `/login?${queryString}`)
})
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useQuery as useQueryV5 } from '@tanstack/react-queryV5'
import PropTypes from 'prop-types'
import { Fragment, useMemo } from 'react'
import { useParams } from 'react-router-dom'
import { useLocation, useParams } from 'react-router-dom'

import { IgnoredIdsQueryOptions } from 'pages/CommitDetailPage/queries/IgnoredIdsQueryOptions'
import {
Expand Down Expand Up @@ -123,6 +123,8 @@ function DiffRenderer({
}

function ErrorDisplayMessage() {
const location = useLocation()

return (
<p className="border border-solid border-ds-gray-tertiary p-4">
There was a problem getting the source code from your provider. Unable to
Expand All @@ -131,9 +133,7 @@ function ErrorDisplayMessage() {
<span>
If you continue to experience this issue, please try{' '}
<A
to={{
pageName: 'login',
}}
to={{ pageName: 'login', options: { to: location.pathname } }}
hook={undefined}
isExternal={undefined}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { render, screen, within } from '@testing-library/react'
import { graphql, HttpResponse } from 'msw'
import { setupServer } from 'msw/node'
import qs from 'qs'
import { Suspense } from 'react'
import { MemoryRouter, Route } from 'react-router-dom'

Expand Down Expand Up @@ -333,13 +334,14 @@ describe('FileDiff', () => {
expect(errorMessage).toBeInTheDocument()
})

it('renders a login link', async () => {
it('renders a login link with redirect to path', async () => {
setup({})
render(<FileDiff path={undefined} />, { wrapper })

const queryString = qs.stringify({ to: '/gh/codecov/cool-repo/pull/1' })
const loginLink = await screen.findByRole('link', { name: /logging in/ })
expect(loginLink).toBeInTheDocument()
expect(loginLink).toHaveAttribute('href', '/login')
expect(loginLink).toHaveAttribute('href', `/login?${queryString}`)
})
})
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Fragment, useMemo } from 'react'
import { useParams } from 'react-router-dom'
import { useLocation, useParams } from 'react-router-dom'

import { useNavLinks } from 'services/navigation/useNavLinks'
import {
Expand Down Expand Up @@ -112,6 +112,8 @@ function DiffRenderer({
}

function ErrorDisplayMessage() {
const location = useLocation()

return (
<p className="border border-solid border-ds-gray-tertiary p-4">
There was a problem getting the source code from your provider. Unable to
Expand All @@ -120,9 +122,7 @@ function ErrorDisplayMessage() {
<span>
If you continue to experience this issue, please try{' '}
<A
to={{
pageName: 'login',
}}
to={{ pageName: 'login', options: { to: location.pathname } }}
hook={undefined}
isExternal={undefined}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { render, screen, within } from '@testing-library/react'
import { graphql, HttpResponse } from 'msw'
import { setupServer } from 'msw/node'
import qs from 'qs'
import { MemoryRouter, Route } from 'react-router-dom'

import PullFileDiff from './PullFileDiff'
Expand Down Expand Up @@ -322,13 +323,14 @@ describe('FileDiff', () => {
expect(errorMessage).toBeInTheDocument()
})

it('renders a login link', async () => {
it('renders a login link with redirect to path', async () => {
setup({})
render(<PullFileDiff path={undefined} />, { wrapper })

const queryString = qs.stringify({ to: '/gh/codecov/cool-repo/pull/1' })
const loginLink = await screen.findByRole('link', { name: /logging in/ })
expect(loginLink).toBeInTheDocument()
expect(loginLink).toHaveAttribute('href', '/login')
expect(loginLink).toHaveAttribute('href', `/login?${queryString}`)
})
})
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Fragment, useMemo } from 'react'
import { useParams } from 'react-router-dom'
import { useLocation, useParams } from 'react-router-dom'

import { useNavLinks } from 'services/navigation/useNavLinks'
import {
Expand Down Expand Up @@ -106,6 +106,8 @@ function DiffRenderer({
}

function ErrorDisplayMessage() {
const location = useLocation()

return (
<p className="border border-solid border-ds-gray-tertiary p-4">
There was a problem getting the source code from your provider. Unable to
Expand All @@ -114,9 +116,7 @@ function ErrorDisplayMessage() {
<span>
If you continue to experience this issue, please try{' '}
<A
to={{
pageName: 'login',
}}
to={{ pageName: 'login', options: { to: location.pathname } }}
hook={undefined}
isExternal={undefined}
>
Expand Down
9 changes: 7 additions & 2 deletions src/shared/RawFileViewer/RawFileViewer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { render, screen, waitFor } from '@testing-library/react'
import { graphql, HttpResponse } from 'msw'
import { setupServer } from 'msw/node'
import qs from 'qs'
import { MemoryRouter, Route } from 'react-router-dom'

import RawFileViewer from './RawFileViewer'
Expand Down Expand Up @@ -359,14 +360,18 @@ describe('RawFileViewer', () => {
expect(errorMessage).toBeInTheDocument()
})

it('renders a login link', async () => {
it('renders a login link with redirect to path', async () => {
render(
<RawFileViewer title="The FileViewer" commit="cool-commit-sha" />,
{ wrapper: wrapper() }
)

const queryString = qs.stringify({
to: '/gh/codecov/cool-repo/blob/branch-name/a/file.js',
})
const link = await screen.findByText(/logging in/)
expect(link).toBeVisible()
expect(link).toHaveAttribute('href', '/login')
expect(link).toHaveAttribute('href', `/login?${queryString}`)
})
})

Expand Down
5 changes: 2 additions & 3 deletions src/shared/RawFileViewer/RawFileViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Title from 'ui/FileViewer/ToggleHeader/Title'
import { VirtualFileRenderer } from 'ui/VirtualRenderers'

function ErrorDisplayMessage() {
const location = useLocation()
return (
<p className="border border-solid border-ds-gray-tertiary p-4">
There was a problem getting the source code from your provider. Unable to
Expand All @@ -24,9 +25,7 @@ function ErrorDisplayMessage() {
<span>
If you continue to experience this issue, please try{' '}
<A
to={{
pageName: 'login',
}}
to={{ pageName: 'login', options: { to: location.pathname } }}
hook={undefined}
isExternal={undefined}
>
Expand Down