2020-12-23 09:10:13 +00:00
|
|
|
import { GlDropdown, GlDropdownItem, GlSearchBoxByType, GlLoadingIcon } from '@gitlab/ui';
|
2021-03-12 15:09:33 +00:00
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import Vue from 'vue';
|
2021-02-14 18:09:20 +00:00
|
|
|
import Vuex from 'vuex';
|
2020-12-23 09:10:13 +00:00
|
|
|
import ProjectSelect from '~/boards/components/project_select.vue';
|
2021-02-14 18:09:20 +00:00
|
|
|
import defaultState from '~/boards/stores/state';
|
2020-12-23 09:10:13 +00:00
|
|
|
|
2021-03-12 15:09:33 +00:00
|
|
|
import { mockList, mockActiveGroupProjects } from './mock_data';
|
2020-12-23 09:10:13 +00:00
|
|
|
|
2021-03-12 15:09:33 +00:00
|
|
|
const mockProjectsList1 = mockActiveGroupProjects.slice(0, 1);
|
2020-12-23 09:10:13 +00:00
|
|
|
|
|
|
|
describe('ProjectSelect component', () => {
|
|
|
|
let wrapper;
|
2021-03-12 15:09:33 +00:00
|
|
|
let store;
|
2020-12-23 09:10:13 +00:00
|
|
|
|
|
|
|
const findLabel = () => wrapper.find("[data-testid='header-label']");
|
|
|
|
const findGlDropdown = () => wrapper.find(GlDropdown);
|
|
|
|
const findGlDropdownLoadingIcon = () =>
|
2020-12-23 12:10:26 +00:00
|
|
|
findGlDropdown().find('button:first-child').find(GlLoadingIcon);
|
2020-12-23 09:10:13 +00:00
|
|
|
const findGlSearchBoxByType = () => wrapper.find(GlSearchBoxByType);
|
|
|
|
const findGlDropdownItems = () => wrapper.findAll(GlDropdownItem);
|
|
|
|
const findFirstGlDropdownItem = () => findGlDropdownItems().at(0);
|
|
|
|
const findInMenuLoadingIcon = () => wrapper.find("[data-testid='dropdown-text-loading-icon']");
|
|
|
|
const findEmptySearchMessage = () => wrapper.find("[data-testid='empty-result-message']");
|
|
|
|
|
2021-03-12 15:09:33 +00:00
|
|
|
const createStore = ({ state, activeGroupProjects }) => {
|
|
|
|
Vue.use(Vuex);
|
|
|
|
|
|
|
|
store = new Vuex.Store({
|
|
|
|
state: {
|
|
|
|
defaultState,
|
|
|
|
groupProjectsFlags: {
|
|
|
|
isLoading: false,
|
|
|
|
pageInfo: {
|
|
|
|
hasNextPage: false,
|
|
|
|
},
|
2021-01-14 09:10:22 +00:00
|
|
|
},
|
2021-03-12 15:09:33 +00:00
|
|
|
...state,
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
fetchGroupProjects: jest.fn(),
|
|
|
|
setSelectedProject: jest.fn(),
|
2021-01-14 09:10:22 +00:00
|
|
|
},
|
2021-03-12 15:09:33 +00:00
|
|
|
getters: {
|
|
|
|
activeGroupProjects: () => activeGroupProjects,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const createWrapper = ({ state = {}, activeGroupProjects = [] } = {}) => {
|
|
|
|
createStore({
|
|
|
|
state,
|
|
|
|
activeGroupProjects,
|
2021-01-14 09:10:22 +00:00
|
|
|
});
|
2020-12-23 09:10:13 +00:00
|
|
|
|
|
|
|
wrapper = mount(ProjectSelect, {
|
|
|
|
propsData: {
|
2021-01-14 09:10:22 +00:00
|
|
|
list: mockList,
|
2020-12-23 09:10:13 +00:00
|
|
|
},
|
2021-01-14 09:10:22 +00:00
|
|
|
store,
|
2020-12-23 09:10:13 +00:00
|
|
|
provide: {
|
|
|
|
groupId: 1,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
2021-01-14 09:10:22 +00:00
|
|
|
it('displays a header title', () => {
|
|
|
|
createWrapper();
|
2020-12-23 09:10:13 +00:00
|
|
|
|
|
|
|
expect(findLabel().text()).toBe('Projects');
|
|
|
|
});
|
|
|
|
|
2021-01-14 09:10:22 +00:00
|
|
|
it('renders a default dropdown text', () => {
|
|
|
|
createWrapper();
|
2020-12-23 09:10:13 +00:00
|
|
|
|
|
|
|
expect(findGlDropdown().exists()).toBe(true);
|
|
|
|
expect(findGlDropdown().text()).toContain('Select a project');
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when mounted', () => {
|
|
|
|
it('displays a loading icon while projects are being fetched', async () => {
|
2021-01-14 09:10:22 +00:00
|
|
|
createWrapper();
|
2020-12-23 09:10:13 +00:00
|
|
|
|
|
|
|
expect(findGlDropdownLoadingIcon().exists()).toBe(true);
|
|
|
|
|
2021-01-14 09:10:22 +00:00
|
|
|
await wrapper.vm.$nextTick();
|
2020-12-23 09:10:13 +00:00
|
|
|
|
|
|
|
expect(findGlDropdownLoadingIcon().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when dropdown menu is open', () => {
|
|
|
|
describe('by default', () => {
|
2021-01-14 09:10:22 +00:00
|
|
|
beforeEach(() => {
|
2021-03-12 15:09:33 +00:00
|
|
|
createWrapper({ activeGroupProjects: mockActiveGroupProjects });
|
2020-12-23 09:10:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('shows GlSearchBoxByType with default attributes', () => {
|
|
|
|
expect(findGlSearchBoxByType().exists()).toBe(true);
|
|
|
|
expect(findGlSearchBoxByType().vm.$attrs).toMatchObject({
|
|
|
|
placeholder: 'Search projects',
|
|
|
|
debounce: '250',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("displays the fetched project's name", () => {
|
|
|
|
expect(findFirstGlDropdownItem().exists()).toBe(true);
|
|
|
|
expect(findFirstGlDropdownItem().text()).toContain(mockProjectsList1[0].name);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("doesn't render loading icon in the menu", () => {
|
|
|
|
expect(findInMenuLoadingIcon().isVisible()).toBe(false);
|
|
|
|
});
|
|
|
|
|
2021-01-14 09:10:22 +00:00
|
|
|
it('does not render empty search result message', () => {
|
|
|
|
expect(findEmptySearchMessage().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when no projects are being returned', () => {
|
|
|
|
it('renders empty search result message', () => {
|
|
|
|
createWrapper();
|
2020-12-23 09:10:13 +00:00
|
|
|
|
|
|
|
expect(findEmptySearchMessage().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when a project is selected', () => {
|
2021-01-14 09:10:22 +00:00
|
|
|
beforeEach(() => {
|
2021-03-12 15:09:33 +00:00
|
|
|
createWrapper({ activeGroupProjects: mockProjectsList1 });
|
2020-12-23 09:10:13 +00:00
|
|
|
|
2021-01-14 09:10:22 +00:00
|
|
|
findFirstGlDropdownItem().find('button').trigger('click');
|
2020-12-23 09:10:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the name of the selected project', () => {
|
2020-12-23 12:10:26 +00:00
|
|
|
expect(findGlDropdown().find('.gl-new-dropdown-button-text').text()).toBe(
|
|
|
|
mockProjectsList1[0].name,
|
|
|
|
);
|
2020-12-23 09:10:13 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-01-14 09:10:22 +00:00
|
|
|
describe('when projects are loading', () => {
|
|
|
|
beforeEach(() => {
|
2021-03-12 15:09:33 +00:00
|
|
|
createWrapper({ state: { groupProjectsFlags: { isLoading: true } } });
|
2020-12-23 09:10:13 +00:00
|
|
|
});
|
|
|
|
|
2021-01-14 09:10:22 +00:00
|
|
|
it('displays and hides gl-loading-icon while and after fetching data', () => {
|
2020-12-23 09:10:13 +00:00
|
|
|
expect(findInMenuLoadingIcon().isVisible()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|