Commit e8a7fbc5 authored by Vitaly Slobodin's avatar Vitaly Slobodin

Migrate ee/add_slack_app to Jest

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/194265
parent 5ac9eb84
import Vue from 'vue'; import Vue from 'vue';
import addGitlabSlackApplication from 'ee/add_gitlab_slack_application/components/add_gitlab_slack_application.vue'; import addGitlabSlackApplication from 'ee/add_gitlab_slack_application/components/add_gitlab_slack_application.vue';
import GitlabSlackService from 'ee/add_gitlab_slack_application/services/gitlab_slack_service'; import GitlabSlackService from 'ee/add_gitlab_slack_application/services/gitlab_slack_service';
import mountComponent from 'spec/helpers/vue_mount_component_helper'; import mountComponent from 'helpers/vue_mount_component_helper';
import { redirectTo } from '~/lib/utils/url_utility';
jest.mock('~/lib/utils/url_utility');
describe('AddGitlabSlackApplication', () => { describe('AddGitlabSlackApplication', () => {
const redirectLink = '//redirectLink'; const redirectLink = '//redirectLink';
...@@ -34,35 +37,31 @@ describe('AddGitlabSlackApplication', () => { ...@@ -34,35 +37,31 @@ describe('AddGitlabSlackApplication', () => {
const AddGitlabSlackApplication = Vue.extend(addGitlabSlackApplication); const AddGitlabSlackApplication = Vue.extend(addGitlabSlackApplication);
it('opens popup when button is clicked', done => { it('opens popup when button is clicked', () => {
const vm = mountComponent(AddGitlabSlackApplication, DEFAULT_PROPS); const vm = mountComponent(AddGitlabSlackApplication, DEFAULT_PROPS);
vm.$el.querySelector('.js-popup-button').click(); vm.$el.querySelector('.js-popup-button').click();
vm.$nextTick() return vm.$nextTick().then(() => {
.then(() => { expect(vm.$el.querySelector('.js-popup')).toBeDefined();
expect(vm.$el.querySelector('.js-popup')).toBeDefined(); });
})
.then(done)
.catch(done.fail);
}); });
it('hides popup when button is clicked', done => { it('hides popup when button is clicked', () => {
const vm = mountComponent(AddGitlabSlackApplication, DEFAULT_PROPS); const vm = mountComponent(AddGitlabSlackApplication, DEFAULT_PROPS);
vm.popupOpen = true; vm.popupOpen = true;
vm.$nextTick() return vm
.$nextTick()
.then(() => vm.$el.querySelector('.js-popup-button').click()) .then(() => vm.$el.querySelector('.js-popup-button').click())
.then(vm.$nextTick) .then(vm.$nextTick)
.then(() => { .then(() => {
expect(vm.$el.querySelector('.js-popup')).toBeNull(); expect(vm.$el.querySelector('.js-popup')).toBeNull();
}) });
.then(done)
.catch(done.fail);
}); });
it('popup has a project select when signed in', done => { it('popup has a project select when signed in', () => {
const vm = mountComponent(AddGitlabSlackApplication, { const vm = mountComponent(AddGitlabSlackApplication, {
...DEFAULT_PROPS, ...DEFAULT_PROPS,
isSignedIn: true, isSignedIn: true,
...@@ -70,15 +69,12 @@ describe('AddGitlabSlackApplication', () => { ...@@ -70,15 +69,12 @@ describe('AddGitlabSlackApplication', () => {
vm.popupOpen = true; vm.popupOpen = true;
vm.$nextTick() return vm.$nextTick().then(() => {
.then(() => { expect(vm.$el.querySelector('.js-project-select')).toBeDefined();
expect(vm.$el.querySelector('.js-project-select')).toBeDefined(); });
})
.then(done)
.catch(done.fail);
}); });
it('popup has a message when there is no projects', done => { it('popup has a message when there is no projects', () => {
const vm = mountComponent(AddGitlabSlackApplication, { const vm = mountComponent(AddGitlabSlackApplication, {
...DEFAULT_PROPS, ...DEFAULT_PROPS,
projects: [], projects: [],
...@@ -87,17 +83,14 @@ describe('AddGitlabSlackApplication', () => { ...@@ -87,17 +83,14 @@ describe('AddGitlabSlackApplication', () => {
vm.popupOpen = true; vm.popupOpen = true;
vm.$nextTick() return vm.$nextTick().then(() => {
.then(() => { expect(vm.$el.querySelector('.js-no-projects').textContent).toMatch(
expect(vm.$el.querySelector('.js-no-projects').textContent).toMatch( "You don't have any projects available.",
"You don't have any projects available.", );
); });
})
.then(done)
.catch(done.fail);
}); });
it('popup has a sign in link when logged out', done => { it('popup has a sign in link when logged out', () => {
const vm = mountComponent(AddGitlabSlackApplication, { const vm = mountComponent(AddGitlabSlackApplication, {
...DEFAULT_PROPS, ...DEFAULT_PROPS,
}); });
...@@ -105,36 +98,31 @@ describe('AddGitlabSlackApplication', () => { ...@@ -105,36 +98,31 @@ describe('AddGitlabSlackApplication', () => {
vm.popupOpen = true; vm.popupOpen = true;
vm.selectedProjectId = 4; vm.selectedProjectId = 4;
vm.$nextTick() return vm.$nextTick().then(() => {
.then(() => { expect(vm.$el.querySelector('.js-gitlab-slack-sign-in-link').href).toMatch(
expect(vm.$el.querySelector('.js-gitlab-slack-sign-in-link').href).toMatch( new RegExp(signInPath, 'i'),
new RegExp(signInPath, 'i'), );
); });
})
.then(done)
.catch(done.fail);
}); });
it('redirects user to external link when submitted', done => { it('redirects user to external link when submitted', () => {
const vm = mountComponent(AddGitlabSlackApplication, { const vm = mountComponent(AddGitlabSlackApplication, {
...DEFAULT_PROPS, ...DEFAULT_PROPS,
isSignedIn: true, isSignedIn: true,
}); });
const addToSlackPromise = Promise.resolve({ data: { add_to_slack_link: redirectLink } }); const addToSlackPromise = Promise.resolve({ data: { add_to_slack_link: redirectLink } });
spyOn(GitlabSlackService, 'addToSlack').and.returnValue(addToSlackPromise); jest.spyOn(GitlabSlackService, 'addToSlack').mockReturnValue(addToSlackPromise);
const redirectTo = spyOnDependency(addGitlabSlackApplication, 'redirectTo');
vm.popupOpen = true; vm.popupOpen = true;
vm.$nextTick() return vm
.$nextTick()
.then(() => vm.$el.querySelector('.js-add-button').click()) .then(() => vm.$el.querySelector('.js-add-button').click())
.then(vm.$nextTick) .then(vm.$nextTick)
.then(addToSlackPromise) .then(addToSlackPromise)
.then(() => { .then(() => {
expect(redirectTo).toHaveBeenCalledWith(redirectLink); expect(redirectTo).toHaveBeenCalledWith(redirectLink);
}) });
.then(done)
.catch(done.fail);
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment