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

116 lines
2.7 KiB
JavaScript
Raw Normal View History

2020-04-22 19:07:51 +05:30
import { shallowMount } from '@vue/test-utils';
2021-03-11 19:13:27 +05:30
import { nextTick } from 'vue';
2020-04-22 19:07:51 +05:30
2020-10-24 23:57:45 +05:30
import { listObj } from 'jest/boards/mock_data';
2021-03-08 18:12:59 +05:30
import BoardColumn from '~/boards/components/board_column.vue';
2020-04-22 19:07:51 +05:30
import { ListType } from '~/boards/constants';
2021-03-08 18:12:59 +05:30
import { createStore } from '~/boards/stores';
2020-04-22 19:07:51 +05:30
describe('Board Column Component', () => {
let wrapper;
2021-03-08 18:12:59 +05:30
let store;
2020-04-22 19:07:51 +05:30
afterEach(() => {
wrapper.destroy();
2021-03-08 18:12:59 +05:30
wrapper = null;
2020-04-22 19:07:51 +05:30
});
2021-09-30 23:02:18 +05:30
const initStore = () => {
store = createStore();
};
2021-03-08 18:12:59 +05:30
const createComponent = ({ listType = ListType.backlog, collapsed = false } = {}) => {
2020-04-22 19:07:51 +05:30
const boardId = '1';
const listMock = {
...listObj,
2021-03-08 18:12:59 +05:30
listType,
2020-04-22 19:07:51 +05:30
collapsed,
};
if (listType === ListType.assignee) {
delete listMock.label;
2021-03-08 18:12:59 +05:30
listMock.assignee = {};
2020-04-22 19:07:51 +05:30
}
2021-03-08 18:12:59 +05:30
wrapper = shallowMount(BoardColumn, {
store,
2020-04-22 19:07:51 +05:30
propsData: {
disabled: false,
2021-03-08 18:12:59 +05:30
list: listMock,
2020-04-22 19:07:51 +05:30
},
2020-11-24 15:15:51 +05:30
provide: {
boardId,
},
2020-04-22 19:07:51 +05:30
});
};
const isExpandable = () => wrapper.classes('is-expandable');
const isCollapsed = () => wrapper.classes('is-collapsed');
describe('Given different list types', () => {
2021-09-30 23:02:18 +05:30
beforeEach(() => {
initStore();
});
2020-04-22 19:07:51 +05:30
it('is expandable when List Type is `backlog`', () => {
createComponent({ listType: ListType.backlog });
expect(isExpandable()).toBe(true);
});
});
2021-01-29 00:20:46 +05:30
describe('expanded / collapsed column', () => {
2020-06-23 00:09:42 +05:30
it('has class is-collapsed when list is collapsed', () => {
createComponent({ collapsed: false });
2020-04-22 19:07:51 +05:30
2021-03-08 18:12:59 +05:30
expect(isCollapsed()).toBe(false);
2020-04-22 19:07:51 +05:30
});
2020-06-23 00:09:42 +05:30
it('does not have class is-collapsed when list is expanded', () => {
2020-04-22 19:07:51 +05:30
createComponent({ collapsed: true });
2020-06-23 00:09:42 +05:30
expect(isCollapsed()).toBe(true);
2020-04-22 19:07:51 +05:30
});
});
2021-03-11 19:13:27 +05:30
describe('highlighting', () => {
it('scrolls to column when highlighted', async () => {
createComponent();
store.state.highlightedLists.push(listObj.id);
await nextTick();
expect(wrapper.element.scrollIntoView).toHaveBeenCalled();
});
});
2021-09-30 23:02:18 +05:30
describe('on mount', () => {
beforeEach(async () => {
initStore();
jest.spyOn(store, 'dispatch').mockImplementation();
});
describe('when list is collapsed', () => {
it('does not call fetchItemsForList when', async () => {
createComponent({ collapsed: true });
await nextTick();
expect(store.dispatch).toHaveBeenCalledTimes(0);
});
});
describe('when the list is not collapsed', () => {
it('calls fetchItemsForList when', async () => {
createComponent({ collapsed: false });
await nextTick();
expect(store.dispatch).toHaveBeenCalledWith('fetchItemsForList', { listId: 300 });
});
});
});
2020-04-22 19:07:51 +05:30
});