Skip to content
This repository was archived by the owner on Jan 16, 2022. It is now read-only.

Commit 6c4098b

Browse files
committed
refactor: address code review comments #116
1 parent 513ad12 commit 6c4098b

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

src/components/PackageList/PackageList.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Fragment, ReactElement } from 'react';
1+
import React, { Fragment, ReactNode } from 'react';
22

33
import Package from '../Package';
44
import Help from '../Help';
@@ -13,8 +13,9 @@ interface Props {
1313
}
1414

1515
export const PackageList: React.FC<Props> = props => {
16-
const renderPackages: () => ReactElement<HTMLElement>[] = () => {
17-
return props.packages.map((pkg, i) => {
16+
const { packages } = props;
17+
const renderPackages: () => ReactNode[] = () => {
18+
return packages.map((pkg, i) => {
1819
const { name, version, description, time, keywords, dist, homepage, bugs, author } = pkg;
1920
// TODO: move format license to API side.
2021
const license = formatLicense(pkg.license);
@@ -27,7 +28,7 @@ export const PackageList: React.FC<Props> = props => {
2728
});
2829
};
2930

30-
const hasPackages: () => boolean = () => props.packages.length > 0;
31+
const hasPackages: () => boolean = () => packages.length > 0;
3132

3233
return (
3334
<div className={'package-list-items'}>

src/components/RegistryInfoContent/RegistryInfoContent.test.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,19 @@ describe('<RegistryInfoContent /> component', () => {
1515
});
1616

1717
test('should load the appropiate tab content when the tab is clicked', () => {
18-
const { container, getByTestId } = render(<RegistryInfoContent registryUrl={'http://localhost:4872'} scope={''} />);
19-
expect(container.textContent).not.toContain('pnpm adduser --registry http://localhost:4872');
18+
const props = { registryUrl: 'http://localhost:4872', scope: '@' };
19+
const pnpmTabTextContent = `pnpm adduser --registry ${props.registryUrl}`;
20+
21+
// Render the component.
22+
const { container, getByTestId } = render(<RegistryInfoContent registryUrl={props.registryUrl} scope={props.scope} />);
23+
24+
// Assert the text content for pnpm tab is not present intially
25+
expect(container.textContent).not.toContain(pnpmTabTextContent);
26+
2027
const pnpmTab = getByTestId('pnpm-tab');
2128
fireEvent.click(pnpmTab);
22-
expect(container.textContent).toContain('pnpm adduser --registry http://localhost:4872');
29+
30+
// Assert the text content is correct after clicking on the tab.
31+
expect(container.textContent).toContain(pnpmTabTextContent);
2332
});
2433
});

src/components/RegistryInfoContent/RegistryInfoContent.tsx

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,33 @@ export const RegistryInfoContent: React.FC<Props> = props => {
2020

2121
const renderNpmTab = (scope: string, registryUrl: string): JSX.Element => {
2222
return (
23-
<React.Fragment>
23+
<>
2424
<CopyToClipBoard text={getCLISetConfigRegistry(`${NODE_MANAGER.npm} set`, scope, registryUrl)} />
2525
<CopyToClipBoard text={getCLISetRegistry(`${NODE_MANAGER.npm} adduser`, registryUrl)} />
2626
<CopyToClipBoard text={getCLIChangePassword(NODE_MANAGER.npm, registryUrl)} />
27-
</React.Fragment>
27+
</>
2828
);
2929
};
3030

31-
const renderPNpmTab = (scope: string, registryUrl: string): JSX.Element => {
31+
const renderPnpmTab = (scope: string, registryUrl: string): JSX.Element => {
3232
return (
33-
<React.Fragment>
33+
<>
3434
<CopyToClipBoard text={getCLISetConfigRegistry(`${NODE_MANAGER.pnpm} set`, scope, registryUrl)} />
3535
<CopyToClipBoard text={getCLISetRegistry(`${NODE_MANAGER.pnpm} adduser`, registryUrl)} />
3636
<CopyToClipBoard text={getCLIChangePassword(NODE_MANAGER.pnpm, registryUrl)} />
37-
</React.Fragment>
37+
</>
3838
);
3939
};
4040

4141
const renderYarnTab = (scope: string, registryUrl: string): JSX.Element => {
42-
return (
43-
<React.Fragment>
44-
<CopyToClipBoard text={getCLISetConfigRegistry(`${NODE_MANAGER.yarn} config set`, scope, registryUrl)} />
45-
</React.Fragment>
46-
);
42+
return <CopyToClipBoard text={getCLISetConfigRegistry(`${NODE_MANAGER.yarn} config set`, scope, registryUrl)} />;
4743
};
4844

4945
const renderTabs = (): JSX.Element => {
5046
const { scope, registryUrl } = props;
5147

5248
return (
53-
<React.Fragment>
49+
<>
5450
<Tabs
5551
data-testid={'tabs-el'}
5652
indicatorColor="primary"
@@ -63,9 +59,9 @@ export const RegistryInfoContent: React.FC<Props> = props => {
6359
<Tab data-testid={'yarn-tab'} label={NODE_MANAGER.yarn} />
6460
</Tabs>
6561
{tabPosition === 0 && <TabContainer>{renderNpmTab(scope, registryUrl)}</TabContainer>}
66-
{tabPosition === 1 && <TabContainer>{renderPNpmTab(scope, registryUrl)}</TabContainer>}
62+
{tabPosition === 1 && <TabContainer>{renderPnpmTab(scope, registryUrl)}</TabContainer>}
6763
{tabPosition === 2 && <TabContainer>{renderYarnTab(scope, registryUrl)}</TabContainer>}
68-
</React.Fragment>
64+
</>
6965
);
7066
};
7167

0 commit comments

Comments
 (0)