Commit 6ca1b292 authored by Denys Mishunov's avatar Denys Mishunov

Merge branch 'emilyring-terraform-mr-fix' into 'master'

Remove Visibility from terraform widget

See merge request gitlab-org/gitlab!30737
parents 1a734ee2 5f514d11
...@@ -5,7 +5,6 @@ import axios from '~/lib/utils/axios_utils'; ...@@ -5,7 +5,6 @@ import axios from '~/lib/utils/axios_utils';
import CiIcon from '../../vue_shared/components/ci_icon.vue'; import CiIcon from '../../vue_shared/components/ci_icon.vue';
import flash from '~/flash'; import flash from '~/flash';
import Poll from '~/lib/utils/poll'; import Poll from '~/lib/utils/poll';
import Visibility from 'visibilityjs';
export default { export default {
name: 'MRWidgetTerraformPlan', name: 'MRWidgetTerraformPlan',
...@@ -68,7 +67,11 @@ export default { ...@@ -68,7 +67,11 @@ export default {
method: 'fetchPlans', method: 'fetchPlans',
successCallback: ({ data }) => { successCallback: ({ data }) => {
this.plans = data; this.plans = data;
if (Object.keys(this.plan).length) {
this.loading = false; this.loading = false;
poll.stop();
}
}, },
errorCallback: () => { errorCallback: () => {
this.plans = {}; this.plans = {};
...@@ -77,17 +80,7 @@ export default { ...@@ -77,17 +80,7 @@ export default {
}, },
}); });
if (!Visibility.hidden()) {
poll.makeRequest(); poll.makeRequest();
}
Visibility.change(() => {
if (!Visibility.hidden()) {
poll.restart();
} else {
poll.stop();
}
});
}, },
}, },
}; };
......
---
title: Remove Visibility from terraform widget
merge_request: 30737
author:
type: fixed
...@@ -3,6 +3,7 @@ import { shallowMount } from '@vue/test-utils'; ...@@ -3,6 +3,7 @@ import { shallowMount } from '@vue/test-utils';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import MrWidgetTerraformPlan from '~/vue_merge_request_widget/components/mr_widget_terraform_plan.vue'; import MrWidgetTerraformPlan from '~/vue_merge_request_widget/components/mr_widget_terraform_plan.vue';
import Poll from '~/lib/utils/poll';
const plan = { const plan = {
create: 10, create: 10,
...@@ -57,11 +58,23 @@ describe('MrWidgetTerraformPlan', () => { ...@@ -57,11 +58,23 @@ describe('MrWidgetTerraformPlan', () => {
}); });
describe('successful poll', () => { describe('successful poll', () => {
let pollRequest;
let pollStop;
beforeEach(() => { beforeEach(() => {
pollRequest = jest.spyOn(Poll.prototype, 'makeRequest');
pollStop = jest.spyOn(Poll.prototype, 'stop');
mockPollingApi(200, { 'tfplan.json': plan }, {}); mockPollingApi(200, { 'tfplan.json': plan }, {});
return mountWrapper(); return mountWrapper();
}); });
afterEach(() => {
pollRequest.mockRestore();
pollStop.mockRestore();
});
it('content change text', () => { it('content change text', () => {
expect(wrapper.find(GlSprintf).exists()).toBe(true); expect(wrapper.find(GlSprintf).exists()).toBe(true);
}); });
...@@ -69,6 +82,11 @@ describe('MrWidgetTerraformPlan', () => { ...@@ -69,6 +82,11 @@ describe('MrWidgetTerraformPlan', () => {
it('renders button when url is found', () => { it('renders button when url is found', () => {
expect(wrapper.find('a').text()).toContain('View full log'); expect(wrapper.find('a').text()).toContain('View full log');
}); });
it('does not make additional requests after poll is successful', () => {
expect(pollRequest).toHaveBeenCalledTimes(1);
expect(pollStop).toHaveBeenCalledTimes(1);
});
}); });
describe('polling fails', () => { describe('polling fails', () => {
......
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