diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-03 00:19:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-03 00:19:21 +0300 |
commit | 90693cc231ba6e1645dc57f2a9111a7b5a5ceae0 (patch) | |
tree | 3b2cffdb40c949b2f061b7fd0f52d3214325cc17 /spec/frontend/graphql_shared | |
parent | b9ce0fe1e6311105b7a748126621f9bfbe37fb2e (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/graphql_shared')
-rw-r--r-- | spec/frontend/graphql_shared/utils_spec.js | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/spec/frontend/graphql_shared/utils_spec.js b/spec/frontend/graphql_shared/utils_spec.js index cd334ef0d97..35ae8de1b1f 100644 --- a/spec/frontend/graphql_shared/utils_spec.js +++ b/spec/frontend/graphql_shared/utils_spec.js @@ -1,3 +1,5 @@ +import Visibility from 'visibilityjs'; + import { isGid, getIdFromGraphQLId, @@ -6,6 +8,8 @@ import { convertFromGraphQLIds, convertNodeIdsFromGraphQLIds, getNodesOrDefault, + toggleQueryPollingByVisibility, + etagQueryHeaders, } from '~/graphql_shared/utils'; const mockType = 'Group'; @@ -160,3 +164,52 @@ describe('getNodesOrDefault', () => { expect(result).toEqual(expected); }); }); + +describe('toggleQueryPollingByVisibility', () => { + let query; + let changeFn; + let interval; + let hidden; + + beforeEach(() => { + hidden = jest.spyOn(Visibility, 'hidden').mockReturnValue(true); + jest.spyOn(Visibility, 'change').mockImplementation((fn) => { + changeFn = fn; + }); + + query = { startPolling: jest.fn(), stopPolling: jest.fn() }; + interval = 5000; + + toggleQueryPollingByVisibility(query, 5000); + }); + + it('starts polling not hidden', () => { + hidden.mockReturnValue(false); + + changeFn(); + expect(query.startPolling).toHaveBeenCalledWith(interval); + }); + + it('stops polling when hidden', () => { + query.stopPolling.mockReset(); + hidden.mockReturnValue(true); + + changeFn(); + expect(query.stopPolling).toHaveBeenCalled(); + }); +}); + +describe('etagQueryHeaders', () => { + it('returns headers necessary for etag caching', () => { + expect(etagQueryHeaders('myFeature', 'myResource')).toEqual({ + fetchOptions: { + method: 'GET', + }, + headers: { + 'X-GITLAB-GRAPHQL-FEATURE-CORRELATION': 'myFeature', + 'X-GITLAB-GRAPHQL-RESOURCE-ETAG': 'myResource', + 'X-Requested-With': 'XMLHttpRequest', + }, + }); + }); +}); |