debian-mirror-gitlab/spec/frontend/design_management/components/toolbar/index_spec.js

126 lines
3.1 KiB
JavaScript
Raw Normal View History

2021-03-11 19:13:27 +05:30
import { GlButton } from '@gitlab/ui';
2020-05-24 23:13:21 +05:30
import { createLocalVue, shallowMount } from '@vue/test-utils';
import VueRouter from 'vue-router';
import DeleteButton from '~/design_management/components/delete_button.vue';
2021-03-11 19:13:27 +05:30
import Toolbar from '~/design_management/components/toolbar/index.vue';
2020-05-24 23:13:21 +05:30
import { DESIGNS_ROUTE_NAME } from '~/design_management/router/constants';
const localVue = createLocalVue();
localVue.use(VueRouter);
const router = new VueRouter();
const RouterLinkStub = {
props: {
to: {
type: Object,
},
},
render(createElement) {
return createElement('a', {}, this.$slots.default);
},
};
describe('Design management toolbar component', () => {
let wrapper;
function createComponent(isLoading = false, createDesign = true, props) {
const updatedAt = new Date();
updatedAt.setHours(updatedAt.getHours() - 1);
wrapper = shallowMount(Toolbar, {
localVue,
router,
propsData: {
id: '1',
isLatestVersion: true,
isLoading,
isDeleting: false,
filename: 'test.jpg',
updatedAt: updatedAt.toString(),
updatedBy: {
name: 'Test Name',
},
image: '/-/designs/306/7f747adcd4693afadbe968d7ba7d983349b9012d',
...props,
},
stubs: {
'router-link': RouterLinkStub,
},
});
wrapper.setData({
permissions: {
createDesign,
},
});
}
afterEach(() => {
wrapper.destroy();
});
it('renders design and updated data', () => {
createComponent();
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.element).toMatchSnapshot();
});
});
it('links back to designs list', () => {
createComponent();
return wrapper.vm.$nextTick().then(() => {
const link = wrapper.find('a');
expect(link.props('to')).toEqual({
name: DESIGNS_ROUTE_NAME,
query: {
version: undefined,
},
});
});
});
it('renders delete button on latest designs version with logged in user', () => {
createComponent();
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.find(DeleteButton).exists()).toBe(true);
});
});
it('does not render delete button on non-latest version', () => {
createComponent(false, true, { isLatestVersion: false });
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.find(DeleteButton).exists()).toBe(false);
});
});
it('does not render delete button when user is not logged in', () => {
createComponent(false, false);
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.find(DeleteButton).exists()).toBe(false);
});
});
2021-04-17 20:07:23 +05:30
it('emits `delete` event on deleteButton `delete-selected-designs` event', () => {
2020-05-24 23:13:21 +05:30
createComponent();
return wrapper.vm.$nextTick().then(() => {
2021-04-17 20:07:23 +05:30
wrapper.find(DeleteButton).vm.$emit('delete-selected-designs');
2020-05-24 23:13:21 +05:30
expect(wrapper.emitted().delete).toBeTruthy();
});
});
it('renders download button with correct link', () => {
2021-03-08 18:12:59 +05:30
createComponent();
2020-10-24 23:57:45 +05:30
expect(wrapper.find(GlButton).attributes('href')).toBe(
2020-05-24 23:13:21 +05:30
'/-/designs/306/7f747adcd4693afadbe968d7ba7d983349b9012d',
);
});
});