2021-01-18 09:11:05 +00:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import AxiosMockAdapter from 'axios-mock-adapter';
|
2021-02-14 18:09:20 +00:00
|
|
|
import Vue from 'vue';
|
2021-01-18 09:11:05 +00:00
|
|
|
|
|
|
|
import { TEST_HOST } from 'helpers/test_constants';
|
|
|
|
import { listObj } from 'jest/boards/mock_data';
|
|
|
|
import BoardListHeader from '~/boards/components/board_list_header_deprecated.vue';
|
2020-11-16 06:09:20 +00:00
|
|
|
import { ListType } from '~/boards/constants';
|
2021-02-14 18:09:20 +00:00
|
|
|
import List from '~/boards/models/list';
|
2021-01-18 09:11:05 +00:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2020-11-16 06:09:20 +00:00
|
|
|
|
|
|
|
describe('Board List Header Component', () => {
|
|
|
|
let wrapper;
|
2021-01-18 09:11:05 +00:00
|
|
|
let axiosMock;
|
2020-11-16 06:09:20 +00:00
|
|
|
|
2021-01-18 09:11:05 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
window.gon = {};
|
|
|
|
axiosMock = new AxiosMockAdapter(axios);
|
|
|
|
axiosMock.onGet(`${TEST_HOST}/lists/1/issues`).reply(200, { issues: [] });
|
|
|
|
});
|
2020-11-16 06:09:20 +00:00
|
|
|
|
|
|
|
afterEach(() => {
|
2021-01-18 09:11:05 +00:00
|
|
|
axiosMock.restore();
|
|
|
|
|
2020-11-16 06:09:20 +00:00
|
|
|
wrapper.destroy();
|
|
|
|
|
|
|
|
localStorage.clear();
|
|
|
|
});
|
|
|
|
|
|
|
|
const createComponent = ({
|
|
|
|
listType = ListType.backlog,
|
|
|
|
collapsed = false,
|
|
|
|
withLocalStorage = true,
|
2021-06-10 09:10:04 +00:00
|
|
|
currentUserId = 1,
|
2020-11-16 06:09:20 +00:00
|
|
|
} = {}) => {
|
|
|
|
const boardId = '1';
|
|
|
|
|
|
|
|
const listMock = {
|
2021-01-18 09:11:05 +00:00
|
|
|
...listObj,
|
|
|
|
list_type: listType,
|
2020-11-16 06:09:20 +00:00
|
|
|
collapsed,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (listType === ListType.assignee) {
|
|
|
|
delete listMock.label;
|
2021-01-18 09:11:05 +00:00
|
|
|
listMock.user = {};
|
2020-11-16 06:09:20 +00:00
|
|
|
}
|
|
|
|
|
2021-01-18 09:11:05 +00:00
|
|
|
// Making List reactive
|
|
|
|
const list = Vue.observable(new List(listMock));
|
|
|
|
|
2020-11-16 06:09:20 +00:00
|
|
|
if (withLocalStorage) {
|
|
|
|
localStorage.setItem(
|
2021-01-18 09:11:05 +00:00
|
|
|
`boards.${boardId}.${list.type}.${list.id}.expanded`,
|
2020-11-16 06:09:20 +00:00
|
|
|
(!collapsed).toString(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
wrapper = shallowMount(BoardListHeader, {
|
|
|
|
propsData: {
|
|
|
|
disabled: false,
|
2021-01-18 09:11:05 +00:00
|
|
|
list,
|
2020-11-16 06:09:20 +00:00
|
|
|
},
|
|
|
|
provide: {
|
|
|
|
boardId,
|
2021-06-10 09:10:04 +00:00
|
|
|
currentUserId,
|
2020-11-16 06:09:20 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-01-18 09:11:05 +00:00
|
|
|
const isCollapsed = () => !wrapper.props().list.isExpanded;
|
|
|
|
const isExpanded = () => wrapper.vm.list.isExpanded;
|
2020-11-16 06:09:20 +00:00
|
|
|
|
|
|
|
const findAddIssueButton = () => wrapper.find({ ref: 'newIssueBtn' });
|
|
|
|
const findCaret = () => wrapper.find('.board-title-caret');
|
|
|
|
|
|
|
|
describe('Add issue button', () => {
|
2020-12-09 21:09:43 +00:00
|
|
|
const hasNoAddButton = [ListType.closed];
|
2021-02-03 21:09:17 +00:00
|
|
|
const hasAddButton = [
|
|
|
|
ListType.backlog,
|
|
|
|
ListType.label,
|
|
|
|
ListType.milestone,
|
|
|
|
ListType.iteration,
|
|
|
|
ListType.assignee,
|
|
|
|
];
|
2020-11-16 06:09:20 +00:00
|
|
|
|
2020-12-23 21:10:24 +00:00
|
|
|
it.each(hasNoAddButton)('does not render when List Type is `%s`', (listType) => {
|
2020-11-16 06:09:20 +00:00
|
|
|
createComponent({ listType });
|
|
|
|
|
|
|
|
expect(findAddIssueButton().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
2020-12-23 21:10:24 +00:00
|
|
|
it.each(hasAddButton)('does render when List Type is `%s`', (listType) => {
|
2020-11-16 06:09:20 +00:00
|
|
|
createComponent({ listType });
|
|
|
|
|
|
|
|
expect(findAddIssueButton().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has a test for each list type', () => {
|
2020-12-23 21:10:24 +00:00
|
|
|
Object.values(ListType).forEach((value) => {
|
2020-11-16 06:09:20 +00:00
|
|
|
expect([...hasAddButton, ...hasNoAddButton]).toContain(value);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-06-10 09:10:04 +00:00
|
|
|
it('does not render when logged out', () => {
|
|
|
|
createComponent({
|
|
|
|
currentUserId: null,
|
|
|
|
});
|
2020-11-16 06:09:20 +00:00
|
|
|
|
2021-06-10 09:10:04 +00:00
|
|
|
expect(findAddIssueButton().exists()).toBe(false);
|
2020-11-16 06:09:20 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('expanding / collapsing the column', () => {
|
2021-01-18 09:11:05 +00:00
|
|
|
it('does not collapse when clicking the header', () => {
|
2020-11-16 06:09:20 +00:00
|
|
|
createComponent();
|
|
|
|
|
|
|
|
expect(isCollapsed()).toBe(false);
|
|
|
|
wrapper.find('[data-testid="board-list-header"]').trigger('click');
|
|
|
|
|
2021-01-18 09:11:05 +00:00
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
expect(isCollapsed()).toBe(false);
|
|
|
|
});
|
2020-11-16 06:09:20 +00:00
|
|
|
});
|
|
|
|
|
2021-01-18 09:11:05 +00:00
|
|
|
it('collapses expanded Column when clicking the collapse icon', () => {
|
2020-11-16 06:09:20 +00:00
|
|
|
createComponent();
|
|
|
|
|
2021-01-18 09:11:05 +00:00
|
|
|
expect(isExpanded()).toBe(true);
|
2020-11-16 06:09:20 +00:00
|
|
|
findCaret().vm.$emit('click');
|
|
|
|
|
2021-01-18 09:11:05 +00:00
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
expect(isCollapsed()).toBe(true);
|
|
|
|
});
|
2020-11-16 06:09:20 +00:00
|
|
|
});
|
|
|
|
|
2021-01-18 09:11:05 +00:00
|
|
|
it('expands collapsed Column when clicking the expand icon', () => {
|
2020-11-16 06:09:20 +00:00
|
|
|
createComponent({ collapsed: true });
|
|
|
|
|
|
|
|
expect(isCollapsed()).toBe(true);
|
|
|
|
findCaret().vm.$emit('click');
|
|
|
|
|
2021-01-18 09:11:05 +00:00
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
expect(isCollapsed()).toBe(false);
|
|
|
|
});
|
2020-11-16 06:09:20 +00:00
|
|
|
});
|
|
|
|
|
2021-01-18 09:11:05 +00:00
|
|
|
it("when logged in it calls list update and doesn't set localStorage", () => {
|
|
|
|
jest.spyOn(List.prototype, 'update');
|
2020-11-16 06:09:20 +00:00
|
|
|
|
2021-01-18 09:11:05 +00:00
|
|
|
createComponent({ withLocalStorage: false });
|
2020-11-16 06:09:20 +00:00
|
|
|
|
|
|
|
findCaret().vm.$emit('click');
|
|
|
|
|
2021-01-18 09:11:05 +00:00
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
expect(wrapper.vm.list.update).toHaveBeenCalledTimes(1);
|
|
|
|
expect(localStorage.getItem(`${wrapper.vm.uniqueKey}.expanded`)).toBe(null);
|
|
|
|
});
|
2020-11-16 06:09:20 +00:00
|
|
|
});
|
2020-12-14 21:09:47 +00:00
|
|
|
|
2021-01-18 09:11:05 +00:00
|
|
|
it("when logged out it doesn't call list update and sets localStorage", () => {
|
|
|
|
jest.spyOn(List.prototype, 'update');
|
2020-12-14 21:09:47 +00:00
|
|
|
|
2021-06-10 09:10:04 +00:00
|
|
|
createComponent({ currentUserId: null });
|
2020-12-14 21:09:47 +00:00
|
|
|
|
2021-01-18 09:11:05 +00:00
|
|
|
findCaret().vm.$emit('click');
|
2020-12-14 21:09:47 +00:00
|
|
|
|
2021-01-18 09:11:05 +00:00
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
expect(wrapper.vm.list.update).not.toHaveBeenCalled();
|
|
|
|
expect(localStorage.getItem(`${wrapper.vm.uniqueKey}.expanded`)).toBe(String(isExpanded()));
|
|
|
|
});
|
2020-12-14 21:09:47 +00:00
|
|
|
});
|
|
|
|
});
|
2020-11-16 06:09:20 +00:00
|
|
|
});
|