Commit 0c004397 authored by Lukas Eipert's avatar Lukas Eipert

Remove unused common utilities

This removes the unused common utils:

- ajaxGet
- nodeMatchesSelector
- normalizeCRLFHeaders
- setFavicon

This was discovered when searching for IE11 polyfills.
parent 316d85c8
......@@ -53,16 +53,6 @@ export const getCspNonceValue = () => {
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 => {
if (val) {
return val.replace(/\s+$/, '');
......@@ -375,34 +365,6 @@ export const insertText = (target, text) => {
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 way we don't run into production issues when nginx gives us lowercased header keys
......@@ -417,24 +379,6 @@ export const normalizeHeaders = headers => {
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.
*
......@@ -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 = () => {
const faviconEl = document.getElementById('favicon');
......
......@@ -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', () => {
it('should parse to integers all string values and return pagination object', () => {
const pagination = {
......@@ -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', () => {
beforeEach(() => {
const favicon = document.createElement('link');
......
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