Commit 5c23cb94 authored by Lukas Eipert's avatar Lukas Eipert

Run prettier on 44 files - 62 of 73

Part of our prettier migration; changing the arrow-parens style.
parent c35cc92c
...@@ -1887,52 +1887,6 @@ spec/frontend/helpers/vuex_action_helper_spec.js ...@@ -1887,52 +1887,6 @@ spec/frontend/helpers/vuex_action_helper_spec.js
spec/frontend/helpers/wait_for_promises.js spec/frontend/helpers/wait_for_promises.js
spec/frontend/helpers/wait_using_real_timer.js spec/frontend/helpers/wait_using_real_timer.js
## practical-murdock
spec/frontend/issuable_spec.js
spec/frontend/issue_show/components/app_spec.js
spec/frontend/issue_show/components/description_spec.js
spec/frontend/issue_show/components/edit_actions_spec.js
spec/frontend/issue_show/components/fields/description_spec.js
spec/frontend/issue_show/components/form_spec.js
spec/frontend/issue_show/components/header_actions_spec.js
spec/frontend/issue_show/components/incidents/highlight_bar_spec.js
spec/frontend/issue_show/components/pinned_links_spec.js
spec/frontend/issue_show/issue_spec.js
spec/frontend/issue_spec.js
spec/frontend/issues_list/components/issuable_spec.js
spec/frontend/issues_list/components/issuables_list_app_spec.js
spec/frontend/jira_import/components/jira_import_form_spec.js
spec/frontend/jira_import/components/jira_import_progress_spec.js
spec/frontend/jira_import/components/jira_import_setup_spec.js
spec/frontend/jobs/components/artifacts_block_spec.js
spec/frontend/jobs/components/empty_state_spec.js
spec/frontend/jobs/components/erased_block_spec.js
spec/frontend/jobs/components/job_app_spec.js
spec/frontend/jobs/components/job_container_item_spec.js
spec/frontend/jobs/components/job_log_controllers_spec.js
spec/frontend/jobs/components/log/line_spec.js
spec/frontend/jobs/components/manual_variables_form_spec.js
spec/frontend/jobs/components/stuck_block_spec.js
spec/frontend/jobs/components/trigger_block_spec.js
spec/frontend/jobs/store/actions_spec.js
spec/frontend/jobs/store/helpers.js
spec/frontend/lazy_loader_spec.js
spec/frontend/lib/dompurify_spec.js
spec/frontend/lib/utils/ajax_cache_spec.js
spec/frontend/lib/utils/apollo_startup_js_link_spec.js
spec/frontend/lib/utils/common_utils_spec.js
spec/frontend/lib/utils/datetime_range_spec.js
spec/frontend/lib/utils/datetime_utility_spec.js
spec/frontend/lib/utils/dom_utils_spec.js
spec/frontend/lib/utils/forms_spec.js
spec/frontend/lib/utils/highlight_spec.js
spec/frontend/lib/utils/icon_utils_spec.js
spec/frontend/lib/utils/poll_spec.js
spec/frontend/lib/utils/poll_until_complete_spec.js
spec/frontend/lib/utils/text_utility_spec.js
spec/frontend/lib/utils/url_utility_spec.js
spec/frontend/lib/utils/users_cache_spec.js
## determined-shamir ## determined-shamir
spec/frontend/logs/components/environment_logs_spec.js spec/frontend/logs/components/environment_logs_spec.js
spec/frontend/logs/components/log_advanced_filters_spec.js spec/frontend/logs/components/log_advanced_filters_spec.js
......
...@@ -49,7 +49,7 @@ describe('Issuable', () => { ...@@ -49,7 +49,7 @@ describe('Issuable', () => {
mock.restore(); mock.restore();
}); });
it('should send request to reset email token', done => { it('should send request to reset email token', (done) => {
jest.spyOn(axios, 'put'); jest.spyOn(axios, 'put');
document.querySelector('.incoming-email-token-reset').click(); document.querySelector('.incoming-email-token-reset').click();
......
...@@ -398,8 +398,8 @@ describe('Issuable output', () => { ...@@ -398,8 +398,8 @@ describe('Issuable output', () => {
wrapper.vm.poll.makeRequest(); wrapper.vm.poll.makeRequest();
return new Promise(resolve => { return new Promise((resolve) => {
wrapper.vm.$watch('formState.lockedWarningVisible', value => { wrapper.vm.$watch('formState.lockedWarningVisible', (value) => {
if (value) { if (value) {
resolve(); resolve();
} }
......
...@@ -74,7 +74,7 @@ describe('Description component', () => { ...@@ -74,7 +74,7 @@ describe('Description component', () => {
let modal; let modal;
const recaptchaChild = vm.$children.find( const recaptchaChild = vm.$children.find(
// eslint-disable-next-line no-underscore-dangle // eslint-disable-next-line no-underscore-dangle
child => child.$options._componentTag === 'recaptcha-modal', (child) => child.$options._componentTag === 'recaptcha-modal',
); );
recaptchaChild.scriptSrc = '//scriptsrc'; recaptchaChild.scriptSrc = '//scriptsrc';
......
...@@ -6,7 +6,7 @@ import Store from '~/issue_show/stores'; ...@@ -6,7 +6,7 @@ import Store from '~/issue_show/stores';
describe('Edit Actions components', () => { describe('Edit Actions components', () => {
let vm; let vm;
beforeEach(done => { beforeEach((done) => {
const Component = Vue.extend(editActions); const Component = Vue.extend(editActions);
const store = new Store({ const store = new Store({
titleHtml: '', titleHtml: '',
...@@ -34,7 +34,7 @@ describe('Edit Actions components', () => { ...@@ -34,7 +34,7 @@ describe('Edit Actions components', () => {
expect(vm.$el.querySelectorAll('[disabled]').length).toBe(0); expect(vm.$el.querySelectorAll('[disabled]').length).toBe(0);
}); });
it('does not render delete button if canUpdate is false', done => { it('does not render delete button if canUpdate is false', (done) => {
vm.canDestroy = false; vm.canDestroy = false;
Vue.nextTick(() => { Vue.nextTick(() => {
...@@ -44,7 +44,7 @@ describe('Edit Actions components', () => { ...@@ -44,7 +44,7 @@ describe('Edit Actions components', () => {
}); });
}); });
it('disables submit button when title is blank', done => { it('disables submit button when title is blank', (done) => {
vm.formState.title = ''; vm.formState.title = '';
Vue.nextTick(() => { Vue.nextTick(() => {
...@@ -54,7 +54,7 @@ describe('Edit Actions components', () => { ...@@ -54,7 +54,7 @@ describe('Edit Actions components', () => {
}); });
}); });
it('should not show delete button if showDeleteButton is false', done => { it('should not show delete button if showDeleteButton is false', (done) => {
vm.showDeleteButton = false; vm.showDeleteButton = false;
Vue.nextTick(() => { Vue.nextTick(() => {
...@@ -70,7 +70,7 @@ describe('Edit Actions components', () => { ...@@ -70,7 +70,7 @@ describe('Edit Actions components', () => {
expect(eventHub.$emit).toHaveBeenCalledWith('update.issuable'); expect(eventHub.$emit).toHaveBeenCalledWith('update.issuable');
}); });
it('disabled button after clicking save button', done => { it('disabled button after clicking save button', (done) => {
vm.$el.querySelector('.btn-success').click(); vm.$el.querySelector('.btn-success').click();
Vue.nextTick(() => { Vue.nextTick(() => {
...@@ -97,7 +97,7 @@ describe('Edit Actions components', () => { ...@@ -97,7 +97,7 @@ describe('Edit Actions components', () => {
expect(eventHub.$emit).toHaveBeenCalledWith('delete.issuable', { destroy_confirm: true }); expect(eventHub.$emit).toHaveBeenCalledWith('delete.issuable', { destroy_confirm: true });
}); });
it('does no actions when confirm is false', done => { it('does no actions when confirm is false', (done) => {
jest.spyOn(window, 'confirm').mockReturnValue(false); jest.spyOn(window, 'confirm').mockReturnValue(false);
vm.$el.querySelector('.btn-danger').click(); vm.$el.querySelector('.btn-danger').click();
......
...@@ -8,7 +8,7 @@ describe('Description field component', () => { ...@@ -8,7 +8,7 @@ describe('Description field component', () => {
let vm; let vm;
let store; let store;
beforeEach(done => { beforeEach((done) => {
const Component = Vue.extend(descriptionField); const Component = Vue.extend(descriptionField);
const el = document.createElement('div'); const el = document.createElement('div');
store = new Store({ store = new Store({
...@@ -38,7 +38,7 @@ describe('Description field component', () => { ...@@ -38,7 +38,7 @@ describe('Description field component', () => {
expect(vm.$el.querySelector('.md-area textarea').value).toBe('test'); expect(vm.$el.querySelector('.md-area textarea').value).toBe('test');
}); });
it('renders markdown field with a markdown description', done => { it('renders markdown field with a markdown description', (done) => {
store.formState.description = '**test**'; store.formState.description = '**test**';
Vue.nextTick(() => { Vue.nextTick(() => {
......
...@@ -26,7 +26,7 @@ describe('Inline edit form component', () => { ...@@ -26,7 +26,7 @@ describe('Inline edit form component', () => {
vm.$destroy(); vm.$destroy();
}); });
const createComponent = props => { const createComponent = (props) => {
const Component = Vue.extend(formComponent); const Component = Vue.extend(formComponent);
vm = mountComponent(Component, { vm = mountComponent(Component, {
......
...@@ -62,7 +62,7 @@ describe('HeaderActions component', () => { ...@@ -62,7 +62,7 @@ describe('HeaderActions component', () => {
const findToggleIssueStateButton = () => wrapper.find(GlButton); const findToggleIssueStateButton = () => wrapper.find(GlButton);
const findDropdownAt = index => wrapper.findAll(GlDropdown).at(index); const findDropdownAt = (index) => wrapper.findAll(GlDropdown).at(index);
const findMobileDropdownItems = () => findDropdownAt(0).findAll(GlDropdownItem); const findMobileDropdownItems = () => findDropdownAt(0).findAll(GlDropdownItem);
...@@ -70,7 +70,7 @@ describe('HeaderActions component', () => { ...@@ -70,7 +70,7 @@ describe('HeaderActions component', () => {
const findModal = () => wrapper.find(GlModal); const findModal = () => wrapper.find(GlModal);
const findModalLinkAt = index => findModal().findAll(GlLink).at(index); const findModalLinkAt = (index) => findModal().findAll(GlLink).at(index);
const mountComponent = ({ const mountComponent = ({
props = {}, props = {},
...@@ -205,7 +205,7 @@ describe('HeaderActions component', () => { ...@@ -205,7 +205,7 @@ describe('HeaderActions component', () => {
it(`${isItemVisible ? 'shows' : 'hides'} "${itemText}" item`, () => { it(`${isItemVisible ? 'shows' : 'hides'} "${itemText}" item`, () => {
expect( expect(
findDropdownItems() findDropdownItems()
.filter(item => item.text() === itemText) .filter((item) => item.text() === itemText)
.exists(), .exists(),
).toBe(isItemVisible); ).toBe(isItemVisible);
}); });
......
...@@ -17,7 +17,7 @@ describe('Highlight Bar', () => { ...@@ -17,7 +17,7 @@ describe('Highlight Bar', () => {
title: 'Alert 1', title: 'Alert 1',
}; };
const mountComponent = options => { const mountComponent = (options) => {
wrapper = shallowMount( wrapper = shallowMount(
HighlightBar, HighlightBar,
merge( merge(
......
...@@ -11,7 +11,7 @@ describe('PinnedLinks', () => { ...@@ -11,7 +11,7 @@ describe('PinnedLinks', () => {
const findButtons = () => wrapper.findAll(GlButton); const findButtons = () => wrapper.findAll(GlButton);
const createComponent = props => { const createComponent = (props) => {
wrapper = shallowMount(PinnedLinks, { wrapper = shallowMount(PinnedLinks, {
propsData: { propsData: {
zoomMeetingUrl: '', zoomMeetingUrl: '',
......
...@@ -14,7 +14,7 @@ useMockIntersectionObserver(); ...@@ -14,7 +14,7 @@ useMockIntersectionObserver();
jest.mock('~/lib/utils/poll'); jest.mock('~/lib/utils/poll');
const setupHTML = initialData => { const setupHTML = (initialData) => {
document.body.innerHTML = `<div id="js-issuable-app"></div>`; document.body.innerHTML = `<div id="js-issuable-app"></div>`;
document.getElementById('js-issuable-app').dataset.initial = JSON.stringify(initialData); document.getElementById('js-issuable-app').dataset.initial = JSON.stringify(initialData);
}; };
......
...@@ -41,7 +41,7 @@ describe('Issue', () => { ...@@ -41,7 +41,7 @@ describe('Issue', () => {
expect($boxOpen).toHaveText('Open'); expect($boxOpen).toHaveText('Open');
} }
[true, false].forEach(isIssueInitiallyOpen => { [true, false].forEach((isIssueInitiallyOpen) => {
describe(`with ${isIssueInitiallyOpen ? 'open' : 'closed'} issue`, () => { describe(`with ${isIssueInitiallyOpen ? 'open' : 'closed'} issue`, () => {
const action = isIssueInitiallyOpen ? 'close' : 'reopen'; const action = isIssueInitiallyOpen ? 'close' : 'reopen';
let mock; let mock;
......
...@@ -72,9 +72,9 @@ describe('Issuable component', () => { ...@@ -72,9 +72,9 @@ describe('Issuable component', () => {
window.Date = DateOrig; window.Date = DateOrig;
}); });
const checkExists = findFn => () => findFn().exists(); const checkExists = (findFn) => () => findFn().exists();
const hasIcon = (iconName, iconWrapper = wrapper) => const hasIcon = (iconName, iconWrapper = wrapper) =>
iconWrapper.findAll(GlIcon).wrappers.some(icon => icon.props('name') === iconName); iconWrapper.findAll(GlIcon).wrappers.some((icon) => icon.props('name') === iconName);
const hasConfidentialIcon = () => hasIcon('eye-slash'); const hasConfidentialIcon = () => hasIcon('eye-slash');
const findTaskStatus = () => wrapper.find('.task-status'); const findTaskStatus = () => wrapper.find('.task-status');
const findOpenedAgoContainer = () => wrapper.find('[data-testid="openedByMessage"]'); const findOpenedAgoContainer = () => wrapper.find('[data-testid="openedByMessage"]');
...@@ -91,8 +91,8 @@ describe('Issuable component', () => { ...@@ -91,8 +91,8 @@ describe('Issuable component', () => {
const findDownvotes = () => wrapper.find('[data-testid="downvotes"]'); const findDownvotes = () => wrapper.find('[data-testid="downvotes"]');
const findNotes = () => wrapper.find('[data-testid="notes-count"]'); const findNotes = () => wrapper.find('[data-testid="notes-count"]');
const findBulkCheckbox = () => wrapper.find('input.selected-issuable'); const findBulkCheckbox = () => wrapper.find('input.selected-issuable');
const findScopedLabels = () => findLabels().filter(w => isScopedLabel({ title: w.text() })); const findScopedLabels = () => findLabels().filter((w) => isScopedLabel({ title: w.text() }));
const findUnscopedLabels = () => findLabels().filter(w => !isScopedLabel({ title: w.text() })); const findUnscopedLabels = () => findLabels().filter((w) => !isScopedLabel({ title: w.text() }));
const findIssuableTitle = () => wrapper.find('[data-testid="issuable-title"]'); const findIssuableTitle = () => wrapper.find('[data-testid="issuable-title"]');
const findIssuableStatus = () => wrapper.find('[data-testid="issuable-status"]'); const findIssuableStatus = () => wrapper.find('[data-testid="issuable-status"]');
const containsJiraLogo = () => wrapper.find('[data-testid="jira-logo"]').exists(); const containsJiraLogo = () => wrapper.find('[data-testid="jira-logo"]').exists();
...@@ -336,13 +336,13 @@ describe('Issuable component', () => { ...@@ -336,13 +336,13 @@ describe('Issuable component', () => {
it('renders labels', () => { it('renders labels', () => {
factory({ issuable }); factory({ issuable });
const labels = findLabels().wrappers.map(label => ({ const labels = findLabels().wrappers.map((label) => ({
href: label.props('target'), href: label.props('target'),
text: label.text(), text: label.text(),
tooltip: label.attributes('description'), tooltip: label.attributes('description'),
})); }));
const expected = testLabels.map(label => ({ const expected = testLabels.map((label) => ({
href: mergeUrlParams({ 'label_name[]': label.name }, TEST_BASE_URL), href: mergeUrlParams({ 'label_name[]': label.name }, TEST_BASE_URL),
text: label.name, text: label.name,
tooltip: label.description, tooltip: label.description,
...@@ -363,13 +363,13 @@ describe('Issuable component', () => { ...@@ -363,13 +363,13 @@ describe('Issuable component', () => {
it('renders labels', () => { it('renders labels', () => {
factory({ issuable }); factory({ issuable });
const labels = findLabels().wrappers.map(label => ({ const labels = findLabels().wrappers.map((label) => ({
href: label.props('target'), href: label.props('target'),
text: label.text(), text: label.text(),
tooltip: label.attributes('description'), tooltip: label.attributes('description'),
})); }));
const expected = testLabels.map(label => ({ const expected = testLabels.map((label) => ({
href: mergeUrlParams({ 'labels[]': label.name }, TEST_BASE_URL), href: mergeUrlParams({ 'labels[]': label.name }, TEST_BASE_URL),
text: label.name, text: label.name,
tooltip: label.description, tooltip: label.description,
......
...@@ -27,7 +27,7 @@ const TEST_ENDPOINT = '/issues'; ...@@ -27,7 +27,7 @@ const TEST_ENDPOINT = '/issues';
const TEST_CREATE_ISSUES_PATH = '/createIssue'; const TEST_CREATE_ISSUES_PATH = '/createIssue';
const TEST_SVG_PATH = '/emptySvg'; const TEST_SVG_PATH = '/emptySvg';
const setUrl = query => { const setUrl = (query) => {
window.location.href = `${TEST_LOCATION}${query}`; window.location.href = `${TEST_LOCATION}${query}`;
window.location.search = query; window.location.search = query;
}; };
...@@ -45,10 +45,10 @@ describe('Issuables list component', () => { ...@@ -45,10 +45,10 @@ describe('Issuables list component', () => {
let wrapper; let wrapper;
let apiSpy; let apiSpy;
const setupApiMock = cb => { const setupApiMock = (cb) => {
apiSpy = jest.fn(cb); apiSpy = jest.fn(cb);
mockAxios.onGet(TEST_ENDPOINT).reply(cfg => apiSpy(cfg)); mockAxios.onGet(TEST_ENDPOINT).reply((cfg) => apiSpy(cfg));
}; };
const factory = (props = { sortKey: 'priority' }) => { const factory = (props = { sortKey: 'priority' }) => {
......
...@@ -37,7 +37,7 @@ describe('JiraImportForm', () => { ...@@ -37,7 +37,7 @@ describe('JiraImportForm', () => {
const getUserDropdown = () => getTable().find(GlDropdown); const getUserDropdown = () => getTable().find(GlDropdown);
const getHeader = name => getByRole(wrapper.element, 'columnheader', { name }); const getHeader = (name) => getByRole(wrapper.element, 'columnheader', { name });
const findLoadMoreUsersButton = () => wrapper.find('[data-testid="load-more-users-button"]'); const findLoadMoreUsersButton = () => wrapper.find('[data-testid="load-more-users-button"]');
......
...@@ -8,7 +8,7 @@ describe('JiraImportProgress', () => { ...@@ -8,7 +8,7 @@ describe('JiraImportProgress', () => {
const importProject = 'JIRAPROJECT'; const importProject = 'JIRAPROJECT';
const getGlEmptyStateProp = attribute => wrapper.find(GlEmptyState).props(attribute); const getGlEmptyStateProp = (attribute) => wrapper.find(GlEmptyState).props(attribute);
const getParagraphText = () => wrapper.find('p').text(); const getParagraphText = () => wrapper.find('p').text();
......
...@@ -6,7 +6,7 @@ import { illustration, jiraIntegrationPath } from '../mock_data'; ...@@ -6,7 +6,7 @@ import { illustration, jiraIntegrationPath } from '../mock_data';
describe('JiraImportSetup', () => { describe('JiraImportSetup', () => {
let wrapper; let wrapper;
const getGlEmptyStateProp = attribute => wrapper.find(GlEmptyState).props(attribute); const getGlEmptyStateProp = (attribute) => wrapper.find(GlEmptyState).props(attribute);
beforeEach(() => { beforeEach(() => {
wrapper = shallowMount(JiraImportSetup, { wrapper = shallowMount(JiraImportSetup, {
......
...@@ -6,7 +6,7 @@ import { trimText } from '../../helpers/text_helper'; ...@@ -6,7 +6,7 @@ import { trimText } from '../../helpers/text_helper';
describe('Artifacts block', () => { describe('Artifacts block', () => {
let wrapper; let wrapper;
const createWrapper = propsData => const createWrapper = (propsData) =>
mount(ArtifactsBlock, { mount(ArtifactsBlock, {
propsData: { propsData: {
helpUrl: 'help-url', helpUrl: 'help-url',
......
...@@ -12,7 +12,7 @@ describe('Empty State', () => { ...@@ -12,7 +12,7 @@ describe('Empty State', () => {
variablesSettingsUrl: '', variablesSettingsUrl: '',
}; };
const createWrapper = props => { const createWrapper = (props) => {
wrapper = mount(EmptyState, { wrapper = mount(EmptyState, {
propsData: { propsData: {
...defaultProps, ...defaultProps,
......
...@@ -10,7 +10,7 @@ describe('Erased block', () => { ...@@ -10,7 +10,7 @@ describe('Erased block', () => {
const timeago = getTimeago(); const timeago = getTimeago();
const formattedDate = timeago.format(erasedAt); const formattedDate = timeago.format(erasedAt);
const createComponent = props => { const createComponent = (props) => {
wrapper = mount(ErasedBlock, { wrapper = mount(ErasedBlock, {
propsData: props, propsData: props,
}); });
......
...@@ -375,7 +375,7 @@ describe('Job App', () => { ...@@ -375,7 +375,7 @@ describe('Job App', () => {
}); });
describe('sidebar', () => { describe('sidebar', () => {
it('has no blank blocks', done => { it('has no blank blocks', (done) => {
setupAndMount({ setupAndMount({
jobData: { jobData: {
duration: null, duration: null,
...@@ -392,7 +392,7 @@ describe('Job App', () => { ...@@ -392,7 +392,7 @@ describe('Job App', () => {
const blocks = wrapper.findAll('.blocks-container > *').wrappers; const blocks = wrapper.findAll('.blocks-container > *').wrappers;
expect(blocks.length).toBeGreaterThan(0); expect(blocks.length).toBeGreaterThan(0);
blocks.forEach(block => { blocks.forEach((block) => {
expect(block.text().trim()).not.toBe(''); expect(block.text().trim()).not.toBe('');
}); });
}) })
......
...@@ -82,7 +82,7 @@ describe('JobContainerItem', () => { ...@@ -82,7 +82,7 @@ describe('JobContainerItem', () => {
); );
}); });
it('displays remaining time in tooltip', done => { it('displays remaining time in tooltip', (done) => {
vm = mountComponent(Component, { vm = mountComponent(Component, {
job: delayedJobFixture, job: delayedJobFixture,
isActive: false, isActive: false,
......
...@@ -21,7 +21,7 @@ describe('Job log controllers', () => { ...@@ -21,7 +21,7 @@ describe('Job log controllers', () => {
isTraceSizeVisible: true, isTraceSizeVisible: true,
}; };
const createWrapper = props => { const createWrapper = (props) => {
wrapper = mount(JobLogControllers, { wrapper = mount(JobLogControllers, {
propsData: { propsData: {
...defaultProps, ...defaultProps,
......
...@@ -34,7 +34,7 @@ describe('Job Log Line', () => { ...@@ -34,7 +34,7 @@ describe('Job Log Line', () => {
const findLine = () => wrapper.find('span'); const findLine = () => wrapper.find('span');
const findLink = () => findLine().find('a'); const findLink = () => findLine().find('a');
const findLinks = () => findLine().findAll('a'); const findLinks = () => findLine().findAll('a');
const findLinkAttributeByIndex = i => findLinks().at(i).attributes(); const findLinkAttributeByIndex = (i) => findLinks().at(i).attributes();
beforeEach(() => { beforeEach(() => {
data = mockProps(); data = mockProps();
......
...@@ -27,7 +27,7 @@ describe('Manual Variables Form', () => { ...@@ -27,7 +27,7 @@ describe('Manual Variables Form', () => {
factory(requiredProps); factory(requiredProps);
}); });
afterEach(done => { afterEach((done) => {
// The component has a `nextTick` callback after some events so we need // The component has a `nextTick` callback after some events so we need
// to wait for those to finish before destroying. // to wait for those to finish before destroying.
setImmediate(() => { setImmediate(() => {
...@@ -54,7 +54,7 @@ describe('Manual Variables Form', () => { ...@@ -54,7 +54,7 @@ describe('Manual Variables Form', () => {
}); });
describe('when adding a new variable', () => { describe('when adding a new variable', () => {
it('creates a new variable when user types a new key and resets the form', done => { it('creates a new variable when user types a new key and resets the form', (done) => {
wrapper.vm wrapper.vm
.$nextTick() .$nextTick()
.then(() => wrapper.find({ ref: 'inputKey' }).setValue('new key')) .then(() => wrapper.find({ ref: 'inputKey' }).setValue('new key'))
...@@ -67,7 +67,7 @@ describe('Manual Variables Form', () => { ...@@ -67,7 +67,7 @@ describe('Manual Variables Form', () => {
.catch(done.fail); .catch(done.fail);
}); });
it('creates a new variable when user types a new value and resets the form', done => { it('creates a new variable when user types a new value and resets the form', (done) => {
wrapper.vm wrapper.vm
.$nextTick() .$nextTick()
.then(() => wrapper.find({ ref: 'inputSecretValue' }).setValue('new value')) .then(() => wrapper.find({ ref: 'inputSecretValue' }).setValue('new value'))
...@@ -82,7 +82,7 @@ describe('Manual Variables Form', () => { ...@@ -82,7 +82,7 @@ describe('Manual Variables Form', () => {
}); });
describe('when deleting a variable', () => { describe('when deleting a variable', () => {
beforeEach(done => { beforeEach((done) => {
wrapper.vm.variables = [ wrapper.vm.variables = [
{ {
key: 'new key', key: 'new key',
......
...@@ -12,7 +12,7 @@ describe('Stuck Block Job component', () => { ...@@ -12,7 +12,7 @@ describe('Stuck Block Job component', () => {
} }
}); });
const createWrapper = props => { const createWrapper = (props) => {
wrapper = shallowMount(StuckBlock, { wrapper = shallowMount(StuckBlock, {
propsData: { propsData: {
...props, ...props,
......
...@@ -32,7 +32,7 @@ describe('Trigger block', () => { ...@@ -32,7 +32,7 @@ describe('Trigger block', () => {
describe('with variables', () => { describe('with variables', () => {
describe('hide/reveal variables', () => { describe('hide/reveal variables', () => {
it('should toggle variables on click', done => { it('should toggle variables on click', (done) => {
vm = mountComponent(Component, { vm = mountComponent(Component, {
trigger: { trigger: {
short_token: 'bd7e', short_token: 'bd7e',
......
...@@ -40,7 +40,7 @@ describe('Job State actions', () => { ...@@ -40,7 +40,7 @@ describe('Job State actions', () => {
}); });
describe('setJobEndpoint', () => { describe('setJobEndpoint', () => {
it('should commit SET_JOB_ENDPOINT mutation', done => { it('should commit SET_JOB_ENDPOINT mutation', (done) => {
testAction( testAction(
setJobEndpoint, setJobEndpoint,
'job/872324.json', 'job/872324.json',
...@@ -53,7 +53,7 @@ describe('Job State actions', () => { ...@@ -53,7 +53,7 @@ describe('Job State actions', () => {
}); });
describe('setTraceOptions', () => { describe('setTraceOptions', () => {
it('should commit SET_TRACE_OPTIONS mutation', done => { it('should commit SET_TRACE_OPTIONS mutation', (done) => {
testAction( testAction(
setTraceOptions, setTraceOptions,
{ pagePath: 'job/872324/trace.json' }, { pagePath: 'job/872324/trace.json' },
...@@ -66,26 +66,26 @@ describe('Job State actions', () => { ...@@ -66,26 +66,26 @@ describe('Job State actions', () => {
}); });
describe('hideSidebar', () => { describe('hideSidebar', () => {
it('should commit HIDE_SIDEBAR mutation', done => { it('should commit HIDE_SIDEBAR mutation', (done) => {
testAction(hideSidebar, null, mockedState, [{ type: types.HIDE_SIDEBAR }], [], done); testAction(hideSidebar, null, mockedState, [{ type: types.HIDE_SIDEBAR }], [], done);
}); });
}); });
describe('showSidebar', () => { describe('showSidebar', () => {
it('should commit HIDE_SIDEBAR mutation', done => { it('should commit HIDE_SIDEBAR mutation', (done) => {
testAction(showSidebar, null, mockedState, [{ type: types.SHOW_SIDEBAR }], [], done); testAction(showSidebar, null, mockedState, [{ type: types.SHOW_SIDEBAR }], [], done);
}); });
}); });
describe('toggleSidebar', () => { describe('toggleSidebar', () => {
describe('when isSidebarOpen is true', () => { describe('when isSidebarOpen is true', () => {
it('should dispatch hideSidebar', done => { it('should dispatch hideSidebar', (done) => {
testAction(toggleSidebar, null, mockedState, [], [{ type: 'hideSidebar' }], done); testAction(toggleSidebar, null, mockedState, [], [{ type: 'hideSidebar' }], done);
}); });
}); });
describe('when isSidebarOpen is false', () => { describe('when isSidebarOpen is false', () => {
it('should dispatch showSidebar', done => { it('should dispatch showSidebar', (done) => {
mockedState.isSidebarOpen = false; mockedState.isSidebarOpen = false;
testAction(toggleSidebar, null, mockedState, [], [{ type: 'showSidebar' }], done); testAction(toggleSidebar, null, mockedState, [], [{ type: 'showSidebar' }], done);
...@@ -94,7 +94,7 @@ describe('Job State actions', () => { ...@@ -94,7 +94,7 @@ describe('Job State actions', () => {
}); });
describe('requestJob', () => { describe('requestJob', () => {
it('should commit REQUEST_JOB mutation', done => { it('should commit REQUEST_JOB mutation', (done) => {
testAction(requestJob, null, mockedState, [{ type: types.REQUEST_JOB }], [], done); testAction(requestJob, null, mockedState, [{ type: types.REQUEST_JOB }], [], done);
}); });
}); });
...@@ -114,7 +114,7 @@ describe('Job State actions', () => { ...@@ -114,7 +114,7 @@ describe('Job State actions', () => {
}); });
describe('success', () => { describe('success', () => {
it('dispatches requestJob and receiveJobSuccess ', done => { it('dispatches requestJob and receiveJobSuccess ', (done) => {
mock.onGet(`${TEST_HOST}/endpoint.json`).replyOnce(200, { id: 121212, name: 'karma' }); mock.onGet(`${TEST_HOST}/endpoint.json`).replyOnce(200, { id: 121212, name: 'karma' });
testAction( testAction(
...@@ -141,7 +141,7 @@ describe('Job State actions', () => { ...@@ -141,7 +141,7 @@ describe('Job State actions', () => {
mock.onGet(`${TEST_HOST}/endpoint.json`).reply(500); mock.onGet(`${TEST_HOST}/endpoint.json`).reply(500);
}); });
it('dispatches requestJob and receiveJobError ', done => { it('dispatches requestJob and receiveJobError ', (done) => {
testAction( testAction(
fetchJob, fetchJob,
null, null,
...@@ -160,7 +160,7 @@ describe('Job State actions', () => { ...@@ -160,7 +160,7 @@ describe('Job State actions', () => {
}); });
}); });
it('fetchTrace is called only if the job has started or has a trace', done => { it('fetchTrace is called only if the job has started or has a trace', (done) => {
mock.onGet(`${TEST_HOST}/endpoint.json`).replyOnce(200, { id: 121212, name: 'karma' }); mock.onGet(`${TEST_HOST}/endpoint.json`).replyOnce(200, { id: 121212, name: 'karma' });
mockedState.job.started = true; mockedState.job.started = true;
...@@ -188,7 +188,7 @@ describe('Job State actions', () => { ...@@ -188,7 +188,7 @@ describe('Job State actions', () => {
}); });
describe('receiveJobSuccess', () => { describe('receiveJobSuccess', () => {
it('should commit RECEIVE_JOB_SUCCESS mutation', done => { it('should commit RECEIVE_JOB_SUCCESS mutation', (done) => {
testAction( testAction(
receiveJobSuccess, receiveJobSuccess,
{ id: 121232132 }, { id: 121232132 },
...@@ -201,25 +201,25 @@ describe('Job State actions', () => { ...@@ -201,25 +201,25 @@ describe('Job State actions', () => {
}); });
describe('receiveJobError', () => { describe('receiveJobError', () => {
it('should commit RECEIVE_JOB_ERROR mutation', done => { it('should commit RECEIVE_JOB_ERROR mutation', (done) => {
testAction(receiveJobError, null, mockedState, [{ type: types.RECEIVE_JOB_ERROR }], [], done); testAction(receiveJobError, null, mockedState, [{ type: types.RECEIVE_JOB_ERROR }], [], done);
}); });
}); });
describe('scrollTop', () => { describe('scrollTop', () => {
it('should dispatch toggleScrollButtons action', done => { it('should dispatch toggleScrollButtons action', (done) => {
testAction(scrollTop, null, mockedState, [], [{ type: 'toggleScrollButtons' }], done); testAction(scrollTop, null, mockedState, [], [{ type: 'toggleScrollButtons' }], done);
}); });
}); });
describe('scrollBottom', () => { describe('scrollBottom', () => {
it('should dispatch toggleScrollButtons action', done => { it('should dispatch toggleScrollButtons action', (done) => {
testAction(scrollBottom, null, mockedState, [], [{ type: 'toggleScrollButtons' }], done); testAction(scrollBottom, null, mockedState, [], [{ type: 'toggleScrollButtons' }], done);
}); });
}); });
describe('requestTrace', () => { describe('requestTrace', () => {
it('should commit REQUEST_TRACE mutation', done => { it('should commit REQUEST_TRACE mutation', (done) => {
testAction(requestTrace, null, mockedState, [{ type: types.REQUEST_TRACE }], [], done); testAction(requestTrace, null, mockedState, [{ type: types.REQUEST_TRACE }], [], done);
}); });
}); });
...@@ -239,7 +239,7 @@ describe('Job State actions', () => { ...@@ -239,7 +239,7 @@ describe('Job State actions', () => {
}); });
describe('success', () => { describe('success', () => {
it('dispatches requestTrace, receiveTraceSuccess and stopPollingTrace when job is complete', done => { it('dispatches requestTrace, receiveTraceSuccess and stopPollingTrace when job is complete', (done) => {
mock.onGet(`${TEST_HOST}/endpoint/trace.json`).replyOnce(200, { mock.onGet(`${TEST_HOST}/endpoint/trace.json`).replyOnce(200, {
html: 'I, [2018-08-17T22:57:45.707325 #1841] INFO -- :', html: 'I, [2018-08-17T22:57:45.707325 #1841] INFO -- :',
complete: true, complete: true,
...@@ -282,7 +282,7 @@ describe('Job State actions', () => { ...@@ -282,7 +282,7 @@ describe('Job State actions', () => {
mock.onGet(`${TEST_HOST}/endpoint/trace.json`).replyOnce(200, tracePayload); mock.onGet(`${TEST_HOST}/endpoint/trace.json`).replyOnce(200, tracePayload);
}); });
it('dispatches startPollingTrace', done => { it('dispatches startPollingTrace', (done) => {
testAction( testAction(
fetchTrace, fetchTrace,
null, null,
...@@ -297,7 +297,7 @@ describe('Job State actions', () => { ...@@ -297,7 +297,7 @@ describe('Job State actions', () => {
); );
}); });
it('does not dispatch startPollingTrace when timeout is non-empty', done => { it('does not dispatch startPollingTrace when timeout is non-empty', (done) => {
mockedState.traceTimeout = 1; mockedState.traceTimeout = 1;
testAction( testAction(
...@@ -320,7 +320,7 @@ describe('Job State actions', () => { ...@@ -320,7 +320,7 @@ describe('Job State actions', () => {
mock.onGet(`${TEST_HOST}/endpoint/trace.json`).reply(500); mock.onGet(`${TEST_HOST}/endpoint/trace.json`).reply(500);
}); });
it('dispatches requestTrace and receiveTraceError ', done => { it('dispatches requestTrace and receiveTraceError ', (done) => {
testAction( testAction(
fetchTrace, fetchTrace,
null, null,
...@@ -385,7 +385,7 @@ describe('Job State actions', () => { ...@@ -385,7 +385,7 @@ describe('Job State actions', () => {
window.clearTimeout = origTimeout; window.clearTimeout = origTimeout;
}); });
it('should commit STOP_POLLING_TRACE mutation ', done => { it('should commit STOP_POLLING_TRACE mutation ', (done) => {
const traceTimeout = 7; const traceTimeout = 7;
testAction( testAction(
...@@ -404,7 +404,7 @@ describe('Job State actions', () => { ...@@ -404,7 +404,7 @@ describe('Job State actions', () => {
}); });
describe('receiveTraceSuccess', () => { describe('receiveTraceSuccess', () => {
it('should commit RECEIVE_TRACE_SUCCESS mutation ', done => { it('should commit RECEIVE_TRACE_SUCCESS mutation ', (done) => {
testAction( testAction(
receiveTraceSuccess, receiveTraceSuccess,
'hello world', 'hello world',
...@@ -417,13 +417,13 @@ describe('Job State actions', () => { ...@@ -417,13 +417,13 @@ describe('Job State actions', () => {
}); });
describe('receiveTraceError', () => { describe('receiveTraceError', () => {
it('should commit stop polling trace', done => { it('should commit stop polling trace', (done) => {
testAction(receiveTraceError, null, mockedState, [], [{ type: 'stopPollingTrace' }], done); testAction(receiveTraceError, null, mockedState, [], [{ type: 'stopPollingTrace' }], done);
}); });
}); });
describe('toggleCollapsibleLine', () => { describe('toggleCollapsibleLine', () => {
it('should commit TOGGLE_COLLAPSIBLE_LINE mutation ', done => { it('should commit TOGGLE_COLLAPSIBLE_LINE mutation ', (done) => {
testAction( testAction(
toggleCollapsibleLine, toggleCollapsibleLine,
{ isClosed: true }, { isClosed: true },
...@@ -436,7 +436,7 @@ describe('Job State actions', () => { ...@@ -436,7 +436,7 @@ describe('Job State actions', () => {
}); });
describe('requestJobsForStage', () => { describe('requestJobsForStage', () => {
it('should commit REQUEST_JOBS_FOR_STAGE mutation ', done => { it('should commit REQUEST_JOBS_FOR_STAGE mutation ', (done) => {
testAction( testAction(
requestJobsForStage, requestJobsForStage,
{ name: 'deploy' }, { name: 'deploy' },
...@@ -460,7 +460,7 @@ describe('Job State actions', () => { ...@@ -460,7 +460,7 @@ describe('Job State actions', () => {
}); });
describe('success', () => { describe('success', () => {
it('dispatches requestJobsForStage and receiveJobsForStageSuccess ', done => { it('dispatches requestJobsForStage and receiveJobsForStageSuccess ', (done) => {
mock mock
.onGet(`${TEST_HOST}/jobs.json`) .onGet(`${TEST_HOST}/jobs.json`)
.replyOnce(200, { latest_statuses: [{ id: 121212, name: 'build' }], retried: [] }); .replyOnce(200, { latest_statuses: [{ id: 121212, name: 'build' }], retried: [] });
...@@ -490,7 +490,7 @@ describe('Job State actions', () => { ...@@ -490,7 +490,7 @@ describe('Job State actions', () => {
mock.onGet(`${TEST_HOST}/jobs.json`).reply(500); mock.onGet(`${TEST_HOST}/jobs.json`).reply(500);
}); });
it('dispatches requestJobsForStage and receiveJobsForStageError', done => { it('dispatches requestJobsForStage and receiveJobsForStageError', (done) => {
testAction( testAction(
fetchJobsForStage, fetchJobsForStage,
{ dropdown_path: `${TEST_HOST}/jobs.json` }, { dropdown_path: `${TEST_HOST}/jobs.json` },
...@@ -512,7 +512,7 @@ describe('Job State actions', () => { ...@@ -512,7 +512,7 @@ describe('Job State actions', () => {
}); });
describe('receiveJobsForStageSuccess', () => { describe('receiveJobsForStageSuccess', () => {
it('should commit RECEIVE_JOBS_FOR_STAGE_SUCCESS mutation ', done => { it('should commit RECEIVE_JOBS_FOR_STAGE_SUCCESS mutation ', (done) => {
testAction( testAction(
receiveJobsForStageSuccess, receiveJobsForStageSuccess,
[{ id: 121212, name: 'karma' }], [{ id: 121212, name: 'karma' }],
...@@ -525,7 +525,7 @@ describe('Job State actions', () => { ...@@ -525,7 +525,7 @@ describe('Job State actions', () => {
}); });
describe('receiveJobsForStageError', () => { describe('receiveJobsForStageError', () => {
it('should commit RECEIVE_JOBS_FOR_STAGE_ERROR mutation ', done => { it('should commit RECEIVE_JOBS_FOR_STAGE_ERROR mutation ', (done) => {
testAction( testAction(
receiveJobsForStageError, receiveJobsForStageError,
null, null,
...@@ -548,7 +548,7 @@ describe('Job State actions', () => { ...@@ -548,7 +548,7 @@ describe('Job State actions', () => {
mock.restore(); mock.restore();
}); });
it('should dispatch fetchTrace', done => { it('should dispatch fetchTrace', (done) => {
const playManualJobEndpoint = `${TEST_HOST}/manual-job/jobs/1000/play`; const playManualJobEndpoint = `${TEST_HOST}/manual-job/jobs/1000/play`;
mock.onPost(playManualJobEndpoint).reply(200); mock.onPost(playManualJobEndpoint).reply(200);
......
import state from '~/jobs/store/state'; import state from '~/jobs/store/state';
export const resetStore = store => { export const resetStore = (store) => {
store.replaceState(state()); store.replaceState(state());
}; };
...@@ -4,7 +4,7 @@ import { useMockMutationObserver, useMockIntersectionObserver } from 'helpers/mo ...@@ -4,7 +4,7 @@ import { useMockMutationObserver, useMockIntersectionObserver } from 'helpers/mo
import LazyLoader from '~/lazy_loader'; import LazyLoader from '~/lazy_loader';
import waitForPromises from './helpers/wait_for_promises'; import waitForPromises from './helpers/wait_for_promises';
const execImmediately = callback => { const execImmediately = (callback) => {
callback(); callback();
}; };
...@@ -20,7 +20,7 @@ describe('LazyLoader', () => { ...@@ -20,7 +20,7 @@ describe('LazyLoader', () => {
triggerMutation(document.body, { options: { childList: true, subtree: true } }); triggerMutation(document.body, { options: { childList: true, subtree: true } });
}; };
const triggerIntersectionWithRatio = img => { const triggerIntersectionWithRatio = (img) => {
triggerIntersection(img, { entry: { intersectionRatio: 0.1 } }); triggerIntersection(img, { entry: { intersectionRatio: 0.1 } });
}; };
......
...@@ -15,8 +15,8 @@ const absoluteGon = { ...@@ -15,8 +15,8 @@ const absoluteGon = {
const expectedSanitized = '<svg><use></use></svg>'; const expectedSanitized = '<svg><use></use></svg>';
const safeUrls = { const safeUrls = {
root: Object.values(rootGon).map(url => `${url}#ellipsis_h`), root: Object.values(rootGon).map((url) => `${url}#ellipsis_h`),
absolute: Object.values(absoluteGon).map(url => `${url}#ellipsis_h`), absolute: Object.values(absoluteGon).map((url) => `${url}#ellipsis_h`),
}; };
const unsafeUrls = [ const unsafeUrls = [
...@@ -60,7 +60,7 @@ describe('~/lib/dompurify', () => { ...@@ -60,7 +60,7 @@ describe('~/lib/dompurify', () => {
expect(sanitize(htmlHref)).toBe(htmlHref); expect(sanitize(htmlHref)).toBe(htmlHref);
}); });
it.each(safeUrls[type])('allows safe URL %s', url => { it.each(safeUrls[type])('allows safe URL %s', (url) => {
const htmlHref = `<svg><use href="${url}"></use></svg>`; const htmlHref = `<svg><use href="${url}"></use></svg>`;
expect(sanitize(htmlHref)).toBe(htmlHref); expect(sanitize(htmlHref)).toBe(htmlHref);
...@@ -68,7 +68,7 @@ describe('~/lib/dompurify', () => { ...@@ -68,7 +68,7 @@ describe('~/lib/dompurify', () => {
expect(sanitize(htmlXlink)).toBe(htmlXlink); expect(sanitize(htmlXlink)).toBe(htmlXlink);
}); });
it.each(unsafeUrls)('sanitizes unsafe URL %s', url => { it.each(unsafeUrls)('sanitizes unsafe URL %s', (url) => {
const htmlHref = `<svg><use href="${url}"></use></svg>`; const htmlHref = `<svg><use href="${url}"></use></svg>`;
const htmlXlink = `<svg><use xlink:href="${url}"></use></svg>`; const htmlXlink = `<svg><use xlink:href="${url}"></use></svg>`;
...@@ -87,7 +87,7 @@ describe('~/lib/dompurify', () => { ...@@ -87,7 +87,7 @@ describe('~/lib/dompurify', () => {
window.gon = originalGon; window.gon = originalGon;
}); });
it.each([...safeUrls.root, ...safeUrls.absolute, ...unsafeUrls])('sanitizes URL %s', url => { it.each([...safeUrls.root, ...safeUrls.absolute, ...unsafeUrls])('sanitizes URL %s', (url) => {
const htmlHref = `<svg><use href="${url}"></use></svg>`; const htmlHref = `<svg><use href="${url}"></use></svg>`;
const htmlXlink = `<svg><use xlink:href="${url}"></use></svg>`; const htmlXlink = `<svg><use xlink:href="${url}"></use></svg>`;
......
...@@ -104,7 +104,7 @@ describe('AjaxCache', () => { ...@@ -104,7 +104,7 @@ describe('AjaxCache', () => {
it('stores and returns data from Ajax call if cache is empty', () => { it('stores and returns data from Ajax call if cache is empty', () => {
mock.onGet(dummyEndpoint).reply(200, dummyResponse); mock.onGet(dummyEndpoint).reply(200, dummyResponse);
return AjaxCache.retrieve(dummyEndpoint).then(data => { return AjaxCache.retrieve(dummyEndpoint).then((data) => {
expect(data).toEqual(dummyResponse); expect(data).toEqual(dummyResponse);
expect(AjaxCache.internalStorage[dummyEndpoint]).toEqual(dummyResponse); expect(AjaxCache.internalStorage[dummyEndpoint]).toEqual(dummyResponse);
}); });
...@@ -126,7 +126,7 @@ describe('AjaxCache', () => { ...@@ -126,7 +126,7 @@ describe('AjaxCache', () => {
mock.onGet(dummyEndpoint).networkError(); mock.onGet(dummyEndpoint).networkError();
expect.assertions(2); expect.assertions(2);
return AjaxCache.retrieve(dummyEndpoint).catch(error => { return AjaxCache.retrieve(dummyEndpoint).catch((error) => {
expect(error.message).toBe(`${dummyEndpoint}: ${errorMessage}`); expect(error.message).toBe(`${dummyEndpoint}: ${errorMessage}`);
expect(error.textStatus).toBe(errorMessage); expect(error.textStatus).toBe(errorMessage);
}); });
...@@ -135,7 +135,7 @@ describe('AjaxCache', () => { ...@@ -135,7 +135,7 @@ describe('AjaxCache', () => {
it('makes no Ajax call if matching data exists', () => { it('makes no Ajax call if matching data exists', () => {
AjaxCache.internalStorage[dummyEndpoint] = dummyResponse; AjaxCache.internalStorage[dummyEndpoint] = dummyResponse;
return AjaxCache.retrieve(dummyEndpoint).then(data => { return AjaxCache.retrieve(dummyEndpoint).then((data) => {
expect(data).toBe(dummyResponse); expect(data).toBe(dummyResponse);
expect(axios.get).not.toHaveBeenCalled(); expect(axios.get).not.toHaveBeenCalled();
}); });
...@@ -153,7 +153,7 @@ describe('AjaxCache', () => { ...@@ -153,7 +153,7 @@ describe('AjaxCache', () => {
return Promise.all([ return Promise.all([
AjaxCache.retrieve(dummyEndpoint), AjaxCache.retrieve(dummyEndpoint),
AjaxCache.retrieve(dummyEndpoint, true), AjaxCache.retrieve(dummyEndpoint, true),
]).then(data => { ]).then((data) => {
expect(data).toEqual([oldDummyResponse, dummyResponse]); expect(data).toEqual([oldDummyResponse, dummyResponse]);
}); });
}); });
......
...@@ -267,7 +267,7 @@ describe('common_utils', () => { ...@@ -267,7 +267,7 @@ describe('common_utils', () => {
}); });
describe('debounceByAnimationFrame', () => { describe('debounceByAnimationFrame', () => {
it('debounces a function to allow a maximum of one call per animation frame', done => { it('debounces a function to allow a maximum of one call per animation frame', (done) => {
const spy = jest.fn(); const spy = jest.fn();
const debouncedSpy = commonUtils.debounceByAnimationFrame(spy); const debouncedSpy = commonUtils.debounceByAnimationFrame(spy);
window.requestAnimationFrame(() => { window.requestAnimationFrame(() => {
...@@ -404,54 +404,54 @@ describe('common_utils', () => { ...@@ -404,54 +404,54 @@ describe('common_utils', () => {
describe('backOff', () => { describe('backOff', () => {
beforeEach(() => { beforeEach(() => {
// shortcut our timeouts otherwise these tests will take a long time to finish // shortcut our timeouts otherwise these tests will take a long time to finish
jest.spyOn(window, 'setTimeout').mockImplementation(cb => setImmediate(cb, 0)); jest.spyOn(window, 'setTimeout').mockImplementation((cb) => setImmediate(cb, 0));
}); });
it('solves the promise from the callback', done => { it('solves the promise from the callback', (done) => {
const expectedResponseValue = 'Success!'; const expectedResponseValue = 'Success!';
commonUtils commonUtils
.backOff((next, stop) => .backOff((next, stop) =>
new Promise(resolve => { new Promise((resolve) => {
resolve(expectedResponseValue); resolve(expectedResponseValue);
}) })
.then(resp => { .then((resp) => {
stop(resp); stop(resp);
}) })
.catch(done.fail), .catch(done.fail),
) )
.then(respBackoff => { .then((respBackoff) => {
expect(respBackoff).toBe(expectedResponseValue); expect(respBackoff).toBe(expectedResponseValue);
done(); done();
}) })
.catch(done.fail); .catch(done.fail);
}); });
it('catches the rejected promise from the callback ', done => { it('catches the rejected promise from the callback ', (done) => {
const errorMessage = 'Mistakes were made!'; const errorMessage = 'Mistakes were made!';
commonUtils commonUtils
.backOff((next, stop) => { .backOff((next, stop) => {
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
reject(new Error(errorMessage)); reject(new Error(errorMessage));
}) })
.then(resp => { .then((resp) => {
stop(resp); stop(resp);
}) })
.catch(err => stop(err)); .catch((err) => stop(err));
}) })
.catch(errBackoffResp => { .catch((errBackoffResp) => {
expect(errBackoffResp instanceof Error).toBe(true); expect(errBackoffResp instanceof Error).toBe(true);
expect(errBackoffResp.message).toBe(errorMessage); expect(errBackoffResp.message).toBe(errorMessage);
done(); done();
}); });
}); });
it('solves the promise correctly after retrying a third time', done => { it('solves the promise correctly after retrying a third time', (done) => {
let numberOfCalls = 1; let numberOfCalls = 1;
const expectedResponseValue = 'Success!'; const expectedResponseValue = 'Success!';
commonUtils commonUtils
.backOff((next, stop) => .backOff((next, stop) =>
Promise.resolve(expectedResponseValue) Promise.resolve(expectedResponseValue)
.then(resp => { .then((resp) => {
if (numberOfCalls < 3) { if (numberOfCalls < 3) {
numberOfCalls += 1; numberOfCalls += 1;
next(); next();
...@@ -461,7 +461,7 @@ describe('common_utils', () => { ...@@ -461,7 +461,7 @@ describe('common_utils', () => {
}) })
.catch(done.fail), .catch(done.fail),
) )
.then(respBackoff => { .then((respBackoff) => {
const timeouts = window.setTimeout.mock.calls.map(([, timeout]) => timeout); const timeouts = window.setTimeout.mock.calls.map(([, timeout]) => timeout);
expect(timeouts).toEqual([2000, 4000]); expect(timeouts).toEqual([2000, 4000]);
...@@ -471,10 +471,10 @@ describe('common_utils', () => { ...@@ -471,10 +471,10 @@ describe('common_utils', () => {
.catch(done.fail); .catch(done.fail);
}); });
it('rejects the backOff promise after timing out', done => { it('rejects the backOff promise after timing out', (done) => {
commonUtils commonUtils
.backOff(next => next(), 64000) .backOff((next) => next(), 64000)
.catch(errBackoffResp => { .catch((errBackoffResp) => {
const timeouts = window.setTimeout.mock.calls.map(([, timeout]) => timeout); const timeouts = window.setTimeout.mock.calls.map(([, timeout]) => timeout);
expect(timeouts).toEqual([2000, 4000, 8000, 16000, 32000, 32000]); expect(timeouts).toEqual([2000, 4000, 8000, 16000, 32000, 32000]);
...@@ -533,8 +533,8 @@ describe('common_utils', () => { ...@@ -533,8 +533,8 @@ describe('common_utils', () => {
}); });
describe('convertObjectProps*', () => { describe('convertObjectProps*', () => {
const mockConversionFunction = prop => `${prop}_converted`; const mockConversionFunction = (prop) => `${prop}_converted`;
const isEmptyObject = obj => const isEmptyObject = (obj) =>
typeof obj === 'object' && obj !== null && Object.keys(obj).length === 0; typeof obj === 'object' && obj !== null && Object.keys(obj).length === 0;
const mockObjects = { const mockObjects = {
......
...@@ -64,7 +64,7 @@ describe('Date time range utils', () => { ...@@ -64,7 +64,7 @@ describe('Date time range utils', () => {
}; };
Object.entries(rangeTypes).forEach(([type, examples]) => { Object.entries(rangeTypes).forEach(([type, examples]) => {
examples.forEach(example => expect(getRangeType(example)).toEqual(type)); examples.forEach((example) => expect(getRangeType(example)).toEqual(type));
}); });
}); });
}); });
......
...@@ -566,7 +566,7 @@ describe('getDatesInRange', () => { ...@@ -566,7 +566,7 @@ describe('getDatesInRange', () => {
it('applies mapper function if provided fro each item in range', () => { it('applies mapper function if provided fro each item in range', () => {
const d1 = new Date('2019-01-01'); const d1 = new Date('2019-01-01');
const d2 = new Date('2019-01-31'); const d2 = new Date('2019-01-31');
const formatter = date => date.getDate(); const formatter = (date) => date.getDate();
const range = datetimeUtility.getDatesInRange(d1, d2, formatter); const range = datetimeUtility.getDatesInRange(d1, d2, formatter);
......
...@@ -45,7 +45,7 @@ describe('DOM Utils', () => { ...@@ -45,7 +45,7 @@ describe('DOM Utils', () => {
}); });
describe('canScrollUp', () => { describe('canScrollUp', () => {
[1, 100].forEach(scrollTop => { [1, 100].forEach((scrollTop) => {
it(`is true if scrollTop is > 0 (${scrollTop})`, () => { it(`is true if scrollTop is > 0 (${scrollTop})`, () => {
expect( expect(
canScrollUp({ canScrollUp({
...@@ -55,7 +55,7 @@ describe('DOM Utils', () => { ...@@ -55,7 +55,7 @@ describe('DOM Utils', () => {
}); });
}); });
[0, -10].forEach(scrollTop => { [0, -10].forEach((scrollTop) => {
it(`is false if scrollTop is <= 0 (${scrollTop})`, () => { it(`is false if scrollTop is <= 0 (${scrollTop})`, () => {
expect( expect(
canScrollUp({ canScrollUp({
......
import { serializeForm, serializeFormObject, isEmptyValue } from '~/lib/utils/forms'; import { serializeForm, serializeFormObject, isEmptyValue } from '~/lib/utils/forms';
describe('lib/utils/forms', () => { describe('lib/utils/forms', () => {
const createDummyForm = inputs => { const createDummyForm = (inputs) => {
const form = document.createElement('form'); const form = document.createElement('form');
form.innerHTML = inputs form.innerHTML = inputs
...@@ -9,7 +9,7 @@ describe('lib/utils/forms', () => { ...@@ -9,7 +9,7 @@ describe('lib/utils/forms', () => {
let str = ``; let str = ``;
if (type === 'select') { if (type === 'select') {
str = `<select name="${name}">`; str = `<select name="${name}">`;
value.forEach(v => { value.forEach((v) => {
if (v.length > 0) { if (v.length > 0) {
str += `<option value="${v}"></option> `; str += `<option value="${v}"></option> `;
} }
...@@ -81,8 +81,8 @@ describe('lib/utils/forms', () => { ...@@ -81,8 +81,8 @@ describe('lib/utils/forms', () => {
jest jest
.spyOn(FormData.prototype, 'getAll') .spyOn(FormData.prototype, 'getAll')
.mockImplementation(name => .mockImplementation((name) =>
formData.map(elem => (elem.name === name ? elem.value : undefined)), formData.map((elem) => (elem.name === name ? elem.value : undefined)),
); );
const data = serializeForm(form); const data = serializeForm(form);
......
...@@ -8,13 +8,13 @@ describe('highlight', () => { ...@@ -8,13 +8,13 @@ describe('highlight', () => {
}); });
it(`should return an empty string in the case of invalid inputs`, () => { it(`should return an empty string in the case of invalid inputs`, () => {
[null, undefined].forEach(input => { [null, undefined].forEach((input) => {
expect(highlight(input, 'match')).toBe(''); expect(highlight(input, 'match')).toBe('');
}); });
}); });
it(`should return the original value if match is null, undefined, or ''`, () => { it(`should return the original value if match is null, undefined, or ''`, () => {
[null, undefined].forEach(match => { [null, undefined].forEach((match) => {
expect(highlight('gitlab', match)).toBe('gitlab'); expect(highlight('gitlab', match)).toBe('gitlab');
}); });
}); });
......
...@@ -34,13 +34,13 @@ describe('Icon utils', () => { ...@@ -34,13 +34,13 @@ describe('Icon utils', () => {
}); });
it('extracts svg icon path content from sprite icons', () => { it('extracts svg icon path content from sprite icons', () => {
return getSvgIconPathContent(mockName).then(path => { return getSvgIconPathContent(mockName).then((path) => {
expect(path).toBe(mockPath); expect(path).toBe(mockPath);
}); });
}); });
it('returns null if icon path content does not exist', () => { it('returns null if icon path content does not exist', () => {
return getSvgIconPathContent('missing-icon').then(path => { return getSvgIconPathContent('missing-icon').then((path) => {
expect(path).toBe(null); expect(path).toBe(null);
}); });
}); });
...@@ -58,22 +58,22 @@ describe('Icon utils', () => { ...@@ -58,22 +58,22 @@ describe('Icon utils', () => {
}); });
it('returns null', () => { it('returns null', () => {
return getSvgIconPathContent(mockName).then(path => { return getSvgIconPathContent(mockName).then((path) => {
expect(path).toBe(null); expect(path).toBe(null);
}); });
}); });
it('extracts svg icon path content, after 2 attempts', () => { it('extracts svg icon path content, after 2 attempts', () => {
return getSvgIconPathContent(mockName) return getSvgIconPathContent(mockName)
.then(path1 => { .then((path1) => {
expect(path1).toBe(null); expect(path1).toBe(null);
return getSvgIconPathContent(mockName); return getSvgIconPathContent(mockName);
}) })
.then(path2 => { .then((path2) => {
expect(path2).toBe(null); expect(path2).toBe(null);
return getSvgIconPathContent(mockName); return getSvgIconPathContent(mockName);
}) })
.then(path3 => { .then((path3) => {
expect(path3).toBe(mockPath); expect(path3).toBe(mockPath);
}); });
}); });
......
...@@ -50,7 +50,7 @@ describe('Poll', () => { ...@@ -50,7 +50,7 @@ describe('Poll', () => {
}; };
}); });
it('calls the success callback when no header for interval is provided', done => { it('calls the success callback when no header for interval is provided', (done) => {
mockServiceCall({ status: 200 }); mockServiceCall({ status: 200 });
setup(); setup();
...@@ -62,7 +62,7 @@ describe('Poll', () => { ...@@ -62,7 +62,7 @@ describe('Poll', () => {
}); });
}); });
it('calls the error callback when the http request returns an error', done => { it('calls the error callback when the http request returns an error', (done) => {
mockServiceCall({ status: 500 }, true); mockServiceCall({ status: 500 }, true);
setup(); setup();
...@@ -74,7 +74,7 @@ describe('Poll', () => { ...@@ -74,7 +74,7 @@ describe('Poll', () => {
}); });
}); });
it('skips the error callback when request is aborted', done => { it('skips the error callback when request is aborted', (done) => {
mockServiceCall({ status: 0 }, true); mockServiceCall({ status: 0 }, true);
setup(); setup();
...@@ -87,7 +87,7 @@ describe('Poll', () => { ...@@ -87,7 +87,7 @@ describe('Poll', () => {
}); });
}); });
it('should call the success callback when the interval header is -1', done => { it('should call the success callback when the interval header is -1', (done) => {
mockServiceCall({ status: 200, headers: { 'poll-interval': -1 } }); mockServiceCall({ status: 200, headers: { 'poll-interval': -1 } });
setup() setup()
.then(() => { .then(() => {
...@@ -100,8 +100,8 @@ describe('Poll', () => { ...@@ -100,8 +100,8 @@ describe('Poll', () => {
}); });
describe('for 2xx status code', () => { describe('for 2xx status code', () => {
successCodes.forEach(httpCode => { successCodes.forEach((httpCode) => {
it(`starts polling when http status is ${httpCode} and interval header is provided`, done => { it(`starts polling when http status is ${httpCode} and interval header is provided`, (done) => {
mockServiceCall({ status: httpCode, headers: { 'poll-interval': 1 } }); mockServiceCall({ status: httpCode, headers: { 'poll-interval': 1 } });
const Polling = new Poll({ const Polling = new Poll({
...@@ -129,7 +129,7 @@ describe('Poll', () => { ...@@ -129,7 +129,7 @@ describe('Poll', () => {
}); });
describe('with delayed initial request', () => { describe('with delayed initial request', () => {
it('delays the first request', async done => { it('delays the first request', async (done) => {
mockServiceCall({ status: 200, headers: { 'poll-interval': 1 } }); mockServiceCall({ status: 200, headers: { 'poll-interval': 1 } });
const Polling = new Poll({ const Polling = new Poll({
...@@ -158,7 +158,7 @@ describe('Poll', () => { ...@@ -158,7 +158,7 @@ describe('Poll', () => {
}); });
describe('stop', () => { describe('stop', () => {
it('stops polling when method is called', done => { it('stops polling when method is called', (done) => {
mockServiceCall({ status: 200, headers: { 'poll-interval': 1 } }); mockServiceCall({ status: 200, headers: { 'poll-interval': 1 } });
const Polling = new Poll({ const Polling = new Poll({
...@@ -186,7 +186,7 @@ describe('Poll', () => { ...@@ -186,7 +186,7 @@ describe('Poll', () => {
}); });
describe('enable', () => { describe('enable', () => {
it('should enable polling upon a response', done => { it('should enable polling upon a response', (done) => {
mockServiceCall({ status: 200 }); mockServiceCall({ status: 200 });
const Polling = new Poll({ const Polling = new Poll({
resource: service, resource: service,
...@@ -212,7 +212,7 @@ describe('Poll', () => { ...@@ -212,7 +212,7 @@ describe('Poll', () => {
}); });
describe('restart', () => { describe('restart', () => {
it('should restart polling when its called', done => { it('should restart polling when its called', (done) => {
mockServiceCall({ status: 200, headers: { 'poll-interval': 1 } }); mockServiceCall({ status: 200, headers: { 'poll-interval': 1 } });
const Polling = new Poll({ const Polling = new Poll({
......
...@@ -70,7 +70,7 @@ describe('pollUntilComplete', () => { ...@@ -70,7 +70,7 @@ describe('pollUntilComplete', () => {
}); });
it('rejects with the error response', () => it('rejects with the error response', () =>
pollUntilComplete(endpoint).catch(error => { pollUntilComplete(endpoint).catch((error) => {
expect(error.response.data).toBe(errorMessage); expect(error.response.data).toBe(errorMessage);
})); }));
}); });
......
...@@ -300,13 +300,13 @@ describe('text_utility', () => { ...@@ -300,13 +300,13 @@ describe('text_utility', () => {
}); });
it(`should return an empty string for invalid inputs`, () => { it(`should return an empty string for invalid inputs`, () => {
[undefined, null, 4, {}, true, new Date()].forEach(input => { [undefined, null, 4, {}, true, new Date()].forEach((input) => {
expect(textUtils.truncateNamespace(input)).toBe(''); expect(textUtils.truncateNamespace(input)).toBe('');
}); });
}); });
it(`should not alter strings that aren't formatted as namespaces`, () => { it(`should not alter strings that aren't formatted as namespaces`, () => {
['', ' ', '\t', 'a', 'a \\ b'].forEach(input => { ['', ' ', '\t', 'a', 'a \\ b'].forEach((input) => {
expect(textUtils.truncateNamespace(input)).toBe(input); expect(textUtils.truncateNamespace(input)).toBe(input);
}); });
}); });
......
...@@ -15,7 +15,7 @@ const shas = { ...@@ -15,7 +15,7 @@ const shas = {
], ],
}; };
const setWindowLocation = value => { const setWindowLocation = (value) => {
Object.defineProperty(window, 'location', { Object.defineProperty(window, 'location', {
writable: true, writable: true,
value, value,
...@@ -337,7 +337,7 @@ describe('URL utility', () => { ...@@ -337,7 +337,7 @@ describe('URL utility', () => {
describe('urlContainsSha', () => { describe('urlContainsSha', () => {
it('returns true when there is a valid 40-character SHA1 hash in the URL', () => { it('returns true when there is a valid 40-character SHA1 hash in the URL', () => {
shas.valid.forEach(sha => { shas.valid.forEach((sha) => {
expect( expect(
urlUtils.urlContainsSha({ url: `http://urlstuff/${sha}/moreurlstuff` }), urlUtils.urlContainsSha({ url: `http://urlstuff/${sha}/moreurlstuff` }),
).toBeTruthy(); ).toBeTruthy();
...@@ -345,7 +345,7 @@ describe('URL utility', () => { ...@@ -345,7 +345,7 @@ describe('URL utility', () => {
}); });
it('returns false when there is not a valid 40-character SHA1 hash in the URL', () => { it('returns false when there is not a valid 40-character SHA1 hash in the URL', () => {
shas.invalid.forEach(str => { shas.invalid.forEach((str) => {
expect(urlUtils.urlContainsSha({ url: `http://urlstuff/${str}/moreurlstuff` })).toBeFalsy(); expect(urlUtils.urlContainsSha({ url: `http://urlstuff/${str}/moreurlstuff` })).toBeFalsy();
}); });
}); });
...@@ -356,8 +356,8 @@ describe('URL utility', () => { ...@@ -356,8 +356,8 @@ describe('URL utility', () => {
let invalidUrls = []; let invalidUrls = [];
beforeAll(() => { beforeAll(() => {
validUrls = shas.valid.map(sha => `http://urlstuff/${sha}/moreurlstuff`); validUrls = shas.valid.map((sha) => `http://urlstuff/${sha}/moreurlstuff`);
invalidUrls = shas.invalid.map(str => `http://urlstuff/${str}/moreurlstuff`); invalidUrls = shas.invalid.map((str) => `http://urlstuff/${str}/moreurlstuff`);
}); });
it('returns the valid 40-character SHA1 hash from the URL', () => { it('returns the valid 40-character SHA1 hash from the URL', () => {
...@@ -367,7 +367,7 @@ describe('URL utility', () => { ...@@ -367,7 +367,7 @@ describe('URL utility', () => {
}); });
it('returns null from a URL with no valid 40-character SHA1 hash', () => { it('returns null from a URL with no valid 40-character SHA1 hash', () => {
invalidUrls.forEach(url => { invalidUrls.forEach((url) => {
expect(urlUtils.getShaFromUrl({ url })).toBeNull(); expect(urlUtils.getShaFromUrl({ url })).toBeNull();
}); });
}); });
...@@ -589,11 +589,11 @@ describe('URL utility', () => { ...@@ -589,11 +589,11 @@ describe('URL utility', () => {
]; ];
describe('with URL constructor support', () => { describe('with URL constructor support', () => {
it.each(safeUrls)('returns true for %s', url => { it.each(safeUrls)('returns true for %s', (url) => {
expect(urlUtils.isSafeURL(url)).toBe(true); expect(urlUtils.isSafeURL(url)).toBe(true);
}); });
it.each(unsafeUrls)('returns false for %s', url => { it.each(unsafeUrls)('returns false for %s', (url) => {
expect(urlUtils.isSafeURL(url)).toBe(false); expect(urlUtils.isSafeURL(url)).toBe(false);
}); });
}); });
...@@ -807,7 +807,7 @@ describe('URL utility', () => { ...@@ -807,7 +807,7 @@ describe('URL utility', () => {
it.each([[httpProtocol], [httpsProtocol]])( it.each([[httpProtocol], [httpsProtocol]])(
'when no url passed, returns correct protocol for %i from window location', 'when no url passed, returns correct protocol for %i from window location',
protocol => { (protocol) => {
setWindowLocation({ setWindowLocation({
protocol, protocol,
}); });
......
...@@ -91,7 +91,7 @@ describe('UsersCache', () => { ...@@ -91,7 +91,7 @@ describe('UsersCache', () => {
jest.spyOn(Api, 'users').mockImplementation((query, options) => apiSpy(query, options)); jest.spyOn(Api, 'users').mockImplementation((query, options) => apiSpy(query, options));
}); });
it('stores and returns data from API call if cache is empty', done => { it('stores and returns data from API call if cache is empty', (done) => {
apiSpy = (query, options) => { apiSpy = (query, options) => {
expect(query).toBe(''); expect(query).toBe('');
expect(options).toEqual({ expect(options).toEqual({
...@@ -104,7 +104,7 @@ describe('UsersCache', () => { ...@@ -104,7 +104,7 @@ describe('UsersCache', () => {
}; };
UsersCache.retrieve(dummyUsername) UsersCache.retrieve(dummyUsername)
.then(user => { .then((user) => {
expect(user).toBe(dummyUser); expect(user).toBe(dummyUser);
expect(UsersCache.internalStorage[dummyUsername]).toBe(dummyUser); expect(UsersCache.internalStorage[dummyUsername]).toBe(dummyUser);
}) })
...@@ -112,7 +112,7 @@ describe('UsersCache', () => { ...@@ -112,7 +112,7 @@ describe('UsersCache', () => {
.catch(done.fail); .catch(done.fail);
}); });
it('returns undefined if Ajax call fails and cache is empty', done => { it('returns undefined if Ajax call fails and cache is empty', (done) => {
const dummyError = new Error('server exploded'); const dummyError = new Error('server exploded');
apiSpy = (query, options) => { apiSpy = (query, options) => {
...@@ -125,21 +125,21 @@ describe('UsersCache', () => { ...@@ -125,21 +125,21 @@ describe('UsersCache', () => {
}; };
UsersCache.retrieve(dummyUsername) UsersCache.retrieve(dummyUsername)
.then(user => done.fail(`Received unexpected user: ${JSON.stringify(user)}`)) .then((user) => done.fail(`Received unexpected user: ${JSON.stringify(user)}`))
.catch(error => { .catch((error) => {
expect(error).toBe(dummyError); expect(error).toBe(dummyError);
}) })
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
}); });
it('makes no Ajax call if matching data exists', done => { it('makes no Ajax call if matching data exists', (done) => {
UsersCache.internalStorage[dummyUsername] = dummyUser; UsersCache.internalStorage[dummyUsername] = dummyUser;
apiSpy = () => done.fail(new Error('expected no Ajax call!')); apiSpy = () => done.fail(new Error('expected no Ajax call!'));
UsersCache.retrieve(dummyUsername) UsersCache.retrieve(dummyUsername)
.then(user => { .then((user) => {
expect(user).toBe(dummyUser); expect(user).toBe(dummyUser);
}) })
.then(done) .then(done)
...@@ -151,11 +151,11 @@ describe('UsersCache', () => { ...@@ -151,11 +151,11 @@ describe('UsersCache', () => {
let apiSpy; let apiSpy;
beforeEach(() => { beforeEach(() => {
jest.spyOn(Api, 'user').mockImplementation(id => apiSpy(id)); jest.spyOn(Api, 'user').mockImplementation((id) => apiSpy(id));
}); });
it('stores and returns data from API call if cache is empty', done => { it('stores and returns data from API call if cache is empty', (done) => {
apiSpy = id => { apiSpy = (id) => {
expect(id).toBe(dummyUserId); expect(id).toBe(dummyUserId);
return Promise.resolve({ return Promise.resolve({
...@@ -164,7 +164,7 @@ describe('UsersCache', () => { ...@@ -164,7 +164,7 @@ describe('UsersCache', () => {
}; };
UsersCache.retrieveById(dummyUserId) UsersCache.retrieveById(dummyUserId)
.then(user => { .then((user) => {
expect(user).toBe(dummyUser); expect(user).toBe(dummyUser);
expect(UsersCache.internalStorage[dummyUserId]).toBe(dummyUser); expect(UsersCache.internalStorage[dummyUserId]).toBe(dummyUser);
}) })
...@@ -172,31 +172,31 @@ describe('UsersCache', () => { ...@@ -172,31 +172,31 @@ describe('UsersCache', () => {
.catch(done.fail); .catch(done.fail);
}); });
it('returns undefined if Ajax call fails and cache is empty', done => { it('returns undefined if Ajax call fails and cache is empty', (done) => {
const dummyError = new Error('server exploded'); const dummyError = new Error('server exploded');
apiSpy = id => { apiSpy = (id) => {
expect(id).toBe(dummyUserId); expect(id).toBe(dummyUserId);
return Promise.reject(dummyError); return Promise.reject(dummyError);
}; };
UsersCache.retrieveById(dummyUserId) UsersCache.retrieveById(dummyUserId)
.then(user => done.fail(`Received unexpected user: ${JSON.stringify(user)}`)) .then((user) => done.fail(`Received unexpected user: ${JSON.stringify(user)}`))
.catch(error => { .catch((error) => {
expect(error).toBe(dummyError); expect(error).toBe(dummyError);
}) })
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
}); });
it('makes no Ajax call if matching data exists', done => { it('makes no Ajax call if matching data exists', (done) => {
UsersCache.internalStorage[dummyUserId] = dummyUser; UsersCache.internalStorage[dummyUserId] = dummyUser;
apiSpy = () => done.fail(new Error('expected no Ajax call!')); apiSpy = () => done.fail(new Error('expected no Ajax call!'));
UsersCache.retrieveById(dummyUserId) UsersCache.retrieveById(dummyUserId)
.then(user => { .then((user) => {
expect(user).toBe(dummyUser); expect(user).toBe(dummyUser);
}) })
.then(done) .then(done)
...@@ -208,11 +208,11 @@ describe('UsersCache', () => { ...@@ -208,11 +208,11 @@ describe('UsersCache', () => {
let apiSpy; let apiSpy;
beforeEach(() => { beforeEach(() => {
jest.spyOn(Api, 'userStatus').mockImplementation(id => apiSpy(id)); jest.spyOn(Api, 'userStatus').mockImplementation((id) => apiSpy(id));
}); });
it('stores and returns data from API call if cache is empty', done => { it('stores and returns data from API call if cache is empty', (done) => {
apiSpy = id => { apiSpy = (id) => {
expect(id).toBe(dummyUserId); expect(id).toBe(dummyUserId);
return Promise.resolve({ return Promise.resolve({
...@@ -221,7 +221,7 @@ describe('UsersCache', () => { ...@@ -221,7 +221,7 @@ describe('UsersCache', () => {
}; };
UsersCache.retrieveStatusById(dummyUserId) UsersCache.retrieveStatusById(dummyUserId)
.then(userStatus => { .then((userStatus) => {
expect(userStatus).toBe(dummyUserStatus); expect(userStatus).toBe(dummyUserStatus);
expect(UsersCache.internalStorage[dummyUserId].status).toBe(dummyUserStatus); expect(UsersCache.internalStorage[dummyUserId].status).toBe(dummyUserStatus);
}) })
...@@ -229,25 +229,25 @@ describe('UsersCache', () => { ...@@ -229,25 +229,25 @@ describe('UsersCache', () => {
.catch(done.fail); .catch(done.fail);
}); });
it('returns undefined if Ajax call fails and cache is empty', done => { it('returns undefined if Ajax call fails and cache is empty', (done) => {
const dummyError = new Error('server exploded'); const dummyError = new Error('server exploded');
apiSpy = id => { apiSpy = (id) => {
expect(id).toBe(dummyUserId); expect(id).toBe(dummyUserId);
return Promise.reject(dummyError); return Promise.reject(dummyError);
}; };
UsersCache.retrieveStatusById(dummyUserId) UsersCache.retrieveStatusById(dummyUserId)
.then(userStatus => done.fail(`Received unexpected user: ${JSON.stringify(userStatus)}`)) .then((userStatus) => done.fail(`Received unexpected user: ${JSON.stringify(userStatus)}`))
.catch(error => { .catch((error) => {
expect(error).toBe(dummyError); expect(error).toBe(dummyError);
}) })
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
}); });
it('makes no Ajax call if matching data exists', done => { it('makes no Ajax call if matching data exists', (done) => {
UsersCache.internalStorage[dummyUserId] = { UsersCache.internalStorage[dummyUserId] = {
status: dummyUserStatus, status: dummyUserStatus,
}; };
...@@ -255,7 +255,7 @@ describe('UsersCache', () => { ...@@ -255,7 +255,7 @@ describe('UsersCache', () => {
apiSpy = () => done.fail(new Error('expected no Ajax call!')); apiSpy = () => done.fail(new Error('expected no Ajax call!'));
UsersCache.retrieveStatusById(dummyUserId) UsersCache.retrieveStatusById(dummyUserId)
.then(userStatus => { .then((userStatus) => {
expect(userStatus).toBe(dummyUserStatus); expect(userStatus).toBe(dummyUserStatus);
}) })
.then(done) .then(done)
......
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