-
Notifications
You must be signed in to change notification settings - Fork 163
GH-367 Render tooltip for Enterprise installations #949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import React from 'react'; | ||
| import {mount} from 'enzyme'; | ||
|
|
||
| import Client from '@/client'; | ||
|
|
||
| import {LinkTooltip} from './link_tooltip'; | ||
|
|
||
| jest.mock('@/client', () => ({ | ||
| getIssue: jest.fn(), | ||
| getPullRequest: jest.fn(), | ||
| })); | ||
|
|
||
| jest.mock('react-markdown', () => () => <div/>); | ||
|
|
||
| describe('LinkTooltip', () => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great job with the tests! They are a much appreciated addition Could we also have a couple of tests that confirm that the "Opened by" link's href attribute changes accordingly based on the mapped props and component state? |
||
| const baseProps = { | ||
| href: 'https://github.com/mattermost/mattermost-plugin-github/issues/1', | ||
| connected: true, | ||
| show: true, | ||
| theme: { | ||
| centerChannelBg: '#ffffff', | ||
| centerChannelColor: '#333333', | ||
| }, | ||
| enterpriseURL: '', | ||
| }; | ||
|
|
||
| let wrapper; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| if (wrapper && wrapper.length) { | ||
| wrapper.unmount(); | ||
| } | ||
| }); | ||
|
|
||
| test('should fetch issue for github.com link', () => { | ||
| // We need to use mount or wait for useEffect? | ||
| // shallow renders the component, useEffect is a hook. | ||
| // Enzyme shallow supports hooks in newer versions, but let's check if we need to manually trigger logic. | ||
| // The component uses useEffect to call initData. | ||
|
Comment on lines
+40
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comments here aren't particularly necessary, they can be safely removed |
||
| wrapper = mount(<LinkTooltip {...baseProps}/>); | ||
| expect(Client.getIssue).toHaveBeenCalledWith('mattermost', 'mattermost-plugin-github', '1'); | ||
| }); | ||
|
|
||
| test('should fetch pull request for github.com link', () => { | ||
| const props = { | ||
| ...baseProps, | ||
| href: 'https://github.com/mattermost/mattermost-plugin-github/pull/2', | ||
| }; | ||
| wrapper = mount(<LinkTooltip {...props}/>); | ||
| expect(Client.getPullRequest).toHaveBeenCalledWith('mattermost', 'mattermost-plugin-github', '2'); | ||
| }); | ||
|
|
||
| test('should fetch issue for enterprise link', () => { | ||
| const props = { | ||
| ...baseProps, | ||
| href: 'https://github.example.com/mattermost/mattermost-plugin-github/issues/3', | ||
| enterpriseURL: 'https://github.example.com', | ||
| }; | ||
| wrapper = mount(<LinkTooltip {...props}/>); | ||
| expect(Client.getIssue).toHaveBeenCalledWith('mattermost', 'mattermost-plugin-github', '3'); | ||
| }); | ||
|
|
||
| test('should fetch pull request for enterprise link', () => { | ||
| const props = { | ||
| ...baseProps, | ||
| href: 'https://github.example.com/mattermost/mattermost-plugin-github/pull/4', | ||
| enterpriseURL: 'https://github.example.com', | ||
| }; | ||
| wrapper = mount(<LinkTooltip {...props}/>); | ||
| expect(Client.getPullRequest).toHaveBeenCalledWith('mattermost', 'mattermost-plugin-github', '4'); | ||
| }); | ||
|
|
||
| test('should handle enterprise URL with trailing slash', () => { | ||
| const props = { | ||
| ...baseProps, | ||
| href: 'https://github.example.com/mattermost/mattermost-plugin-github/issues/5', | ||
| enterpriseURL: 'https://github.example.com/', | ||
| }; | ||
| wrapper = mount(<LinkTooltip {...props}/>); | ||
| expect(Client.getIssue).toHaveBeenCalledWith('mattermost', 'mattermost-plugin-github', '5'); | ||
| }); | ||
|
|
||
| test('should not fetch if enterprise URL does not match', () => { | ||
| const props = { | ||
| ...baseProps, | ||
| href: 'https://other-github.com/mattermost/mattermost-plugin-github/issues/6', | ||
| enterpriseURL: 'https://github.example.com', | ||
| }; | ||
| wrapper = mount(<LinkTooltip {...props}/>); | ||
| expect(Client.getIssue).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that for enterprise installations we will end up with the Opened By link sending users directly to the
enterpriseURLURL instead of what would be the user's profileIt feels like we could have a useMemo-wrapped function that attempts to first map to the user's
html_urlproperty, which both the Get issue and Get Pull Request endpoints should return. With a fallback values to each base URL for good measureSomething that would look like this
This way we can also safely render the link based on
openedByLink's value in line 145 instead ofdata?.user?.login