Commit f6b8ef31 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'ek-fix-complex-deprecated-create-flash-variants' into 'master'

Fix complex variants of createFlash imports

See merge request gitlab-org/gitlab!63740
parents c3d09683 3e9d50c8
/* global Flash */ /* global createFlash */
import $ from 'jquery'; import $ from 'jquery';
import axios from './lib/utils/axios_utils'; import axios from './lib/utils/axios_utils';
...@@ -71,5 +71,9 @@ export function fetchCommitMergeRequests() { ...@@ -71,5 +71,9 @@ export function fetchCommitMergeRequests() {
$container.html($content); $container.html($content);
}) })
.catch(() => Flash(s__('Commits|An error occurred while fetching merge requests data.'))); .catch(() =>
createFlash({
message: s__('Commits|An error occurred while fetching merge requests data.'),
}),
);
} }
<script> <script>
/* global Flash */
import { GlLoadingIcon, GlModal } from '@gitlab/ui'; import { GlLoadingIcon, GlModal } from '@gitlab/ui';
import createFlash from '~/flash';
import { getParameterByName } from '~/lib/utils/common_utils'; import { getParameterByName } from '~/lib/utils/common_utils';
import { HIDDEN_CLASS } from '~/lib/utils/constants'; import { HIDDEN_CLASS } from '~/lib/utils/constants';
import { mergeUrlParams } from '~/lib/utils/url_utility'; import { mergeUrlParams } from '~/lib/utils/url_utility';
...@@ -116,7 +115,7 @@ export default { ...@@ -116,7 +115,7 @@ export default {
this.isLoading = false; this.isLoading = false;
window.scrollTo({ top: 0, behavior: 'smooth' }); window.scrollTo({ top: 0, behavior: 'smooth' });
Flash(COMMON_STR.FAILURE); createFlash({ message: COMMON_STR.FAILURE });
}); });
}, },
fetchAllGroups() { fetchAllGroups() {
...@@ -202,7 +201,7 @@ export default { ...@@ -202,7 +201,7 @@ export default {
if (err.status === 403) { if (err.status === 403) {
message = COMMON_STR.LEAVE_FORBIDDEN; message = COMMON_STR.LEAVE_FORBIDDEN;
} }
Flash(message); createFlash({ message });
this.targetGroup.isBeingRemoved = false; this.targetGroup.isBeingRemoved = false;
}); });
}, },
......
...@@ -3,7 +3,7 @@ import $ from 'jquery'; ...@@ -3,7 +3,7 @@ import $ from 'jquery';
import loadAwardsHandler from '~/awards_handler'; import loadAwardsHandler from '~/awards_handler';
import ShortcutsNavigation from '~/behaviors/shortcuts/shortcuts_navigation'; import ShortcutsNavigation from '~/behaviors/shortcuts/shortcuts_navigation';
import Diff from '~/diff'; import Diff from '~/diff';
import flash from '~/flash'; import createFlash from '~/flash';
import initChangesDropdown from '~/init_changes_dropdown'; import initChangesDropdown from '~/init_changes_dropdown';
import initNotes from '~/init_notes'; import initNotes from '~/init_notes';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
...@@ -39,7 +39,7 @@ if (filesContainer.length) { ...@@ -39,7 +39,7 @@ if (filesContainer.length) {
new Diff(); new Diff();
}) })
.catch(() => { .catch(() => {
flash({ message: __('An error occurred while retrieving diff files') }); createFlash({ message: __('An error occurred while retrieving diff files') });
}); });
} else { } else {
new Diff(); new Diff();
......
...@@ -170,7 +170,7 @@ export default { ...@@ -170,7 +170,7 @@ export default {
}) })
.catch(() => { .catch(() => {
this.loading = false; this.loading = false;
createFlash(ERROR_MESSAGE); createFlash({ message: ERROR_MESSAGE });
}); });
}, },
formData() { formData() {
......
...@@ -90,7 +90,9 @@ export default { ...@@ -90,7 +90,9 @@ export default {
try { try {
await this.contentEditor.setSerializedContent(this.content); await this.contentEditor.setSerializedContent(this.content);
} catch (e) { } catch (e) {
createFlash(__('There was an error loading content in the editor'), e); createFlash({
message: __('There was an error loading content in the editor'), error: e
});
} }
}, },
methods: { methods: {
......
...@@ -106,7 +106,7 @@ In this file, we write the actions that call mutations for handling a list of us ...@@ -106,7 +106,7 @@ In this file, we write the actions that call mutations for handling a list of us
.then(({ data }) => commit(types.RECEIVE_USERS_SUCCESS, data)) .then(({ data }) => commit(types.RECEIVE_USERS_SUCCESS, data))
.catch((error) => { .catch((error) => {
commit(types.RECEIVE_USERS_ERROR, error) commit(types.RECEIVE_USERS_ERROR, error)
createFlash('There was an error') createFlash({ message: 'There was an error' })
}); });
} }
......
import '~/flash';
import { GlModal, GlLoadingIcon } from '@gitlab/ui'; import { GlModal, GlLoadingIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import AxiosMockAdapter from 'axios-mock-adapter'; import AxiosMockAdapter from 'axios-mock-adapter';
import Vue from 'vue'; import Vue from 'vue';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import createFlash from '~/flash';
import appComponent from '~/groups/components/app.vue'; import appComponent from '~/groups/components/app.vue';
import groupFolderComponent from '~/groups/components/group_folder.vue'; import groupFolderComponent from '~/groups/components/group_folder.vue';
import groupItemComponent from '~/groups/components/group_item.vue'; import groupItemComponent from '~/groups/components/group_item.vue';
...@@ -27,6 +27,7 @@ import { ...@@ -27,6 +27,7 @@ import {
const $toast = { const $toast = {
show: jest.fn(), show: jest.fn(),
}; };
jest.mock('~/flash');
describe('AppComponent', () => { describe('AppComponent', () => {
let wrapper; let wrapper;
...@@ -123,12 +124,12 @@ describe('AppComponent', () => { ...@@ -123,12 +124,12 @@ describe('AppComponent', () => {
mock.onGet('/dashboard/groups.json').reply(400); mock.onGet('/dashboard/groups.json').reply(400);
jest.spyOn(window, 'scrollTo').mockImplementation(() => {}); jest.spyOn(window, 'scrollTo').mockImplementation(() => {});
jest.spyOn(window, 'Flash').mockImplementation(() => {});
return vm.fetchGroups({}).then(() => { return vm.fetchGroups({}).then(() => {
expect(vm.isLoading).toBe(false); expect(vm.isLoading).toBe(false);
expect(window.scrollTo).toHaveBeenCalledWith({ behavior: 'smooth', top: 0 }); expect(window.scrollTo).toHaveBeenCalledWith({ behavior: 'smooth', top: 0 });
expect(window.Flash).toHaveBeenCalledWith('An error occurred. Please try again.'); expect(createFlash).toHaveBeenCalledWith({
message: 'An error occurred. Please try again.',
});
}); });
}); });
}); });
...@@ -324,15 +325,13 @@ describe('AppComponent', () => { ...@@ -324,15 +325,13 @@ describe('AppComponent', () => {
const message = 'An error occurred. Please try again.'; const message = 'An error occurred. Please try again.';
jest.spyOn(vm.service, 'leaveGroup').mockRejectedValue({ status: 500 }); jest.spyOn(vm.service, 'leaveGroup').mockRejectedValue({ status: 500 });
jest.spyOn(vm.store, 'removeGroup'); jest.spyOn(vm.store, 'removeGroup');
jest.spyOn(window, 'Flash').mockImplementation(() => {});
vm.leaveGroup(); vm.leaveGroup();
expect(vm.targetGroup.isBeingRemoved).toBe(true); expect(vm.targetGroup.isBeingRemoved).toBe(true);
expect(vm.service.leaveGroup).toHaveBeenCalledWith(childGroupItem.leavePath); expect(vm.service.leaveGroup).toHaveBeenCalledWith(childGroupItem.leavePath);
return waitForPromises().then(() => { return waitForPromises().then(() => {
expect(vm.store.removeGroup).not.toHaveBeenCalled(); expect(vm.store.removeGroup).not.toHaveBeenCalled();
expect(window.Flash).toHaveBeenCalledWith(message); expect(createFlash).toHaveBeenCalledWith({ message });
expect(vm.targetGroup.isBeingRemoved).toBe(false); expect(vm.targetGroup.isBeingRemoved).toBe(false);
}); });
}); });
...@@ -341,15 +340,13 @@ describe('AppComponent', () => { ...@@ -341,15 +340,13 @@ describe('AppComponent', () => {
const message = 'Failed to leave the group. Please make sure you are not the only owner.'; const message = 'Failed to leave the group. Please make sure you are not the only owner.';
jest.spyOn(vm.service, 'leaveGroup').mockRejectedValue({ status: 403 }); jest.spyOn(vm.service, 'leaveGroup').mockRejectedValue({ status: 403 });
jest.spyOn(vm.store, 'removeGroup'); jest.spyOn(vm.store, 'removeGroup');
jest.spyOn(window, 'Flash').mockImplementation(() => {});
vm.leaveGroup(childGroupItem, groupItem); vm.leaveGroup(childGroupItem, groupItem);
expect(vm.targetGroup.isBeingRemoved).toBe(true); expect(vm.targetGroup.isBeingRemoved).toBe(true);
expect(vm.service.leaveGroup).toHaveBeenCalledWith(childGroupItem.leavePath); expect(vm.service.leaveGroup).toHaveBeenCalledWith(childGroupItem.leavePath);
return waitForPromises().then(() => { return waitForPromises().then(() => {
expect(vm.store.removeGroup).not.toHaveBeenCalled(); expect(vm.store.removeGroup).not.toHaveBeenCalled();
expect(window.Flash).toHaveBeenCalledWith(message); expect(createFlash).toHaveBeenCalledWith({ message });
expect(vm.targetGroup.isBeingRemoved).toBe(false); expect(vm.targetGroup.isBeingRemoved).toBe(false);
}); });
}); });
......
...@@ -190,7 +190,9 @@ describe('UploadBlobModal', () => { ...@@ -190,7 +190,9 @@ describe('UploadBlobModal', () => {
}); });
it('creates a flash error', () => { it('creates a flash error', () => {
expect(createFlash).toHaveBeenCalledWith('Error uploading file. Please try again.'); expect(createFlash).toHaveBeenCalledWith({
message: 'Error uploading file. Please try again.',
});
}); });
afterEach(() => { afterEach(() => {
......
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