Commit 18d0850c authored by Ash McKenzie's avatar Ash McKenzie Committed by Phil Hughes

Geo: Allow nodes to be editable in more scenarios

parent 67d06dcf
...@@ -108,19 +108,15 @@ export default { ...@@ -108,19 +108,15 @@ export default {
eventHub.$emit('nodeDetailsLoaded', this.store.getNodeDetails(nodeId)); eventHub.$emit('nodeDetailsLoaded', this.store.getNodeDetails(nodeId));
}) })
.catch(err => { .catch(err => {
if (err.response && err.response.data) {
this.store.setNodeDetails(nodeId, { this.store.setNodeDetails(nodeId, {
geo_node_id: nodeId, geo_node_id: nodeId,
health: err.message, health: err.message,
health_status: 'Unknown', health_status: 'Unknown',
missing_oauth_application: false, missing_oauth_application: null,
sync_status_unavailable: true, sync_status_unavailable: true,
storage_shards_match: null, storage_shards_match: null,
}); });
eventHub.$emit('nodeDetailsLoaded', this.store.getNodeDetails(nodeId)); eventHub.$emit('nodeDetailsLoaded', this.store.getNodeDetails(nodeId));
} else {
eventHub.$emit('nodeDetailsLoadFailed', nodeId, err);
}
}); });
}, },
repairNode(targetNode) { repairNode(targetNode) {
......
...@@ -46,14 +46,12 @@ export default { ...@@ -46,14 +46,12 @@ export default {
}, },
created() { created() {
eventHub.$on('nodeDetailsLoaded', this.handleNodeDetails); eventHub.$on('nodeDetailsLoaded', this.handleNodeDetails);
eventHub.$on('nodeDetailsLoadFailed', this.handleNodeDetailsFailure);
}, },
mounted() { mounted() {
this.handleMounted(); this.handleMounted();
}, },
beforeDestroy() { beforeDestroy() {
eventHub.$off('nodeDetailsLoaded', this.handleNodeDetails); eventHub.$off('nodeDetailsLoaded', this.handleNodeDetails);
eventHub.$off('nodeDetailsLoadFailed', this.handleNodeDetailsFailure);
}, },
methods: { methods: {
handleNodeDetails(nodeDetails) { handleNodeDetails(nodeDetails) {
...@@ -65,13 +63,6 @@ export default { ...@@ -65,13 +63,6 @@ export default {
this.nodeHealthStatus = nodeDetails.health; this.nodeHealthStatus = nodeDetails.health;
} }
}, },
handleNodeDetailsFailure(nodeId, err) {
if (this.node.id === nodeId) {
this.isNodeDetailsLoading = false;
this.isNodeDetailsFailed = true;
this.errorMessage = err.message;
}
},
handleMounted() { handleMounted() {
eventHub.$emit('pollNodeDetails', this.node); eventHub.$emit('pollNodeDetails', this.node);
}, },
......
---
title: 'Geo: Allow nodes to be editable in more scenarios'
merge_request: 7832
author:
type: changed
...@@ -156,9 +156,9 @@ describe('AppComponent', () => { ...@@ -156,9 +156,9 @@ describe('AppComponent', () => {
.catch(done.fail); .catch(done.fail);
}); });
it('emits `nodeDetailsLoaded` event with fake nodeDetails object on 500 failure', done => { it('emits `nodeDetailsLoaded` event with fake nodeDetails object when a network error occurs', done => {
spyOn(eventHub, '$emit'); spyOn(eventHub, '$emit');
mock.onGet(mockNode.statusPath).reply(500, {}); mock.onGet(mockNode.statusPath).networkError();
spyOn(vm.service, 'getGeoNodeDetails').and.callThrough(); spyOn(vm.service, 'getGeoNodeDetails').and.callThrough();
vm vm
...@@ -168,26 +168,25 @@ describe('AppComponent', () => { ...@@ -168,26 +168,25 @@ describe('AppComponent', () => {
const nodeDetails = vm.store.state.nodeDetails['1']; const nodeDetails = vm.store.state.nodeDetails['1'];
expect(nodeDetails).toBeDefined(); expect(nodeDetails).toBeDefined();
expect(nodeDetails.syncStatusUnavailable).toBe(true); expect(nodeDetails.syncStatusUnavailable).toBe(true);
expect(nodeDetails.health).toBe('Request failed with status code 500'); expect(nodeDetails.health).toBe('Network Error');
}) })
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
}); });
it('emits `nodeDetailsLoadFailed` event on failure when there is no response', done => { it('emits `nodeDetailsLoaded` event with fake nodeDetails object when a timeout occurs', done => {
spyOn(eventHub, '$emit'); spyOn(eventHub, '$emit');
mock.onGet(mockNode.statusPath).reply(500, null); mock.onGet(mockNode.statusPath).timeout();
spyOn(vm.service, 'getGeoNodeDetails').and.callThrough(); spyOn(vm.service, 'getGeoNodeDetails').and.callThrough();
vm vm
.fetchNodeDetails(mockNode) .fetchNodeDetails(mockNode)
.then(() => { .then(() => {
expect(eventHub.$emit).toHaveBeenCalledWith( expect(eventHub.$emit).toHaveBeenCalledWith('nodeDetailsLoaded', jasmine.any(Object));
'nodeDetailsLoadFailed', const nodeDetails = vm.store.state.nodeDetails['1'];
mockNode.id, expect(nodeDetails).toBeDefined();
jasmine.any(Object), expect(nodeDetails.syncStatusUnavailable).toBe(true);
); expect(nodeDetails.health).toBe('timeout of 0ms exceeded');
done();
}) })
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
......
...@@ -99,16 +99,6 @@ describe('GeoNodeItemComponent', () => { ...@@ -99,16 +99,6 @@ describe('GeoNodeItemComponent', () => {
}); });
}); });
describe('handleNodeDetailsFailure', () => {
it('initializes props for Node details failure', () => {
const err = 'Something went wrong';
vm.handleNodeDetailsFailure(1, { message: err });
expect(vm.isNodeDetailsLoading).toBeFalsy();
expect(vm.isNodeDetailsFailed).toBeTruthy();
expect(vm.errorMessage).toBe(err);
});
});
describe('handleMounted', () => { describe('handleMounted', () => {
it('emits `pollNodeDetails` event and passes node ID', () => { it('emits `pollNodeDetails` event and passes node ID', () => {
spyOn(eventHub, '$emit'); spyOn(eventHub, '$emit');
...@@ -125,7 +115,6 @@ describe('GeoNodeItemComponent', () => { ...@@ -125,7 +115,6 @@ describe('GeoNodeItemComponent', () => {
const vmX = createComponent(); const vmX = createComponent();
expect(eventHub.$on).toHaveBeenCalledWith('nodeDetailsLoaded', jasmine.any(Function)); expect(eventHub.$on).toHaveBeenCalledWith('nodeDetailsLoaded', jasmine.any(Function));
expect(eventHub.$on).toHaveBeenCalledWith('nodeDetailsLoadFailed', jasmine.any(Function));
vmX.$destroy(); vmX.$destroy();
}); });
}); });
...@@ -137,7 +126,6 @@ describe('GeoNodeItemComponent', () => { ...@@ -137,7 +126,6 @@ describe('GeoNodeItemComponent', () => {
const vmX = createComponent(); const vmX = createComponent();
vmX.$destroy(); vmX.$destroy();
expect(eventHub.$off).toHaveBeenCalledWith('nodeDetailsLoaded', jasmine.any(Function)); expect(eventHub.$off).toHaveBeenCalledWith('nodeDetailsLoaded', jasmine.any(Function));
expect(eventHub.$off).toHaveBeenCalledWith('nodeDetailsLoadFailed', jasmine.any(Function));
}); });
}); });
......
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