Commit 12a419dc authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch '229831-allow-refresh-rate-feature-to-be-disabled' into 'master'

Use VisibilityJS instead of document.hidden

Closes #229831

See merge request gitlab-org/gitlab!37189
parents c4247c9c 5a2b9855
<script> <script>
import { n__, __ } from '~/locale'; import Visibility from 'visibilityjs';
import { mapActions } from 'vuex'; import { mapActions } from 'vuex';
import { n__, __ } from '~/locale';
import { import {
GlButtonGroup, GlButtonGroup,
...@@ -98,7 +99,8 @@ export default { ...@@ -98,7 +99,8 @@ export default {
}; };
this.stopAutoRefresh(); this.stopAutoRefresh();
if (document.hidden) {
if (Visibility.hidden()) {
// Inactive tab? Skip fetch and schedule again // Inactive tab? Skip fetch and schedule again
schedule(); schedule();
} else { } else {
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import Visibility from 'visibilityjs';
import { createStore } from '~/monitoring/stores'; import { createStore } from '~/monitoring/stores';
import { GlNewDropdown, GlNewDropdownItem, GlButton } from '@gitlab/ui'; import { GlNewDropdown, GlNewDropdownItem, GlButton } from '@gitlab/ui';
import RefreshButton from '~/monitoring/components/refresh_button.vue'; import RefreshButton from '~/monitoring/components/refresh_button.vue';
describe('RefreshButton', () => { describe('RefreshButton', () => {
...@@ -31,14 +31,8 @@ describe('RefreshButton', () => { ...@@ -31,14 +31,8 @@ describe('RefreshButton', () => {
jest.spyOn(store, 'dispatch').mockResolvedValue(); jest.spyOn(store, 'dispatch').mockResolvedValue();
dispatch = store.dispatch; dispatch = store.dispatch;
// Document can be mock hidden by overriding the `hidden` property
documentHidden = false; documentHidden = false;
Object.defineProperty(document, 'hidden', { jest.spyOn(Visibility, 'hidden').mockImplementation(() => documentHidden);
configurable: true,
get() {
return documentHidden;
},
});
createWrapper(); createWrapper();
}); });
......
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