debian-mirror-gitlab/spec/frontend/repository/components/blob_edit_spec.js

101 lines
2.4 KiB
JavaScript
Raw Normal View History

2021-09-04 01:27:46 +05:30
import { GlButton } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
2021-09-30 23:02:18 +05:30
import BlobEdit from '~/repository/components/blob_edit.vue';
2021-09-04 01:27:46 +05:30
import WebIdeLink from '~/vue_shared/components/web_ide_link.vue';
const DEFAULT_PROPS = {
editPath: 'some_file.js/edit',
webIdePath: 'some_file.js/ide/edit',
2021-10-27 15:23:28 +05:30
showEditButton: true,
2021-11-18 22:05:49 +05:30
needsToFork: false,
2021-09-04 01:27:46 +05:30
};
2021-09-30 23:02:18 +05:30
describe('BlobEdit component', () => {
2021-09-04 01:27:46 +05:30
let wrapper;
const createComponent = (consolidatedEditButton = false, props = {}) => {
2021-09-30 23:02:18 +05:30
wrapper = shallowMount(BlobEdit, {
2021-09-04 01:27:46 +05:30
propsData: {
...DEFAULT_PROPS,
...props,
},
provide: {
glFeatures: {
consolidatedEditButton,
},
},
});
};
afterEach(() => {
wrapper.destroy();
wrapper = null;
});
const findButtons = () => wrapper.findAll(GlButton);
2021-10-27 15:23:28 +05:30
const findEditButton = () => wrapper.find('[data-testid="edit"]');
const findWebIdeButton = () => wrapper.find('[data-testid="web-ide"]');
2021-09-04 01:27:46 +05:30
const findWebIdeLink = () => wrapper.find(WebIdeLink);
it('renders component', () => {
createComponent();
const { editPath, webIdePath } = DEFAULT_PROPS;
expect(wrapper.props()).toMatchObject({
editPath,
webIdePath,
});
});
it('renders both buttons', () => {
createComponent();
expect(findButtons()).toHaveLength(2);
});
it('renders the Edit button', () => {
createComponent();
expect(findEditButton().text()).toBe('Edit');
expect(findEditButton()).not.toBeDisabled();
});
it('renders the Web IDE button', () => {
createComponent();
expect(findWebIdeButton().text()).toBe('Web IDE');
expect(findWebIdeButton()).not.toBeDisabled();
});
it('renders WebIdeLink component', () => {
createComponent(true);
2021-11-18 22:05:49 +05:30
const { editPath: editUrl, webIdePath: webIdeUrl, needsToFork } = DEFAULT_PROPS;
2021-09-04 01:27:46 +05:30
expect(findWebIdeLink().props()).toMatchObject({
editUrl,
webIdeUrl,
isBlob: true,
2021-10-27 15:23:28 +05:30
showEditButton: true,
2021-11-18 22:05:49 +05:30
needsToFork,
2021-10-27 15:23:28 +05:30
});
});
describe('Without Edit button', () => {
const showEditButton = false;
it('renders WebIdeLink component without an edit button', () => {
createComponent(true, { showEditButton });
expect(findWebIdeLink().props()).toMatchObject({ showEditButton });
});
it('does not render an Edit button', () => {
createComponent(false, { showEditButton });
expect(findEditButton().exists()).toBe(false);
2021-09-04 01:27:46 +05:30
});
});
});