Replace material-ui Link with backstage Link

Signed-off-by: Erik Engervall <erik.engervall@gmail.com>
This commit is contained in:
Erik Engervall
2021-05-06 14:33:45 +02:00
parent 1156773572
commit a8ae9a5234
12 changed files with 45 additions and 54 deletions
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import { renderHook, act } from '@testing-library/react-hooks';
import { waitFor } from '@testing-library/react';
@@ -28,9 +27,8 @@ import {
import { useCreateReleaseCandidate } from './useCreateReleaseCandidate';
jest.mock('@backstage/core', () => ({
...jest.requireActual('@backstage/core'),
useApi: () => mockApiClient,
createApiRef: jest.fn(),
Progress: (props: Record<string, any>) => <div {...props} />,
}));
jest.mock('../../../contexts/UserContext', () => ({
useUserContext: () => ({ user: mockUser }),
@@ -78,7 +76,7 @@ describe('useCreateReleaseCandidate', () => {
"progress": 100,
"responseSteps": Array [
Object {
"link": "latestCommit.html_url",
"link": "https://latestCommit.html_url",
"message": "Fetched latest commit from \\"mock_defaultBranch\\"",
"secondaryMessage": "with message \\"latestCommit.commit.message\\"",
},
@@ -95,12 +93,12 @@ describe('useCreateReleaseCandidate', () => {
"secondaryMessage": "with ref \\"mock_createRef_ref\\"",
},
Object {
"link": "mock_compareCommits_html_url",
"link": "https://mock_compareCommits_html_url",
"message": "Fetched commit comparison",
"secondaryMessage": "rc/2020.01.01_1...rc/2020.01.01_1",
},
Object {
"link": "mock_createRelease_html_url",
"link": "https://mock_createRelease_html_url",
"message": "Created Release Candidate \\"mock_createRelease_name\\"",
"secondaryMessage": "with tag \\"rc-2020.01.01_1\\"",
},
@@ -22,13 +22,8 @@ import { mockApiClient, mockCalverProject } from '../test-helpers/test-helpers';
import { TEST_IDS } from '../test-helpers/test-ids';
jest.mock('@backstage/core', () => ({
...jest.requireActual('@backstage/core'),
useApi: () => mockApiClient,
createApiRef: jest.fn(),
ErrorBoundary: ({ children }: { children: React.ReactNode }) => (
<>{children}</>
),
InfoCard: ({ children }: { children: React.ReactNode }) => <>{children}</>,
Progress: (props: Record<string, any>) => <div {...props} />,
}));
jest.mock('../contexts/ProjectContext', () => ({
useProjectContext: () => ({
@@ -55,7 +50,7 @@ describe('Features', () => {
expect(getByTestId(TEST_IDS.info.info)).toMatchInlineSnapshot(`
<div
class="MuiBox-root MuiBox-root-2"
class="MuiBox-root MuiBox-root-9"
data-testid="grm--info"
>
<h6
@@ -75,6 +70,7 @@ describe('Features', () => {
class="MuiTypography-root MuiLink-root MuiLink-underlineHover MuiTypography-colorPrimary"
href="https://docs.github.com/en/github/administering-a-repository/managing-releases-in-a-repository"
target="_blank"
to="https://docs.github.com/en/github/administering-a-repository/managing-releases-in-a-repository"
>
Git releases
</a>
@@ -15,7 +15,7 @@
*/
import React, { useState } from 'react';
import { Link, Typography, Button, Box } from '@material-ui/core';
import { Typography, Button, Box } from '@material-ui/core';
import BarChartIcon from '@material-ui/icons/BarChart';
import {
@@ -28,6 +28,7 @@ import { Stats } from '../Stats/Stats';
import { TEST_IDS } from '../../test-helpers/test-ids';
import { useProjectContext } from '../../contexts/ProjectContext';
import flowImage from './flow.png';
import { Link } from '@backstage/core';
interface InfoCardProps {
releaseBranch: GetBranchResult['branch'] | null;
@@ -52,7 +53,7 @@ export const Info = ({
<strong>Git</strong>: The source control system where releases reside
in a practical sense. Read more about{' '}
<Link
href="https://docs.github.com/en/github/administering-a-repository/managing-releases-in-a-repository"
to="https://docs.github.com/en/github/administering-a-repository/managing-releases-in-a-repository"
target="_blank"
>
Git releases
@@ -30,9 +30,8 @@ import { PatchBody } from './PatchBody';
import { TEST_IDS } from '../../test-helpers/test-ids';
jest.mock('@backstage/core', () => ({
...jest.requireActual('@backstage/core'),
useApi: () => mockApiClient,
createApiRef: jest.fn(),
Progress: (props: Record<string, any>) => <div {...props} />,
}));
jest.mock('../../contexts/ProjectContext', () => ({
useProjectContext: () => ({
@@ -22,7 +22,6 @@ import {
Button,
Checkbox,
IconButton,
Link,
List,
ListItem,
ListItemIcon,
@@ -33,7 +32,7 @@ import {
} from '@material-ui/core';
import FileCopyIcon from '@material-ui/icons/FileCopy';
import OpenInNewIcon from '@material-ui/icons/OpenInNew';
import { Progress, useApi } from '@backstage/core';
import { Link, Progress, useApi } from '@backstage/core';
import {
GetBranchResult,
@@ -230,18 +229,20 @@ export const PatchBody = ({
<>
<Link
color="primary"
href={commit.htmlUrl}
to={commit.htmlUrl}
target="_blank"
>
{commit.sha}
</Link>{' '}
<Link
color="primary"
href={commit.author.htmlUrl}
target="_blank"
>
@{commit.author.login}
</Link>
{commit.author.htmlUrl && (
<Link
color="primary"
to={commit.author.htmlUrl}
target="_blank"
>
@{commit.author.login}
</Link>
)}
</>
}
/>
@@ -29,8 +29,8 @@ import {
import { usePatch } from './usePatch';
jest.mock('@backstage/core', () => ({
...jest.requireActual('@backstage/core'),
useApi: () => mockApiClient,
createApiRef: jest.fn(),
}));
jest.mock('../../../contexts/UserContext', () => ({
useUserContext: () => ({ user: mockUser }),
@@ -79,7 +79,7 @@ describe('patch', () => {
"progress": 100,
"responseSteps": Array [
Object {
"link": "mock_branch_links_html",
"link": "https://mock_branch_links_html",
"message": "Fetched release branch \\"rc/1.2.3\\"",
},
Object {
@@ -90,7 +90,7 @@ describe('patch', () => {
"message": "Forced branch \\"rc/2020.01.01_1\\" to temporary commit \\"mock_commit_sha\\"",
},
Object {
"link": "mock_merge_html_url",
"link": "https://mock_merge_html_url",
"message": "Merged temporary commit into \\"rc/2020.01.01_1\\"",
"secondaryMessage": "with message \\"mock_merge_commit_message\\"",
},
@@ -110,7 +110,7 @@ describe('patch', () => {
"secondaryMessage": "for tag object \\"mock_tag_object_tag\\"",
},
Object {
"link": "mock_update_release_html_url",
"link": "https://mock_update_release_html_url",
"message": "Updated release \\"mock_update_release_name\\"",
"secondaryMessage": "with tag mock_update_release_tag_name",
},
@@ -26,8 +26,8 @@ import {
import { usePromoteRc } from './usePromoteRc';
jest.mock('@backstage/core', () => ({
...jest.requireActual('@backstage/core'),
useApi: () => mockApiClient,
createApiRef: jest.fn(),
}));
jest.mock('../../../contexts/ProjectContext', () => ({
useProjectContext: () => ({
@@ -88,7 +88,7 @@ describe('usePromoteRc', () => {
"secondaryMessage": "with ref \\"mock_createRef_ref\\"",
},
Object {
"link": "mock_update_release_html_url",
"link": "https://mock_update_release_html_url",
"message": "Promoted \\"mock_update_release_name\\"",
"secondaryMessage": "from \\"rc-2020.01.01_1\\" to \\"mock_update_release_tag_name\\"",
},
@@ -34,9 +34,8 @@ jest.mock('react-router', () => ({
})),
}));
jest.mock('@backstage/core', () => ({
...jest.requireActual('@backstage/core'),
useApi: () => mockApiClient,
createApiRef: jest.fn(),
Progress: (props: Record<string, any>) => <div {...props} />,
}));
jest.mock('../../contexts/ProjectContext', () => ({
useProjectContext: jest.fn(() => ({
@@ -33,9 +33,8 @@ jest.mock('react-router', () => ({
})),
}));
jest.mock('@backstage/core', () => ({
...jest.requireActual('@backstage/core'),
useApi: () => mockApiClient,
createApiRef: jest.fn(),
Progress: (props: Record<string, any>) => <div {...props} />,
}));
jest.mock('../../contexts/ProjectContext', () => ({
useProjectContext: jest.fn(() => ({
@@ -19,13 +19,13 @@ import { DateTime } from 'luxon';
import {
Collapse,
IconButton,
Link,
makeStyles,
TableCell,
TableRow,
} from '@material-ui/core';
import KeyboardArrowDownIcon from '@material-ui/icons/KeyboardArrowDown';
import ChevronRightIcon from '@material-ui/icons/ChevronRight';
import { Link } from '@backstage/core';
import { ReleaseStats } from '../contexts/ReleaseStatsContext';
import { RowCollapsed } from './RowCollapsed/RowCollapsed';
@@ -61,7 +61,7 @@ export function Row({ baseVersion, releaseStat }: RowProps) {
</TableCell>
<TableCell component="th" scope="row">
<Link href={releaseStat.htmlUrl} target="_blank">
<Link to={releaseStat.htmlUrl} target="_blank">
{baseVersion}
{releaseStat.versions.length === 0 ? ' (prerelease)' : ''}
</Link>
@@ -26,7 +26,6 @@ describe('useGetHubBatchInfo', () => {
useGetGitBatchInfo({
pluginApiClient: mockApiClient,
project: mockSemverProject,
refetchTrigger: 1337,
}),
);
@@ -39,7 +38,7 @@ describe('useGetHubBatchInfo', () => {
"loading": false,
"value": Object {
"latestRelease": Object {
"htmlUrl": "mock_release_html_url",
"htmlUrl": "https://mock_release_html_url",
"id": 1,
"prerelease": false,
"tagName": "rc-2020.01.01_1",
@@ -55,7 +54,7 @@ describe('useGetHubBatchInfo', () => {
"sha": "mock_branch_commit_sha",
},
"links": Object {
"html": "mock_branch_links_html",
"html": "https://mock_branch_links_html",
},
"name": "rc/1.2.3",
},
@@ -76,7 +75,6 @@ describe('useGetHubBatchInfo', () => {
useGetGitBatchInfo({
pluginApiClient: mockApiClient,
project: mockSemverProject,
refetchTrigger: 1337,
}),
);
@@ -62,7 +62,7 @@ export const createMockCommit = (
commit: {
message: 'mock_commit_commit_message',
},
htmlUrl: 'mock_commit_html_url',
htmlUrl: 'https://mock_commit_html_url',
sha: 'mock_commit_sha',
createdAt: '2000-01-01T10:00:00.000Z',
...overrides,
@@ -129,7 +129,7 @@ const createMockRelease = ({
NonNullable<GetLatestReleaseResult['latestRelease']>
> = {}): NonNullable<GetLatestReleaseResult['latestRelease']> => ({
id,
htmlUrl: 'mock_release_html_url',
htmlUrl: 'https://mock_release_html_url',
prerelease,
tagName: MOCK_RELEASE_CANDIDATE_TAG_NAME_CALVER,
targetCommitish: MOCK_RELEASE_BRANCH_NAME_CALVER,
@@ -175,7 +175,7 @@ const createMockBranch = ({
},
},
links: {
html: 'mock_branch_links_html',
html: 'https://mock_branch_links_html',
},
...rest,
});
@@ -188,7 +188,7 @@ const createMockRecentCommit = ({
...rest
}: Partial<GetRecentCommitsResultSingle>): GetRecentCommitsResultSingle => ({
author: {
htmlUrl: 'author_html_url',
htmlUrl: 'https://author_html_url',
login: 'author_login',
},
commit: {
@@ -196,7 +196,7 @@ const createMockRecentCommit = ({
},
sha: 'mock_sha',
firstParentSha: 'mock_first_parent_sha',
htmlUrl: 'mock_htmlUrl',
htmlUrl: 'https://mock_htmlUrl',
...rest,
});
@@ -249,7 +249,7 @@ export const mockApiClient: GitReleaseApi = {
getCommit: jest.fn(async () => ({
commit: {
sha: 'latestCommit.sha',
htmlUrl: 'latestCommit.html_url',
htmlUrl: 'https://latestCommit.html_url',
commit: {
message: 'latestCommit.commit.message',
},
@@ -271,14 +271,14 @@ export const mockApiClient: GitReleaseApi = {
createRelease: jest.fn(async () => ({
release: {
name: 'mock_createRelease_name',
htmlUrl: 'mock_createRelease_html_url',
htmlUrl: 'https://mock_createRelease_html_url',
tagName: 'mock_createRelease_tag_name',
},
})),
getComparison: jest.fn(async () => ({
comparison: {
htmlUrl: 'mock_compareCommits_html_url',
htmlUrl: 'https://mock_compareCommits_html_url',
aheadBy: 1,
},
})),
@@ -308,7 +308,7 @@ export const mockApiClient: GitReleaseApi = {
merge: jest.fn(async () => ({
merge: {
htmlUrl: 'mock_merge_html_url',
htmlUrl: 'https://mock_merge_html_url',
commit: {
message: 'mock_merge_commit_message',
tree: {
@@ -322,7 +322,7 @@ export const mockApiClient: GitReleaseApi = {
release: {
name: 'mock_update_release_name',
tagName: 'mock_update_release_tag_name',
htmlUrl: 'mock_update_release_html_url',
htmlUrl: 'https://mock_update_release_html_url',
},
})),
@@ -343,7 +343,7 @@ export const mockApiClient: GitReleaseApi = {
name: 'mock_release_name',
tagName: 'mock_release_tag_name',
createdAt: 'mock_release_published_at',
htmlUrl: 'mock_release_html_url',
htmlUrl: 'https://mock_release_html_url',
},
],
})),