2020-04-02 14:08:11 -04:00
|
|
|
import Vue from 'vue';
|
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import AxiosMockAdapter from 'axios-mock-adapter';
|
|
|
|
|
2020-08-17 17:09:56 -04:00
|
|
|
import { TEST_HOST } from 'helpers/test_constants';
|
|
|
|
import { listObj } from 'jest/boards/mock_data';
|
2020-04-02 14:08:11 -04:00
|
|
|
import Board from '~/boards/components/board_column.vue';
|
|
|
|
import List from '~/boards/models/list';
|
|
|
|
import { ListType } from '~/boards/constants';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
|
|
|
|
describe('Board Column Component', () => {
|
|
|
|
let wrapper;
|
|
|
|
let axiosMock;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
window.gon = {};
|
|
|
|
axiosMock = new AxiosMockAdapter(axios);
|
|
|
|
axiosMock.onGet(`${TEST_HOST}/lists/1/issues`).reply(200, { issues: [] });
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
axiosMock.restore();
|
|
|
|
|
|
|
|
wrapper.destroy();
|
|
|
|
|
|
|
|
localStorage.clear();
|
|
|
|
});
|
|
|
|
|
|
|
|
const createComponent = ({
|
|
|
|
listType = ListType.backlog,
|
|
|
|
collapsed = false,
|
|
|
|
withLocalStorage = true,
|
|
|
|
} = {}) => {
|
|
|
|
const boardId = '1';
|
|
|
|
|
|
|
|
const listMock = {
|
|
|
|
...listObj,
|
|
|
|
list_type: listType,
|
|
|
|
collapsed,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (listType === ListType.assignee) {
|
|
|
|
delete listMock.label;
|
|
|
|
listMock.user = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Making List reactive
|
|
|
|
const list = Vue.observable(new List(listMock));
|
|
|
|
|
|
|
|
if (withLocalStorage) {
|
|
|
|
localStorage.setItem(
|
|
|
|
`boards.${boardId}.${list.type}.${list.id}.expanded`,
|
|
|
|
(!collapsed).toString(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
wrapper = shallowMount(Board, {
|
|
|
|
propsData: {
|
|
|
|
boardId,
|
|
|
|
disabled: false,
|
|
|
|
list,
|
|
|
|
},
|
2020-09-17 05:09:32 -04:00
|
|
|
provide: {
|
|
|
|
boardId,
|
|
|
|
},
|
2020-04-02 14:08:11 -04:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const isExpandable = () => wrapper.classes('is-expandable');
|
|
|
|
const isCollapsed = () => wrapper.classes('is-collapsed');
|
|
|
|
|
|
|
|
describe('Given different list types', () => {
|
|
|
|
it('is expandable when List Type is `backlog`', () => {
|
|
|
|
createComponent({ listType: ListType.backlog });
|
|
|
|
|
|
|
|
expect(isExpandable()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-11-16 01:09:20 -05:00
|
|
|
describe('expanded / collapsed column', () => {
|
2020-06-11 05:08:16 -04:00
|
|
|
it('has class is-collapsed when list is collapsed', () => {
|
|
|
|
createComponent({ collapsed: false });
|
2020-04-02 14:08:11 -04:00
|
|
|
|
|
|
|
expect(wrapper.vm.list.isExpanded).toBe(true);
|
|
|
|
});
|
|
|
|
|
2020-06-11 05:08:16 -04:00
|
|
|
it('does not have class is-collapsed when list is expanded', () => {
|
2020-04-02 14:08:11 -04:00
|
|
|
createComponent({ collapsed: true });
|
|
|
|
|
2020-06-11 05:08:16 -04:00
|
|
|
expect(isCollapsed()).toBe(true);
|
2020-04-02 14:08:11 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|