diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-09 21:09:32 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-09 21:09:32 +0300 |
commit | 1268cfeaf73a73c5593f13639530513716826e2b (patch) | |
tree | 2508ffb2fddaa666d99b4e5984d3340eb9194782 /spec/frontend/integrations | |
parent | be769d5fcced48143e92f83c997b7d5ba14873e1 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/integrations')
-rw-r--r-- | spec/frontend/integrations/gitlab_slack_application/components/gitlab_slack_application_spec.js | 105 | ||||
-rw-r--r-- | spec/frontend/integrations/gitlab_slack_application/mock_data.js | 14 |
2 files changed, 119 insertions, 0 deletions
diff --git a/spec/frontend/integrations/gitlab_slack_application/components/gitlab_slack_application_spec.js b/spec/frontend/integrations/gitlab_slack_application/components/gitlab_slack_application_spec.js new file mode 100644 index 00000000000..64b3b47d741 --- /dev/null +++ b/spec/frontend/integrations/gitlab_slack_application/components/gitlab_slack_application_spec.js @@ -0,0 +1,105 @@ +import { GlButton, GlLink } from '@gitlab/ui'; + +import { nextTick } from 'vue'; +import GitlabSlackApplication from '~/integrations/gitlab_slack_application/components/gitlab_slack_application.vue'; +import { addProjectToSlack } from '~/integrations/gitlab_slack_application/api'; +import { i18n } from '~/integrations/gitlab_slack_application/constants'; +import ProjectsDropdown from '~/integrations/gitlab_slack_application/components/projects_dropdown.vue'; + +import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; +import waitForPromises from 'helpers/wait_for_promises'; + +import { redirectTo } from '~/lib/utils/url_utility'; // eslint-disable-line import/no-deprecated +import { mockProjects } from '../mock_data'; + +jest.mock('~/integrations/gitlab_slack_application/api'); +jest.mock('~/lib/utils/url_utility'); + +describe('GitlabSlackApplication', () => { + let wrapper; + + const defaultProps = { + projects: [], + gitlabForSlackGifPath: '//gitlabForSlackGifPath', + signInPath: '//signInPath', + slackLinkPath: '//slackLinkPath', + docsPath: '//docsPath', + gitlabLogoPath: '//gitlabLogoPath', + slackLogoPath: '//slackLogoPath', + isSignedIn: true, + }; + + const createComponent = ({ props = {} } = {}) => { + wrapper = shallowMountExtended(GitlabSlackApplication, { + propsData: { ...defaultProps, ...props }, + }); + }; + + const findGlButton = () => wrapper.findComponent(GlButton); + const findGlLink = () => wrapper.findComponent(GlLink); + const findProjectsDropdown = () => wrapper.findComponent(ProjectsDropdown); + const findAppContent = () => wrapper.findByTestId('gitlab-slack-content'); + + describe('template', () => { + describe('when user is not signed in', () => { + it('renders "Sign in" button', () => { + createComponent({ + props: { isSignedIn: false }, + }); + + expect(findGlButton().attributes('href')).toBe(defaultProps.signInPath); + }); + }); + + describe('when user is signed in', () => { + describe('user does not have any projects', () => { + it('renders empty text', () => { + createComponent(); + + expect(findAppContent().text()).toContain(i18n.noProjects); + expect(findAppContent().text()).toContain(i18n.noProjectsDescription); + }); + + it('renders "Learn more" link', () => { + createComponent(); + + expect(findGlLink().text()).toBe(i18n.learnMore); + }); + }); + + describe('user has projects', () => { + beforeEach(() => { + createComponent({ + props: { + projects: mockProjects, + }, + }); + }); + + it('renders ProjectsDropdown', () => { + expect(findProjectsDropdown().props('projects')).toBe(mockProjects); + }); + + it('redirects to slackLinkPath when submitted', async () => { + const redirectLink = '//redirectLink'; + const mockProject = mockProjects[1]; + const addToSlackData = { data: { add_to_slack_link: redirectLink } }; + + addProjectToSlack.mockResolvedValue(addToSlackData); + + findProjectsDropdown().vm.$emit('project-selected', mockProject); + await nextTick(); + + expect(findProjectsDropdown().props('selectedProject')).toBe(mockProject); + expect(findGlButton().props('disabled')).toBe(false); + + findGlButton().vm.$emit('click'); + + await waitForPromises(); + + expect(redirectTo).toHaveBeenCalledWith(redirectLink); // eslint-disable-line import/no-deprecated + }); + }); + }); + }); +}); diff --git a/spec/frontend/integrations/gitlab_slack_application/mock_data.js b/spec/frontend/integrations/gitlab_slack_application/mock_data.js new file mode 100644 index 00000000000..9ada528d69e --- /dev/null +++ b/spec/frontend/integrations/gitlab_slack_application/mock_data.js @@ -0,0 +1,14 @@ +export const mockProjects = [ + { + id: 1, + name: 'Test', + avatar_url: 'avatar.jpg', + name_with_namespace: 'Test org / Test', + }, + { + id: 2, + name: 'Shell', + avatar_url: 'avatar.jpg', + name_with_namespace: 'Test org / Shell', + }, +]; |