Skip to content

Commit 822d109

Browse files
ref: Convert DirEntry to TSX (#3775)
1 parent 94a8f22 commit 822d109

File tree

2 files changed

+16
-36
lines changed

2 files changed

+16
-36
lines changed

src/shared/ContentsTable/TableEntries/BaseEntries/DirEntry.test.jsx renamed to src/shared/ContentsTable/TableEntries/BaseEntries/DirEntry.test.tsx

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,16 @@ import { MemoryRouter, Route } from 'react-router-dom'
44

55
import DirEntry from './DirEntry'
66

7-
const wrapper = ({ children }) => (
7+
const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => (
88
<MemoryRouter initialEntries={['/gh/codecov/test-repo']}>
99
<Route path="/:provider/:owner/:repo/">{children}</Route>
1010
</MemoryRouter>
1111
)
1212

1313
describe('DirEntry', () => {
1414
it('displays the directory name', () => {
15-
const runPrefetchMock = vi.fn()
1615
render(
17-
<DirEntry
18-
linkRef="branch"
19-
name="dir"
20-
urlPath="path/to/directory"
21-
runPrefetch={runPrefetchMock}
22-
/>,
16+
<DirEntry linkRef="branch" name="dir" urlPath="path/to/directory" />,
2317
{ wrapper }
2418
)
2519

@@ -29,14 +23,8 @@ describe('DirEntry', () => {
2923

3024
describe('path is given', () => {
3125
it('sets the correct href', () => {
32-
const runPrefetchMock = vi.fn()
3326
render(
34-
<DirEntry
35-
linkRef="branch"
36-
name="dir"
37-
urlPath="path/to/directory"
38-
runPrefetch={runPrefetchMock}
39-
/>,
27+
<DirEntry linkRef="branch" name="dir" urlPath="path/to/directory" />,
4028
{ wrapper }
4129
)
4230

@@ -50,11 +38,7 @@ describe('DirEntry', () => {
5038

5139
describe('no path is given', () => {
5240
it('sets the correct href', () => {
53-
const runPrefetchMock = vi.fn()
54-
render(
55-
<DirEntry linkRef="branch" name="dir" runPrefetch={runPrefetchMock} />,
56-
{ wrapper }
57-
)
41+
render(<DirEntry linkRef="branch" name="dir" />, { wrapper })
5842

5943
const a = screen.getByRole('link')
6044
expect(a).toHaveAttribute('href', '/gh/codecov/test-repo/tree/branch/dir')
@@ -63,12 +47,10 @@ describe('DirEntry', () => {
6347

6448
describe('query params value is passed', () => {
6549
it('sets the correct href', () => {
66-
const runPrefetchMock = vi.fn()
6750
render(
6851
<DirEntry
6952
linkRef="branch"
7053
name="dir"
71-
runPrefetch={runPrefetchMock}
7254
queryParams={{ flags: ['flag-1'] }}
7355
/>,
7456
{ wrapper }
@@ -102,13 +84,11 @@ describe('DirEntry', () => {
10284

10385
describe('pageName prop is passed', () => {
10486
it('sets the correct href', () => {
105-
const runPrefetchMock = vi.fn()
10687
render(
10788
<DirEntry
10889
commitSha="coolCommitSha"
10990
name="dir"
11091
urlPath="path/to/directory"
111-
runPrefetch={runPrefetchMock}
11292
pageName="commitTreeView"
11393
/>,
11494
{ wrapper }
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
import PropTypes from 'prop-types'
2-
31
import A from 'ui/A'
42
import Icon from 'ui/Icon'
53

64
function DirEntry({
75
linkRef,
86
name,
97
urlPath,
10-
runPrefetch,
8+
runPrefetch = () => Promise.resolve(),
119
pageName = 'treeView',
1210
commitSha,
1311
queryParams,
14-
}) {
12+
}: DirEntryProps) {
1513
return (
1614
<div className="flex gap-3" onMouseEnter={async () => await runPrefetch()}>
1715
<A
@@ -24,6 +22,8 @@ function DirEntry({
2422
queryParams,
2523
},
2624
}}
25+
hook="expand-dir-entry"
26+
isExternal={false}
2727
>
2828
<Icon name="folder" size="md" variant="solid" />
2929
<span className="whitespace-pre">{name}</span>
@@ -32,14 +32,14 @@ function DirEntry({
3232
)
3333
}
3434

35-
DirEntry.propTypes = {
36-
linkRef: PropTypes.string,
37-
name: PropTypes.string.isRequired,
38-
urlPath: PropTypes.string,
39-
runPrefetch: PropTypes.func,
40-
pageName: PropTypes.string,
41-
commitSha: PropTypes.string,
42-
queryParams: PropTypes.object,
35+
interface DirEntryProps {
36+
linkRef?: string
37+
name: string
38+
urlPath?: string
39+
runPrefetch?: () => Promise<void>
40+
pageName?: string
41+
commitSha?: string
42+
queryParams?: any
4343
}
4444

4545
export default DirEntry

0 commit comments

Comments
 (0)