diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-12 18:09:33 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-12 18:09:33 +0300 |
commit | 006000e366ad5dc61966770d33e3afd4c07e728d (patch) | |
tree | 2724bc1cd73a6f829d62f5ca68a423b921bd1af8 /spec/frontend | |
parent | 26e44c6225a19c3ec4e7d607f92b16d42b437c80 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
-rw-r--r-- | spec/frontend/boards/mock_data.js | 44 | ||||
-rw-r--r-- | spec/frontend/boards/project_select_deprecated_spec.js | 1 | ||||
-rw-r--r-- | spec/frontend/boards/project_select_spec.js | 64 | ||||
-rw-r--r-- | spec/frontend/boards/stores/getters_spec.js | 12 |
4 files changed, 78 insertions, 43 deletions
diff --git a/spec/frontend/boards/mock_data.js b/spec/frontend/boards/mock_data.js index e106b9235d6..500240d00fc 100644 --- a/spec/frontend/boards/mock_data.js +++ b/spec/frontend/boards/mock_data.js @@ -351,6 +351,7 @@ export const issues = { [mockIssue4.id]: mockIssue4, }; +// The response from group project REST API export const mockRawGroupProjects = [ { id: 0, @@ -366,17 +367,34 @@ export const mockRawGroupProjects = [ }, ]; -export const mockGroupProjects = [ - { - id: 0, - name: 'Example Project', - nameWithNamespace: 'Awesome Group / Example Project', - fullPath: 'awesome-group/example-project', - }, - { - id: 1, - name: 'Foobar Project', - nameWithNamespace: 'Awesome Group / Foobar Project', - fullPath: 'awesome-group/foobar-project', - }, +// The response from GraphQL endpoint +export const mockGroupProject1 = { + id: 0, + name: 'Example Project', + nameWithNamespace: 'Awesome Group / Example Project', + fullPath: 'awesome-group/example-project', + archived: false, +}; + +export const mockGroupProject2 = { + id: 1, + name: 'Foobar Project', + nameWithNamespace: 'Awesome Group / Foobar Project', + fullPath: 'awesome-group/foobar-project', + archived: false, +}; + +export const mockArchivedGroupProject = { + id: 2, + name: 'Archived Project', + nameWithNamespace: 'Awesome Group / Archived Project', + fullPath: 'awesome-group/archived-project', + archived: true, +}; + +export const mockGroupProjects = [mockGroupProject1, mockGroupProject2]; + +export const mockActiveGroupProjects = [ + { ...mockGroupProject1, archived: false }, + { ...mockGroupProject2, archived: false }, ]; diff --git a/spec/frontend/boards/project_select_deprecated_spec.js b/spec/frontend/boards/project_select_deprecated_spec.js index 9042c4bf9ba..37f519ef5b9 100644 --- a/spec/frontend/boards/project_select_deprecated_spec.js +++ b/spec/frontend/boards/project_select_deprecated_spec.js @@ -27,6 +27,7 @@ const mockDefaultFetchOptions = { with_shared: false, include_subgroups: true, order_by: 'similarity', + archived: false, }; const itemsPerPage = 20; diff --git a/spec/frontend/boards/project_select_spec.js b/spec/frontend/boards/project_select_spec.js index aa71952c42b..de823094630 100644 --- a/spec/frontend/boards/project_select_spec.js +++ b/spec/frontend/boards/project_select_spec.js @@ -1,30 +1,17 @@ import { GlDropdown, GlDropdownItem, GlSearchBoxByType, GlLoadingIcon } from '@gitlab/ui'; -import { createLocalVue, mount } from '@vue/test-utils'; +import { mount } from '@vue/test-utils'; +import Vue from 'vue'; import Vuex from 'vuex'; import ProjectSelect from '~/boards/components/project_select.vue'; import defaultState from '~/boards/stores/state'; -import { mockList, mockGroupProjects } from './mock_data'; +import { mockList, mockActiveGroupProjects } from './mock_data'; -const localVue = createLocalVue(); -localVue.use(Vuex); - -const actions = { - fetchGroupProjects: jest.fn(), - setSelectedProject: jest.fn(), -}; - -const createStore = (state = defaultState) => { - return new Vuex.Store({ - state, - actions, - }); -}; - -const mockProjectsList1 = mockGroupProjects.slice(0, 1); +const mockProjectsList1 = mockActiveGroupProjects.slice(0, 1); describe('ProjectSelect component', () => { let wrapper; + let store; const findLabel = () => wrapper.find("[data-testid='header-label']"); const findGlDropdown = () => wrapper.find(GlDropdown); @@ -36,20 +23,37 @@ describe('ProjectSelect component', () => { const findInMenuLoadingIcon = () => wrapper.find("[data-testid='dropdown-text-loading-icon']"); const findEmptySearchMessage = () => wrapper.find("[data-testid='empty-result-message']"); - const createWrapper = (state = {}) => { - const store = createStore({ - groupProjects: [], - groupProjectsFlags: { - isLoading: false, - pageInfo: { - hasNextPage: false, + const createStore = ({ state, activeGroupProjects }) => { + Vue.use(Vuex); + + store = new Vuex.Store({ + state: { + defaultState, + groupProjectsFlags: { + isLoading: false, + pageInfo: { + hasNextPage: false, + }, }, + ...state, + }, + actions: { + fetchGroupProjects: jest.fn(), + setSelectedProject: jest.fn(), }, - ...state, + getters: { + activeGroupProjects: () => activeGroupProjects, + }, + }); + }; + + const createWrapper = ({ state = {}, activeGroupProjects = [] } = {}) => { + createStore({ + state, + activeGroupProjects, }); wrapper = mount(ProjectSelect, { - localVue, propsData: { list: mockList, }, @@ -93,7 +97,7 @@ describe('ProjectSelect component', () => { describe('when dropdown menu is open', () => { describe('by default', () => { beforeEach(() => { - createWrapper({ groupProjects: mockGroupProjects }); + createWrapper({ activeGroupProjects: mockActiveGroupProjects }); }); it('shows GlSearchBoxByType with default attributes', () => { @@ -128,7 +132,7 @@ describe('ProjectSelect component', () => { describe('when a project is selected', () => { beforeEach(() => { - createWrapper({ groupProjects: mockProjectsList1 }); + createWrapper({ activeGroupProjects: mockProjectsList1 }); findFirstGlDropdownItem().find('button').trigger('click'); }); @@ -142,7 +146,7 @@ describe('ProjectSelect component', () => { describe('when projects are loading', () => { beforeEach(() => { - createWrapper({ groupProjectsFlags: { isLoading: true } }); + createWrapper({ state: { groupProjectsFlags: { isLoading: true } } }); }); it('displays and hides gl-loading-icon while and after fetching data', () => { diff --git a/spec/frontend/boards/stores/getters_spec.js b/spec/frontend/boards/stores/getters_spec.js index c0c19e9d797..32d73d861bc 100644 --- a/spec/frontend/boards/stores/getters_spec.js +++ b/spec/frontend/boards/stores/getters_spec.js @@ -7,6 +7,8 @@ import { mockIssuesByListId, issues, mockLists, + mockGroupProject1, + mockArchivedGroupProject, } from '../mock_data'; describe('Boards - Getters', () => { @@ -165,4 +167,14 @@ describe('Boards - Getters', () => { expect(getters.getListByTitle(boardsState)('To Do')).toEqual(mockLists[1]); }); }); + + describe('activeGroupProjects', () => { + const state = { + groupProjects: [mockGroupProject1, mockArchivedGroupProject], + }; + + it('returns only returns non-archived group projects', () => { + expect(getters.activeGroupProjects(state)).toEqual([mockGroupProject1]); + }); + }); }); |