debian-mirror-gitlab/spec/frontend/issues/show/components/edit_actions_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

100 lines
2.6 KiB
JavaScript
Raw Normal View History

2022-01-26 12:08:38 +05:30
import { GlButton } from '@gitlab/ui';
import Vue from 'vue';
2021-09-04 01:27:46 +05:30
import VueApollo from 'vue-apollo';
import createMockApollo from 'helpers/mock_apollo_helper';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
2022-01-26 12:08:38 +05:30
import IssuableEditActions from '~/issues/show/components/edit_actions.vue';
import eventHub from '~/issues/show/event_hub';
2021-09-04 01:27:46 +05:30
describe('Edit Actions component', () => {
let wrapper;
let fakeApollo;
let mockIssueStateData;
2022-01-26 12:08:38 +05:30
Vue.use(VueApollo);
2021-09-04 01:27:46 +05:30
const mockResolvers = {
Query: {
issueState() {
return {
__typename: 'IssueState',
rawData: mockIssueStateData(),
};
},
},
};
2017-09-10 17:25:29 +05:30
2021-09-04 01:27:46 +05:30
const createComponent = ({ props, data } = {}) => {
fakeApollo = createMockApollo([], mockResolvers);
2017-09-10 17:25:29 +05:30
2021-09-04 01:27:46 +05:30
wrapper = shallowMountExtended(IssuableEditActions, {
apolloProvider: fakeApollo,
2017-09-10 17:25:29 +05:30
propsData: {
2021-09-04 01:27:46 +05:30
formState: {
title: 'GitLab Issue',
},
2017-09-10 17:25:29 +05:30
canDestroy: true,
2022-01-26 12:08:38 +05:30
endpoint: 'gitlab-org/gitlab-test/-/issues/1',
2018-12-05 23:21:45 +05:30
issuableType: 'issue',
2021-09-04 01:27:46 +05:30
...props,
2017-09-10 17:25:29 +05:30
},
2021-09-04 01:27:46 +05:30
data() {
return {
issueState: {},
...data,
};
},
});
};
2017-09-10 17:25:29 +05:30
2021-09-04 01:27:46 +05:30
const findEditButtons = () => wrapper.findAllComponents(GlButton);
const findSaveButton = () => wrapper.findByTestId('issuable-save-button');
const findCancelButton = () => wrapper.findByTestId('issuable-cancel-button');
2017-09-10 17:25:29 +05:30
2021-09-04 01:27:46 +05:30
beforeEach(() => {
mockIssueStateData = jest.fn();
createComponent();
2017-09-10 17:25:29 +05:30
});
2021-09-04 01:27:46 +05:30
afterEach(() => {
wrapper.destroy();
});
2017-09-10 17:25:29 +05:30
2021-09-04 01:27:46 +05:30
it('renders all buttons as enabled', () => {
const buttons = findEditButtons().wrappers;
buttons.forEach((button) => {
2022-08-27 11:52:29 +05:30
expect(button.attributes('disabled')).toBeUndefined();
2017-09-10 17:25:29 +05:30
});
});
2021-09-04 01:27:46 +05:30
it('disables save button when title is blank', () => {
createComponent({ props: { formState: { title: '', issue_type: '' } } });
2017-09-10 17:25:29 +05:30
2021-09-04 01:27:46 +05:30
expect(findSaveButton().attributes('disabled')).toBe('true');
2017-09-10 17:25:29 +05:30
});
describe('updateIssuable', () => {
2021-09-04 01:27:46 +05:30
beforeEach(() => {
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
2017-09-10 17:25:29 +05:30
});
2021-09-04 01:27:46 +05:30
it('sends update.issauble event when clicking save button', () => {
findSaveButton().vm.$emit('click', { preventDefault: jest.fn() });
2017-09-10 17:25:29 +05:30
2021-09-04 01:27:46 +05:30
expect(eventHub.$emit).toHaveBeenCalledWith('update.issuable');
2017-09-10 17:25:29 +05:30
});
});
describe('closeForm', () => {
2021-09-04 01:27:46 +05:30
beforeEach(() => {
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
});
2017-09-10 17:25:29 +05:30
it('emits close.form when clicking cancel', () => {
2021-09-04 01:27:46 +05:30
findCancelButton().vm.$emit('click');
2017-09-10 17:25:29 +05:30
2018-12-13 13:39:08 +05:30
expect(eventHub.$emit).toHaveBeenCalledWith('close.form');
2017-09-10 17:25:29 +05:30
});
});
});