Skip to content

Commit 008a93c

Browse files
Merge branch 'main' into gh-eng-3453-update-not-found-error-to-have-login-button
2 parents 337080c + 9699c04 commit 008a93c

File tree

16 files changed

+233
-79
lines changed

16 files changed

+233
-79
lines changed

src/layouts/Header/components/GuestHeader/GuestHeader.test.tsx

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
22
import { render, screen } from '@testing-library/react'
3+
import qs from 'qs'
34
import React from 'react'
45
import { MemoryRouter, Route } from 'react-router-dom'
56

@@ -47,6 +48,7 @@ describe('GuestHeader', () => {
4748
expect(link).toHaveAttribute('href', 'https://about.codecov.io')
4849
})
4950
})
51+
5052
describe('why test code link', () => {
5153
it('directs user to what is code coverage page', async () => {
5254
render(<GuestHeader />, {
@@ -61,6 +63,7 @@ describe('GuestHeader', () => {
6163
)
6264
})
6365
})
66+
6467
describe('Get a demo link', () => {
6568
it('directs user to demo page', async () => {
6669
render(<GuestHeader />, {
@@ -72,6 +75,7 @@ describe('GuestHeader', () => {
7275
expect(link).toHaveAttribute('href', 'https://about.codecov.io/demo')
7376
})
7477
})
78+
7579
describe('pricing link', () => {
7680
it('directs user to pricing page', async () => {
7781
render(<GuestHeader />, {
@@ -83,17 +87,20 @@ describe('GuestHeader', () => {
8387
expect(link).toHaveAttribute('href', 'https://about.codecov.io/pricing')
8488
})
8589
})
90+
8691
describe('login link', () => {
87-
it('directs user to login page', async () => {
92+
it('directs user to login page with redirect to path', async () => {
8893
render(<GuestHeader />, {
8994
wrapper,
9095
})
9196

97+
const queryString = qs.stringify({ to: '/gh' })
9298
const link = await screen.findByTestId('login-link')
9399
expect(link).toBeInTheDocument()
94-
expect(link).toHaveAttribute('href', '/login')
100+
expect(link).toHaveAttribute('href', `/login?${queryString}`)
95101
})
96102
})
103+
97104
describe('start trial link', () => {
98105
it('directs user to start trial page', async () => {
99106
render(<GuestHeader />, {
@@ -128,18 +135,21 @@ describe('GuestHeader', () => {
128135
const pricing = screen.queryByText('Pricing')
129136
expect(pricing).not.toBeInTheDocument()
130137
})
138+
131139
it('does not render start free trial link', () => {
132140
render(<GuestHeader />, { wrapper })
133141

134142
const startFreeTrial = screen.queryByText('Start Free Trial')
135143
expect(startFreeTrial).not.toBeInTheDocument()
136144
})
137-
it('renders a login button', () => {
145+
146+
it('renders a login button with redirect to path', () => {
138147
render(<GuestHeader />, { wrapper })
139148

149+
const queryString = qs.stringify({ to: '/gh' })
140150
const login = screen.queryByText('Login')
141151
expect(login).toBeInTheDocument()
142-
expect(login).toHaveAttribute('href', '/')
152+
expect(login).toHaveAttribute('href', `/?${queryString}`)
143153
})
144154
})
145155
})

src/layouts/Header/components/GuestHeader/GuestHeader.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { useLocation } from 'react-router'
2+
13
import config from 'config'
24

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

2729
function GuestHeader() {
2830
const isSelfHosted = config.IS_SELF_HOSTED
31+
const location = useLocation()
2932

3033
return (
3134
<div className="border-b">
@@ -69,7 +72,7 @@ function GuestHeader() {
6972
<ThemeToggle />
7073
{isSelfHosted ? (
7174
<Button
72-
to={{ pageName: 'login' }}
75+
to={{ pageName: 'login', options: { to: location.pathname } }}
7376
variant="primary"
7477
activeClassName="hidden"
7578
exact={true}
@@ -86,7 +89,7 @@ function GuestHeader() {
8689
className="mx-2 flex items-center justify-between gap-4 md:mx-0"
8790
>
8891
<A
89-
to={{ pageName: 'login' }}
92+
to={{ pageName: 'login', options: { to: location.pathname } }}
9093
variant="guestHeader"
9194
activeClassName="hidden"
9295
isExternal={false}

src/pages/CommitDetailPage/CommitCoverage/routes/FilesChangedTab/shared/CommitFileDiff/CommitFileDiff.test.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
import { render, screen, waitFor, within } from '@testing-library/react'
77
import { graphql, HttpResponse } from 'msw'
88
import { setupServer } from 'msw/node'
9+
import qs from 'qs'
910
import { Suspense } from 'react'
1011
import { MemoryRouter, Route } from 'react-router-dom'
1112
import { type MockInstance } from 'vitest'
@@ -364,13 +365,16 @@ describe('CommitFileDiff', () => {
364365
expect(errorMessage).toBeInTheDocument()
365366
})
366367

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

372+
const queryString = qs.stringify({
373+
to: '/gh/codecov/gazebo/commit/123sha/folder/subfolder/file.js',
374+
})
371375
const link = await screen.findByText(/logging in/)
372376
expect(link).toBeVisible()
373-
expect(link).toHaveAttribute('href', '/login')
377+
expect(link).toHaveAttribute('href', `/login?${queryString}`)
374378
})
375379
})
376380

src/pages/CommitDetailPage/CommitCoverage/routes/FilesChangedTab/shared/CommitFileDiff/CommitFileDiff.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useQuery as useQueryV5 } from '@tanstack/react-queryV5'
22
import { Fragment, useMemo } from 'react'
3-
import { useParams } from 'react-router-dom'
3+
import { useLocation, useParams } from 'react-router-dom'
44

55
import { IgnoredIdsQueryOptions } from 'pages/CommitDetailPage/queries/IgnoredIdsQueryOptions'
66
import {
@@ -122,6 +122,8 @@ function DiffRenderer({
122122
}
123123

124124
function ErrorDisplayMessage() {
125+
const location = useLocation()
126+
125127
return (
126128
<p className="border border-solid border-ds-gray-tertiary p-4">
127129
There was a problem getting the source code from your provider. Unable to
@@ -132,6 +134,7 @@ function ErrorDisplayMessage() {
132134
<A
133135
to={{
134136
pageName: 'login',
137+
options: { to: location.pathname },
135138
}}
136139
hook={undefined}
137140
isExternal={undefined}

src/pages/CommitDetailPage/CommitCoverage/routes/IndirectChangesTab/IndirectChangesTable/CommitFileDiff/CommitFileDiff.test.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
import { render, screen, waitFor, within } from '@testing-library/react'
77
import { graphql, HttpResponse } from 'msw'
88
import { setupServer } from 'msw/node'
9+
import qs from 'qs'
910
import { Suspense } from 'react'
1011
import { MemoryRouter, Route } from 'react-router-dom'
1112
import { type MockInstance } from 'vitest'
@@ -357,9 +358,12 @@ describe('CommitFileDiff', () => {
357358
setup({ impactedFile: null })
358359
render(<CommitFileDiff path={'random/path'} />, { wrapper })
359360

361+
const queryString = qs.stringify({
362+
to: '/gh/codecov/gazebo/commit/123sha/folder/subfolder/file.js',
363+
})
360364
const link = await screen.findByText(/logging in/)
361365
expect(link).toBeVisible()
362-
expect(link).toHaveAttribute('href', '/login')
366+
expect(link).toHaveAttribute('href', `/login?${queryString}`)
363367
})
364368
})
365369

src/pages/CommitDetailPage/CommitCoverage/routes/IndirectChangesTab/IndirectChangesTable/CommitFileDiff/CommitFileDiff.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useQuery as useQueryV5 } from '@tanstack/react-queryV5'
22
import PropTypes from 'prop-types'
33
import { Fragment, useMemo } from 'react'
4-
import { useParams } from 'react-router-dom'
4+
import { useLocation, useParams } from 'react-router-dom'
55

66
import { IgnoredIdsQueryOptions } from 'pages/CommitDetailPage/queries/IgnoredIdsQueryOptions'
77
import {
@@ -123,6 +123,8 @@ function DiffRenderer({
123123
}
124124

125125
function ErrorDisplayMessage() {
126+
const location = useLocation()
127+
126128
return (
127129
<p className="border border-solid border-ds-gray-tertiary p-4">
128130
There was a problem getting the source code from your provider. Unable to
@@ -131,9 +133,7 @@ function ErrorDisplayMessage() {
131133
<span>
132134
If you continue to experience this issue, please try{' '}
133135
<A
134-
to={{
135-
pageName: 'login',
136-
}}
136+
to={{ pageName: 'login', options: { to: location.pathname } }}
137137
hook={undefined}
138138
isExternal={undefined}
139139
>

src/pages/PullRequestPage/PullCoverage/routes/FilesChangedTab/FilesChanged/PullFileDiff/PullFileDiff.test.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
22
import { render, screen, within } from '@testing-library/react'
33
import { graphql, HttpResponse } from 'msw'
44
import { setupServer } from 'msw/node'
5+
import qs from 'qs'
56
import { Suspense } from 'react'
67
import { MemoryRouter, Route } from 'react-router-dom'
78

@@ -333,13 +334,14 @@ describe('FileDiff', () => {
333334
expect(errorMessage).toBeInTheDocument()
334335
})
335336

336-
it('renders a login link', async () => {
337+
it('renders a login link with redirect to path', async () => {
337338
setup({})
338339
render(<FileDiff path={undefined} />, { wrapper })
339340

341+
const queryString = qs.stringify({ to: '/gh/codecov/cool-repo/pull/1' })
340342
const loginLink = await screen.findByRole('link', { name: /logging in/ })
341343
expect(loginLink).toBeInTheDocument()
342-
expect(loginLink).toHaveAttribute('href', '/login')
344+
expect(loginLink).toHaveAttribute('href', `/login?${queryString}`)
343345
})
344346
})
345347
})

src/pages/PullRequestPage/PullCoverage/routes/FilesChangedTab/FilesChanged/PullFileDiff/PullFileDiff.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Fragment, useMemo } from 'react'
2-
import { useParams } from 'react-router-dom'
2+
import { useLocation, useParams } from 'react-router-dom'
33

44
import { useNavLinks } from 'services/navigation/useNavLinks'
55
import {
@@ -112,6 +112,8 @@ function DiffRenderer({
112112
}
113113

114114
function ErrorDisplayMessage() {
115+
const location = useLocation()
116+
115117
return (
116118
<p className="border border-solid border-ds-gray-tertiary p-4">
117119
There was a problem getting the source code from your provider. Unable to
@@ -120,9 +122,7 @@ function ErrorDisplayMessage() {
120122
<span>
121123
If you continue to experience this issue, please try{' '}
122124
<A
123-
to={{
124-
pageName: 'login',
125-
}}
125+
to={{ pageName: 'login', options: { to: location.pathname } }}
126126
hook={undefined}
127127
isExternal={undefined}
128128
>

src/pages/PullRequestPage/PullCoverage/routes/IndirectChangesTab/PullFileDiff/PullFileDiff.test.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
22
import { render, screen, within } from '@testing-library/react'
33
import { graphql, HttpResponse } from 'msw'
44
import { setupServer } from 'msw/node'
5+
import qs from 'qs'
56
import { MemoryRouter, Route } from 'react-router-dom'
67

78
import PullFileDiff from './PullFileDiff'
@@ -322,13 +323,14 @@ describe('FileDiff', () => {
322323
expect(errorMessage).toBeInTheDocument()
323324
})
324325

325-
it('renders a login link', async () => {
326+
it('renders a login link with redirect to path', async () => {
326327
setup({})
327328
render(<PullFileDiff path={undefined} />, { wrapper })
328329

330+
const queryString = qs.stringify({ to: '/gh/codecov/cool-repo/pull/1' })
329331
const loginLink = await screen.findByRole('link', { name: /logging in/ })
330332
expect(loginLink).toBeInTheDocument()
331-
expect(loginLink).toHaveAttribute('href', '/login')
333+
expect(loginLink).toHaveAttribute('href', `/login?${queryString}`)
332334
})
333335
})
334336
})

src/pages/PullRequestPage/PullCoverage/routes/IndirectChangesTab/PullFileDiff/PullFileDiff.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Fragment, useMemo } from 'react'
2-
import { useParams } from 'react-router-dom'
2+
import { useLocation, useParams } from 'react-router-dom'
33

44
import { useNavLinks } from 'services/navigation/useNavLinks'
55
import {
@@ -106,6 +106,8 @@ function DiffRenderer({
106106
}
107107

108108
function ErrorDisplayMessage() {
109+
const location = useLocation()
110+
109111
return (
110112
<p className="border border-solid border-ds-gray-tertiary p-4">
111113
There was a problem getting the source code from your provider. Unable to
@@ -114,9 +116,7 @@ function ErrorDisplayMessage() {
114116
<span>
115117
If you continue to experience this issue, please try{' '}
116118
<A
117-
to={{
118-
pageName: 'login',
119-
}}
119+
to={{ pageName: 'login', options: { to: location.pathname } }}
120120
hook={undefined}
121121
isExternal={undefined}
122122
>

0 commit comments

Comments
 (0)