2021-02-22 17:27:13 +05:30
|
|
|
import { GlDropdown, GlLoadingIcon, GlDropdownSectionHeader } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
2021-12-11 22:18:48 +05:30
|
|
|
import Vue, { nextTick } from 'vue';
|
|
|
|
import VueApollo from 'vue-apollo';
|
|
|
|
import Vuex from 'vuex';
|
2020-04-08 14:13:33 +05:30
|
|
|
import { TEST_HOST } from 'spec/test_constants';
|
|
|
|
import BoardsSelector from '~/boards/components/boards_selector.vue';
|
2022-04-04 11:22:00 +05:30
|
|
|
import { BoardType } from '~/boards/constants';
|
2021-12-11 22:18:48 +05:30
|
|
|
import groupBoardQuery from '~/boards/graphql/group_board.query.graphql';
|
|
|
|
import projectBoardQuery from '~/boards/graphql/project_board.query.graphql';
|
2022-04-04 11:22:00 +05:30
|
|
|
import groupBoardsQuery from '~/boards/graphql/group_boards.query.graphql';
|
|
|
|
import projectBoardsQuery from '~/boards/graphql/project_boards.query.graphql';
|
|
|
|
import groupRecentBoardsQuery from '~/boards/graphql/group_recent_boards.query.graphql';
|
|
|
|
import projectRecentBoardsQuery from '~/boards/graphql/project_recent_boards.query.graphql';
|
2021-12-11 22:18:48 +05:30
|
|
|
import defaultStore from '~/boards/stores';
|
|
|
|
import createMockApollo from 'helpers/mock_apollo_helper';
|
2022-04-04 11:22:00 +05:30
|
|
|
import {
|
|
|
|
mockGroupBoardResponse,
|
|
|
|
mockProjectBoardResponse,
|
|
|
|
mockGroupAllBoardsResponse,
|
|
|
|
mockProjectAllBoardsResponse,
|
|
|
|
mockGroupRecentBoardsResponse,
|
|
|
|
mockProjectRecentBoardsResponse,
|
|
|
|
mockSmallProjectAllBoardsResponse,
|
|
|
|
mockEmptyProjectRecentBoardsResponse,
|
|
|
|
boards,
|
|
|
|
recentIssueBoards,
|
|
|
|
} from '../mock_data';
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
const throttleDuration = 1;
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
Vue.use(VueApollo);
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
describe('BoardsSelector', () => {
|
|
|
|
let wrapper;
|
2021-12-11 22:18:48 +05:30
|
|
|
let fakeApollo;
|
|
|
|
let store;
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
const createStore = ({ isGroupBoard = false, isProjectBoard = false } = {}) => {
|
|
|
|
store = new Vuex.Store({
|
|
|
|
...defaultStore,
|
|
|
|
actions: {
|
|
|
|
setError: jest.fn(),
|
|
|
|
},
|
|
|
|
getters: {
|
|
|
|
isGroupBoard: () => isGroupBoard,
|
|
|
|
isProjectBoard: () => isProjectBoard,
|
|
|
|
},
|
|
|
|
state: {
|
|
|
|
boardType: isGroupBoard ? 'group' : 'project',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const fillSearchBox = (filterTerm) => {
|
2020-04-08 14:13:33 +05:30
|
|
|
const searchBox = wrapper.find({ ref: 'searchBox' });
|
|
|
|
const searchBoxInput = searchBox.find('input');
|
|
|
|
searchBoxInput.setValue(filterTerm);
|
|
|
|
searchBoxInput.trigger('input');
|
|
|
|
};
|
|
|
|
|
|
|
|
const getDropdownItems = () => wrapper.findAll('.js-dropdown-item');
|
2022-04-04 11:22:00 +05:30
|
|
|
const getDropdownHeaders = () => wrapper.findAllComponents(GlDropdownSectionHeader);
|
|
|
|
const getLoadingIcon = () => wrapper.findComponent(GlLoadingIcon);
|
|
|
|
const findDropdown = () => wrapper.findComponent(GlDropdown);
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
const projectBoardQueryHandlerSuccess = jest.fn().mockResolvedValue(mockProjectBoardResponse);
|
|
|
|
const groupBoardQueryHandlerSuccess = jest.fn().mockResolvedValue(mockGroupBoardResponse);
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
const projectBoardsQueryHandlerSuccess = jest
|
|
|
|
.fn()
|
|
|
|
.mockResolvedValue(mockProjectAllBoardsResponse);
|
|
|
|
const groupBoardsQueryHandlerSuccess = jest.fn().mockResolvedValue(mockGroupAllBoardsResponse);
|
|
|
|
|
|
|
|
const projectRecentBoardsQueryHandlerSuccess = jest
|
|
|
|
.fn()
|
|
|
|
.mockResolvedValue(mockProjectRecentBoardsResponse);
|
|
|
|
const groupRecentBoardsQueryHandlerSuccess = jest
|
|
|
|
.fn()
|
|
|
|
.mockResolvedValue(mockGroupRecentBoardsResponse);
|
|
|
|
|
|
|
|
const smallBoardsQueryHandlerSuccess = jest
|
|
|
|
.fn()
|
|
|
|
.mockResolvedValue(mockSmallProjectAllBoardsResponse);
|
|
|
|
const emptyRecentBoardsQueryHandlerSuccess = jest
|
|
|
|
.fn()
|
|
|
|
.mockResolvedValue(mockEmptyProjectRecentBoardsResponse);
|
|
|
|
|
|
|
|
const createComponent = ({
|
|
|
|
projectBoardsQueryHandler = projectBoardsQueryHandlerSuccess,
|
|
|
|
projectRecentBoardsQueryHandler = projectRecentBoardsQueryHandlerSuccess,
|
|
|
|
} = {}) => {
|
2021-12-11 22:18:48 +05:30
|
|
|
fakeApollo = createMockApollo([
|
|
|
|
[projectBoardQuery, projectBoardQueryHandlerSuccess],
|
|
|
|
[groupBoardQuery, groupBoardQueryHandlerSuccess],
|
2022-04-04 11:22:00 +05:30
|
|
|
[projectBoardsQuery, projectBoardsQueryHandler],
|
|
|
|
[groupBoardsQuery, groupBoardsQueryHandlerSuccess],
|
|
|
|
[projectRecentBoardsQuery, projectRecentBoardsQueryHandler],
|
|
|
|
[groupRecentBoardsQuery, groupRecentBoardsQueryHandlerSuccess],
|
2021-12-11 22:18:48 +05:30
|
|
|
]);
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
wrapper = mount(BoardsSelector, {
|
2021-12-11 22:18:48 +05:30
|
|
|
store,
|
|
|
|
apolloProvider: fakeApollo,
|
2020-04-08 14:13:33 +05:30
|
|
|
propsData: {
|
|
|
|
throttleDuration,
|
|
|
|
boardBaseUrl: `${TEST_HOST}/board/base/url`,
|
|
|
|
hasMissingBoards: false,
|
|
|
|
canAdminBoard: true,
|
|
|
|
multipleIssueBoardsAvailable: true,
|
|
|
|
scopedIssueBoardFeatureEnabled: true,
|
|
|
|
weights: [],
|
|
|
|
},
|
2021-03-08 18:12:59 +05:30
|
|
|
attachTo: document.body,
|
2021-03-11 19:13:27 +05:30
|
|
|
provide: {
|
|
|
|
fullPath: '',
|
|
|
|
},
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
2021-12-11 22:18:48 +05:30
|
|
|
};
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
2022-04-04 11:22:00 +05:30
|
|
|
fakeApollo = null;
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
describe('template', () => {
|
2021-12-11 22:18:48 +05:30
|
|
|
beforeEach(() => {
|
2022-04-04 11:22:00 +05:30
|
|
|
createStore({ isProjectBoard: true });
|
2021-12-11 22:18:48 +05:30
|
|
|
createComponent();
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
describe('loading', () => {
|
|
|
|
// we are testing loading state, so don't resolve responses until after the tests
|
|
|
|
afterEach(async () => {
|
|
|
|
await nextTick();
|
2021-02-22 17:27:13 +05:30
|
|
|
});
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
it('shows loading spinner', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
// Emits gl-dropdown show event to simulate the dropdown is opened at initialization time
|
|
|
|
findDropdown().vm.$emit('show');
|
|
|
|
|
|
|
|
expect(getLoadingIcon().exists()).toBe(true);
|
2021-12-11 22:18:48 +05:30
|
|
|
expect(getDropdownHeaders()).toHaveLength(0);
|
|
|
|
expect(getDropdownItems()).toHaveLength(0);
|
|
|
|
});
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
describe('loaded', () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
// Wait for current board to be loaded
|
|
|
|
await nextTick();
|
|
|
|
|
|
|
|
// Emits gl-dropdown show event to simulate the dropdown is opened at initialization time
|
|
|
|
findDropdown().vm.$emit('show');
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
await nextTick();
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('fetches all issue boards', () => {
|
|
|
|
expect(projectBoardsQueryHandlerSuccess).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
it('hides loading spinner', async () => {
|
|
|
|
await nextTick();
|
|
|
|
expect(getLoadingIcon().exists()).toBe(false);
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
describe('filtering', () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
await nextTick();
|
|
|
|
});
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
it('shows all boards without filtering', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(getDropdownItems()).toHaveLength(boards.length + recentIssueBoards.length);
|
2021-12-11 22:18:48 +05:30
|
|
|
});
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
it('shows only matching boards when filtering', async () => {
|
|
|
|
const filterTerm = 'board1';
|
2022-04-04 11:22:00 +05:30
|
|
|
const expectedCount = boards.filter((board) => board.node.name.includes(filterTerm))
|
|
|
|
.length;
|
2021-12-11 22:18:48 +05:30
|
|
|
|
|
|
|
fillSearchBox(filterTerm);
|
|
|
|
|
|
|
|
await nextTick();
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(getDropdownItems()).toHaveLength(expectedCount);
|
|
|
|
});
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
it('shows message if there are no matching boards', async () => {
|
|
|
|
fillSearchBox('does not exist');
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
await nextTick();
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(getDropdownItems()).toHaveLength(0);
|
|
|
|
expect(wrapper.text().includes('No matching boards found')).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
describe('recent boards section', () => {
|
|
|
|
it('shows only when boards are greater than 10', async () => {
|
|
|
|
await nextTick();
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(projectRecentBoardsQueryHandlerSuccess).toHaveBeenCalled();
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(getDropdownHeaders()).toHaveLength(2);
|
|
|
|
});
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
it('does not show when boards are less than 10', async () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
createComponent({ projectBoardsQueryHandler: smallBoardsQueryHandlerSuccess });
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
await nextTick();
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(getDropdownHeaders()).toHaveLength(0);
|
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('does not show when recentIssueBoards api returns empty array', async () => {
|
|
|
|
createComponent({
|
|
|
|
projectRecentBoardsQueryHandler: emptyRecentBoardsQueryHandlerSuccess,
|
2021-12-11 22:18:48 +05:30
|
|
|
});
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
await nextTick();
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(getDropdownHeaders()).toHaveLength(0);
|
|
|
|
});
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
it('does not show when search is active', async () => {
|
|
|
|
fillSearchBox('Random string');
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
await nextTick();
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(getDropdownHeaders()).toHaveLength(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-12-11 22:18:48 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
describe('fetching all boards', () => {
|
|
|
|
it.each`
|
|
|
|
boardType | queryHandler | notCalledHandler
|
|
|
|
${BoardType.group} | ${groupBoardsQueryHandlerSuccess} | ${projectBoardsQueryHandlerSuccess}
|
|
|
|
${BoardType.project} | ${projectBoardsQueryHandlerSuccess} | ${groupBoardsQueryHandlerSuccess}
|
|
|
|
`('fetches $boardType boards', async ({ boardType, queryHandler, notCalledHandler }) => {
|
|
|
|
createStore({
|
|
|
|
isProjectBoard: boardType === BoardType.project,
|
|
|
|
isGroupBoard: boardType === BoardType.group,
|
|
|
|
});
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
await nextTick();
|
|
|
|
|
|
|
|
// Emits gl-dropdown show event to simulate the dropdown is opened at initialization time
|
|
|
|
findDropdown().vm.$emit('show');
|
|
|
|
|
|
|
|
await nextTick();
|
|
|
|
|
|
|
|
expect(queryHandler).toHaveBeenCalled();
|
|
|
|
expect(notCalledHandler).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
describe('fetching current board', () => {
|
|
|
|
it.each`
|
2022-04-04 11:22:00 +05:30
|
|
|
boardType | queryHandler | notCalledHandler
|
|
|
|
${BoardType.group} | ${groupBoardQueryHandlerSuccess} | ${projectBoardQueryHandlerSuccess}
|
|
|
|
${BoardType.project} | ${projectBoardQueryHandlerSuccess} | ${groupBoardQueryHandlerSuccess}
|
2021-12-11 22:18:48 +05:30
|
|
|
`('fetches $boardType board', async ({ boardType, queryHandler, notCalledHandler }) => {
|
|
|
|
createStore({
|
2022-04-04 11:22:00 +05:30
|
|
|
isProjectBoard: boardType === BoardType.project,
|
|
|
|
isGroupBoard: boardType === BoardType.group,
|
2021-12-11 22:18:48 +05:30
|
|
|
});
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
await nextTick();
|
|
|
|
|
|
|
|
expect(queryHandler).toHaveBeenCalled();
|
|
|
|
expect(notCalledHandler).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|