diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 01:45:44 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 01:45:44 +0000 |
commit | 85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch) | |
tree | 9160f299afd8c80c038f08e1545be119f5e3f1e1 /spec/frontend/releases/stores | |
parent | 15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff) | |
download | gitlab-ce-85dc423f7090da0a52c73eb66faf22ddb20efff9.tar.gz |
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'spec/frontend/releases/stores')
3 files changed, 117 insertions, 38 deletions
diff --git a/spec/frontend/releases/stores/modules/list/actions_spec.js b/spec/frontend/releases/stores/modules/list/actions_spec.js index 4c3af157684..95e30659d6c 100644 --- a/spec/frontend/releases/stores/modules/list/actions_spec.js +++ b/spec/frontend/releases/stores/modules/list/actions_spec.js @@ -1,3 +1,4 @@ +import { cloneDeep } from 'lodash'; import testAction from 'helpers/vuex_action_helper'; import { requestReleases, @@ -5,21 +6,43 @@ import { receiveReleasesSuccess, receiveReleasesError, } from '~/releases/stores/modules/list/actions'; -import state from '~/releases/stores/modules/list/state'; +import createState from '~/releases/stores/modules/list/state'; import * as types from '~/releases/stores/modules/list/mutation_types'; import api from '~/api'; +import { gqClient, convertGraphQLResponse } from '~/releases/util'; import { parseIntPagination, convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; -import { pageInfoHeadersWithoutPagination, releases as originalReleases } from '../../../mock_data'; +import { + pageInfoHeadersWithoutPagination, + releases as originalReleases, + graphqlReleasesResponse as originalGraphqlReleasesResponse, +} from '../../../mock_data'; +import allReleasesQuery from '~/releases/queries/all_releases.query.graphql'; describe('Releases State actions', () => { let mockedState; let pageInfo; let releases; + let graphqlReleasesResponse; + + const projectPath = 'root/test-project'; + const projectId = 19; beforeEach(() => { - mockedState = state(); + mockedState = { + ...createState({ + projectId, + projectPath, + }), + featureFlags: { + graphqlReleaseData: true, + graphqlReleasesPage: true, + graphqlMilestoneStats: true, + }, + }; + pageInfo = parseIntPagination(pageInfoHeadersWithoutPagination); releases = convertObjectPropsToCamelCase(originalReleases, { deep: true }); + graphqlReleasesResponse = cloneDeep(originalGraphqlReleasesResponse); }); describe('requestReleases', () => { @@ -31,15 +54,17 @@ describe('Releases State actions', () => { describe('fetchReleases', () => { describe('success', () => { it('dispatches requestReleases and receiveReleasesSuccess', done => { - jest.spyOn(api, 'releases').mockImplementation((id, options) => { - expect(id).toEqual(1); - expect(options.page).toEqual('1'); - return Promise.resolve({ data: releases, headers: pageInfoHeadersWithoutPagination }); + jest.spyOn(gqClient, 'query').mockImplementation(({ query, variables }) => { + expect(query).toBe(allReleasesQuery); + expect(variables).toEqual({ + fullPath: projectPath, + }); + return Promise.resolve(graphqlReleasesResponse); }); testAction( fetchReleases, - { projectId: 1 }, + {}, mockedState, [], [ @@ -47,31 +72,7 @@ describe('Releases State actions', () => { type: 'requestReleases', }, { - payload: { data: releases, headers: pageInfoHeadersWithoutPagination }, - type: 'receiveReleasesSuccess', - }, - ], - done, - ); - }); - - it('dispatches requestReleases and receiveReleasesSuccess on page two', done => { - jest.spyOn(api, 'releases').mockImplementation((_, options) => { - expect(options.page).toEqual('2'); - return Promise.resolve({ data: releases, headers: pageInfoHeadersWithoutPagination }); - }); - - testAction( - fetchReleases, - { page: '2', projectId: 1 }, - mockedState, - [], - [ - { - type: 'requestReleases', - }, - { - payload: { data: releases, headers: pageInfoHeadersWithoutPagination }, + payload: convertGraphQLResponse(graphqlReleasesResponse), type: 'receiveReleasesSuccess', }, ], @@ -82,11 +83,11 @@ describe('Releases State actions', () => { describe('error', () => { it('dispatches requestReleases and receiveReleasesError', done => { - jest.spyOn(api, 'releases').mockReturnValue(Promise.reject()); + jest.spyOn(gqClient, 'query').mockRejectedValue(); testAction( fetchReleases, - { projectId: null }, + {}, mockedState, [], [ @@ -101,6 +102,85 @@ describe('Releases State actions', () => { ); }); }); + + describe('when the graphqlReleaseData feature flag is disabled', () => { + beforeEach(() => { + mockedState.featureFlags.graphqlReleasesPage = false; + }); + + describe('success', () => { + it('dispatches requestReleases and receiveReleasesSuccess', done => { + jest.spyOn(api, 'releases').mockImplementation((id, options) => { + expect(id).toBe(projectId); + expect(options.page).toBe('1'); + return Promise.resolve({ data: releases, headers: pageInfoHeadersWithoutPagination }); + }); + + testAction( + fetchReleases, + {}, + mockedState, + [], + [ + { + type: 'requestReleases', + }, + { + payload: { data: releases, headers: pageInfoHeadersWithoutPagination }, + type: 'receiveReleasesSuccess', + }, + ], + done, + ); + }); + + it('dispatches requestReleases and receiveReleasesSuccess on page two', done => { + jest.spyOn(api, 'releases').mockImplementation((_, options) => { + expect(options.page).toBe('2'); + return Promise.resolve({ data: releases, headers: pageInfoHeadersWithoutPagination }); + }); + + testAction( + fetchReleases, + { page: '2' }, + mockedState, + [], + [ + { + type: 'requestReleases', + }, + { + payload: { data: releases, headers: pageInfoHeadersWithoutPagination }, + type: 'receiveReleasesSuccess', + }, + ], + done, + ); + }); + }); + + describe('error', () => { + it('dispatches requestReleases and receiveReleasesError', done => { + jest.spyOn(api, 'releases').mockReturnValue(Promise.reject()); + + testAction( + fetchReleases, + {}, + mockedState, + [], + [ + { + type: 'requestReleases', + }, + { + type: 'receiveReleasesError', + }, + ], + done, + ); + }); + }); + }); }); describe('receiveReleasesSuccess', () => { diff --git a/spec/frontend/releases/stores/modules/list/helpers.js b/spec/frontend/releases/stores/modules/list/helpers.js index 435ca36047e..3ca255eaf8c 100644 --- a/spec/frontend/releases/stores/modules/list/helpers.js +++ b/spec/frontend/releases/stores/modules/list/helpers.js @@ -1,6 +1,5 @@ import state from '~/releases/stores/modules/list/state'; -// eslint-disable-next-line import/prefer-default-export export const resetStore = store => { store.replaceState(state()); }; diff --git a/spec/frontend/releases/stores/modules/list/mutations_spec.js b/spec/frontend/releases/stores/modules/list/mutations_spec.js index 3035b916ff6..27ad05846e7 100644 --- a/spec/frontend/releases/stores/modules/list/mutations_spec.js +++ b/spec/frontend/releases/stores/modules/list/mutations_spec.js @@ -1,4 +1,4 @@ -import state from '~/releases/stores/modules/list/state'; +import createState from '~/releases/stores/modules/list/state'; import mutations from '~/releases/stores/modules/list/mutations'; import * as types from '~/releases/stores/modules/list/mutation_types'; import { parseIntPagination } from '~/lib/utils/common_utils'; @@ -9,7 +9,7 @@ describe('Releases Store Mutations', () => { let pageInfo; beforeEach(() => { - stateCopy = state(); + stateCopy = createState({}); pageInfo = parseIntPagination(pageInfoHeadersWithoutPagination); }); |