Commit b244f028 authored by Martin Wortschack's avatar Martin Wortschack

Merge branch '211862_02-cleanup-unused-errors' into 'master'

Cleanup Legacy Geo Errors

See merge request gitlab-org/gitlab!29823
parents 4b98cead 4c11b1fd
<script>
import { GlLoadingIcon } from '@gitlab/ui';
import { s__ } from '~/locale';
import icon from '~/vue_shared/components/icon.vue';
import tooltip from '~/vue_shared/directives/tooltip';
......@@ -17,49 +16,17 @@ export default {
type: Object,
required: true,
},
nodeDetails: {
type: Object,
required: true,
},
nodeDetailsLoading: {
type: Boolean,
required: true,
},
nodeDetailsFailed: {
type: Boolean,
required: true,
},
},
computed: {
isNodeHTTP() {
return this.node.url.startsWith('http://');
},
showNodeStatusIcon() {
if (this.nodeDetailsLoading) {
return false;
}
return this.isNodeHTTP || this.nodeDetailsFailed;
},
nodeStatusIconClass() {
return [
'ml-2',
{ 'text-danger-500': this.nodeDetailsFailed, 'text-warning-500': !this.nodeDetailsFailed },
];
},
nodeStatusIconName() {
if (this.nodeDetailsFailed) {
return 'status_failed_borderless';
}
return 'warning';
},
nodeStatusIconTooltip() {
if (this.nodeDetailsFailed) {
return '';
}
return s__(
'GeoNodes|You have configured Geo nodes using an insecure HTTP connection. We recommend the use of HTTPS.',
);
showNodeWarningIcon() {
return !this.nodeDetailsLoading && this.isNodeHTTP;
},
},
};
......@@ -76,12 +43,16 @@ export default {
class="node-details-loading prepend-left-10 inline"
/>
<icon
v-if="showNodeStatusIcon"
v-if="showNodeWarningIcon"
v-tooltip
:name="nodeStatusIconName"
class="ml-2 text-warning-500"
name="warning"
:size="18"
:class="nodeStatusIconClass"
:title="nodeStatusIconTooltip"
:title="
s__(
'GeoNodes|You have configured Geo nodes using an insecure HTTP connection. We recommend the use of HTTPS.',
)
"
data-container="body"
data-placement="bottom"
/>
......
<script>
import { GlLink } from '@gitlab/ui';
import eventHub from '../event_hub';
import GeoNodeHeader from './geo_node_header.vue';
......@@ -8,7 +6,6 @@ import GeoNodeDetails from './geo_node_details.vue';
export default {
components: {
GlLink,
GeoNodeHeader,
GeoNodeDetails,
},
......@@ -41,20 +38,10 @@ export default {
data() {
return {
isNodeDetailsLoading: true,
isNodeDetailsFailed: false,
nodeHealthStatus: '',
errorMessage: '',
nodeDetails: {},
};
},
computed: {
showNodeDetails() {
if (!this.isNodeDetailsLoading) {
return !this.isNodeDetailsFailed;
}
return false;
},
},
created() {
eventHub.$on('nodeDetailsLoaded', this.handleNodeDetails);
},
......@@ -68,8 +55,6 @@ export default {
handleNodeDetails(nodeDetails) {
if (this.node.id === nodeDetails.id) {
this.isNodeDetailsLoading = false;
this.isNodeDetailsFailed = false;
this.errorMessage = '';
this.nodeDetails = nodeDetails;
this.nodeHealthStatus = nodeDetails.health;
}
......@@ -83,14 +68,9 @@ export default {
<template>
<div :class="{ 'node-action-active': node.nodeActionActive }" class="card">
<geo-node-header
:node="node"
:node-details="nodeDetails"
:node-details-loading="isNodeDetailsLoading"
:node-details-failed="isNodeDetailsFailed"
/>
<geo-node-header :node="node" :node-details-loading="isNodeDetailsLoading" />
<geo-node-details
v-if="showNodeDetails"
v-if="!isNodeDetailsLoading"
:node="node"
:node-details="nodeDetails"
:node-edit-allowed="nodeEditAllowed"
......@@ -98,13 +78,5 @@ export default {
:node-removal-allowed="nodeRemovalAllowed"
:geo-troubleshooting-help-path="geoTroubleshootingHelpPath"
/>
<div v-if="isNodeDetailsFailed">
<p class="p-3 mb-0 bg-danger-100 text-danger-500">
{{ errorMessage
}}<gl-link :href="geoTroubleshootingHelpPath">{{
s__('Geo|Please refer to Geo Troubleshooting.')
}}</gl-link>
</p>
</div>
</div>
</template>
......@@ -48,47 +48,24 @@ describe('GeoNodeHeader', () => {
});
});
describe('showNodeStatusIcon', () => {
it('returns `false` when Node details are still loading', done => {
vm.nodeDetailsLoading = true;
Vue.nextTick()
.then(() => {
expect(vm.showNodeStatusIcon).toBe(false);
})
.then(done)
.catch(done.fail);
describe.each`
nodeDetailsLoading | url | showWarning
${false} | ${'https://127.0.0.1:3001'} | ${false}
${false} | ${'http://127.0.0.1:3001'} | ${true}
${true} | ${'https://127.0.0.1:3001'} | ${false}
${true} | ${'http://127.0.0.1:3001'} | ${false}
`(`showNodeWarningIcon`, ({ nodeDetailsLoading, url, showWarning }) => {
beforeEach(() => {
vm.nodeDetailsLoading = nodeDetailsLoading;
vm.node.url = url;
});
it('returns `true` when Node details failed to load', done => {
vm.nodeDetailsFailed = true;
Vue.nextTick()
.then(() => {
expect(vm.showNodeStatusIcon).toBe(true);
})
.then(done)
.catch(done.fail);
it(`should return ${showWarning}`, () => {
expect(vm.showNodeWarningIcon).toBe(showWarning);
});
it('returns `true` when Node details loaded and Node URL is non-HTTPS', done => {
vm.nodeDetailsLoading = false;
vm.nodeDetailsFailed = false;
vm.node.url = mockNode.url;
Vue.nextTick()
.then(() => {
expect(vm.showNodeStatusIcon).toBe(true);
})
.then(done)
.catch(done.fail);
});
it('returns `false` when Node details loaded and Node URL is HTTPS', done => {
vm.node.url = 'https://127.0.0.1:3001/';
Vue.nextTick()
.then(() => {
expect(vm.showNodeStatusIcon).toBe(false);
})
.then(done)
.catch(done.fail);
it(`should ${showWarning ? 'render' : 'not render'} the status icon`, () => {
expect(Boolean(vm.$el.querySelector('.ic-warning'))).toBe(showWarning);
});
});
});
......
import { shallowMount } from '@vue/test-utils';
import { GlLink } from '@gitlab/ui';
import geoNodeItemComponent from 'ee/geo_nodes/components/geo_node_item.vue';
import GeoNodeDetails from 'ee/geo_nodes/components/geo_node_details.vue';
import eventHub from 'ee/geo_nodes/event_hub';
import { mockNode, mockNodeDetails } from '../mock_data';
......@@ -32,6 +32,8 @@ describe('GeoNodeItemComponent', () => {
createComponent();
});
const findGeoNodeDetails = () => wrapper.find(GeoNodeDetails);
afterEach(() => {
wrapper.destroy();
});
......@@ -39,50 +41,11 @@ describe('GeoNodeItemComponent', () => {
describe('data', () => {
it('returns default data props', () => {
expect(wrapper.vm.isNodeDetailsLoading).toBe(true);
expect(wrapper.vm.isNodeDetailsFailed).toBe(false);
expect(wrapper.vm.nodeHealthStatus).toBe('');
expect(wrapper.vm.errorMessage).toBe('');
expect(typeof wrapper.vm.nodeDetails).toBe('object');
});
});
describe('computed', () => {
let httpsNode;
beforeEach(() => {
// Altered mock data for secure URL
httpsNode = Object.assign({}, mockNode, {
id: mockNodeDetails.id,
url: 'https://127.0.0.1:3001/',
});
createComponent({ node: httpsNode });
});
describe('showNodeDetails', () => {
it('returns `false` if Node details are still loading', () => {
wrapper.vm.isNodeDetailsLoading = true;
expect(wrapper.vm.showNodeDetails).toBeFalsy();
});
it('returns `false` if Node details failed to load', () => {
wrapper.vm.isNodeDetailsLoading = false;
wrapper.vm.isNodeDetailsFailed = true;
expect(wrapper.vm.showNodeDetails).toBeFalsy();
});
it('returns `true` if Node details loaded', () => {
wrapper.vm.handleNodeDetails(mockNodeDetails);
wrapper.vm.isNodeDetailsLoading = false;
wrapper.vm.isNodeDetailsFailed = false;
expect(wrapper.vm.showNodeDetails).toBeTruthy();
});
});
});
describe('methods', () => {
describe('handleNodeDetails', () => {
describe('with matching ID', () => {
......@@ -100,8 +63,6 @@ describe('GeoNodeItemComponent', () => {
wrapper.vm.handleNodeDetails(mockNodeDetails);
expect(wrapper.vm.isNodeDetailsLoading).toBeFalsy();
expect(wrapper.vm.isNodeDetailsFailed).toBeFalsy();
expect(wrapper.vm.errorMessage).toBe('');
expect(wrapper.vm.nodeDetails).toBe(mockNodeDetails);
expect(wrapper.vm.nodeHealthStatus).toBe(mockNodeDetails.health);
});
......@@ -144,27 +105,26 @@ describe('GeoNodeItemComponent', () => {
describe('template', () => {
it('renders container element', () => {
expect(wrapper.vm.$el.classList.contains('card', 'geo-node-item')).toBe(true);
expect(wrapper.classes('card')).toBeTruthy();
});
describe('with error', () => {
let err;
describe('when isNodeDetailsLoading is true', () => {
beforeEach(() => {
err = 'Something error message';
wrapper.setData({ errorMessage: err, isNodeDetailsFailed: true });
wrapper.setData({ isNodeDetailsLoading: true });
});
it('renders node error message', () => {
const findErrorMessage = () => wrapper.find('.bg-danger-100');
it('does not render details section', () => {
expect(findGeoNodeDetails().exists()).toBeFalsy();
});
});
describe('when isNodeDetailsLoading is false', () => {
beforeEach(() => {
wrapper.setData({ isNodeDetailsLoading: false });
});
expect(findErrorMessage().exists()).toBeTruthy();
expect(findErrorMessage().text()).toContain(err);
expect(
findErrorMessage()
.find(GlLink)
.attributes('href'),
).toBe('/foo/bar');
it('renders details section', () => {
expect(findGeoNodeDetails().exists()).toBeTruthy();
});
});
});
......
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