2020-10-24 23:57:45 +05:30
|
|
|
import axios from 'axios';
|
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { merge } from 'lodash';
|
|
|
|
import Vuex from 'vuex';
|
2022-04-04 11:22:00 +05:30
|
|
|
import { nextTick } from 'vue';
|
2022-08-13 15:12:31 +05:30
|
|
|
import { GlDatepicker, GlFormCheckbox } from '@gitlab/ui';
|
|
|
|
import originalOneReleaseForEditingQueryResponse from 'test_fixtures/graphql/releases/graphql/queries/one_release_for_editing.query.graphql.json';
|
|
|
|
import { convertOneReleaseGraphQLResponse } from '~/releases/util';
|
|
|
|
import { mountExtended } from 'helpers/vue_test_utils_helper';
|
2021-10-27 15:23:28 +05:30
|
|
|
import setWindowLocation from 'helpers/set_window_location_helper';
|
2021-07-02 01:05:55 +05:30
|
|
|
import { TEST_HOST } from 'helpers/test_constants';
|
2021-03-11 19:13:27 +05:30
|
|
|
import ReleaseEditNewApp from '~/releases/components/app_edit_new.vue';
|
2020-04-22 19:07:51 +05:30
|
|
|
import AssetLinksForm from '~/releases/components/asset_links_form.vue';
|
2022-08-13 15:12:31 +05:30
|
|
|
import ConfirmDeleteModal from '~/releases/components/confirm_delete_modal.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { BACK_URL_PARAM } from '~/releases/constants';
|
2022-07-16 23:28:13 +05:30
|
|
|
import MarkdownField from '~/vue_shared/components/markdown/field.vue';
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
const originalRelease = originalOneReleaseForEditingQueryResponse.data.project.release;
|
2021-01-03 14:25:43 +05:30
|
|
|
const originalMilestones = originalRelease.milestones;
|
2021-07-02 01:05:55 +05:30
|
|
|
const releasesPagePath = 'path/to/releases/page';
|
2022-08-13 15:12:31 +05:30
|
|
|
const upcomingReleaseDocsPath = 'path/to/upcoming/release/docs';
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
describe('Release edit/new 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;
|
2020-04-22 19:07:51 +05:30
|
|
|
let getters;
|
2019-12-26 22:10:19 +05:30
|
|
|
let state;
|
2020-05-24 23:13:21 +05:30
|
|
|
let mock;
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
const factory = async ({ featureFlags = {}, store: storeUpdates = {} } = {}) => {
|
2019-12-26 22:10:19 +05:30
|
|
|
state = {
|
2020-04-08 14:13:33 +05:30
|
|
|
release,
|
2022-08-13 15:12:31 +05:30
|
|
|
isExistingRelease: true,
|
2019-12-21 20:55:43 +05:30
|
|
|
markdownDocsPath: 'path/to/markdown/docs',
|
2021-07-02 01:05:55 +05:30
|
|
|
releasesPagePath,
|
2020-05-24 23:13:21 +05:30
|
|
|
projectId: '8',
|
2021-01-29 00:20:46 +05:30
|
|
|
groupId: '42',
|
|
|
|
groupMilestonesAvailable: true,
|
2022-08-13 15:12:31 +05:30
|
|
|
upcomingReleaseDocsPath,
|
2019-12-21 20:55:43 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
actions = {
|
2020-10-24 23:57:45 +05:30
|
|
|
initializeRelease: jest.fn(),
|
|
|
|
saveRelease: jest.fn(),
|
2020-04-22 19:07:51 +05:30
|
|
|
addEmptyAssetLink: jest.fn(),
|
2022-08-13 15:12:31 +05:30
|
|
|
deleteRelease: jest.fn(),
|
2019-12-21 20:55:43 +05:30
|
|
|
};
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
getters = {
|
|
|
|
isValid: () => true,
|
|
|
|
validationErrors: () => ({
|
|
|
|
assets: {
|
|
|
|
links: [],
|
2020-03-13 15:44:24 +05:30
|
|
|
},
|
2020-04-22 19:07:51 +05:30
|
|
|
}),
|
2022-07-16 23:28:13 +05:30
|
|
|
formattedReleaseNotes: () => 'these notes are formatted',
|
2020-04-22 19:07:51 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
const store = new Vuex.Store(
|
|
|
|
merge(
|
|
|
|
{
|
|
|
|
modules: {
|
2021-04-29 21:17:54 +05:30
|
|
|
editNew: {
|
2020-04-22 19:07:51 +05:30
|
|
|
namespaced: true,
|
|
|
|
actions,
|
|
|
|
state,
|
|
|
|
getters,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
storeUpdates,
|
|
|
|
),
|
|
|
|
);
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
wrapper = mountExtended(ReleaseEditNewApp, {
|
2020-03-13 15:44:24 +05:30
|
|
|
store,
|
2020-04-22 19:07:51 +05:30
|
|
|
provide: {
|
|
|
|
glFeatures: featureFlags,
|
|
|
|
},
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
wrapper.element.querySelectorAll('input').forEach((input) => jest.spyOn(input, 'focus'));
|
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(() => {
|
2021-10-27 15:23:28 +05:30
|
|
|
setWindowLocation(TEST_HOST);
|
2021-07-02 01:05:55 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
mock = new MockAdapter(axios);
|
2020-04-08 14:13:33 +05:30
|
|
|
gon.api_version = 'v4';
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
mock.onGet('/api/v4/projects/8/milestones').reply(200, originalMilestones);
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
release = convertOneReleaseGraphQLResponse(originalOneReleaseForEditingQueryResponse).data;
|
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-22 19:07:51 +05:30
|
|
|
const findSubmitButton = () => wrapper.find('button[type=submit]');
|
2020-10-24 23:57:45 +05:30
|
|
|
const findForm = () => wrapper.find('form');
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
describe(`basic functionality tests: all tests unrelated to the "${BACK_URL_PARAM}" parameter`, () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
beforeEach(async () => {
|
|
|
|
await factory();
|
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
it('calls initializeRelease when the component is created', () => {
|
|
|
|
expect(actions.initializeRelease).toHaveBeenCalledTimes(1);
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
it('focuses the first non-disabled input element once the page is shown', () => {
|
|
|
|
const firstEnabledInput = wrapper.element.querySelector('input:enabled');
|
|
|
|
const allInputs = wrapper.element.querySelectorAll('input');
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
allInputs.forEach((input) => {
|
2020-10-24 23:57:45 +05:30
|
|
|
const expectedFocusCalls = input === firstEnabledInput ? 1 : 0;
|
|
|
|
expect(input.focus).toHaveBeenCalledTimes(expectedFocusCalls);
|
|
|
|
});
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
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(
|
2021-04-29 21:17:54 +05:30
|
|
|
'Releases are based on Git tags. We recommend tags that use semantic versioning, for example v1.0.0, v2.1.0-pre.',
|
2020-04-08 14:13:33 +05:30
|
|
|
);
|
|
|
|
});
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
it('renders the correct release title in the "Release title" field', () => {
|
|
|
|
expect(wrapper.find('#release-title').element.value).toBe(release.name);
|
|
|
|
});
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
it('renders the released at date in the "Released at" datepicker', () => {
|
|
|
|
expect(wrapper.findComponent(GlDatepicker).props('value')).toBe(release.releasedAt);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('links to the documentation on upcoming releases in the "Released at" description', () => {
|
|
|
|
const link = wrapper.findByRole('link', { name: 'Upcoming Release' });
|
|
|
|
|
|
|
|
expect(link.exists()).toBe(true);
|
|
|
|
|
|
|
|
expect(link.attributes('href')).toBe(upcomingReleaseDocsPath);
|
|
|
|
});
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
it('renders the release notes in the "Release notes" textarea', () => {
|
|
|
|
expect(wrapper.find('#release-notes').element.value).toBe(release.description);
|
|
|
|
});
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
it('sets the preview text to be the formatted release notes', () => {
|
|
|
|
const notes = getters.formattedReleaseNotes();
|
|
|
|
expect(wrapper.findComponent(MarkdownField).props('textareaValue')).toBe(notes);
|
|
|
|
});
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
it('renders the "Save changes" button as type="submit"', () => {
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(findSubmitButton().attributes('type')).toBe('submit');
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
it('calls saveRelease when the form is submitted', () => {
|
|
|
|
findForm().trigger('submit');
|
|
|
|
|
|
|
|
expect(actions.saveRelease).toHaveBeenCalledTimes(1);
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
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`, () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
beforeEach(async () => {
|
|
|
|
await factory();
|
|
|
|
});
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
2021-07-02 01:05:55 +05:30
|
|
|
// eslint-disable-next-line no-script-url
|
|
|
|
const xssBackUrl = 'javascript:alert(1)';
|
|
|
|
describe.each`
|
|
|
|
backUrl | expectedHref
|
|
|
|
${`${TEST_HOST}/back/url`} | ${`${TEST_HOST}/back/url`}
|
|
|
|
${`/back/url?page=2`} | ${`/back/url?page=2`}
|
|
|
|
${`back/url?page=3`} | ${`back/url?page=3`}
|
|
|
|
${'http://phishing.test/back/url'} | ${releasesPagePath}
|
|
|
|
${'//phishing.test/back/url'} | ${releasesPagePath}
|
|
|
|
${xssBackUrl} | ${releasesPagePath}
|
|
|
|
`(
|
|
|
|
`when the URL contains a "${BACK_URL_PARAM}=$backUrl" parameter`,
|
|
|
|
({ backUrl, expectedHref }) => {
|
|
|
|
beforeEach(async () => {
|
2021-10-27 15:23:28 +05:30
|
|
|
setWindowLocation(`${TEST_HOST}?${BACK_URL_PARAM}=${encodeURIComponent(backUrl)}`);
|
2021-07-02 01:05:55 +05:30
|
|
|
|
|
|
|
await factory();
|
|
|
|
});
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2021-07-02 01:05:55 +05:30
|
|
|
it(`renders a "Cancel" button with an href pointing to ${expectedHref}`, () => {
|
|
|
|
const cancelButton = wrapper.find('.js-cancel-button');
|
|
|
|
expect(cancelButton.attributes().href).toBe(expectedHref);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
describe('when creating a new release', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
beforeEach(async () => {
|
|
|
|
await factory({
|
2020-10-24 23:57:45 +05:30
|
|
|
store: {
|
|
|
|
modules: {
|
2021-04-29 21:17:54 +05:30
|
|
|
editNew: {
|
2022-08-13 15:12:31 +05:30
|
|
|
state: { isExistingRelease: false },
|
2020-10-24 23:57:45 +05:30
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the submit button with the text "Create release"', () => {
|
|
|
|
expect(findSubmitButton().text()).toBe('Create release');
|
|
|
|
});
|
2022-07-16 23:28:13 +05:30
|
|
|
|
|
|
|
it('renders a checkbox to include release notes', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
expect(wrapper.findComponent(GlFormCheckbox).exists()).toBe(true);
|
2022-07-16 23:28:13 +05:30
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('when editing an existing release', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
beforeEach(async () => {
|
|
|
|
await factory();
|
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
it('renders the submit button with the text "Save changes"', () => {
|
|
|
|
expect(findSubmitButton().text()).toBe('Save changes');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
describe('asset links form', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
beforeEach(factory);
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
it('renders the asset links portion of the form', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
expect(wrapper.findComponent(AssetLinksForm).exists()).toBe(true);
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('validation', () => {
|
|
|
|
describe('when the form is valid', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
beforeEach(async () => {
|
|
|
|
await factory({
|
2020-04-22 19:07:51 +05:30
|
|
|
store: {
|
|
|
|
modules: {
|
2021-04-29 21:17:54 +05:30
|
|
|
editNew: {
|
2020-04-22 19:07:51 +05:30
|
|
|
getters: {
|
|
|
|
isValid: () => true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the submit button as enabled', () => {
|
|
|
|
expect(findSubmitButton().attributes('disabled')).toBeUndefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when the form is invalid', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
beforeEach(async () => {
|
|
|
|
await factory({
|
2020-04-22 19:07:51 +05:30
|
|
|
store: {
|
|
|
|
modules: {
|
2021-04-29 21:17:54 +05:30
|
|
|
editNew: {
|
2020-04-22 19:07:51 +05:30
|
|
|
getters: {
|
|
|
|
isValid: () => false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the submit button as disabled', () => {
|
|
|
|
expect(findSubmitButton().attributes('disabled')).toBe('disabled');
|
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
it('does not allow the form to be submitted', () => {
|
|
|
|
findForm().trigger('submit');
|
|
|
|
|
|
|
|
expect(actions.saveRelease).not.toHaveBeenCalled();
|
|
|
|
});
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
});
|
2022-08-13 15:12:31 +05:30
|
|
|
|
|
|
|
describe('delete', () => {
|
|
|
|
const findConfirmDeleteModal = () => wrapper.findComponent(ConfirmDeleteModal);
|
|
|
|
|
|
|
|
it('calls the deleteRelease action on confirmation', async () => {
|
|
|
|
await factory();
|
|
|
|
findConfirmDeleteModal().vm.$emit('delete');
|
|
|
|
|
|
|
|
expect(actions.deleteRelease).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is hidden if this is a new release', async () => {
|
|
|
|
await factory({
|
|
|
|
store: {
|
|
|
|
modules: {
|
|
|
|
editNew: {
|
|
|
|
state: {
|
|
|
|
isExistingRelease: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(findConfirmDeleteModal().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
2019-12-21 20:55:43 +05:30
|
|
|
});
|