2022-06-21 17:19:12 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2023-04-23 21:23:45 +05:30
|
|
|
import Vue, { nextTick } from 'vue';
|
|
|
|
import VueApollo from 'vue-apollo';
|
2022-06-21 17:19:12 +05:30
|
|
|
import Vuex from 'vuex';
|
2023-04-23 21:23:45 +05:30
|
|
|
import createMockApollo from 'helpers/mock_apollo_helper';
|
2022-06-21 17:19:12 +05:30
|
|
|
|
|
|
|
import BoardTopBar from '~/boards/components/board_top_bar.vue';
|
|
|
|
import BoardAddNewColumnTrigger from '~/boards/components/board_add_new_column_trigger.vue';
|
|
|
|
import BoardsSelector from '~/boards/components/boards_selector.vue';
|
|
|
|
import ConfigToggle from '~/boards/components/config_toggle.vue';
|
|
|
|
import IssueBoardFilteredSearch from '~/boards/components/issue_board_filtered_search.vue';
|
|
|
|
import NewBoardButton from '~/boards/components/new_board_button.vue';
|
|
|
|
import ToggleFocus from '~/boards/components/toggle_focus.vue';
|
2023-04-23 21:23:45 +05:30
|
|
|
import { BoardType } from '~/boards/constants';
|
|
|
|
|
|
|
|
import groupBoardQuery from '~/boards/graphql/group_board.query.graphql';
|
|
|
|
import projectBoardQuery from '~/boards/graphql/project_board.query.graphql';
|
|
|
|
import { mockProjectBoardResponse, mockGroupBoardResponse } from '../mock_data';
|
|
|
|
|
|
|
|
Vue.use(VueApollo);
|
|
|
|
Vue.use(Vuex);
|
2022-06-21 17:19:12 +05:30
|
|
|
|
|
|
|
describe('BoardTopBar', () => {
|
|
|
|
let wrapper;
|
2023-04-23 21:23:45 +05:30
|
|
|
let mockApollo;
|
2022-06-21 17:19:12 +05:30
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
const createStore = () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
return new Vuex.Store({
|
|
|
|
state: {},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
const projectBoardQueryHandlerSuccess = jest.fn().mockResolvedValue(mockProjectBoardResponse);
|
|
|
|
const groupBoardQueryHandlerSuccess = jest.fn().mockResolvedValue(mockGroupBoardResponse);
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
const createComponent = ({ provide = {} } = {}) => {
|
|
|
|
const store = createStore();
|
2023-04-23 21:23:45 +05:30
|
|
|
mockApollo = createMockApollo([
|
|
|
|
[projectBoardQuery, projectBoardQueryHandlerSuccess],
|
|
|
|
[groupBoardQuery, groupBoardQueryHandlerSuccess],
|
|
|
|
]);
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
wrapper = shallowMount(BoardTopBar, {
|
|
|
|
store,
|
2023-04-23 21:23:45 +05:30
|
|
|
apolloProvider: mockApollo,
|
|
|
|
props: {
|
|
|
|
boardId: 'gid://gitlab/Board/1',
|
|
|
|
},
|
2022-06-21 17:19:12 +05:30
|
|
|
provide: {
|
|
|
|
swimlanesFeatureAvailable: false,
|
|
|
|
canAdminList: false,
|
|
|
|
isSignedIn: false,
|
|
|
|
fullPath: 'gitlab-org',
|
|
|
|
boardType: 'group',
|
|
|
|
releasesFetchPath: '/releases',
|
2023-01-13 00:05:48 +05:30
|
|
|
isIssueBoard: true,
|
2023-04-23 21:23:45 +05:30
|
|
|
isEpicBoard: false,
|
2023-03-17 16:20:25 +05:30
|
|
|
isGroupBoard: true,
|
2023-04-23 21:23:45 +05:30
|
|
|
isApolloBoard: false,
|
2022-06-21 17:19:12 +05:30
|
|
|
...provide,
|
|
|
|
},
|
|
|
|
stubs: { IssueBoardFilteredSearch },
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
2023-04-23 21:23:45 +05:30
|
|
|
mockApollo = null;
|
2022-06-21 17:19:12 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('base template', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders BoardsSelector component', () => {
|
|
|
|
expect(wrapper.findComponent(BoardsSelector).exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders IssueBoardFilteredSearch component', () => {
|
|
|
|
expect(wrapper.findComponent(IssueBoardFilteredSearch).exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders NewBoardButton component', () => {
|
|
|
|
expect(wrapper.findComponent(NewBoardButton).exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders ConfigToggle component', () => {
|
|
|
|
expect(wrapper.findComponent(ConfigToggle).exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders ToggleFocus component', () => {
|
|
|
|
expect(wrapper.findComponent(ToggleFocus).exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render BoardAddNewColumnTrigger component', () => {
|
|
|
|
expect(wrapper.findComponent(BoardAddNewColumnTrigger).exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when user can admin list', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({ provide: { canAdminList: true } });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders BoardAddNewColumnTrigger component', () => {
|
|
|
|
expect(wrapper.findComponent(BoardAddNewColumnTrigger).exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
2023-04-23 21:23:45 +05:30
|
|
|
|
|
|
|
describe('Apollo boards', () => {
|
|
|
|
it.each`
|
|
|
|
boardType | queryHandler | notCalledHandler
|
|
|
|
${BoardType.group} | ${groupBoardQueryHandlerSuccess} | ${projectBoardQueryHandlerSuccess}
|
|
|
|
${BoardType.project} | ${projectBoardQueryHandlerSuccess} | ${groupBoardQueryHandlerSuccess}
|
|
|
|
`('fetches $boardType boards', async ({ boardType, queryHandler, notCalledHandler }) => {
|
|
|
|
createComponent({
|
|
|
|
provide: {
|
|
|
|
boardType,
|
|
|
|
isProjectBoard: boardType === BoardType.project,
|
|
|
|
isGroupBoard: boardType === BoardType.group,
|
|
|
|
isApolloBoard: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
await nextTick();
|
|
|
|
|
|
|
|
expect(queryHandler).toHaveBeenCalled();
|
|
|
|
expect(notCalledHandler).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
2022-06-21 17:19:12 +05:30
|
|
|
});
|