Skip to content

Commit dd310af

Browse files
update login links in RawFileViewer
1 parent 399752f commit dd310af

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/shared/RawFileViewer/RawFileViewer.test.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
22
import { render, screen, waitFor } 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 RawFileViewer from './RawFileViewer'
@@ -359,14 +360,18 @@ describe('RawFileViewer', () => {
359360
expect(errorMessage).toBeInTheDocument()
360361
})
361362

362-
it('renders a login link', async () => {
363+
it('renders a login link with redirect to path', async () => {
363364
render(
364365
<RawFileViewer title="The FileViewer" commit="cool-commit-sha" />,
365366
{ wrapper: wrapper() }
366367
)
368+
369+
const queryString = qs.stringify({
370+
to: '/gh/codecov/cool-repo/blob/branch-name/a/file.js',
371+
})
367372
const link = await screen.findByText(/logging in/)
368373
expect(link).toBeVisible()
369-
expect(link).toHaveAttribute('href', '/login')
374+
expect(link).toHaveAttribute('href', `/login?${queryString}`)
370375
})
371376
})
372377

src/shared/RawFileViewer/RawFileViewer.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Title from 'ui/FileViewer/ToggleHeader/Title'
1616
import { VirtualFileRenderer } from 'ui/VirtualRenderers'
1717

1818
function ErrorDisplayMessage() {
19+
const location = useLocation()
1920
return (
2021
<p className="border border-solid border-ds-gray-tertiary p-4">
2122
There was a problem getting the source code from your provider. Unable to
@@ -24,9 +25,7 @@ function ErrorDisplayMessage() {
2425
<span>
2526
If you continue to experience this issue, please try{' '}
2627
<A
27-
to={{
28-
pageName: 'login',
29-
}}
28+
to={{ pageName: 'login', options: { to: location.pathname } }}
3029
hook={undefined}
3130
isExternal={undefined}
3231
>

0 commit comments

Comments
 (0)