debian-mirror-gitlab/spec/frontend/boards/components/board_content_spec.js

118 lines
2.9 KiB
JavaScript
Raw Normal View History

2020-11-24 15:15:51 +05:30
import { GlAlert } from '@gitlab/ui';
2021-09-30 23:02:18 +05:30
import { shallowMount } from '@vue/test-utils';
import Vue from 'vue';
2021-02-22 17:27:13 +05:30
import Draggable from 'vuedraggable';
2021-03-11 19:13:27 +05:30
import Vuex from 'vuex';
2020-11-24 15:15:51 +05:30
import EpicsSwimlanes from 'ee_component/boards/components/epics_swimlanes.vue';
import getters from 'ee_else_ce/boards/stores/getters';
2021-03-08 18:12:59 +05:30
import BoardColumnDeprecated from '~/boards/components/board_column_deprecated.vue';
2020-11-24 15:15:51 +05:30
import BoardContent from '~/boards/components/board_content.vue';
2021-03-11 19:13:27 +05:30
import { mockLists, mockListsWithModel } from '../mock_data';
2020-11-24 15:15:51 +05:30
2021-09-30 23:02:18 +05:30
Vue.use(Vuex);
2020-11-24 15:15:51 +05:30
2021-02-22 17:27:13 +05:30
const actions = {
moveList: jest.fn(),
};
2020-11-24 15:15:51 +05:30
describe('BoardContent', () => {
let wrapper;
2021-03-08 18:12:59 +05:30
window.gon = {};
2020-11-24 15:15:51 +05:30
const defaultState = {
isShowingEpicsSwimlanes: false,
2021-02-22 17:27:13 +05:30
boardLists: mockLists,
2020-11-24 15:15:51 +05:30
error: undefined,
};
const createStore = (state = defaultState) => {
return new Vuex.Store({
2021-02-22 17:27:13 +05:30
actions,
2020-11-24 15:15:51 +05:30
getters,
state,
});
};
2021-04-29 21:17:54 +05:30
const createComponent = ({
state,
props = {},
graphqlBoardListsEnabled = false,
canAdminList = true,
} = {}) => {
2020-11-24 15:15:51 +05:30
const store = createStore({
...defaultState,
...state,
});
wrapper = shallowMount(BoardContent, {
propsData: {
lists: mockListsWithModel,
disabled: false,
2021-02-22 17:27:13 +05:30
...props,
},
provide: {
2021-04-29 21:17:54 +05:30
canAdminList,
2021-02-22 17:27:13 +05:30
glFeatures: { graphqlBoardLists: graphqlBoardListsEnabled },
2020-11-24 15:15:51 +05:30
},
store,
});
};
afterEach(() => {
wrapper.destroy();
});
2021-03-08 18:12:59 +05:30
it('renders a BoardColumnDeprecated component per list', () => {
2021-02-22 17:27:13 +05:30
createComponent();
2021-03-08 18:12:59 +05:30
expect(wrapper.findAllComponents(BoardColumnDeprecated)).toHaveLength(
mockListsWithModel.length,
);
2020-11-24 15:15:51 +05:30
});
it('does not display EpicsSwimlanes component', () => {
2021-02-22 17:27:13 +05:30
createComponent();
2020-11-24 15:15:51 +05:30
expect(wrapper.find(EpicsSwimlanes).exists()).toBe(false);
expect(wrapper.find(GlAlert).exists()).toBe(false);
});
2021-02-22 17:27:13 +05:30
describe('graphqlBoardLists feature flag enabled', () => {
2021-03-08 18:12:59 +05:30
beforeEach(() => {
createComponent({ graphqlBoardListsEnabled: true });
gon.features = {
graphqlBoardLists: true,
};
});
2021-02-22 17:27:13 +05:30
describe('can admin list', () => {
beforeEach(() => {
2021-04-29 21:17:54 +05:30
createComponent({ graphqlBoardListsEnabled: true, canAdminList: true });
2021-02-22 17:27:13 +05:30
});
it('renders draggable component', () => {
expect(wrapper.find(Draggable).exists()).toBe(true);
});
});
describe('can not admin list', () => {
beforeEach(() => {
2021-04-29 21:17:54 +05:30
createComponent({ graphqlBoardListsEnabled: true, canAdminList: false });
2021-02-22 17:27:13 +05:30
});
2021-03-08 18:12:59 +05:30
it('does not render draggable component', () => {
2021-02-22 17:27:13 +05:30
expect(wrapper.find(Draggable).exists()).toBe(false);
});
});
});
describe('graphqlBoardLists feature flag disabled', () => {
beforeEach(() => {
createComponent({ graphqlBoardListsEnabled: false });
});
it('does not render draggable component', () => {
expect(wrapper.find(Draggable).exists()).toBe(false);
});
});
2020-11-24 15:15:51 +05:30
});