From 0ac974d55154737a0ee826930859f9a3ca9ef1ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20N=C3=A4sman?= Date: Tue, 26 Apr 2022 10:51:41 +0200 Subject: [PATCH] fix gitlab url and add test for it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Camila Belo Signed-off-by: Anders Näsman --- .../src/ReportIssue/IssueLink.tsx | 2 +- .../src/ReportIssue/ReportIssue.test.tsx | 69 ++++++++++++++++++- 2 files changed, 67 insertions(+), 4 deletions(-) diff --git a/plugins/techdocs-module-addons-contrib/src/ReportIssue/IssueLink.tsx b/plugins/techdocs-module-addons-contrib/src/ReportIssue/IssueLink.tsx index 0a1a64218a..bb2de22350 100644 --- a/plugins/techdocs-module-addons-contrib/src/ReportIssue/IssueLink.tsx +++ b/plugins/techdocs-module-addons-contrib/src/ReportIssue/IssueLink.tsx @@ -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) => { diff --git a/plugins/techdocs-module-addons-contrib/src/ReportIssue/ReportIssue.test.tsx b/plugins/techdocs-module-addons-contrib/src/ReportIssue/ReportIssue.test.tsx index 3a05f1358e..41186a9e5e 100644 --- a/plugins/techdocs-module-addons-contrib/src/ReportIssue/ReportIssue.test.tsx +++ b/plugins/techdocs-module-addons-contrib/src/ReportIssue/ReportIssue.test.tsx @@ -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([ , @@ -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([ + , + ]) + .withDom( + + + +
+
+
+ + + , + ) + .withApis([[scmIntegrationsApiRef, { byUrl }]]) + .renderWithEffects(); + + (shadowRoot as ShadowRoot & Pick).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', + ); }); }); });