fix gitlab url and add test for it

Co-authored-by: Camila Belo <camilaibs@gmail.com>
Signed-off-by: Anders Näsman <andersn@spotify.com>
This commit is contained in:
Anders Näsman
2022-04-26 10:51:41 +02:00
parent 52fddad92d
commit 0ac974d551
2 changed files with 67 additions and 4 deletions
@@ -66,7 +66,7 @@ const getUrl = (repository: Repository, template: ReportIssueTemplate) => {
if (type === 'github') {
return `${url}/issues/new?title=${encodedTitle}&body=${encodedBody}`;
}
return `${url}/issues/new?[title]=${encodedTitle}&[body]=${encodedBody}`;
return `${url}/issues/new?issue[title]=${encodedTitle}&issue[description]=${encodedBody}`;
};
export const IssueLink = ({ template, repository }: IssueLinkProps) => {
@@ -22,7 +22,7 @@ import { fireEvent, waitFor } from '@testing-library/react';
import { scmIntegrationsApiRef } from '@backstage/integration-react';
import { ReportIssue } from '..';
const byUrl = jest.fn().mockReturnValue({ type: 'github' });
const byUrl = jest.fn();
const fireSelectionChangeEvent = (window: Window) => {
const selectionChangeEvent = window.document.createEvent('Event');
@@ -56,7 +56,8 @@ describe('ReportIssue', () => {
jest.clearAllMocks();
});
it('renders without exploding', async () => {
it('renders github link without exploding', async () => {
byUrl.mockReturnValue({ type: 'github' });
const { shadowRoot, getByText } =
await TechDocsAddonBuilder.buildAddonsInTechDocs([
<ReportIssue debounceTime={0} />,
@@ -105,7 +106,69 @@ describe('ReportIssue', () => {
fireSelectionChangeEvent(window);
await waitFor(() => {
expect(getByText('Open new Github issue')).toBeInTheDocument();
const link = getByText('Open new Github issue');
expect(link).toHaveAttribute(
'href',
'https://github.com/backstage/backstage/issues/new?title=Documentation%20feedback%3A%20his%20&body=%23%23%20Documentation%20Feedback%20%F0%9F%93%9D%0A%0A%20%23%23%23%23%20The%20highlighted%20text%3A%20%0A%0A%20%3E%20his%0A%0A%20%23%23%23%23%20The%20comment%20on%20the%20text%3A%20%0A%20_%3Ereplace%20this%20line%20with%20your%20comment%3C_%0A%0A%20___%0ABackstage%20URL%3A%20%3Chttp%3A%2F%2Flocalhost%2F%3E%20%0AMarkdown%20URL%3A%20%3Chttps%3A%2F%2Fgithub.com%2Fbackstage%2Fbackstage%2Fblob%2Fmaster%2Fdocs%2FREADME.md%3E',
);
});
});
it('renders gitlab link without exploding', async () => {
byUrl.mockReturnValue({ type: 'gitlab' });
const { shadowRoot, getByText } =
await TechDocsAddonBuilder.buildAddonsInTechDocs([
<ReportIssue debounceTime={0} />,
])
.withDom(
<html lang="en">
<head />
<body>
<div data-md-component="content">
<div data-md-component="navigation" />
<div data-md-component="toc" />
<div data-md-component="sidebar" />
<div data-md-component="main">
<div className="md-content">
<article>
<a
title="Leave feedback for this page"
href="https://gitlab.com/backstage/backstage/issues/new"
>
Leave feedback
</a>
<a
title="Edit this page"
href="https://gitlab.com/backstage/backstage/-/edit/master/docs/README.md"
>
Edit page
</a>
</article>
</div>
</div>
</div>
</body>
</html>,
)
.withApis([[scmIntegrationsApiRef, { byUrl }]])
.renderWithEffects();
(shadowRoot as ShadowRoot & Pick<Document, 'getSelection'>).getSelection =
() => selection;
await waitFor(() => {
expect(getByText('Edit page')).toBeInTheDocument();
});
fireSelectionChangeEvent(window);
await waitFor(() => {
const link = getByText('Open new Gitlab issue');
expect(link).toHaveAttribute(
'href',
'https://gitlab.com/backstage/backstage/issues/new?issue[title]=Documentation%20feedback%3A%20his%20&issue[description]=%23%23%20Documentation%20Feedback%20%F0%9F%93%9D%0A%0A%20%23%23%23%23%20The%20highlighted%20text%3A%20%0A%0A%20%3E%20his%0A%0A%20%23%23%23%23%20The%20comment%20on%20the%20text%3A%20%0A%20_%3Ereplace%20this%20line%20with%20your%20comment%3C_%0A%0A%20___%0ABackstage%20URL%3A%20%3Chttp%3A%2F%2Flocalhost%2F%3E%20%0AMarkdown%20URL%3A%20%3Chttps%3A%2F%2Fgitlab.com%2Fbackstage%2Fbackstage%2F-%2Fblob%2Fmaster%2Fdocs%2FREADME.md%3E',
);
});
});
});