Commit 7485ecc5 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Merge branch 'leipert-remove-unused-utility' into 'master'

Remove unused window.gl.utils

See merge request gitlab-org/gitlab!36849
parents 15ae2869 12bf2a7d
import $ from 'jquery'; import $ from 'jquery';
import { getSelectedFragment } from '~/lib/utils/common_utils'; import { getSelectedFragment, insertText } from '~/lib/utils/common_utils';
export class CopyAsGFM { export class CopyAsGFM {
constructor() { constructor() {
...@@ -79,7 +79,7 @@ export class CopyAsGFM { ...@@ -79,7 +79,7 @@ export class CopyAsGFM {
} }
static insertPastedText(target, text, gfm) { static insertPastedText(target, text, gfm) {
window.gl.utils.insertText(target, textBefore => { insertText(target, textBefore => {
// If the text before the cursor contains an odd number of backticks, // If the text before the cursor contains an odd number of backticks,
// we are either inside an inline code span that starts with 1 backtick // we are either inside an inline code span that starts with 1 backtick
// or a code block that starts with 3 backticks. // or a code block that starts with 3 backticks.
......
...@@ -5,7 +5,7 @@ import NewCommitForm from '../new_commit_form'; ...@@ -5,7 +5,7 @@ import NewCommitForm from '../new_commit_form';
import EditBlob from './edit_blob'; import EditBlob from './edit_blob';
import BlobFileDropzone from '../blob/blob_file_dropzone'; import BlobFileDropzone from '../blob/blob_file_dropzone';
import initPopover from '~/blob/suggest_gitlab_ci_yml'; import initPopover from '~/blob/suggest_gitlab_ci_yml';
import { setCookie } from '~/lib/utils/common_utils'; import { disableButtonIfEmptyField, setCookie } from '~/lib/utils/common_utils';
import Tracking from '~/tracking'; import Tracking from '~/tracking';
export default () => { export default () => {
...@@ -51,10 +51,7 @@ export default () => { ...@@ -51,10 +51,7 @@ export default () => {
new BlobFileDropzone(uploadBlobForm, method); new BlobFileDropzone(uploadBlobForm, method);
new NewCommitForm(uploadBlobForm); new NewCommitForm(uploadBlobForm);
window.gl.utils.disableButtonIfEmptyField( disableButtonIfEmptyField(uploadBlobForm.find('.js-commit-message'), '.btn-upload-file');
uploadBlobForm.find('.js-commit-message'),
'.btn-upload-file',
);
} }
if (deleteBlobForm.length) { if (deleteBlobForm.length) {
......
...@@ -3,6 +3,7 @@ import autosize from 'autosize'; ...@@ -3,6 +3,7 @@ import autosize from 'autosize';
import GfmAutoComplete, { defaultAutocompleteConfig } from 'ee_else_ce/gfm_auto_complete'; import GfmAutoComplete, { defaultAutocompleteConfig } from 'ee_else_ce/gfm_auto_complete';
import dropzoneInput from './dropzone_input'; import dropzoneInput from './dropzone_input';
import { addMarkdownListeners, removeMarkdownListeners } from './lib/utils/text_markdown'; import { addMarkdownListeners, removeMarkdownListeners } from './lib/utils/text_markdown';
import { disableButtonIfEmptyField } from '~/lib/utils/common_utils';
export default class GLForm { export default class GLForm {
constructor(form, enableGFM = {}) { constructor(form, enableGFM = {}) {
...@@ -45,7 +46,7 @@ export default class GLForm { ...@@ -45,7 +46,7 @@ export default class GLForm {
this.form.find('.div-dropzone').remove(); this.form.find('.div-dropzone').remove();
this.form.addClass('gfm-form'); this.form.addClass('gfm-form');
// remove notify commit author checkbox for non-commit notes // remove notify commit author checkbox for non-commit notes
gl.utils.disableButtonIfEmptyField( disableButtonIfEmptyField(
this.form.find('.js-note-text'), this.form.find('.js-note-text'),
this.form.find('.js-comment-button, .js-note-new-discussion'), this.form.find('.js-comment-button, .js-note-new-discussion'),
); );
......
...@@ -53,16 +53,6 @@ export const getCspNonceValue = () => { ...@@ -53,16 +53,6 @@ export const getCspNonceValue = () => {
return metaTag && metaTag.content; return metaTag && metaTag.content;
}; };
export const ajaxGet = url =>
axios
.get(url, {
params: { format: 'js' },
responseType: 'text',
})
.then(({ data }) => {
$.globalEval(data, { nonce: getCspNonceValue() });
});
export const rstrip = val => { export const rstrip = val => {
if (val) { if (val) {
return val.replace(/\s+$/, ''); return val.replace(/\s+$/, '');
...@@ -375,34 +365,6 @@ export const insertText = (target, text) => { ...@@ -375,34 +365,6 @@ export const insertText = (target, text) => {
target.dispatchEvent(event); target.dispatchEvent(event);
}; };
export const nodeMatchesSelector = (node, selector) => {
const matches =
Element.prototype.matches ||
Element.prototype.matchesSelector ||
Element.prototype.mozMatchesSelector ||
Element.prototype.msMatchesSelector ||
Element.prototype.oMatchesSelector ||
Element.prototype.webkitMatchesSelector;
if (matches) {
return matches.call(node, selector);
}
// IE11 doesn't support `node.matches(selector)`
let { parentNode } = node;
if (!parentNode) {
parentNode = document.createElement('div');
// eslint-disable-next-line no-param-reassign
node = node.cloneNode(true);
parentNode.appendChild(node);
}
const matchingNodes = parentNode.querySelectorAll(selector);
return Array.prototype.indexOf.call(matchingNodes, node) !== -1;
};
/** /**
this will take in the headers from an API response and normalize them this will take in the headers from an API response and normalize them
this way we don't run into production issues when nginx gives us lowercased header keys this way we don't run into production issues when nginx gives us lowercased header keys
...@@ -417,24 +379,6 @@ export const normalizeHeaders = headers => { ...@@ -417,24 +379,6 @@ export const normalizeHeaders = headers => {
return upperCaseHeaders; return upperCaseHeaders;
}; };
/**
this will take in the getAllResponseHeaders result and normalize them
this way we don't run into production issues when nginx gives us lowercased header keys
*/
export const normalizeCRLFHeaders = headers => {
const headersObject = {};
const headersArray = headers.split('\n');
headersArray.forEach(header => {
const keyValue = header.split(': ');
// eslint-disable-next-line prefer-destructuring
headersObject[keyValue[0]] = keyValue[1];
});
return normalizeHeaders(headersObject);
};
/** /**
* Parses pagination object string values into numbers. * Parses pagination object string values into numbers.
* *
...@@ -643,13 +587,6 @@ export const setFaviconOverlay = overlayPath => { ...@@ -643,13 +587,6 @@ export const setFaviconOverlay = overlayPath => {
); );
}; };
export const setFavicon = faviconPath => {
const faviconEl = document.getElementById('favicon');
if (faviconEl && faviconPath) {
faviconEl.setAttribute('href', faviconPath);
}
};
export const resetFavicon = () => { export const resetFavicon = () => {
const faviconEl = document.getElementById('favicon'); const faviconEl = document.getElementById('favicon');
...@@ -888,35 +825,6 @@ export const searchBy = (query = '', searchSpace = {}) => { ...@@ -888,35 +825,6 @@ export const searchBy = (query = '', searchSpace = {}) => {
*/ */
export const isScopedLabel = ({ title = '' }) => title.indexOf('::') !== -1; export const isScopedLabel = ({ title = '' }) => title.indexOf('::') !== -1;
window.gl = window.gl || {};
window.gl.utils = {
...(window.gl.utils || {}),
getPagePath,
isInGroupsPage,
isInProjectPage,
getProjectSlug,
getGroupSlug,
isInIssuePage,
ajaxGet,
rstrip,
updateTooltipTitle,
disableButtonIfEmptyField,
handleLocationHash,
isInViewport,
parseUrl,
parseUrlPathname,
getUrlParamsArray,
isMetaKey,
isMetaClick,
scrollToElement,
getParameterByName,
getSelectedFragment,
insertText,
nodeMatchesSelector,
spriteIcon,
imagePath,
};
// Methods to set and get Cookie // Methods to set and get Cookie
export const setCookie = (name, value) => Cookies.set(name, value, { expires: 365 }); export const setCookie = (name, value) => Cookies.set(name, value, { expires: 365 });
......
...@@ -427,7 +427,6 @@ export const dayInQuarter = (date, quarter) => { ...@@ -427,7 +427,6 @@ export const dayInQuarter = (date, quarter) => {
window.gl = window.gl || {}; window.gl = window.gl || {};
window.gl.utils = { window.gl.utils = {
...(window.gl.utils || {}), ...(window.gl.utils || {}),
getTimeago,
localTimeAgo, localTimeAgo,
}; };
......
import $ from 'jquery'; import $ from 'jquery';
import { disableButtonIfEmptyField } from '~/lib/utils/common_utils';
export default class Members { export default class Members {
constructor() { constructor() {
...@@ -13,7 +14,7 @@ export default class Members { ...@@ -13,7 +14,7 @@ export default class Members {
$('.js-edit-member-form') $('.js-edit-member-form')
.off('ajax:success') .off('ajax:success')
.on('ajax:success', this.formSuccess.bind(this)); .on('ajax:success', this.formSuccess.bind(this));
gl.utils.disableButtonIfEmptyField('#user_ids', 'input[name=commit]', 'change'); disableButtonIfEmptyField('#user_ids', 'input[name=commit]', 'change');
} }
dropdownClicked(options) { dropdownClicked(options) {
......
...@@ -11,6 +11,7 @@ import sidebarSubscriptions from './components/subscriptions/sidebar_subscriptio ...@@ -11,6 +11,7 @@ import sidebarSubscriptions from './components/subscriptions/sidebar_subscriptio
import Translate from '../vue_shared/translate'; import Translate from '../vue_shared/translate';
import createDefaultClient from '~/lib/graphql'; import createDefaultClient from '~/lib/graphql';
import { store } from '~/notes/stores'; import { store } from '~/notes/stores';
import { isInIssuePage } from '~/lib/utils/common_utils';
Vue.use(Translate); Vue.use(Translate);
Vue.use(VueApollo); Vue.use(VueApollo);
...@@ -43,7 +44,7 @@ function mountAssigneesComponent(mediator) { ...@@ -43,7 +44,7 @@ function mountAssigneesComponent(mediator) {
projectPath: fullPath, projectPath: fullPath,
field: el.dataset.field, field: el.dataset.field,
signedIn: el.hasAttribute('data-signed-in'), signedIn: el.hasAttribute('data-signed-in'),
issuableType: gl.utils.isInIssuePage() ? 'issue' : 'merge_request', issuableType: isInIssuePage() ? 'issue' : 'merge_request',
}, },
}), }),
}); });
...@@ -93,7 +94,7 @@ function mountLockComponent(mediator) { ...@@ -93,7 +94,7 @@ function mountLockComponent(mediator) {
isLocked: initialData.is_locked, isLocked: initialData.is_locked,
isEditable: initialData.is_editable, isEditable: initialData.is_editable,
mediator, mediator,
issuableType: gl.utils.isInIssuePage() ? 'issue' : 'merge_request', issuableType: isInIssuePage() ? 'issue' : 'merge_request',
}, },
}).$mount(el); }).$mount(el);
} }
......
...@@ -20,7 +20,7 @@ export default { ...@@ -20,7 +20,7 @@ export default {
Here is an example `change` method: Here is an example `change` method:
change(pagenum) { change(pagenum) {
gl.utils.visitUrl(`?page=${pagenum}`); visitUrl(`?page=${pagenum}`);
}, },
*/ */
change: { change: {
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
import { __ } from '~/locale'; import { __ } from '~/locale';
import Flash from '~/flash'; import Flash from '~/flash';
import { redirectTo } from '~/lib/utils/url_utility'; import { redirectTo } from '~/lib/utils/url_utility';
import { spriteIcon } from '~/lib/utils/common_utils';
import GitlabSlackService from '../services/gitlab_slack_service'; import GitlabSlackService from '../services/gitlab_slack_service';
...@@ -59,11 +60,11 @@ export default { ...@@ -59,11 +60,11 @@ export default {
computed: { computed: {
doubleHeadedArrowSvg() { doubleHeadedArrowSvg() {
return gl.utils.spriteIcon('double-headed-arrow'); return spriteIcon('double-headed-arrow');
}, },
arrowRightSvg() { arrowRightSvg() {
return gl.utils.spriteIcon('arrow-right'); return spriteIcon('arrow-right');
}, },
hasProjects() { hasProjects() {
......
import GfmAutoCompleteEE from 'ee/gfm_auto_complete'; import GfmAutoCompleteEE from 'ee/gfm_auto_complete';
import $ from 'jquery'; import $ from 'jquery';
import { TEST_HOST } from 'jest/helpers/test_constants';
describe('GfmAutoCompleteEE', () => { describe('GfmAutoCompleteEE', () => {
const dataSources = { const dataSources = {
labels: `${gl.TEST_HOST}/autocomplete_sources/labels`, labels: `${TEST_HOST}/autocomplete_sources/labels`,
}; };
let instance; let instance;
const $input = $('<input type="text" />'); const $input = $('<input type="text" />');
......
...@@ -2,6 +2,7 @@ import MockAdapter from 'axios-mock-adapter'; ...@@ -2,6 +2,7 @@ import MockAdapter from 'axios-mock-adapter';
import testAction from 'helpers/vuex_action_helper'; import testAction from 'helpers/vuex_action_helper';
import * as actions from '~/batch_comments/stores/modules/batch_comments/actions'; import * as actions from '~/batch_comments/stores/modules/batch_comments/actions';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { TEST_HOST } from 'jest/helpers/test_constants';
describe('Batch comments store actions', () => { describe('Batch comments store actions', () => {
let res = {}; let res = {};
...@@ -33,7 +34,7 @@ describe('Batch comments store actions', () => { ...@@ -33,7 +34,7 @@ describe('Batch comments store actions', () => {
testAction( testAction(
actions.addDraftToDiscussion, actions.addDraftToDiscussion,
{ endpoint: gl.TEST_HOST, data: 'test' }, { endpoint: TEST_HOST, data: 'test' },
null, null,
[{ type: 'ADD_NEW_DRAFT', payload: res }], [{ type: 'ADD_NEW_DRAFT', payload: res }],
[], [],
...@@ -46,7 +47,7 @@ describe('Batch comments store actions', () => { ...@@ -46,7 +47,7 @@ describe('Batch comments store actions', () => {
testAction( testAction(
actions.addDraftToDiscussion, actions.addDraftToDiscussion,
{ endpoint: gl.TEST_HOST, data: 'test' }, { endpoint: TEST_HOST, data: 'test' },
null, null,
[], [],
[], [],
...@@ -62,7 +63,7 @@ describe('Batch comments store actions', () => { ...@@ -62,7 +63,7 @@ describe('Batch comments store actions', () => {
testAction( testAction(
actions.createNewDraft, actions.createNewDraft,
{ endpoint: gl.TEST_HOST, data: 'test' }, { endpoint: TEST_HOST, data: 'test' },
null, null,
[{ type: 'ADD_NEW_DRAFT', payload: res }], [{ type: 'ADD_NEW_DRAFT', payload: res }],
[], [],
...@@ -73,14 +74,7 @@ describe('Batch comments store actions', () => { ...@@ -73,14 +74,7 @@ describe('Batch comments store actions', () => {
it('does not commit ADD_NEW_DRAFT if errors returned', done => { it('does not commit ADD_NEW_DRAFT if errors returned', done => {
mock.onAny().reply(500); mock.onAny().reply(500);
testAction( testAction(actions.createNewDraft, { endpoint: TEST_HOST, data: 'test' }, null, [], [], done);
actions.createNewDraft,
{ endpoint: gl.TEST_HOST, data: 'test' },
null,
[],
[],
done,
);
}); });
}); });
...@@ -90,7 +84,7 @@ describe('Batch comments store actions', () => { ...@@ -90,7 +84,7 @@ describe('Batch comments store actions', () => {
beforeEach(() => { beforeEach(() => {
getters = { getters = {
getNotesData: { getNotesData: {
draftsDiscardPath: gl.TEST_HOST, draftsDiscardPath: TEST_HOST,
}, },
}; };
}); });
...@@ -137,7 +131,7 @@ describe('Batch comments store actions', () => { ...@@ -137,7 +131,7 @@ describe('Batch comments store actions', () => {
beforeEach(() => { beforeEach(() => {
getters = { getters = {
getNotesData: { getNotesData: {
draftsPath: gl.TEST_HOST, draftsPath: TEST_HOST,
}, },
}; };
}); });
...@@ -171,7 +165,7 @@ describe('Batch comments store actions', () => { ...@@ -171,7 +165,7 @@ describe('Batch comments store actions', () => {
dispatch = jest.fn(); dispatch = jest.fn();
commit = jest.fn(); commit = jest.fn();
getters = { getters = {
getNotesData: { draftsPublishPath: gl.TEST_HOST, discussionsPath: gl.TEST_HOST }, getNotesData: { draftsPublishPath: TEST_HOST, discussionsPath: TEST_HOST },
}; };
rootGetters = { discussionsStructuredByLineCode: 'discussions' }; rootGetters = { discussionsStructuredByLineCode: 'discussions' };
}); });
...@@ -208,7 +202,7 @@ describe('Batch comments store actions', () => { ...@@ -208,7 +202,7 @@ describe('Batch comments store actions', () => {
describe('discardReview', () => { describe('discardReview', () => {
it('commits mutations', done => { it('commits mutations', done => {
const getters = { const getters = {
getNotesData: { draftsDiscardPath: gl.TEST_HOST }, getNotesData: { draftsDiscardPath: TEST_HOST },
}; };
const commit = jest.fn(); const commit = jest.fn();
mock.onAny().reply(200); mock.onAny().reply(200);
...@@ -225,7 +219,7 @@ describe('Batch comments store actions', () => { ...@@ -225,7 +219,7 @@ describe('Batch comments store actions', () => {
it('commits error mutations', done => { it('commits error mutations', done => {
const getters = { const getters = {
getNotesData: { draftsDiscardPath: gl.TEST_HOST }, getNotesData: { draftsDiscardPath: TEST_HOST },
}; };
const commit = jest.fn(); const commit = jest.fn();
mock.onAny().reply(500); mock.onAny().reply(500);
...@@ -247,7 +241,7 @@ describe('Batch comments store actions', () => { ...@@ -247,7 +241,7 @@ describe('Batch comments store actions', () => {
beforeEach(() => { beforeEach(() => {
getters = { getters = {
getNotesData: { getNotesData: {
draftsPath: gl.TEST_HOST, draftsPath: TEST_HOST,
}, },
}; };
}); });
......
import * as commonUtils from '~/lib/utils/common_utils';
import initCopyAsGFM, { CopyAsGFM } from '~/behaviors/markdown/copy_as_gfm'; import initCopyAsGFM, { CopyAsGFM } from '~/behaviors/markdown/copy_as_gfm';
describe('CopyAsGFM', () => { describe('CopyAsGFM', () => {
...@@ -27,7 +28,7 @@ describe('CopyAsGFM', () => { ...@@ -27,7 +28,7 @@ describe('CopyAsGFM', () => {
} }
it('wraps pasted code when not already in code tags', () => { it('wraps pasted code when not already in code tags', () => {
jest.spyOn(window.gl.utils, 'insertText').mockImplementation((el, textFunc) => { jest.spyOn(commonUtils, 'insertText').mockImplementation((el, textFunc) => {
const insertedText = textFunc('This is code: ', ''); const insertedText = textFunc('This is code: ', '');
expect(insertedText).toEqual('`code`'); expect(insertedText).toEqual('`code`');
...@@ -37,7 +38,7 @@ describe('CopyAsGFM', () => { ...@@ -37,7 +38,7 @@ describe('CopyAsGFM', () => {
}); });
it('does not wrap pasted code when already in code tags', () => { it('does not wrap pasted code when already in code tags', () => {
jest.spyOn(window.gl.utils, 'insertText').mockImplementation((el, textFunc) => { jest.spyOn(commonUtils, 'insertText').mockImplementation((el, textFunc) => {
const insertedText = textFunc('This is code: `', '`'); const insertedText = textFunc('This is code: `', '`');
expect(insertedText).toEqual('code'); expect(insertedText).toEqual('code');
......
...@@ -46,7 +46,7 @@ describe('ShortcutsIssuable', () => { ...@@ -46,7 +46,7 @@ describe('ShortcutsIssuable', () => {
}); });
describe('replyWithSelectedText', () => { describe('replyWithSelectedText', () => {
// Stub window.gl.utils.getSelectedFragment to return a node with the provided HTML. // Stub getSelectedFragment to return a node with the provided HTML.
const stubSelection = (html, invalidNode) => { const stubSelection = (html, invalidNode) => {
getSelectedFragment.mockImplementation(() => { getSelectedFragment.mockImplementation(() => {
const documentFragment = document.createDocumentFragment(); const documentFragment = document.createDocumentFragment();
......
...@@ -3,14 +3,15 @@ import { mount } from '@vue/test-utils'; ...@@ -3,14 +3,15 @@ import { mount } from '@vue/test-utils';
import boardsStore from '~/boards/stores/boards_store'; import boardsStore from '~/boards/stores/boards_store';
import boardForm from '~/boards/components/board_form.vue'; import boardForm from '~/boards/components/board_form.vue';
import DeprecatedModal from '~/vue_shared/components/deprecated_modal.vue'; import DeprecatedModal from '~/vue_shared/components/deprecated_modal.vue';
import { TEST_HOST } from 'jest/helpers/test_constants';
describe('board_form.vue', () => { describe('board_form.vue', () => {
let wrapper; let wrapper;
const propsData = { const propsData = {
canAdminBoard: false, canAdminBoard: false,
labelsPath: `${gl.TEST_HOST}/labels/path`, labelsPath: `${TEST_HOST}/labels/path`,
milestonePath: `${gl.TEST_HOST}/milestone/path`, milestonePath: `${TEST_HOST}/milestone/path`,
}; };
const findModal = () => wrapper.find(DeprecatedModal); const findModal = () => wrapper.find(DeprecatedModal);
......
...@@ -59,6 +59,7 @@ import { mergeUrlParams } from '~/lib/utils/url_utility'; ...@@ -59,6 +59,7 @@ import { mergeUrlParams } from '~/lib/utils/url_utility';
import { useLocalStorageSpy } from 'helpers/local_storage_helper'; import { useLocalStorageSpy } from 'helpers/local_storage_helper';
import { diffMetadata } from '../mock_data/diff_metadata'; import { diffMetadata } from '../mock_data/diff_metadata';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { TEST_HOST } from 'jest/helpers/test_constants';
jest.mock('~/flash', () => jest.fn()); jest.mock('~/flash', () => jest.fn());
...@@ -1259,12 +1260,12 @@ describe('DiffsStoreActions', () => { ...@@ -1259,12 +1260,12 @@ describe('DiffsStoreActions', () => {
describe('success', () => { describe('success', () => {
beforeEach(() => { beforeEach(() => {
mock.onGet(`${gl.TEST_HOST}/context`).replyOnce(200, ['test']); mock.onGet(`${TEST_HOST}/context`).replyOnce(200, ['test']);
}); });
it('commits the success and dispatches an action to expand the new lines', done => { it('commits the success and dispatches an action to expand the new lines', done => {
const file = { const file = {
context_lines_path: `${gl.TEST_HOST}/context`, context_lines_path: `${TEST_HOST}/context`,
file_path: 'test', file_path: 'test',
file_hash: 'test', file_hash: 'test',
}; };
...@@ -1281,13 +1282,13 @@ describe('DiffsStoreActions', () => { ...@@ -1281,13 +1282,13 @@ describe('DiffsStoreActions', () => {
describe('error', () => { describe('error', () => {
beforeEach(() => { beforeEach(() => {
mock.onGet(`${gl.TEST_HOST}/context`).replyOnce(500); mock.onGet(`${TEST_HOST}/context`).replyOnce(500);
}); });
it('dispatches receiveFullDiffError', done => { it('dispatches receiveFullDiffError', done => {
testAction( testAction(
fetchFullDiff, fetchFullDiff,
{ context_lines_path: `${gl.TEST_HOST}/context`, file_path: 'test', file_hash: 'test' }, { context_lines_path: `${TEST_HOST}/context`, file_path: 'test', file_hash: 'test' },
null, null,
[], [],
[{ type: 'receiveFullDiffError', payload: 'test' }], [{ type: 'receiveFullDiffError', payload: 'test' }],
...@@ -1451,7 +1452,7 @@ describe('DiffsStoreActions', () => { ...@@ -1451,7 +1452,7 @@ describe('DiffsStoreActions', () => {
describe('setSuggestPopoverDismissed', () => { describe('setSuggestPopoverDismissed', () => {
it('commits SET_SHOW_SUGGEST_POPOVER', done => { it('commits SET_SHOW_SUGGEST_POPOVER', done => {
const state = { dismissEndpoint: `${gl.TEST_HOST}/-/user_callouts` }; const state = { dismissEndpoint: `${TEST_HOST}/-/user_callouts` };
const mock = new MockAdapter(axios); const mock = new MockAdapter(axios);
mock.onPost(state.dismissEndpoint).reply(200, {}); mock.onPost(state.dismissEndpoint).reply(200, {});
......
...@@ -2,7 +2,6 @@ import RecentSearchesService from '~/filtered_search/services/recent_searches_se ...@@ -2,7 +2,6 @@ import RecentSearchesService from '~/filtered_search/services/recent_searches_se
import RecentSearchesServiceError from '~/filtered_search/services/recent_searches_service_error'; import RecentSearchesServiceError from '~/filtered_search/services/recent_searches_service_error';
import RecentSearchesRoot from '~/filtered_search/recent_searches_root'; import RecentSearchesRoot from '~/filtered_search/recent_searches_root';
import IssuableFilteredSearchTokenKeys from '~/filtered_search/issuable_filtered_search_token_keys'; import IssuableFilteredSearchTokenKeys from '~/filtered_search/issuable_filtered_search_token_keys';
import '~/lib/utils/common_utils';
import DropdownUtils from '~/filtered_search/dropdown_utils'; import DropdownUtils from '~/filtered_search/dropdown_utils';
import FilteredSearchVisualTokens from '~/filtered_search/filtered_search_visual_tokens'; import FilteredSearchVisualTokens from '~/filtered_search/filtered_search_visual_tokens';
import FilteredSearchDropdownManager from '~/filtered_search/filtered_search_dropdown_manager'; import FilteredSearchDropdownManager from '~/filtered_search/filtered_search_dropdown_manager';
...@@ -10,6 +9,7 @@ import FilteredSearchManager from '~/filtered_search/filtered_search_manager'; ...@@ -10,6 +9,7 @@ import FilteredSearchManager from '~/filtered_search/filtered_search_manager';
import FilteredSearchSpecHelper from '../helpers/filtered_search_spec_helper'; import FilteredSearchSpecHelper from '../helpers/filtered_search_spec_helper';
import { BACKSPACE_KEY_CODE, DELETE_KEY_CODE } from '~/lib/utils/keycodes'; import { BACKSPACE_KEY_CODE, DELETE_KEY_CODE } from '~/lib/utils/keycodes';
import { visitUrl } from '~/lib/utils/url_utility'; import { visitUrl } from '~/lib/utils/url_utility';
import * as commonUtils from '~/lib/utils/common_utils';
jest.mock('~/lib/utils/url_utility', () => ({ jest.mock('~/lib/utils/url_utility', () => ({
...jest.requireActual('~/lib/utils/url_utility'), ...jest.requireActual('~/lib/utils/url_utility'),
...@@ -83,7 +83,7 @@ describe('Filtered Search Manager', () => { ...@@ -83,7 +83,7 @@ describe('Filtered Search Manager', () => {
jest jest
.spyOn(FilteredSearchDropdownManager.prototype, 'updateDropdownOffset') .spyOn(FilteredSearchDropdownManager.prototype, 'updateDropdownOffset')
.mockImplementation(); .mockImplementation();
jest.spyOn(gl.utils, 'getParameterByName').mockReturnValue(null); jest.spyOn(commonUtils, 'getParameterByName').mockReturnValue(null);
jest.spyOn(FilteredSearchVisualTokens, 'unselectTokens'); jest.spyOn(FilteredSearchVisualTokens, 'unselectTokens');
input = document.querySelector('.filtered-search'); input = document.querySelector('.filtered-search');
......
...@@ -4,6 +4,7 @@ import AjaxCache from '~/lib/utils/ajax_cache'; ...@@ -4,6 +4,7 @@ import AjaxCache from '~/lib/utils/ajax_cache';
import UsersCache from '~/lib/utils/users_cache'; import UsersCache from '~/lib/utils/users_cache';
import DropdownUtils from '~/filtered_search//dropdown_utils'; import DropdownUtils from '~/filtered_search//dropdown_utils';
import FilteredSearchSpecHelper from '../helpers/filtered_search_spec_helper'; import FilteredSearchSpecHelper from '../helpers/filtered_search_spec_helper';
import { TEST_HOST } from 'jest/helpers/test_constants';
describe('Filtered Search Visual Tokens', () => { describe('Filtered Search Visual Tokens', () => {
const findElements = tokenElement => { const findElements = tokenElement => {
...@@ -106,7 +107,7 @@ describe('Filtered Search Visual Tokens', () => { ...@@ -106,7 +107,7 @@ describe('Filtered Search Visual Tokens', () => {
it('escapes user name when creating token', done => { it('escapes user name when creating token', done => {
const dummyUser = { const dummyUser = {
name: '<script>', name: '<script>',
avatar_url: `${gl.TEST_HOST}/mypics/avatar.png`, avatar_url: `${TEST_HOST}/mypics/avatar.png`,
}; };
const { subject, tokenValueContainer, tokenValueElement } = findElements(authorToken); const { subject, tokenValueContainer, tokenValueElement } = findElements(authorToken);
const tokenValue = tokenValueElement.innerText; const tokenValue = tokenValueElement.innerText;
......
...@@ -9,6 +9,8 @@ describe('GLForm', () => { ...@@ -9,6 +9,8 @@ describe('GLForm', () => {
describe('when instantiated', () => { describe('when instantiated', () => {
beforeEach(done => { beforeEach(done => {
window.gl = window.gl || {};
testContext.form = $('<form class="gfm-form"><textarea class="js-gfm-input"></form>'); testContext.form = $('<form class="gfm-form"><textarea class="js-gfm-input"></form>');
testContext.textarea = testContext.form.find('textarea'); testContext.textarea = testContext.form.find('textarea');
jest.spyOn($.prototype, 'off').mockReturnValue(testContext.textarea); jest.spyOn($.prototype, 'off').mockReturnValue(testContext.textarea);
......
...@@ -7,6 +7,7 @@ import { createStore } from '~/ide/stores'; ...@@ -7,6 +7,7 @@ import { createStore } from '~/ide/stores';
import service from '~/ide/services'; import service from '~/ide/services';
import { createRouter } from '~/ide/ide_router'; import { createRouter } from '~/ide/ide_router';
import { file, createEntriesFromPaths } from '../../helpers'; import { file, createEntriesFromPaths } from '../../helpers';
import { TEST_HOST } from 'jest/helpers/test_constants';
describe('Multi-file store tree actions', () => { describe('Multi-file store tree actions', () => {
let projectTree; let projectTree;
...@@ -97,7 +98,7 @@ describe('Multi-file store tree actions', () => { ...@@ -97,7 +98,7 @@ describe('Multi-file store tree actions', () => {
store.state.projects = { store.state.projects = {
'abc/def': { 'abc/def': {
web_url: `${gl.TEST_HOST}/files`, web_url: `${TEST_HOST}/files`,
branches: { branches: {
'master-testing': { 'master-testing': {
commit: { commit: {
......
import * as commentIndicatorHelper from '~/image_diff/helpers/comment_indicator_helper'; import * as commentIndicatorHelper from '~/image_diff/helpers/comment_indicator_helper';
import * as mockData from '../mock_data'; import * as mockData from '../mock_data';
import { TEST_HOST } from 'jest/helpers/test_constants';
describe('commentIndicatorHelper', () => { describe('commentIndicatorHelper', () => {
const { coordinate } = mockData; const { coordinate } = mockData;
...@@ -52,7 +53,7 @@ describe('commentIndicatorHelper', () => { ...@@ -52,7 +53,7 @@ describe('commentIndicatorHelper', () => {
beforeEach(() => { beforeEach(() => {
containerEl.innerHTML = ` containerEl.innerHTML = `
<div class="comment-indicator" style="left:${coordinate.x}px; top: ${coordinate.y}px;"> <div class="comment-indicator" style="left:${coordinate.x}px; top: ${coordinate.y}px;">
<img src="${gl.TEST_HOST}/image.png"> <img src="${TEST_HOST}/image.png">
</div> </div>
`; `;
result = commentIndicatorHelper.removeCommentIndicator(containerEl); result = commentIndicatorHelper.removeCommentIndicator(containerEl);
......
import * as utilsHelper from '~/image_diff/helpers/utils_helper'; import * as utilsHelper from '~/image_diff/helpers/utils_helper';
import ImageBadge from '~/image_diff/image_badge'; import ImageBadge from '~/image_diff/image_badge';
import * as mockData from '../mock_data'; import * as mockData from '../mock_data';
import { TEST_HOST } from 'jest/helpers/test_constants';
describe('utilsHelper', () => { describe('utilsHelper', () => {
const { noteId, discussionId, image, imageProperties, imageMeta } = mockData; const { noteId, discussionId, image, imageProperties, imageMeta } = mockData;
...@@ -36,7 +37,7 @@ describe('utilsHelper', () => { ...@@ -36,7 +37,7 @@ describe('utilsHelper', () => {
beforeEach(() => { beforeEach(() => {
const imageFrameEl = document.createElement('div'); const imageFrameEl = document.createElement('div');
imageFrameEl.innerHTML = ` imageFrameEl.innerHTML = `
<img src="${gl.TEST_HOST}/image.png"> <img src="${TEST_HOST}/image.png">
`; `;
discussionEl = document.createElement('div'); discussionEl = document.createElement('div');
discussionEl.dataset.discussionId = discussionId; discussionEl.dataset.discussionId = discussionId;
......
...@@ -2,6 +2,7 @@ import ImageDiff from '~/image_diff/image_diff'; ...@@ -2,6 +2,7 @@ import ImageDiff from '~/image_diff/image_diff';
import * as imageUtility from '~/lib/utils/image_utility'; import * as imageUtility from '~/lib/utils/image_utility';
import imageDiffHelper from '~/image_diff/helpers/index'; import imageDiffHelper from '~/image_diff/helpers/index';
import * as mockData from './mock_data'; import * as mockData from './mock_data';
import { TEST_HOST } from 'jest/helpers/test_constants';
describe('ImageDiff', () => { describe('ImageDiff', () => {
let element; let element;
...@@ -12,7 +13,7 @@ describe('ImageDiff', () => { ...@@ -12,7 +13,7 @@ describe('ImageDiff', () => {
<div id="element"> <div id="element">
<div class="diff-file"> <div class="diff-file">
<div class="js-image-frame"> <div class="js-image-frame">
<img src="${gl.TEST_HOST}/image.png"> <img src="${TEST_HOST}/image.png">
<div class="comment-indicator"></div> <div class="comment-indicator"></div>
<div id="badge-1" class="badge">1</div> <div id="badge-1" class="badge">1</div>
<div id="badge-2" class="badge">2</div> <div id="badge-2" class="badge">2</div>
......
...@@ -2,6 +2,7 @@ import ReplacedImageDiff from '~/image_diff/replaced_image_diff'; ...@@ -2,6 +2,7 @@ import ReplacedImageDiff from '~/image_diff/replaced_image_diff';
import ImageDiff from '~/image_diff/image_diff'; import ImageDiff from '~/image_diff/image_diff';
import { viewTypes } from '~/image_diff/view_types'; import { viewTypes } from '~/image_diff/view_types';
import imageDiffHelper from '~/image_diff/helpers/index'; import imageDiffHelper from '~/image_diff/helpers/index';
import { TEST_HOST } from 'jest/helpers/test_constants';
describe('ReplacedImageDiff', () => { describe('ReplacedImageDiff', () => {
let element; let element;
...@@ -12,17 +13,17 @@ describe('ReplacedImageDiff', () => { ...@@ -12,17 +13,17 @@ describe('ReplacedImageDiff', () => {
<div id="element"> <div id="element">
<div class="two-up"> <div class="two-up">
<div class="js-image-frame"> <div class="js-image-frame">
<img src="${gl.TEST_HOST}/image.png"> <img src="${TEST_HOST}/image.png">
</div> </div>
</div> </div>
<div class="swipe"> <div class="swipe">
<div class="js-image-frame"> <div class="js-image-frame">
<img src="${gl.TEST_HOST}/image.png"> <img src="${TEST_HOST}/image.png">
</div> </div>
</div> </div>
<div class="onion-skin"> <div class="onion-skin">
<div class="js-image-frame"> <div class="js-image-frame">
<img src="${gl.TEST_HOST}/image.png"> <img src="${TEST_HOST}/image.png">
</div> </div>
</div> </div>
<div class="view-modes-menu"> <div class="view-modes-menu">
......
...@@ -4,6 +4,7 @@ import Icon from '~/vue_shared/components/icon.vue'; ...@@ -4,6 +4,7 @@ import Icon from '~/vue_shared/components/icon.vue';
import UserAvatarImage from '~/vue_shared/components/user_avatar/user_avatar_image.vue'; import UserAvatarImage from '~/vue_shared/components/user_avatar/user_avatar_image.vue';
import Suggestion from '~/issuable_suggestions/components/item.vue'; import Suggestion from '~/issuable_suggestions/components/item.vue';
import mockData from '../mock_data'; import mockData from '../mock_data';
import { TEST_HOST } from 'jest/helpers/test_constants';
describe('Issuable suggestions suggestion component', () => { describe('Issuable suggestions suggestion component', () => {
let vm; let vm;
...@@ -34,7 +35,7 @@ describe('Issuable suggestions suggestion component', () => { ...@@ -34,7 +35,7 @@ describe('Issuable suggestions suggestion component', () => {
const link = vm.find(GlLink); const link = vm.find(GlLink);
expect(link.attributes('href')).toBe(`${gl.TEST_HOST}/test/issue/1`); expect(link.attributes('href')).toBe(`${TEST_HOST}/test/issue/1`);
}); });
it('renders IID', () => { it('renders IID', () => {
...@@ -100,7 +101,7 @@ describe('Issuable suggestions suggestion component', () => { ...@@ -100,7 +101,7 @@ describe('Issuable suggestions suggestion component', () => {
const image = vm.find(UserAvatarImage); const image = vm.find(UserAvatarImage);
expect(image.props('imgSrc')).toBe(`${gl.TEST_HOST}/avatar`); expect(image.props('imgSrc')).toBe(`${TEST_HOST}/avatar`);
}); });
}); });
......
import { TEST_HOST } from 'jest/helpers/test_constants';
function getDate(daysMinus) { function getDate(daysMinus) {
const today = new Date(); const today = new Date();
today.setDate(today.getDate() - daysMinus); today.setDate(today.getDate() - daysMinus);
...@@ -15,12 +17,12 @@ export default () => ({ ...@@ -15,12 +17,12 @@ export default () => ({
createdAt: getDate(3), createdAt: getDate(3),
updatedAt: getDate(2), updatedAt: getDate(2),
confidential: false, confidential: false,
webUrl: `${gl.TEST_HOST}/test/issue/1`, webUrl: `${TEST_HOST}/test/issue/1`,
title: 'Test issue', title: 'Test issue',
author: { author: {
avatarUrl: `${gl.TEST_HOST}/avatar`, avatarUrl: `${TEST_HOST}/avatar`,
name: 'Author Name', name: 'Author Name',
username: 'author.username', username: 'author.username',
webUrl: `${gl.TEST_HOST}/author`, webUrl: `${TEST_HOST}/author`,
}, },
}); });
...@@ -6,6 +6,7 @@ import axios from '~/lib/utils/axios_utils'; ...@@ -6,6 +6,7 @@ import axios from '~/lib/utils/axios_utils';
import JobApp from '~/jobs/components/job_app.vue'; import JobApp from '~/jobs/components/job_app.vue';
import createStore from '~/jobs/store'; import createStore from '~/jobs/store';
import job from '../mock_data'; import job from '../mock_data';
import { TEST_HOST } from 'jest/helpers/test_constants';
describe('Job App', () => { describe('Job App', () => {
const localVue = createLocalVue(); const localVue = createLocalVue();
...@@ -18,8 +19,8 @@ describe('Job App', () => { ...@@ -18,8 +19,8 @@ describe('Job App', () => {
let mock; let mock;
const initSettings = { const initSettings = {
endpoint: `${gl.TEST_HOST}jobs/123.json`, endpoint: `${TEST_HOST}jobs/123.json`,
pagePath: `${gl.TEST_HOST}jobs/123`, pagePath: `${TEST_HOST}jobs/123`,
logState: logState:
'eyJvZmZzZXQiOjE3NDUxLCJuX29wZW5fdGFncyI6MCwiZmdfY29sb3IiOm51bGwsImJnX2NvbG9yIjpudWxsLCJzdHlsZV9tYXNrIjowfQ%3D%3D', 'eyJvZmZzZXQiOjE3NDUxLCJuX29wZW5fdGFncyI6MCwiZmdfY29sb3IiOm51bGwsImJnX2NvbG9yIjpudWxsLCJzdHlsZV9tYXNrIjowfQ%3D%3D',
}; };
......
...@@ -330,32 +330,6 @@ describe('common_utils', () => { ...@@ -330,32 +330,6 @@ describe('common_utils', () => {
}); });
}); });
describe('normalizeCRLFHeaders', () => {
const testContext = {};
beforeEach(() => {
testContext.CLRFHeaders =
'a-header: a-value\nAnother-Header: ANOTHER-VALUE\nLaSt-HeAdEr: last-VALUE';
jest.spyOn(String.prototype, 'split');
testContext.normalizeCRLFHeaders = commonUtils.normalizeCRLFHeaders(testContext.CLRFHeaders);
});
it('should split by newline', () => {
expect(String.prototype.split).toHaveBeenCalledWith('\n');
});
it('should split by colon+space for each header', () => {
expect(String.prototype.split.mock.calls.filter(args => args[0] === ': ').length).toBe(3);
});
it('should return a normalized headers object', () => {
expect(testContext.normalizeCRLFHeaders).toEqual({
'A-HEADER': 'a-value',
'ANOTHER-HEADER': 'ANOTHER-VALUE',
'LAST-HEADER': 'last-VALUE',
});
});
});
describe('parseIntPagination', () => { describe('parseIntPagination', () => {
it('should parse to integers all string values and return pagination object', () => { it('should parse to integers all string values and return pagination object', () => {
const pagination = { const pagination = {
...@@ -510,27 +484,6 @@ describe('common_utils', () => { ...@@ -510,27 +484,6 @@ describe('common_utils', () => {
}); });
}); });
describe('setFavicon', () => {
beforeEach(() => {
const favicon = document.createElement('link');
favicon.setAttribute('id', 'favicon');
favicon.setAttribute('href', 'default/favicon');
favicon.setAttribute('data-default-href', 'default/favicon');
document.body.appendChild(favicon);
});
afterEach(() => {
document.body.removeChild(document.getElementById('favicon'));
});
it('should set page favicon to provided favicon', () => {
const faviconPath = '//custom_favicon';
commonUtils.setFavicon(faviconPath);
expect(document.getElementById('favicon').getAttribute('href')).toEqual(faviconPath);
});
});
describe('resetFavicon', () => { describe('resetFavicon', () => {
beforeEach(() => { beforeEach(() => {
const favicon = document.createElement('link'); const favicon = document.createElement('link');
......
...@@ -492,7 +492,7 @@ describe('Actions Notes Store', () => { ...@@ -492,7 +492,7 @@ describe('Actions Notes Store', () => {
it('commits ADD_NEW_NOTE and dispatches updateMergeRequestWidget', done => { it('commits ADD_NEW_NOTE and dispatches updateMergeRequestWidget', done => {
testAction( testAction(
actions.createNewNote, actions.createNewNote,
{ endpoint: `${gl.TEST_HOST}`, data: {} }, { endpoint: `${TEST_HOST}`, data: {} },
store.state, store.state,
[ [
{ {
...@@ -528,7 +528,7 @@ describe('Actions Notes Store', () => { ...@@ -528,7 +528,7 @@ describe('Actions Notes Store', () => {
it('does not commit ADD_NEW_NOTE or dispatch updateMergeRequestWidget', done => { it('does not commit ADD_NEW_NOTE or dispatch updateMergeRequestWidget', done => {
testAction( testAction(
actions.createNewNote, actions.createNewNote,
{ endpoint: `${gl.TEST_HOST}`, data: {} }, { endpoint: `${TEST_HOST}`, data: {} },
store.state, store.state,
[], [],
[], [],
...@@ -551,7 +551,7 @@ describe('Actions Notes Store', () => { ...@@ -551,7 +551,7 @@ describe('Actions Notes Store', () => {
it('commits UPDATE_NOTE and dispatches updateMergeRequestWidget', done => { it('commits UPDATE_NOTE and dispatches updateMergeRequestWidget', done => {
testAction( testAction(
actions.toggleResolveNote, actions.toggleResolveNote,
{ endpoint: `${gl.TEST_HOST}`, isResolved: true, discussion: false }, { endpoint: `${TEST_HOST}`, isResolved: true, discussion: false },
store.state, store.state,
[ [
{ {
...@@ -576,7 +576,7 @@ describe('Actions Notes Store', () => { ...@@ -576,7 +576,7 @@ describe('Actions Notes Store', () => {
it('commits UPDATE_DISCUSSION and dispatches updateMergeRequestWidget', done => { it('commits UPDATE_DISCUSSION and dispatches updateMergeRequestWidget', done => {
testAction( testAction(
actions.toggleResolveNote, actions.toggleResolveNote,
{ endpoint: `${gl.TEST_HOST}`, isResolved: true, discussion: true }, { endpoint: `${TEST_HOST}`, isResolved: true, discussion: true },
store.state, store.state,
[ [
{ {
......
...@@ -3,6 +3,7 @@ import MockAdapter from 'axios-mock-adapter'; ...@@ -3,6 +3,7 @@ import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import Pager from '~/pager'; import Pager from '~/pager';
import { removeParams } from '~/lib/utils/url_utility'; import { removeParams } from '~/lib/utils/url_utility';
import { TEST_HOST } from 'jest/helpers/test_constants';
jest.mock('~/lib/utils/url_utility', () => ({ jest.mock('~/lib/utils/url_utility', () => ({
removeParams: jest.fn().mockName('removeParams'), removeParams: jest.fn().mockName('removeParams'),
...@@ -32,7 +33,7 @@ describe('pager', () => { ...@@ -32,7 +33,7 @@ describe('pager', () => {
}); });
it('should use data-href attribute from list element', () => { it('should use data-href attribute from list element', () => {
const href = `${gl.TEST_HOST}/some_list.json`; const href = `${TEST_HOST}/some_list.json`;
setFixtures(`<div class="content_list" data-href="${href}"></div>`); setFixtures(`<div class="content_list" data-href="${href}"></div>`);
Pager.init(); Pager.init();
...@@ -40,7 +41,7 @@ describe('pager', () => { ...@@ -40,7 +41,7 @@ describe('pager', () => {
}); });
it('should use current url if data-href attribute not provided', () => { it('should use current url if data-href attribute not provided', () => {
const href = `${gl.TEST_HOST}/some_list`; const href = `${TEST_HOST}/some_list`;
removeParams.mockReturnValue(href); removeParams.mockReturnValue(href);
Pager.init(); Pager.init();
...@@ -56,7 +57,7 @@ describe('pager', () => { ...@@ -56,7 +57,7 @@ describe('pager', () => {
it('keeps extra query parameters from url', () => { it('keeps extra query parameters from url', () => {
window.history.replaceState({}, null, '?filter=test&offset=100'); window.history.replaceState({}, null, '?filter=test&offset=100');
const href = `${gl.TEST_HOST}/some_list?filter=test`; const href = `${TEST_HOST}/some_list?filter=test`;
removeParams.mockReturnValue(href); removeParams.mockReturnValue(href);
Pager.init(); Pager.init();
......
...@@ -3,6 +3,7 @@ import { redirectTo } from '~/lib/utils/url_utility'; ...@@ -3,6 +3,7 @@ import { redirectTo } from '~/lib/utils/url_utility';
import mountComponent from 'helpers/vue_mount_component_helper'; import mountComponent from 'helpers/vue_mount_component_helper';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import stopJobsModal from '~/pages/admin/jobs/index/components/stop_jobs_modal.vue'; import stopJobsModal from '~/pages/admin/jobs/index/components/stop_jobs_modal.vue';
import { TEST_HOST } from 'jest/helpers/test_constants';
jest.mock('~/lib/utils/url_utility', () => ({ jest.mock('~/lib/utils/url_utility', () => ({
...jest.requireActual('~/lib/utils/url_utility'), ...jest.requireActual('~/lib/utils/url_utility'),
...@@ -11,7 +12,7 @@ jest.mock('~/lib/utils/url_utility', () => ({ ...@@ -11,7 +12,7 @@ jest.mock('~/lib/utils/url_utility', () => ({
describe('stop_jobs_modal.vue', () => { describe('stop_jobs_modal.vue', () => {
const props = { const props = {
url: `${gl.TEST_HOST}/stop_jobs_modal.vue/stopAll`, url: `${TEST_HOST}/stop_jobs_modal.vue/stopAll`,
}; };
let vm; let vm;
...@@ -26,7 +27,7 @@ describe('stop_jobs_modal.vue', () => { ...@@ -26,7 +27,7 @@ describe('stop_jobs_modal.vue', () => {
describe('onSubmit', () => { describe('onSubmit', () => {
it('stops jobs and redirects to overview page', done => { it('stops jobs and redirects to overview page', done => {
const responseURL = `${gl.TEST_HOST}/stop_jobs_modal.vue/jobs`; const responseURL = `${TEST_HOST}/stop_jobs_modal.vue/jobs`;
jest.spyOn(axios, 'post').mockImplementation(url => { jest.spyOn(axios, 'post').mockImplementation(url => {
expect(url).toBe(props.url); expect(url).toBe(props.url);
return Promise.resolve({ return Promise.resolve({
......
...@@ -3,6 +3,7 @@ import mountComponent from 'helpers/vue_mount_component_helper'; ...@@ -3,6 +3,7 @@ import mountComponent from 'helpers/vue_mount_component_helper';
import promoteLabelModal from '~/pages/projects/labels/components/promote_label_modal.vue'; import promoteLabelModal from '~/pages/projects/labels/components/promote_label_modal.vue';
import eventHub from '~/pages/projects/labels/event_hub'; import eventHub from '~/pages/projects/labels/event_hub';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { TEST_HOST } from 'jest/helpers/test_constants';
describe('Promote label modal', () => { describe('Promote label modal', () => {
let vm; let vm;
...@@ -11,7 +12,7 @@ describe('Promote label modal', () => { ...@@ -11,7 +12,7 @@ describe('Promote label modal', () => {
labelTitle: 'Documentation', labelTitle: 'Documentation',
labelColor: '#5cb85c', labelColor: '#5cb85c',
labelTextColor: '#ffffff', labelTextColor: '#ffffff',
url: `${gl.TEST_HOST}/dummy/promote/labels`, url: `${TEST_HOST}/dummy/promote/labels`,
groupName: 'group', groupName: 'group',
}; };
...@@ -51,7 +52,7 @@ describe('Promote label modal', () => { ...@@ -51,7 +52,7 @@ describe('Promote label modal', () => {
}); });
it('redirects when a label is promoted', done => { it('redirects when a label is promoted', done => {
const responseURL = `${gl.TEST_HOST}/dummy/endpoint`; const responseURL = `${TEST_HOST}/dummy/endpoint`;
jest.spyOn(axios, 'post').mockImplementation(url => { jest.spyOn(axios, 'post').mockImplementation(url => {
expect(url).toBe(labelMockData.url); expect(url).toBe(labelMockData.url);
expect(eventHub.$emit).toHaveBeenCalledWith( expect(eventHub.$emit).toHaveBeenCalledWith(
......
...@@ -4,6 +4,7 @@ import mountComponent from 'helpers/vue_mount_component_helper'; ...@@ -4,6 +4,7 @@ import mountComponent from 'helpers/vue_mount_component_helper';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import deleteMilestoneModal from '~/pages/milestones/shared/components/delete_milestone_modal.vue'; import deleteMilestoneModal from '~/pages/milestones/shared/components/delete_milestone_modal.vue';
import eventHub from '~/pages/milestones/shared/event_hub'; import eventHub from '~/pages/milestones/shared/event_hub';
import { TEST_HOST } from 'jest/helpers/test_constants';
jest.mock('~/lib/utils/url_utility', () => ({ jest.mock('~/lib/utils/url_utility', () => ({
...jest.requireActual('~/lib/utils/url_utility'), ...jest.requireActual('~/lib/utils/url_utility'),
...@@ -17,7 +18,7 @@ describe('delete_milestone_modal.vue', () => { ...@@ -17,7 +18,7 @@ describe('delete_milestone_modal.vue', () => {
mergeRequestCount: 2, mergeRequestCount: 2,
milestoneId: 3, milestoneId: 3,
milestoneTitle: 'my milestone title', milestoneTitle: 'my milestone title',
milestoneUrl: `${gl.TEST_HOST}/delete_milestone_modal.vue/milestone`, milestoneUrl: `${TEST_HOST}/delete_milestone_modal.vue/milestone`,
}; };
let vm; let vm;
...@@ -32,7 +33,7 @@ describe('delete_milestone_modal.vue', () => { ...@@ -32,7 +33,7 @@ describe('delete_milestone_modal.vue', () => {
}); });
it('deletes milestone and redirects to overview page', done => { it('deletes milestone and redirects to overview page', done => {
const responseURL = `${gl.TEST_HOST}/delete_milestone_modal.vue/milestoneOverview`; const responseURL = `${TEST_HOST}/delete_milestone_modal.vue/milestoneOverview`;
jest.spyOn(axios, 'delete').mockImplementation(url => { jest.spyOn(axios, 'delete').mockImplementation(url => {
expect(url).toBe(props.milestoneUrl); expect(url).toBe(props.milestoneUrl);
expect(eventHub.$emit).toHaveBeenCalledWith( expect(eventHub.$emit).toHaveBeenCalledWith(
......
...@@ -3,13 +3,14 @@ import mountComponent from 'helpers/vue_mount_component_helper'; ...@@ -3,13 +3,14 @@ import mountComponent from 'helpers/vue_mount_component_helper';
import promoteMilestoneModal from '~/pages/milestones/shared/components/promote_milestone_modal.vue'; import promoteMilestoneModal from '~/pages/milestones/shared/components/promote_milestone_modal.vue';
import eventHub from '~/pages/milestones/shared/event_hub'; import eventHub from '~/pages/milestones/shared/event_hub';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { TEST_HOST } from 'jest/helpers/test_constants';
describe('Promote milestone modal', () => { describe('Promote milestone modal', () => {
let vm; let vm;
const Component = Vue.extend(promoteMilestoneModal); const Component = Vue.extend(promoteMilestoneModal);
const milestoneMockData = { const milestoneMockData = {
milestoneTitle: 'v1.0', milestoneTitle: 'v1.0',
url: `${gl.TEST_HOST}/dummy/promote/milestones`, url: `${TEST_HOST}/dummy/promote/milestones`,
groupName: 'group', groupName: 'group',
}; };
...@@ -46,7 +47,7 @@ describe('Promote milestone modal', () => { ...@@ -46,7 +47,7 @@ describe('Promote milestone modal', () => {
}); });
it('redirects when a milestone is promoted', done => { it('redirects when a milestone is promoted', done => {
const responseURL = `${gl.TEST_HOST}/dummy/endpoint`; const responseURL = `${TEST_HOST}/dummy/endpoint`;
jest.spyOn(axios, 'post').mockImplementation(url => { jest.spyOn(axios, 'post').mockImplementation(url => {
expect(url).toBe(milestoneMockData.url); expect(url).toBe(milestoneMockData.url);
expect(eventHub.$emit).toHaveBeenCalledWith( expect(eventHub.$emit).toHaveBeenCalledWith(
......
import $ from 'jquery'; import $ from 'jquery';
import projectNew from '~/projects/project_new'; import projectNew from '~/projects/project_new';
import { TEST_HOST } from 'jest/helpers/test_constants';
describe('New Project', () => { describe('New Project', () => {
let $projectImportUrl; let $projectImportUrl;
...@@ -33,7 +34,7 @@ describe('New Project', () => { ...@@ -33,7 +34,7 @@ describe('New Project', () => {
}); });
describe('deriveProjectPathFromUrl', () => { describe('deriveProjectPathFromUrl', () => {
const dummyImportUrl = `${gl.TEST_HOST}/dummy/import/url.git`; const dummyImportUrl = `${TEST_HOST}/dummy/import/url.git`;
beforeEach(() => { beforeEach(() => {
projectNew.bindEvents(); projectNew.bindEvents();
......
...@@ -113,6 +113,7 @@ describe('Search autocomplete dropdown', () => { ...@@ -113,6 +113,7 @@ describe('Search autocomplete dropdown', () => {
window.gon = {}; window.gon = {};
window.gon.current_user_id = userId; window.gon.current_user_id = userId;
window.gon.current_username = userName; window.gon.current_username = userName;
window.gl = window.gl || (window.gl = {});
return (widget = initSearchAutocomplete({ autocompletePath })); return (widget = initSearchAutocomplete({ autocompletePath }));
}); });
......
...@@ -3,6 +3,7 @@ import { mount } from '@vue/test-utils'; ...@@ -3,6 +3,7 @@ import { mount } from '@vue/test-utils';
import { formatDate } from '~/lib/utils/datetime_utility'; import { formatDate } from '~/lib/utils/datetime_utility';
import RelatedIssuableItem from '~/vue_shared/components/issue/related_issuable_item.vue'; import RelatedIssuableItem from '~/vue_shared/components/issue/related_issuable_item.vue';
import { defaultAssignees, defaultMilestone } from './related_issuable_mock_data'; import { defaultAssignees, defaultMilestone } from './related_issuable_mock_data';
import { TEST_HOST } from 'jest/helpers/test_constants';
describe('RelatedIssuableItem', () => { describe('RelatedIssuableItem', () => {
let wrapper; let wrapper;
...@@ -19,7 +20,7 @@ describe('RelatedIssuableItem', () => { ...@@ -19,7 +20,7 @@ describe('RelatedIssuableItem', () => {
idKey: 1, idKey: 1,
displayReference: 'gitlab-org/gitlab-test#1', displayReference: 'gitlab-org/gitlab-test#1',
pathIdSeparator: '#', pathIdSeparator: '#',
path: `${gl.TEST_HOST}/path`, path: `${TEST_HOST}/path`,
title: 'title', title: 'title',
confidential: true, confidential: true,
dueDate: '1990-12-31', dueDate: '1990-12-31',
......
import { TEST_HOST } from 'jest/helpers/test_constants';
export const defaultProps = { export const defaultProps = {
endpoint: '/foo/bar/issues/1/related_issues', endpoint: '/foo/bar/issues/1/related_issues',
currentNamespacePath: 'foo', currentNamespacePath: 'foo',
...@@ -83,8 +85,8 @@ export const defaultAssignees = [ ...@@ -83,8 +85,8 @@ export const defaultAssignees = [
name: 'Administrator', name: 'Administrator',
username: 'root', username: 'root',
state: 'active', state: 'active',
avatar_url: `${gl.TEST_HOST}`, avatar_url: `${TEST_HOST}`,
web_url: `${gl.TEST_HOST}/root`, web_url: `${TEST_HOST}/root`,
status_tooltip_html: null, status_tooltip_html: null,
path: '/root', path: '/root',
}, },
...@@ -93,8 +95,8 @@ export const defaultAssignees = [ ...@@ -93,8 +95,8 @@ export const defaultAssignees = [
name: 'Brooks Beatty', name: 'Brooks Beatty',
username: 'brynn_champlin', username: 'brynn_champlin',
state: 'active', state: 'active',
avatar_url: `${gl.TEST_HOST}`, avatar_url: `${TEST_HOST}`,
web_url: `${gl.TEST_HOST}/brynn_champlin`, web_url: `${TEST_HOST}/brynn_champlin`,
status_tooltip_html: null, status_tooltip_html: null,
path: '/brynn_champlin', path: '/brynn_champlin',
}, },
...@@ -103,8 +105,8 @@ export const defaultAssignees = [ ...@@ -103,8 +105,8 @@ export const defaultAssignees = [
name: 'Bryce Turcotte', name: 'Bryce Turcotte',
username: 'melynda', username: 'melynda',
state: 'active', state: 'active',
avatar_url: `${gl.TEST_HOST}`, avatar_url: `${TEST_HOST}`,
web_url: `${gl.TEST_HOST}/melynda`, web_url: `${TEST_HOST}/melynda`,
status_tooltip_html: null, status_tooltip_html: null,
path: '/melynda', path: '/melynda',
}, },
...@@ -113,8 +115,8 @@ export const defaultAssignees = [ ...@@ -113,8 +115,8 @@ export const defaultAssignees = [
name: 'Conchita Eichmann', name: 'Conchita Eichmann',
username: 'juliana_gulgowski', username: 'juliana_gulgowski',
state: 'active', state: 'active',
avatar_url: `${gl.TEST_HOST}`, avatar_url: `${TEST_HOST}`,
web_url: `${gl.TEST_HOST}/juliana_gulgowski`, web_url: `${TEST_HOST}/juliana_gulgowski`,
status_tooltip_html: null, status_tooltip_html: null,
path: '/juliana_gulgowski', path: '/juliana_gulgowski',
}, },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment