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

107 lines
2.5 KiB
JavaScript
Raw Normal View History

2021-01-29 00:20:46 +05:30
import { shallowMount } from '@vue/test-utils';
2021-03-08 18:12:59 +05:30
import AxiosMockAdapter from 'axios-mock-adapter';
2021-03-11 19:13:27 +05:30
import Vue, { nextTick } from 'vue';
2021-01-29 00:20:46 +05:30
2021-03-08 18:12:59 +05:30
import { TEST_HOST } from 'helpers/test_constants';
2021-01-29 00:20:46 +05:30
import { listObj } from 'jest/boards/mock_data';
2021-03-08 18:12:59 +05:30
import Board from '~/boards/components/board_column_deprecated.vue';
2021-01-29 00:20:46 +05:30
import { ListType } from '~/boards/constants';
2021-03-11 19:13:27 +05:30
import List from '~/boards/models/list';
2021-03-08 18:12:59 +05:30
import axios from '~/lib/utils/axios_utils';
2021-01-29 00:20:46 +05:30
describe('Board Column Component', () => {
let wrapper;
2021-03-08 18:12:59 +05:30
let axiosMock;
beforeEach(() => {
window.gon = {};
axiosMock = new AxiosMockAdapter(axios);
axiosMock.onGet(`${TEST_HOST}/lists/1/issues`).reply(200, { issues: [] });
});
2021-01-29 00:20:46 +05:30
afterEach(() => {
2021-03-08 18:12:59 +05:30
axiosMock.restore();
2021-01-29 00:20:46 +05:30
wrapper.destroy();
2021-03-08 18:12:59 +05:30
localStorage.clear();
2021-01-29 00:20:46 +05:30
});
2021-03-08 18:12:59 +05:30
const createComponent = ({
listType = ListType.backlog,
collapsed = false,
2021-03-11 19:13:27 +05:30
highlighted = false,
2021-03-08 18:12:59 +05:30
withLocalStorage = true,
} = {}) => {
2021-01-29 00:20:46 +05:30
const boardId = '1';
const listMock = {
...listObj,
2021-03-08 18:12:59 +05:30
list_type: listType,
2021-03-11 19:13:27 +05:30
highlighted,
2021-01-29 00:20:46 +05:30
collapsed,
};
if (listType === ListType.assignee) {
delete listMock.label;
2021-03-08 18:12:59 +05:30
listMock.user = {};
2021-01-29 00:20:46 +05:30
}
2021-03-08 18:12:59 +05:30
// Making List reactive
const list = Vue.observable(new List(listMock));
2021-01-29 00:20:46 +05:30
2021-03-08 18:12:59 +05:30
if (withLocalStorage) {
localStorage.setItem(
`boards.${boardId}.${list.type}.${list.id}.expanded`,
(!collapsed).toString(),
);
}
wrapper = shallowMount(Board, {
2021-01-29 00:20:46 +05:30
propsData: {
2021-03-08 18:12:59 +05:30
boardId,
2021-01-29 00:20:46 +05:30
disabled: false,
2021-03-08 18:12:59 +05:30
list,
2021-01-29 00:20:46 +05:30
},
provide: {
boardId,
},
});
};
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);
});
});
describe('expanded / collapsed column', () => {
it('has class is-collapsed when list is collapsed', () => {
createComponent({ collapsed: false });
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.list.isExpanded).toBe(true);
2021-01-29 00:20:46 +05:30
});
it('does not have class is-collapsed when list is expanded', () => {
createComponent({ collapsed: true });
expect(isCollapsed()).toBe(true);
});
});
2021-03-11 19:13:27 +05:30
describe('highlighting', () => {
it('scrolls to column when highlighted', async () => {
createComponent({ highlighted: true });
await nextTick();
expect(wrapper.element.scrollIntoView).toHaveBeenCalled();
});
});
2021-01-29 00:20:46 +05:30
});