diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /spec/frontend/jira_connect/subscriptions/components/app_spec.js | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/frontend/jira_connect/subscriptions/components/app_spec.js')
-rw-r--r-- | spec/frontend/jira_connect/subscriptions/components/app_spec.js | 67 |
1 files changed, 33 insertions, 34 deletions
diff --git a/spec/frontend/jira_connect/subscriptions/components/app_spec.js b/spec/frontend/jira_connect/subscriptions/components/app_spec.js index ce02144f22f..9894141be5a 100644 --- a/spec/frontend/jira_connect/subscriptions/components/app_spec.js +++ b/spec/frontend/jira_connect/subscriptions/components/app_spec.js @@ -3,8 +3,8 @@ import { nextTick } from 'vue'; import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper'; import JiraConnectApp from '~/jira_connect/subscriptions/components/app.vue'; -import SignInPage from '~/jira_connect/subscriptions/pages/sign_in.vue'; -import SubscriptionsPage from '~/jira_connect/subscriptions/pages/subscriptions.vue'; +import SignInPage from '~/jira_connect/subscriptions/pages/sign_in/sign_in_page.vue'; +import SubscriptionsPage from '~/jira_connect/subscriptions/pages/subscriptions_page.vue'; import UserLink from '~/jira_connect/subscriptions/components/user_link.vue'; import BrowserSupportAlert from '~/jira_connect/subscriptions/components/browser_support_alert.vue'; import createStore from '~/jira_connect/subscriptions/store'; @@ -12,6 +12,7 @@ import { SET_ALERT } from '~/jira_connect/subscriptions/store/mutation_types'; import { I18N_DEFAULT_SIGN_IN_ERROR_MESSAGE } from '~/jira_connect/subscriptions/constants'; import { __ } from '~/locale'; import AccessorUtilities from '~/lib/utils/accessor'; +import * as api from '~/jira_connect/subscriptions/api'; import { mockSubscription } from '../mock_data'; jest.mock('~/jira_connect/subscriptions/utils', () => ({ @@ -31,7 +32,8 @@ describe('JiraConnectApp', () => { const findBrowserSupportAlert = () => wrapper.findComponent(BrowserSupportAlert); const createComponent = ({ provide, mountFn = shallowMountExtended } = {}) => { - store = createStore(); + store = createStore({ subscriptions: [mockSubscription] }); + jest.spyOn(store, 'dispatch').mockImplementation(); wrapper = mountFn(JiraConnectApp, { store, @@ -53,7 +55,6 @@ describe('JiraConnectApp', () => { createComponent({ provide: { usersPath, - subscriptions: [mockSubscription], }, }); }); @@ -79,14 +80,13 @@ describe('JiraConnectApp', () => { createComponent({ provide: { usersPath: '/user', - subscriptions: [], }, }); const userLink = findUserLink(); expect(userLink.exists()).toBe(true); expect(userLink.props()).toEqual({ - hasSubscriptions: false, + hasSubscriptions: true, user: null, userSignedIn: false, }); @@ -161,39 +161,11 @@ describe('JiraConnectApp', () => { }); describe('when user signed out', () => { - describe('when sign in page emits `sign-in-oauth` event', () => { - const mockUser = { name: 'test' }; - beforeEach(async () => { - createComponent({ - provide: { - usersPath: '/mock', - subscriptions: [], - }, - }); - findSignInPage().vm.$emit('sign-in-oauth', mockUser); - - await nextTick(); - }); - - it('hides sign in page and renders subscriptions page', () => { - expect(findSignInPage().exists()).toBe(false); - expect(findSubscriptionsPage().exists()).toBe(true); - }); - - it('sets correct UserLink props', () => { - expect(findUserLink().props()).toMatchObject({ - user: mockUser, - userSignedIn: true, - }); - }); - }); - describe('when sign in page emits `error` event', () => { beforeEach(async () => { createComponent({ provide: { usersPath: '/mock', - subscriptions: [], }, }); findSignInPage().vm.$emit('error'); @@ -235,4 +207,31 @@ describe('JiraConnectApp', () => { }); }, ); + + describe('when `jiraConnectOauth` feature flag is enabled', () => { + const mockSubscriptionsPath = '/mockSubscriptionsPath'; + + beforeEach(() => { + jest.spyOn(api, 'fetchSubscriptions').mockResolvedValue({ data: { subscriptions: [] } }); + + createComponent({ + provide: { + glFeatures: { jiraConnectOauth: true }, + subscriptionsPath: mockSubscriptionsPath, + }, + }); + }); + + describe('when component mounts', () => { + it('dispatches `fetchSubscriptions` action', async () => { + expect(store.dispatch).toHaveBeenCalledWith('fetchSubscriptions', mockSubscriptionsPath); + }); + }); + + describe('when oauth button emits `sign-in-oauth` event', () => { + it('dispatches `fetchSubscriptions` action', () => { + expect(store.dispatch).toHaveBeenCalledWith('fetchSubscriptions', mockSubscriptionsPath); + }); + }); + }); }); |