debian-mirror-gitlab/spec/frontend/releases/components/app_edit_spec.js

136 lines
4.1 KiB
JavaScript
Raw Normal View History

2019-12-21 20:55:43 +05:30
import Vuex from 'vuex';
import { mount } from '@vue/test-utils';
2020-03-13 15:44:24 +05:30
import ReleaseEditApp from '~/releases/components/app_edit.vue';
2020-04-08 14:13:33 +05:30
import { release as originalRelease } from '../mock_data';
import * as commonUtils from '~/lib/utils/common_utils';
import { BACK_URL_PARAM } from '~/releases/constants';
2019-12-21 20:55:43 +05:30
2020-03-13 15:44:24 +05:30
describe('Release edit component', () => {
2019-12-21 20:55:43 +05:30
let wrapper;
2020-04-08 14:13:33 +05:30
let release;
2019-12-21 20:55:43 +05:30
let actions;
2019-12-26 22:10:19 +05:30
let state;
2019-12-21 20:55:43 +05:30
2020-04-08 14:13:33 +05:30
const factory = () => {
2019-12-26 22:10:19 +05:30
state = {
2020-04-08 14:13:33 +05:30
release,
2019-12-21 20:55:43 +05:30
markdownDocsPath: 'path/to/markdown/docs',
2019-12-26 22:10:19 +05:30
updateReleaseApiDocsPath: 'path/to/update/release/api/docs',
2020-04-08 14:13:33 +05:30
releasesPagePath: 'path/to/releases/page',
2019-12-21 20:55:43 +05:30
};
actions = {
fetchRelease: jest.fn(),
updateRelease: jest.fn(),
};
2020-03-13 15:44:24 +05:30
const store = new Vuex.Store({
modules: {
detail: {
namespaced: true,
actions,
state,
},
},
});
wrapper = mount(ReleaseEditApp, {
store,
});
2020-04-08 14:13:33 +05:30
};
2019-12-21 20:55:43 +05:30
2020-04-08 14:13:33 +05:30
beforeEach(() => {
gon.api_version = 'v4';
2019-12-21 20:55:43 +05:30
2020-04-08 14:13:33 +05:30
release = commonUtils.convertObjectPropsToCamelCase(originalRelease, { deep: true });
2019-12-21 20:55:43 +05:30
});
2020-04-08 14:13:33 +05:30
afterEach(() => {
wrapper.destroy();
wrapper = null;
2019-12-21 20:55:43 +05:30
});
2020-04-08 14:13:33 +05:30
describe(`basic functionality tests: all tests unrelated to the "${BACK_URL_PARAM}" parameter`, () => {
beforeEach(() => {
factory();
});
2019-12-21 20:55:43 +05:30
2020-04-08 14:13:33 +05:30
it('calls fetchRelease when the component is created', () => {
expect(actions.fetchRelease).toHaveBeenCalledTimes(1);
});
2019-12-26 22:10:19 +05:30
2020-04-08 14:13:33 +05:30
it('renders the description text at the top of the page', () => {
expect(wrapper.find('.js-subtitle-text').text()).toBe(
'Releases are based on Git tags. We recommend naming tags that fit within semantic versioning, for example v1.0, v2.0-pre.',
);
});
2019-12-21 20:55:43 +05:30
2020-04-08 14:13:33 +05:30
it('renders the correct tag name in the "Tag name" field', () => {
expect(wrapper.find('#git-ref').element.value).toBe(release.tagName);
});
it('renders the correct help text under the "Tag name" field', () => {
const helperText = wrapper.find('#tag-name-help');
const helperTextLink = helperText.find('a');
const helperTextLinkAttrs = helperTextLink.attributes();
expect(helperText.text()).toBe(
'Changing a Release tag is only supported via Releases API. More information',
);
expect(helperTextLink.text()).toBe('More information');
expect(helperTextLinkAttrs).toEqual(
expect.objectContaining({
href: state.updateReleaseApiDocsPath,
rel: 'noopener noreferrer',
target: '_blank',
}),
);
});
it('renders the correct release title in the "Release title" field', () => {
expect(wrapper.find('#release-title').element.value).toBe(release.name);
});
it('renders the release notes in the "Release notes" textarea', () => {
expect(wrapper.find('#release-notes').element.value).toBe(release.description);
});
it('renders the "Save changes" button as type="submit"', () => {
expect(wrapper.find('.js-submit-button').attributes('type')).toBe('submit');
});
2019-12-21 20:55:43 +05:30
2020-04-08 14:13:33 +05:30
it('calls updateRelease when the form is submitted', () => {
wrapper.find('form').trigger('submit');
expect(actions.updateRelease).toHaveBeenCalledTimes(1);
});
2019-12-21 20:55:43 +05:30
});
2020-04-08 14:13:33 +05:30
describe(`when the URL does not contain a "${BACK_URL_PARAM}" parameter`, () => {
beforeEach(() => {
factory();
});
it(`renders a "Cancel" button with an href pointing to "${BACK_URL_PARAM}"`, () => {
const cancelButton = wrapper.find('.js-cancel-button');
expect(cancelButton.attributes().href).toBe(state.releasesPagePath);
});
2019-12-21 20:55:43 +05:30
});
2020-04-08 14:13:33 +05:30
describe(`when the URL contains a "${BACK_URL_PARAM}" parameter`, () => {
const backUrl = 'https://example.gitlab.com/back/url';
beforeEach(() => {
commonUtils.getParameterByName = jest
.fn()
.mockImplementation(paramToGet => ({ [BACK_URL_PARAM]: backUrl }[paramToGet]));
factory();
});
it('renders a "Cancel" button with an href pointing to the main Releases page', () => {
const cancelButton = wrapper.find('.js-cancel-button');
expect(cancelButton.attributes().href).toBe(backUrl);
});
2019-12-21 20:55:43 +05:30
});
});