2021-04-17 20:07:23 +05:30
|
|
|
import { GlLoadingIcon, GlIcon } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
2020-01-01 13:55:28 +05:30
|
|
|
import MrCollapsibleSection from '~/vue_merge_request_widget/components/mr_collapsible_extension.vue';
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
describe('Merge Request Collapsible Extension', () => {
|
|
|
|
let wrapper;
|
|
|
|
const data = {
|
|
|
|
title: 'View artifacts',
|
|
|
|
};
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const mountComponent = (props) => {
|
2019-12-21 20:55:43 +05:30
|
|
|
wrapper = mount(MrCollapsibleSection, {
|
|
|
|
propsData: {
|
|
|
|
...props,
|
|
|
|
},
|
|
|
|
slots: {
|
|
|
|
default: '<div class="js-slot">Foo</div>',
|
2021-04-17 20:07:23 +05:30
|
|
|
header: '<span data-testid="collapsed-header">hello there</span>',
|
2019-12-21 20:55:43 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
const findTitle = () => wrapper.find('[data-testid="mr-collapsible-title"]');
|
2019-12-21 20:55:43 +05:30
|
|
|
const findErrorMessage = () => wrapper.find('.js-error-state');
|
2021-04-17 20:07:23 +05:30
|
|
|
const findIcon = () => wrapper.find(GlIcon);
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('while collapsed', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mountComponent(data);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders provided title', () => {
|
|
|
|
expect(findTitle().text()).toBe(data.title);
|
|
|
|
});
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it('renders the header slot', () => {
|
|
|
|
expect(wrapper.find('[data-testid="collapsed-header"]').text()).toBe('hello there');
|
|
|
|
});
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
it('renders angle-right icon', () => {
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(findIcon().props('name')).toBe('angle-right');
|
2019-12-21 20:55:43 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('onClick', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper.find('button').trigger('click');
|
2020-03-13 15:44:24 +05:30
|
|
|
return wrapper.vm.$nextTick();
|
2019-12-21 20:55:43 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('rendes the provided slot', () => {
|
|
|
|
expect(wrapper.find('.js-slot').isVisible()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders `Collapse` as the title', () => {
|
|
|
|
expect(findTitle().text()).toBe('Collapse');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders angle-down icon', () => {
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(findIcon().props('name')).toBe('angle-down');
|
2019-12-21 20:55:43 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('while loading', () => {
|
|
|
|
beforeEach(() => {
|
2020-05-24 23:13:21 +05:30
|
|
|
mountComponent({ ...data, isLoading: true });
|
2019-12-21 20:55:43 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the buttons disabled', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(wrapper.findAll('button').at(0).attributes('disabled')).toEqual('disabled');
|
|
|
|
expect(wrapper.findAll('button').at(1).attributes('disabled')).toEqual('disabled');
|
2019-12-21 20:55:43 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders loading spinner', () => {
|
|
|
|
expect(wrapper.find(GlLoadingIcon).isVisible()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with error', () => {
|
|
|
|
beforeEach(() => {
|
2020-05-24 23:13:21 +05:30
|
|
|
mountComponent({ ...data, hasError: true });
|
2019-12-21 20:55:43 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render the buttons', () => {
|
|
|
|
expect(wrapper.findAll('button').exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders title message provided', () => {
|
|
|
|
expect(findErrorMessage().text()).toBe(data.title);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|