Commit 0869e9f4 authored by Martin Wortschack's avatar Martin Wortschack

Merge branch '199988_02-replace-notice-with-toast-vue' into 'master'

Replace Geo Notice with Toast (Frontend)

See merge request gitlab-org/gitlab!24407
parents a919526a 9f9ae8da
import Api from 'ee/api'; import Api from 'ee/api';
import createFlash from '~/flash'; import createFlash from '~/flash';
import toast from '~/vue_shared/plugins/global_toast';
import { __ } from '~/locale'; import { __ } from '~/locale';
import { import {
parseIntPagination, parseIntPagination,
...@@ -50,7 +51,8 @@ export const fetchDesigns = ({ state, dispatch }) => { ...@@ -50,7 +51,8 @@ export const fetchDesigns = ({ state, dispatch }) => {
// Initiate All Design Syncs // Initiate All Design Syncs
export const requestInitiateAllDesignSyncs = ({ commit }) => export const requestInitiateAllDesignSyncs = ({ commit }) =>
commit(types.REQUEST_INITIATE_ALL_DESIGN_SYNCS); commit(types.REQUEST_INITIATE_ALL_DESIGN_SYNCS);
export const receiveInitiateAllDesignSyncsSuccess = ({ commit, dispatch }) => { export const receiveInitiateAllDesignSyncsSuccess = ({ commit, dispatch }, { action }) => {
toast(__(`All designs are being scheduled for ${action}`));
commit(types.RECEIVE_INITIATE_ALL_DESIGN_SYNCS_SUCCESS); commit(types.RECEIVE_INITIATE_ALL_DESIGN_SYNCS_SUCCESS);
dispatch('fetchDesigns'); dispatch('fetchDesigns');
}; };
...@@ -63,7 +65,7 @@ export const initiateAllDesignSyncs = ({ dispatch }, action) => { ...@@ -63,7 +65,7 @@ export const initiateAllDesignSyncs = ({ dispatch }, action) => {
dispatch('requestInitiateAllDesignSyncs'); dispatch('requestInitiateAllDesignSyncs');
Api.initiateAllGeoDesignSyncs(action) Api.initiateAllGeoDesignSyncs(action)
.then(() => dispatch('receiveInitiateAllDesignSyncsSuccess')) .then(() => dispatch('receiveInitiateAllDesignSyncsSuccess', { action }))
.catch(() => { .catch(() => {
dispatch('receiveInitiateAllDesignSyncsError'); dispatch('receiveInitiateAllDesignSyncsError');
}); });
...@@ -71,7 +73,8 @@ export const initiateAllDesignSyncs = ({ dispatch }, action) => { ...@@ -71,7 +73,8 @@ export const initiateAllDesignSyncs = ({ dispatch }, action) => {
// Initiate Design Sync // Initiate Design Sync
export const requestInitiateDesignSync = ({ commit }) => commit(types.REQUEST_INITIATE_DESIGN_SYNC); export const requestInitiateDesignSync = ({ commit }) => commit(types.REQUEST_INITIATE_DESIGN_SYNC);
export const receiveInitiateDesignSyncSuccess = ({ commit, dispatch }) => { export const receiveInitiateDesignSyncSuccess = ({ commit, dispatch }, { name, action }) => {
toast(__(`${name} is scheduled for ${action}`));
commit(types.RECEIVE_INITIATE_DESIGN_SYNC_SUCCESS); commit(types.RECEIVE_INITIATE_DESIGN_SYNC_SUCCESS);
dispatch('fetchDesigns'); dispatch('fetchDesigns');
}; };
...@@ -84,7 +87,7 @@ export const initiateDesignSync = ({ dispatch }, { projectId, name, action }) => ...@@ -84,7 +87,7 @@ export const initiateDesignSync = ({ dispatch }, { projectId, name, action }) =>
dispatch('requestInitiateDesignSync'); dispatch('requestInitiateDesignSync');
Api.initiateGeoDesignSync({ projectId, action }) Api.initiateGeoDesignSync({ projectId, action })
.then(() => dispatch('receiveInitiateDesignSyncSuccess')) .then(() => dispatch('receiveInitiateDesignSyncSuccess', { name, action }))
.catch(() => { .catch(() => {
dispatch('receiveInitiateDesignSyncError', { name }); dispatch('receiveInitiateDesignSyncError', { name });
}); });
......
...@@ -131,7 +131,7 @@ export default { ...@@ -131,7 +131,7 @@ export default {
.repairNode(targetNode) .repairNode(targetNode)
.then(() => { .then(() => {
this.setNodeActionStatus(targetNode, false); this.setNodeActionStatus(targetNode, false);
Flash(s__('GeoNodes|Node Authentication was successfully repaired.'), 'notice'); this.$toast.show(s__('GeoNodes|Node Authentication was successfully repaired.'));
}) })
.catch(() => { .catch(() => {
this.setNodeActionStatus(targetNode, false); this.setNodeActionStatus(targetNode, false);
...@@ -160,7 +160,7 @@ export default { ...@@ -160,7 +160,7 @@ export default {
.removeNode(targetNode) .removeNode(targetNode)
.then(() => { .then(() => {
this.store.removeNode(targetNode); this.store.removeNode(targetNode);
Flash(s__('GeoNodes|Node was successfully removed.'), 'notice'); this.$toast.show(s__('GeoNodes|Node was successfully removed.'));
}) })
.catch(() => { .catch(() => {
this.setNodeActionStatus(targetNode, false); this.setNodeActionStatus(targetNode, false);
......
import Vue from 'vue'; import Vue from 'vue';
import { GlToast } from '@gitlab/ui';
import Translate from '~/vue_shared/translate'; import Translate from '~/vue_shared/translate';
import { parseBoolean } from '~/lib/utils/common_utils'; import { parseBoolean } from '~/lib/utils/common_utils';
...@@ -9,6 +10,7 @@ import GeoNodesService from './service/geo_nodes_service'; ...@@ -9,6 +10,7 @@ import GeoNodesService from './service/geo_nodes_service';
import geoNodesApp from './components/app.vue'; import geoNodesApp from './components/app.vue';
Vue.use(Translate); Vue.use(Translate);
Vue.use(GlToast);
export default () => { export default () => {
const el = document.getElementById('js-geo-nodes'); const el = document.getElementById('js-geo-nodes');
......
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import testAction from 'helpers/vuex_action_helper'; import testAction from 'helpers/vuex_action_helper';
import flash from '~/flash'; import flash from '~/flash';
import toast from '~/vue_shared/plugins/global_toast';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import * as actions from 'ee/geo_designs/store/actions'; import * as actions from 'ee/geo_designs/store/actions';
import * as types from 'ee/geo_designs/store/mutation_types'; import * as types from 'ee/geo_designs/store/mutation_types';
...@@ -13,6 +14,7 @@ import { ...@@ -13,6 +14,7 @@ import {
} from '../mock_data'; } from '../mock_data';
jest.mock('~/flash'); jest.mock('~/flash');
jest.mock('~/vue_shared/plugins/global_toast');
describe('GeoDesigns Store Actions', () => { describe('GeoDesigns Store Actions', () => {
let state; let state;
...@@ -182,14 +184,17 @@ describe('GeoDesigns Store Actions', () => { ...@@ -182,14 +184,17 @@ describe('GeoDesigns Store Actions', () => {
}); });
describe('receiveInitiateAllDesignSyncsSuccess', () => { describe('receiveInitiateAllDesignSyncsSuccess', () => {
it('should commit mutation RECEIVE_INITIATE_ALL_DESIGN_SYNCS_SUCCESS and fetchDesigns', done => { it('should commit mutation RECEIVE_INITIATE_ALL_DESIGN_SYNCS_SUCCESS and call fetchDesigns and toast', () => {
testAction( testAction(
actions.receiveInitiateAllDesignSyncsSuccess, actions.receiveInitiateAllDesignSyncsSuccess,
null, { action: ACTION_TYPES.RESYNC },
state, state,
[{ type: types.RECEIVE_INITIATE_ALL_DESIGN_SYNCS_SUCCESS }], [{ type: types.RECEIVE_INITIATE_ALL_DESIGN_SYNCS_SUCCESS }],
[{ type: 'fetchDesigns' }], [{ type: 'fetchDesigns' }],
done, () => {
expect(toast).toHaveBeenCalledTimes(1);
toast.mockClear();
},
); );
}); });
}); });
...@@ -228,7 +233,7 @@ describe('GeoDesigns Store Actions', () => { ...@@ -228,7 +233,7 @@ describe('GeoDesigns Store Actions', () => {
[], [],
[ [
{ type: 'requestInitiateAllDesignSyncs' }, { type: 'requestInitiateAllDesignSyncs' },
{ type: 'receiveInitiateAllDesignSyncsSuccess' }, { type: 'receiveInitiateAllDesignSyncsSuccess', payload: { action } },
], ],
done, done,
); );
...@@ -272,14 +277,17 @@ describe('GeoDesigns Store Actions', () => { ...@@ -272,14 +277,17 @@ describe('GeoDesigns Store Actions', () => {
}); });
describe('receiveInitiateDesignSyncSuccess', () => { describe('receiveInitiateDesignSyncSuccess', () => {
it('should commit mutation RECEIVE_INITIATE_DESIGN_SYNC_SUCCESS and fetchDesigns', done => { it('should commit mutation RECEIVE_INITIATE_DESIGN_SYNC_SUCCESS and call fetchDesigns and toast', () => {
testAction( testAction(
actions.receiveInitiateDesignSyncSuccess, actions.receiveInitiateDesignSyncSuccess,
null, { action: ACTION_TYPES.RESYNC, projectName: 'test' },
state, state,
[{ type: types.RECEIVE_INITIATE_DESIGN_SYNC_SUCCESS }], [{ type: types.RECEIVE_INITIATE_DESIGN_SYNC_SUCCESS }],
[{ type: 'fetchDesigns' }], [{ type: 'fetchDesigns' }],
done, () => {
expect(toast).toHaveBeenCalledTimes(1);
toast.mockClear();
},
); );
}); });
}); });
...@@ -320,7 +328,10 @@ describe('GeoDesigns Store Actions', () => { ...@@ -320,7 +328,10 @@ describe('GeoDesigns Store Actions', () => {
{ projectId, name, action }, { projectId, name, action },
state, state,
[], [],
[{ type: 'requestInitiateDesignSync' }, { type: 'receiveInitiateDesignSyncSuccess' }], [
{ type: 'requestInitiateDesignSync' },
{ type: 'receiveInitiateDesignSyncSuccess', payload: { name, action } },
],
done, done,
); );
}); });
......
...@@ -8,6 +8,8 @@ import GeoNodesService from 'ee/geo_nodes/service/geo_nodes_service'; ...@@ -8,6 +8,8 @@ import GeoNodesService from 'ee/geo_nodes/service/geo_nodes_service';
import mountComponent from 'helpers/vue_mount_component_helper'; import mountComponent from 'helpers/vue_mount_component_helper';
import { NODE_ACTIONS } from 'ee/geo_nodes/constants'; import { NODE_ACTIONS } from 'ee/geo_nodes/constants';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import '~/vue_shared/plugins/global_toast';
import { import {
PRIMARY_VERSION, PRIMARY_VERSION,
NODE_DETAILS_PATH, NODE_DETAILS_PATH,
...@@ -33,6 +35,9 @@ const createComponent = () => { ...@@ -33,6 +35,9 @@ const createComponent = () => {
}); });
}; };
const getToastMessage = () => document.querySelector('.gl-toast').innerText.trim();
const cleanupToastMessage = () => document.querySelector('.gl-toast').remove();
describe('AppComponent', () => { describe('AppComponent', () => {
let vm; let vm;
let mock; let mock;
...@@ -46,6 +51,7 @@ describe('AppComponent', () => { ...@@ -46,6 +51,7 @@ describe('AppComponent', () => {
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
document.body.innerHTML += '<div class="flash-container"></div>'; document.body.innerHTML += '<div class="flash-container"></div>';
mock.onGet(/(.*)\/geo_nodes$/).reply(() => [statusCode, response]); mock.onGet(/(.*)\/geo_nodes$/).reply(() => [statusCode, response]);
vm = createComponent(); vm = createComponent();
}); });
...@@ -193,7 +199,7 @@ describe('AppComponent', () => { ...@@ -193,7 +199,7 @@ describe('AppComponent', () => {
}); });
describe('repairNode', () => { describe('repairNode', () => {
it('calls service.repairNode and shows success Flash message on request success', done => { it('calls service.repairNode and shows success Toast message on request success', done => {
const node = { ...mockNode }; const node = { ...mockNode };
mock.onPost(node.repairPath).reply(() => { mock.onPost(node.repairPath).reply(() => {
expect(node.nodeActionActive).toBe(true); expect(node.nodeActionActive).toBe(true);
...@@ -204,9 +210,8 @@ describe('AppComponent', () => { ...@@ -204,9 +210,8 @@ describe('AppComponent', () => {
vm.repairNode(node) vm.repairNode(node)
.then(() => { .then(() => {
expect(vm.service.repairNode).toHaveBeenCalledWith(node); expect(vm.service.repairNode).toHaveBeenCalledWith(node);
expect(document.querySelector('.flash-text').innerText.trim()).toBe( expect(getToastMessage()).toBe('Node Authentication was successfully repaired.');
'Node Authentication was successfully repaired.', cleanupToastMessage();
);
expect(node.nodeActionActive).toBe(false); expect(node.nodeActionActive).toBe(false);
}) })
...@@ -285,7 +290,7 @@ describe('AppComponent', () => { ...@@ -285,7 +290,7 @@ describe('AppComponent', () => {
}); });
describe('removeNode', () => { describe('removeNode', () => {
it('calls service.removeNode for removing node and shows Flash message on request success', done => { it('calls service.removeNode for removing node and shows Toast message on request success', done => {
const node = { ...mockNode }; const node = { ...mockNode };
mock.onDelete(node.basePath).reply(() => { mock.onDelete(node.basePath).reply(() => {
expect(node.nodeActionActive).toBe(true); expect(node.nodeActionActive).toBe(true);
...@@ -298,9 +303,8 @@ describe('AppComponent', () => { ...@@ -298,9 +303,8 @@ describe('AppComponent', () => {
.then(() => { .then(() => {
expect(vm.service.removeNode).toHaveBeenCalledWith(node); expect(vm.service.removeNode).toHaveBeenCalledWith(node);
expect(vm.store.removeNode).toHaveBeenCalledWith(node); expect(vm.store.removeNode).toHaveBeenCalledWith(node);
expect(document.querySelector('.flash-text').innerText.trim()).toBe( expect(getToastMessage()).toBe('Node was successfully removed.');
'Node was successfully removed.', cleanupToastMessage();
);
}) })
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
......
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