Commit 01122b77 authored by Emily Ring's avatar Emily Ring

Adjusted styles and test for mr_widget_terraform

parent e8da2a7b
...@@ -20,16 +20,20 @@ export default { ...@@ -20,16 +20,20 @@ export default {
return { return {
loading: true, loading: true,
plans: {}, plans: {},
poll: null,
}; };
}, },
created() { created() {
this.fetchPlans(); this.fetchPlans();
}, },
beforeDestroy() {
this.poll.stop();
},
methods: { methods: {
fetchPlans() { fetchPlans() {
this.loading = true; this.loading = true;
const poll = new Poll({ this.poll = new Poll({
resource: { resource: {
fetchPlans: () => axios.get(this.endpoint), fetchPlans: () => axios.get(this.endpoint),
}, },
...@@ -40,17 +44,17 @@ export default { ...@@ -40,17 +44,17 @@ export default {
if (Object.keys(this.plans).length) { if (Object.keys(this.plans).length) {
this.loading = false; this.loading = false;
poll.stop(); this.poll.stop();
} }
}, },
errorCallback: () => { errorCallback: () => {
this.plans = { bad_plan: {} }; this.plans = { bad_plan: {} };
this.loading = false; this.loading = false;
poll.stop(); this.poll.stop();
}, },
}); });
poll.makeRequest(); this.poll.makeRequest();
}, },
}, },
}; };
......
...@@ -12,7 +12,6 @@ export default { ...@@ -12,7 +12,6 @@ export default {
props: { props: {
plan: { plan: {
required: true, required: true,
default: () => {},
type: Object, type: Object,
}, },
}, },
...@@ -51,7 +50,9 @@ export default { ...@@ -51,7 +50,9 @@ export default {
<template> <template>
<div class="gl-display-flex"> <div class="gl-display-flex">
<span class="append-right-default gl-align-self-start gl-mt-3"> <span
class="gl-display-flex gl-align-items-center gl-justify-content-center append-right-default gl-align-self-start gl-mt-1"
>
<gl-icon name="status_warning" :size="24" /> <gl-icon name="status_warning" :size="24" />
</span> </span>
...@@ -82,7 +83,7 @@ export default { ...@@ -82,7 +83,7 @@ export default {
</p> </p>
</div> </div>
<div class="terraform-mr-plan-actions"> <div>
<gl-link <gl-link
v-if="plan.job_path" v-if="plan.job_path"
:href="plan.job_path" :href="plan.job_path"
......
...@@ -13,6 +13,8 @@ describe('MrWidgetTerraformConainer', () => { ...@@ -13,6 +13,8 @@ describe('MrWidgetTerraformConainer', () => {
const propsData = { endpoint: '/path/to/terraform/report.json' }; const propsData = { endpoint: '/path/to/terraform/report.json' };
const findPlans = () => wrapper.findAll(TerraformPlan).wrappers.map(x => x.props('plan'));
const mockPollingApi = (response, body, header) => { const mockPollingApi = (response, body, header) => {
mock.onGet(propsData.endpoint).reply(response, body, header); mock.onGet(propsData.endpoint).reply(response, body, header);
}; };
...@@ -44,7 +46,7 @@ describe('MrWidgetTerraformConainer', () => { ...@@ -44,7 +46,7 @@ describe('MrWidgetTerraformConainer', () => {
it('diplays loading skeleton', () => { it('diplays loading skeleton', () => {
expect(wrapper.find(GlSkeletonLoading).exists()).toBe(true); expect(wrapper.find(GlSkeletonLoading).exists()).toBe(true);
expect(wrapper.find(TerraformPlan).exists()).toBe(false); expect(findPlans()).toEqual([]);
}); });
}); });
...@@ -72,7 +74,7 @@ describe('MrWidgetTerraformConainer', () => { ...@@ -72,7 +74,7 @@ describe('MrWidgetTerraformConainer', () => {
it('diplays terraform components and stops loading', () => { it('diplays terraform components and stops loading', () => {
expect(wrapper.find(GlSkeletonLoading).exists()).toBe(false); expect(wrapper.find(GlSkeletonLoading).exists()).toBe(false);
expect(wrapper.findAll(TerraformPlan).length).toEqual(Object.keys(plans).length); expect(findPlans().length).toEqual(Object.keys(plans).length);
}); });
it('does not make additional requests after poll is successful', () => { it('does not make additional requests after poll is successful', () => {
...@@ -92,11 +94,7 @@ describe('MrWidgetTerraformConainer', () => { ...@@ -92,11 +94,7 @@ describe('MrWidgetTerraformConainer', () => {
}); });
it('generates one broken plan', () => { it('generates one broken plan', () => {
const displayPlans = wrapper.findAll(TerraformPlan); expect(findPlans()).toEqual([{}]);
expect(displayPlans.length).toEqual(1);
expect(displayPlans.at(0).props('plan')).toEqual({});
}); });
it('does not make additional requests after poll is unsuccessful', () => { it('does not make additional requests after poll is unsuccessful', () => {
......
...@@ -6,6 +6,8 @@ import TerraformPlan from '~/vue_merge_request_widget/components/terraform/terra ...@@ -6,6 +6,8 @@ import TerraformPlan from '~/vue_merge_request_widget/components/terraform/terra
describe('TerraformPlan', () => { describe('TerraformPlan', () => {
let wrapper; let wrapper;
const findLogButton = () => wrapper.find('.js-terraform-report-link');
const mountWrapper = propsData => { const mountWrapper = propsData => {
wrapper = shallowMount(TerraformPlan, { stubs: { GlLink, GlSprintf }, propsData }); wrapper = shallowMount(TerraformPlan, { stubs: { GlLink, GlSprintf }, propsData });
}; };
...@@ -32,7 +34,8 @@ describe('TerraformPlan', () => { ...@@ -32,7 +34,8 @@ describe('TerraformPlan', () => {
}); });
it('renders button when url is found', () => { it('renders button when url is found', () => {
expect(wrapper.text()).toContain('View full log'); expect(findLogButton().exists()).toBe(true);
expect(findLogButton().text()).toEqual('View full log');
}); });
}); });
...@@ -50,7 +53,7 @@ describe('TerraformPlan', () => { ...@@ -50,7 +53,7 @@ describe('TerraformPlan', () => {
}); });
it('does not render button because url is missing', () => { it('does not render button because url is missing', () => {
expect(wrapper.text()).not.toContain('View full log'); expect(findLogButton().exists()).toBe(false);
}); });
}); });
}); });
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