Commit 33df949e authored by Phil Hughes's avatar Phil Hughes

updated specs

[ci skip]
parent b48516fe
...@@ -9,6 +9,13 @@ import MRWidgetService from '../services/mr_widget_service'; ...@@ -9,6 +9,13 @@ import MRWidgetService from '../services/mr_widget_service';
export default { export default {
name: 'Deployment', name: 'Deployment',
components: {
MemoryUsage,
StatusIcon,
},
directives: {
tooltip,
},
mixins: [ mixins: [
timeagoMixin, timeagoMixin,
], ],
...@@ -18,22 +25,21 @@ export default { ...@@ -18,22 +25,21 @@ export default {
required: true, required: true,
}, },
}, },
components: {
MemoryUsage,
StatusIcon,
},
computed: { computed: {
deployTimeago() { deployTimeago() {
return this.timeFormated(this.deployment.deployed_at); return this.timeFormated(this.deployment.deployed_at);
}, },
hasExternalUrls() { hasExternalUrls() {
return this.deployment.external_url && this.deployment.external_url_formatted; return !!(this.deployment.external_url && this.deployment.external_url_formatted);
}, },
hasDeploymentTime() { hasDeploymentTime() {
return this.deployment.deployed_at && this.deployment.deployed_at_formatted; return !!(this.deployment.deployed_at && this.deployment.deployed_at_formatted);
}, },
hasDeploymentMeta() { hasDeploymentMeta() {
return this.deployment.url && this.deployment.name; return !!(this.deployment.url && this.deployment.name);
},
hasMetrics() {
return !!(this.deployment.metrics_url);
}, },
}, },
methods: { methods: {
...@@ -67,7 +73,8 @@ export default { ...@@ -67,7 +73,8 @@ export default {
<div class="media-body"> <div class="media-body">
<div class="deploy-body"> <div class="deploy-body">
<span <span
v-if="hasDeploymentMeta"> v-if="hasDeploymentMeta"
>
Deployed to Deployed to
</span> </span>
<span class="deploy-link"> <span class="deploy-link">
...@@ -77,11 +84,12 @@ export default { ...@@ -77,11 +84,12 @@ export default {
target="_blank" target="_blank"
rel="noopener noreferrer nofollow" rel="noopener noreferrer nofollow"
class="js-deploy-meta"> class="js-deploy-meta">
{{deployment.name}} {{ deployment.name }}
</a> </a>
</span> </span>
<span <span
v-if="hasExternalUrls"> v-if="hasExternalUrls"
>
on on
</span> </span>
<span class="deploy-link"> <span class="deploy-link">
...@@ -93,8 +101,10 @@ export default { ...@@ -93,8 +101,10 @@ export default {
class="js-deploy-url"> class="js-deploy-url">
<i <i
class="fa fa-external-link" class="fa fa-external-link"
aria-hidden="true" /> aria-hidden="true"
{{deployment.external_url_formatted}} >
</i>
{{ deployment.external_url_formatted }}
</a> </a>
</span> </span>
<span <span
...@@ -103,7 +113,7 @@ export default { ...@@ -103,7 +113,7 @@ export default {
class="js-deploy-time" class="js-deploy-time"
data-toggle="tooltip" data-toggle="tooltip"
data-placement="top"> data-placement="top">
{{deployTimeago}} {{ deployTimeago }}
</span> </span>
<button <button
type="button" type="button"
...@@ -114,7 +124,7 @@ export default { ...@@ -114,7 +124,7 @@ export default {
</button> </button>
</div> </div>
<memory-usage <memory-usage
v-if="deployment.metrics_url" v-if="hasMetrics"
:metrics-url="deployment.metrics_url" :metrics-url="deployment.metrics_url"
:metrics-monitoring-url="deployment.metrics_monitoring_url" :metrics-monitoring-url="deployment.metrics_monitoring_url"
/> />
......
import Vue from 'vue'; import Vue from 'vue';
import * as urlUtils from '~/lib/utils/url_utility'; import * as urlUtils from '~/lib/utils/url_utility';
import deploymentComponent from '~/vue_merge_request_widget/components/mr_widget_deployment'; import deploymentComponent from '~/vue_merge_request_widget/components/deployment.vue';
import MRWidgetService from '~/vue_merge_request_widget/services/mr_widget_service'; import MRWidgetService from '~/vue_merge_request_widget/services/mr_widget_service';
import { getTimeago } from '~/lib/utils/datetime_utility'; import { getTimeago } from '~/lib/utils/datetime_utility';
const deploymentMockData = [ const deploymentMockData = {
{ id: 15,
id: 15, name: 'review/diplo',
name: 'review/diplo', url: '/root/acets-review-apps/environments/15',
url: '/root/acets-review-apps/environments/15', stop_url: '/root/acets-review-apps/environments/15/stop',
stop_url: '/root/acets-review-apps/environments/15/stop', metrics_url: '/root/acets-review-apps/environments/15/deployments/1/metrics',
metrics_url: '/root/acets-review-apps/environments/15/deployments/1/metrics', metrics_monitoring_url: '/root/acets-review-apps/environments/15/metrics',
metrics_monitoring_url: '/root/acets-review-apps/environments/15/metrics', external_url: 'http://diplo.',
external_url: 'http://diplo.', external_url_formatted: 'diplo.',
external_url_formatted: 'diplo.', deployed_at: '2017-03-22T22:44:42.258Z',
deployed_at: '2017-03-22T22:44:42.258Z', deployed_at_formatted: 'Mar 22, 2017 10:44pm',
deployed_at_formatted: 'Mar 22, 2017 10:44pm', };
},
];
const createComponent = () => { const createComponent = () => {
const Component = Vue.extend(deploymentComponent); const Component = Vue.extend(deploymentComponent);
const mr = {
deployments: deploymentMockData,
};
const service = {};
return new Component({ return new Component({
el: document.createElement('div'), el: document.createElement('div'),
propsData: { mr, service }, propsData: { deployment: { ...deploymentMockData } },
}); });
}; };
describe('MRWidgetDeployment', () => { describe('Deployment component', () => {
describe('props', () => { let vm;
it('should have props', () => {
const { mr, service } = deploymentComponent.props;
expect(mr.type instanceof Object).toBeTruthy();
expect(mr.required).toBeTruthy();
expect(service.type instanceof Object).toBeTruthy(); beforeEach(() => {
expect(service.required).toBeTruthy(); vm = createComponent();
});
}); });
describe('methods', () => { afterEach(() => {
let vm = createComponent(); vm.$destroy();
const deployment = deploymentMockData[0]; });
describe('formatDate', () => { describe('computed', () => {
it('should work', () => { describe('deployTimeago', () => {
const readable = getTimeago().format(deployment.deployed_at); it('return formatted date', () => {
expect(vm.formatDate(deployment.deployed_at)).toEqual(readable); const readable = getTimeago().format(deploymentMockData.deployed_at);
expect(vm.deployTimeago).toEqual(readable);
}); });
}); });
describe('hasExternalUrls', () => { describe('hasExternalUrls', () => {
it('should return true', () => { it('should return true', () => {
expect(vm.hasExternalUrls(deployment)).toBeTruthy(); expect(vm.hasExternalUrls).toEqual(true);
});
it('should return false when deployment has no external_url_formatted', () => {
vm.deployment.external_url_formatted = null;
expect(vm.hasExternalUrls).toEqual(false);
}); });
it('should return false when there is not enough information', () => { it('should return false when deployment has no external_url', () => {
expect(vm.hasExternalUrls()).toBeFalsy(); vm.deployment.external_url = null;
expect(vm.hasExternalUrls({ external_url: 'Diplo' })).toBeFalsy();
expect(vm.hasExternalUrls({ external_url_formatted: 'Diplo' })).toBeFalsy(); expect(vm.hasExternalUrls).toEqual(false);
}); });
}); });
describe('hasDeploymentTime', () => { describe('hasDeploymentTime', () => {
it('should return true', () => { it('should return true', () => {
expect(vm.hasDeploymentTime(deployment)).toBeTruthy(); expect(vm.hasDeploymentTime).toEqual(true);
}); });
it('should return false when there is not enough information', () => { it('should return false when deployment has no deployed_at', () => {
expect(vm.hasDeploymentTime()).toBeFalsy(); vm.deployment.deployed_at = null;
expect(vm.hasDeploymentTime({ deployed_at: 'Diplo' })).toBeFalsy();
expect(vm.hasDeploymentTime({ deployed_at_formatted: 'Diplo' })).toBeFalsy(); expect(vm.hasDeploymentTime).toEqual(false);
});
it('should return false when deployment has no deployed_at_formatted', () => {
vm.deployment.deployed_at_formatted = null;
expect(vm.hasDeploymentTime).toEqual(false);
}); });
}); });
describe('hasDeploymentMeta', () => { describe('hasDeploymentMeta', () => {
it('should return true', () => { it('should return true', () => {
expect(vm.hasDeploymentMeta(deployment)).toBeTruthy(); expect(vm.hasDeploymentMeta).toEqual(true);
}); });
it('should return false when there is not enough information', () => { it('should return false when deployment has no url', () => {
expect(vm.hasDeploymentMeta()).toBeFalsy(); vm.deployment.url = null;
expect(vm.hasDeploymentMeta({ url: 'Diplo' })).toBeFalsy();
expect(vm.hasDeploymentMeta({ name: 'Diplo' })).toBeFalsy(); expect(vm.hasDeploymentMeta).toEqual(false);
});
it('should return false when deployment has no name', () => {
vm.deployment.name = null;
expect(vm.hasDeploymentMeta).toEqual(false);
}); });
}); });
});
describe('methods', () => {
describe('stopEnvironment', () => { describe('stopEnvironment', () => {
const url = '/foo/bar'; const url = '/foo/bar';
const returnPromise = () => new Promise((resolve) => { const returnPromise = () => new Promise((resolve) => {
...@@ -131,9 +140,7 @@ describe('MRWidgetDeployment', () => { ...@@ -131,9 +140,7 @@ describe('MRWidgetDeployment', () => {
}); });
describe('template', () => { describe('template', () => {
let vm;
let el; let el;
const [deployment] = deploymentMockData;
beforeEach(() => { beforeEach(() => {
vm = createComponent(deploymentMockData); vm = createComponent(deploymentMockData);
...@@ -141,39 +148,15 @@ describe('MRWidgetDeployment', () => { ...@@ -141,39 +148,15 @@ describe('MRWidgetDeployment', () => {
}); });
it('should render template elements correctly', () => { it('should render template elements correctly', () => {
expect(el.classList.contains('mr-widget-heading')).toBeTruthy(); expect(el.classList.contains('mr-widget-heading')).toEqual(true);
expect(el.querySelector('.js-icon-link')).toBeDefined(); expect(el.querySelector('.js-icon-link')).not.toBeNull();
expect(el.querySelector('.js-deploy-meta').getAttribute('href')).toEqual(deployment.url); expect(el.querySelector('.js-deploy-meta').getAttribute('href')).toEqual(deploymentMockData.url);
expect(el.querySelector('.js-deploy-meta').innerText).toContain(deployment.name); expect(el.querySelector('.js-deploy-meta').innerText).toContain(deploymentMockData.name);
expect(el.querySelector('.js-deploy-url').getAttribute('href')).toEqual(deployment.external_url); expect(el.querySelector('.js-deploy-url').getAttribute('href')).toEqual(deploymentMockData.external_url);
expect(el.querySelector('.js-deploy-url').innerText).toContain(deployment.external_url_formatted); expect(el.querySelector('.js-deploy-url').innerText).toContain(deploymentMockData.external_url_formatted);
expect(el.querySelector('.js-deploy-time').innerText).toContain(vm.formatDate(deployment.deployed_at)); expect(el.querySelector('.js-deploy-time').innerText).toContain(vm.deployTimeago);
expect(el.querySelector('.js-mr-memory-usage')).toBeDefined(); expect(el.querySelector('.js-mr-memory-usage')).not.toBeNull();
expect(el.querySelector('button')).toBeDefined(); expect(el.querySelector('button')).not.toBeNull();
});
it('should list multiple deployments', (done) => {
vm.mr.deployments.push(deployment);
vm.mr.deployments.push(deployment);
Vue.nextTick(() => {
expect(el.querySelectorAll('.ci-widget').length).toEqual(3);
expect(el.querySelectorAll('.js-mr-memory-usage').length).toEqual(3);
done();
});
});
it('should not have some elements when there is not enough data', (done) => {
vm.mr.deployments = [{}];
Vue.nextTick(() => {
expect(el.querySelectorAll('.js-deploy-meta').length).toEqual(0);
expect(el.querySelectorAll('.js-deploy-url').length).toEqual(0);
expect(el.querySelectorAll('.js-deploy-time').length).toEqual(0);
expect(el.querySelectorAll('.js-mr-memory-usage').length).toEqual(0);
expect(el.querySelectorAll('.button').length).toEqual(0);
done();
});
}); });
}); });
}); });
...@@ -12,7 +12,7 @@ const returnPromise = data => new Promise((resolve) => { ...@@ -12,7 +12,7 @@ const returnPromise = data => new Promise((resolve) => {
}); });
}); });
describe('mrWidgetOptions', () => { fdescribe('mrWidgetOptions', () => {
let vm; let vm;
let MrWidgetOptions; let MrWidgetOptions;
...@@ -189,16 +189,16 @@ describe('mrWidgetOptions', () => { ...@@ -189,16 +189,16 @@ describe('mrWidgetOptions', () => {
describe('fetchDeployments', () => { describe('fetchDeployments', () => {
it('should fetch deployments', (done) => { it('should fetch deployments', (done) => {
spyOn(vm.service, 'fetchDeployments').and.returnValue(returnPromise([{ deployment: 1 }])); spyOn(vm.service, 'fetchDeployments').and.returnValue(returnPromise([{ id: 1 }]));
vm.fetchDeployments(); vm.fetchDeployments();
setTimeout(() => { setTimeout(() => {
expect(vm.service.fetchDeployments).toHaveBeenCalled(); expect(vm.service.fetchDeployments).toHaveBeenCalled();
expect(vm.mr.deployments.length).toEqual(1); expect(vm.mr.deployments.length).toEqual(1);
expect(vm.mr.deployments[0].deployment).toEqual(1); expect(vm.mr.deployments[0].id).toBe(1);
done(); done();
}, 333); });
}); });
}); });
...@@ -374,7 +374,7 @@ describe('mrWidgetOptions', () => { ...@@ -374,7 +374,7 @@ describe('mrWidgetOptions', () => {
expect(comps['mr-widget-header']).toBeDefined(); expect(comps['mr-widget-header']).toBeDefined();
expect(comps['mr-widget-merge-help']).toBeDefined(); expect(comps['mr-widget-merge-help']).toBeDefined();
expect(comps['mr-widget-pipeline']).toBeDefined(); expect(comps['mr-widget-pipeline']).toBeDefined();
expect(comps['mr-widget-deployment']).toBeDefined(); expect(comps.Deployment).toBeDefined();
expect(comps['mr-widget-related-links']).toBeDefined(); expect(comps['mr-widget-related-links']).toBeDefined();
expect(comps['mr-widget-merged']).toBeDefined(); expect(comps['mr-widget-merged']).toBeDefined();
expect(comps['mr-widget-closed']).toBeDefined(); expect(comps['mr-widget-closed']).toBeDefined();
...@@ -454,4 +454,34 @@ describe('mrWidgetOptions', () => { ...@@ -454,4 +454,34 @@ describe('mrWidgetOptions', () => {
}); });
}); });
}); });
describe('rendering deployments', () => {
const deploymentMockData = {
id: 15,
name: 'review/diplo',
url: '/root/acets-review-apps/environments/15',
stop_url: '/root/acets-review-apps/environments/15/stop',
metrics_url: '/root/acets-review-apps/environments/15/deployments/1/metrics',
metrics_monitoring_url: '/root/acets-review-apps/environments/15/metrics',
external_url: 'http://diplo.',
external_url_formatted: 'diplo.',
deployed_at: '2017-03-22T22:44:42.258Z',
deployed_at_formatted: 'Mar 22, 2017 10:44pm',
};
beforeEach((done) => {
vm.mr.deployments.push({
...deploymentMockData,
}, {
...deploymentMockData,
id: deploymentMockData.id + 1,
});
vm.$nextTick(done);
});
it('renders multiple deployments', () => {
expect(vm.$el.querySelectorAll('.deploy-heading').length).toBe(2);
});
});
}); });
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