From 8312cf4d5c72d1115b78a528e5dd978059c94650 Mon Sep 17 00:00:00 2001 From: Bogdan Christescu Date: Thu, 16 Feb 2023 21:28:20 +0100 Subject: [PATCH] added test case for gitlab repository located in a subgroup Signed-off-by: Bogdan Christescu --- .../src/ReportIssue/IssueLink.test.tsx | 46 ++++++++++++++++--- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/plugins/techdocs-module-addons-contrib/src/ReportIssue/IssueLink.test.tsx b/plugins/techdocs-module-addons-contrib/src/ReportIssue/IssueLink.test.tsx index 5fff56ecb7..9a34fcf011 100644 --- a/plugins/techdocs-module-addons-contrib/src/ReportIssue/IssueLink.test.tsx +++ b/plugins/techdocs-module-addons-contrib/src/ReportIssue/IssueLink.test.tsx @@ -26,7 +26,7 @@ import { import { IssueLink } from './IssueLink'; -const defaultProps = { +const defaultGithubProps = { repository: { type: 'github', name: 'backstage', @@ -40,14 +40,28 @@ const defaultProps = { }, }; +const defaultGitlabProps = { + repository: { + type: 'gitlab', + name: 'backstageSubgroup/backstage', + owner: 'backstage', + protocol: 'https', + resource: 'gitlab.com', + }, + template: { + title: 'Documentation feedback', + body: '## Documentation Feedback 📝', + }, +}; + describe('FeedbackLink', () => { const apiSpy = new MockAnalyticsApi(); - it('Should open new issue tab', () => { + it('Should open new Github issue tab', () => { render( wrapInTestApp( - + , ), ); @@ -55,19 +69,39 @@ describe('FeedbackLink', () => { const link = screen.getByText(/Open new Github issue/); expect(link).toBeInTheDocument(); expect(link).toHaveAttribute('target', '_blank'); - const encodedTitle = encodeURIComponent(defaultProps.template.title); - const encodedBody = encodeURIComponent(defaultProps.template.body); + const encodedTitle = encodeURIComponent(defaultGithubProps.template.title); + const encodedBody = encodeURIComponent(defaultGithubProps.template.body); expect(link).toHaveAttribute( 'href', `https://github.com/backstage/backstage/issues/new?title=${encodedTitle}&body=${encodedBody}`, ); }); + it('Should open new Gitlab issue tab', () => { + render( + wrapInTestApp( + + + , + ), + ); + + const link = screen.getByText(/Open new Gitlab issue/); + expect(link).toBeInTheDocument(); + expect(link).toHaveAttribute('target', '_blank'); + const encodedTitle = encodeURIComponent(defaultGithubProps.template.title); + const encodedBody = encodeURIComponent(defaultGithubProps.template.body); + expect(link).toHaveAttribute( + 'href', + `https://gitlab.com/backstage/backstageSubgroup/backstage/issues/new?issue[title]=${encodedTitle}&issue[description]=${encodedBody}`, + ); + }); + it('Should track click events', async () => { render( wrapInTestApp( - + , ), );