2019-09-27 08:06:07 -04:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import { GlLoadingIcon } from '@gitlab/ui';
|
|
|
|
|
|
|
|
import SidebarTodos from '~/sidebar/components/todo_toggle/todo.vue';
|
|
|
|
import Icon from '~/vue_shared/components/icon.vue';
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
issuableId: 1,
|
|
|
|
issuableType: 'epic',
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('SidebarTodo', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const createComponent = (props = {}) => {
|
|
|
|
wrapper = shallowMount(SidebarTodos, {
|
|
|
|
propsData: {
|
|
|
|
...defaultProps,
|
|
|
|
...props,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
state | classes
|
|
|
|
${false} | ${['btn', 'btn-default', 'btn-todo', 'issuable-header-btn', 'float-right']}
|
|
|
|
${true} | ${['btn-blank', 'btn-todo', 'sidebar-collapsed-icon', 'dont-change-state']}
|
|
|
|
`('returns todo button classes for when `collapsed` prop is `$state`', ({ state, classes }) => {
|
|
|
|
createComponent({ collapsed: state });
|
|
|
|
expect(wrapper.find('button').classes()).toStrictEqual(classes);
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
isTodo | iconClass | label | icon
|
|
|
|
${false} | ${''} | ${'Add a To Do'} | ${'todo-add'}
|
|
|
|
${true} | ${'todo-undone'} | ${'Mark as done'} | ${'todo-done'}
|
|
|
|
`(
|
|
|
|
'renders proper button when `isTodo` prop is `$isTodo`',
|
|
|
|
({ isTodo, iconClass, label, icon }) => {
|
|
|
|
createComponent({ isTodo });
|
|
|
|
|
2019-10-02 17:06:22 -04:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find(Icon)
|
|
|
|
.classes()
|
|
|
|
.join(' '),
|
|
|
|
).toStrictEqual(iconClass);
|
2019-09-27 08:06:07 -04:00
|
|
|
expect(wrapper.find(Icon).props('name')).toStrictEqual(icon);
|
|
|
|
expect(wrapper.find('button').text()).toBe(label);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
describe('template', () => {
|
|
|
|
it('emits `toggleTodo` event when clicked on button', () => {
|
|
|
|
createComponent();
|
|
|
|
wrapper.find('button').trigger('click');
|
|
|
|
|
2020-01-01 01:09:01 -05:00
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
expect(wrapper.emitted().toggleTodo).toBeTruthy();
|
|
|
|
});
|
2019-09-27 08:06:07 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders component container element with proper data attributes', () => {
|
|
|
|
createComponent({
|
|
|
|
issuableId: 1,
|
|
|
|
issuableType: 'epic',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.element).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders button label element when `collapsed` prop is `false`', () => {
|
|
|
|
createComponent({ collapsed: false });
|
|
|
|
|
|
|
|
expect(wrapper.find('span.issuable-todo-inner').text()).toBe('Mark as done');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders button icon when `collapsed` prop is `true`', () => {
|
|
|
|
createComponent({ collapsed: true });
|
|
|
|
|
|
|
|
expect(wrapper.find(Icon).props('name')).toBe('todo-done');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders loading icon when `isActionActive` prop is true', () => {
|
|
|
|
createComponent({ isActionActive: true });
|
|
|
|
|
|
|
|
expect(wrapper.find(GlLoadingIcon).exists()).toBe(true);
|
|
|
|
});
|
2019-11-21 10:06:17 -05:00
|
|
|
|
|
|
|
it('hides button icon when `isActionActive` prop is true', () => {
|
|
|
|
createComponent({ collapsed: true, isActionActive: true });
|
|
|
|
|
|
|
|
expect(wrapper.find(Icon).isVisible()).toBe(false);
|
|
|
|
});
|
2019-09-27 08:06:07 -04:00
|
|
|
});
|
|
|
|
});
|