Tests for TaskPageLinks

Signed-off-by: James Turley <james.turley@signalmedia.co>
Signed-off-by: James Turley <jamesturley1905@googlemail.com>
This commit is contained in:
James Turley
2021-03-22 15:27:13 +00:00
committed by James Turley
parent baee14e5d6
commit b1ad7eae8a
2 changed files with 76 additions and 1 deletions
@@ -18,7 +18,6 @@ import React from 'react';
import { IconComponent } from '@backstage/core-api';
import { Grid, LinkProps, makeStyles, Typography } from '@material-ui/core';
import LanguageIcon from '@material-ui/icons/Language';
import { omit } from 'lodash';
import { Link } from '../Link';
const useStyles = makeStyles({
@@ -0,0 +1,76 @@
/*
* Copyright 2020 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import { TaskPageLinks } from './TaskPageLinks';
import { renderInTestApp } from '@backstage/test-utils';
describe('TaskPageLinks', () => {
beforeEach(() => {});
afterEach(() => {
jest.resetAllMocks();
});
it('renders the entityRef link', async () => {
const output = { entityRef: 'Component:default/my-app' };
const { findByText } = await renderInTestApp(
<TaskPageLinks output={output} />,
);
const element = await findByText('Open in catalog');
expect(element).toBeInTheDocument();
expect(element).toHaveAttribute(
'href',
'/catalog/default/Component/my-app',
);
});
it('renders the remoteUrl link', async () => {
const output = { remoteUrl: 'https://remote.url' };
const { findByText } = await renderInTestApp(
<TaskPageLinks output={output} />,
);
const element = await findByText('Repo');
expect(element).toBeInTheDocument();
expect(element).toHaveAttribute('href', 'https://remote.url');
});
it('renders further links', async () => {
const output = {
links: [
{ url: 'https://first.url', title: 'Cool link 1' },
{ url: 'https://second.url', title: 'Cool link 2' },
],
};
const { findByText } = await renderInTestApp(
<TaskPageLinks output={output} />,
);
let element = await findByText('Cool link 1');
expect(element).toBeInTheDocument();
expect(element).toHaveAttribute('href', 'https://first.url');
element = await findByText('Cool link 2');
expect(element).toBeInTheDocument();
expect(element).toHaveAttribute('href', 'https://second.url');
});
});