debian-mirror-gitlab/spec/frontend/diffs/components/edit_button_spec.js

76 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-03-09 13:42:32 +05:30
import { shallowMount } from '@vue/test-utils';
2020-05-24 23:13:21 +05:30
import { GlDeprecatedButton } from '@gitlab/ui';
2019-07-07 11:18:12 +05:30
import EditButton from '~/diffs/components/edit_button.vue';
const editPath = 'test-path';
describe('EditButton', () => {
let wrapper;
const createComponent = (props = {}) => {
wrapper = shallowMount(EditButton, {
propsData: { ...props },
});
};
afterEach(() => {
wrapper.destroy();
});
it('has correct href attribute', () => {
createComponent({
editPath,
canCurrentUserFork: false,
});
2020-05-24 23:13:21 +05:30
expect(wrapper.find(GlDeprecatedButton).attributes('href')).toBe(editPath);
2019-07-07 11:18:12 +05:30
});
it('emits a show fork message event if current user can fork', () => {
createComponent({
editPath,
canCurrentUserFork: true,
});
2020-05-24 23:13:21 +05:30
wrapper.find(GlDeprecatedButton).trigger('click');
2019-07-07 11:18:12 +05:30
2020-03-09 13:42:32 +05:30
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted('showForkMessage')).toBeTruthy();
});
2019-07-07 11:18:12 +05:30
});
it('doesnt emit a show fork message event if current user cannot fork', () => {
createComponent({
editPath,
canCurrentUserFork: false,
});
2020-05-24 23:13:21 +05:30
wrapper.find(GlDeprecatedButton).trigger('click');
2019-07-07 11:18:12 +05:30
2020-03-09 13:42:32 +05:30
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted('showForkMessage')).toBeFalsy();
});
2019-07-07 11:18:12 +05:30
});
it('doesnt emit a show fork message event if current user can modify blob', () => {
createComponent({
editPath,
canCurrentUserFork: true,
canModifyBlob: true,
});
2020-05-24 23:13:21 +05:30
wrapper.find(GlDeprecatedButton).trigger('click');
2019-07-07 11:18:12 +05:30
2020-03-09 13:42:32 +05:30
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted('showForkMessage')).toBeFalsy();
});
2019-07-07 11:18:12 +05:30
});
2020-05-24 23:13:21 +05:30
it('disables button if editPath is empty', () => {
createComponent({
editPath: '',
canCurrentUserFork: true,
canModifyBlob: true,
});
expect(wrapper.find(GlDeprecatedButton).attributes('disabled')).toBe('true');
});
2019-07-07 11:18:12 +05:30
});