diff options
author | Winnie Hellmann <winnie@gitlab.com> | 2019-03-23 17:52:35 +0100 |
---|---|---|
committer | Winnie Hellmann <winnie@gitlab.com> | 2019-03-23 17:53:46 +0100 |
commit | 514ee63826e47229bfd03bdbb740f2dd1eae1d03 (patch) | |
tree | 3f0d96a4402e8aa54c375084cc4c5e6cf546824b /spec/frontend/performance_bar | |
parent | 6d330015dfdb1979a0773c87c53b84cc86b28a6d (diff) | |
download | gitlab-ce-514ee63826e47229bfd03bdbb740f2dd1eae1d03.tar.gz |
Move some tests from Karma to Jest
Diffstat (limited to 'spec/frontend/performance_bar')
-rw-r--r-- | spec/frontend/performance_bar/services/performance_bar_service_spec.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/spec/frontend/performance_bar/services/performance_bar_service_spec.js b/spec/frontend/performance_bar/services/performance_bar_service_spec.js new file mode 100644 index 00000000000..cfec4b779e4 --- /dev/null +++ b/spec/frontend/performance_bar/services/performance_bar_service_spec.js @@ -0,0 +1,68 @@ +import PerformanceBarService from '~/performance_bar/services/performance_bar_service'; + +describe('PerformanceBarService', () => { + describe('callbackParams', () => { + describe('fireCallback', () => { + function fireCallback(response, peekUrl) { + return PerformanceBarService.callbackParams(response, peekUrl)[0]; + } + + it('returns false when the request URL is the peek URL', () => { + expect( + fireCallback({ headers: { 'x-request-id': '123' }, url: '/peek' }, '/peek'), + ).toBeFalsy(); + }); + + it('returns false when there is no request ID', () => { + expect(fireCallback({ headers: {}, url: '/request' }, '/peek')).toBeFalsy(); + }); + + it('returns false when the request is an API request', () => { + expect( + fireCallback({ headers: { 'x-request-id': '123' }, url: '/api/' }, '/peek'), + ).toBeFalsy(); + }); + + it('returns false when the response is from the cache', () => { + expect( + fireCallback( + { headers: { 'x-request-id': '123', 'x-gitlab-from-cache': 'true' }, url: '/request' }, + '/peek', + ), + ).toBeFalsy(); + }); + + it('returns true when all conditions are met', () => { + expect( + fireCallback({ headers: { 'x-request-id': '123' }, url: '/request' }, '/peek'), + ).toBeTruthy(); + }); + }); + + describe('requestId', () => { + function requestId(response, peekUrl) { + return PerformanceBarService.callbackParams(response, peekUrl)[1]; + } + + it('gets the request ID from the headers', () => { + expect(requestId({ headers: { 'x-request-id': '123' } }, '/peek')).toEqual('123'); + }); + }); + + describe('requestUrl', () => { + function requestUrl(response, peekUrl) { + return PerformanceBarService.callbackParams(response, peekUrl)[2]; + } + + it('gets the request URL from the response object', () => { + expect(requestUrl({ headers: {}, url: '/request' }, '/peek')).toEqual('/request'); + }); + + it('gets the request URL from response.config if present', () => { + expect( + requestUrl({ headers: {}, config: { url: '/config-url' }, url: '/request' }, '/peek'), + ).toEqual('/config-url'); + }); + }); + }); +}); |