diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-20 12:06:17 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-20 12:06:17 +0300 |
commit | 8ac91ecfd1bb445a0a1572b3c0885c41c9037e8a (patch) | |
tree | 4b8c9d2a99ad50ef84421b57758869863ea477a2 /spec/javascripts | |
parent | 7e20809103e1f9c0c96c3a96705224c81bf448d5 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/javascripts')
-rw-r--r-- | spec/javascripts/blob/balsamiq/balsamiq_viewer_spec.js | 63 |
1 files changed, 43 insertions, 20 deletions
diff --git a/spec/javascripts/blob/balsamiq/balsamiq_viewer_spec.js b/spec/javascripts/blob/balsamiq/balsamiq_viewer_spec.js index fd73fb4bfcc..d175c8ba853 100644 --- a/spec/javascripts/blob/balsamiq/balsamiq_viewer_spec.js +++ b/spec/javascripts/blob/balsamiq/balsamiq_viewer_spec.js @@ -1,8 +1,10 @@ import sqljs from 'sql.js'; +import axios from '~/lib/utils/axios_utils'; import BalsamiqViewer from '~/blob/balsamiq/balsamiq_viewer'; import ClassSpecHelper from '../../helpers/class_spec_helper'; describe('BalsamiqViewer', () => { + const mockArrayBuffer = new ArrayBuffer(10); let balsamiqViewer; let viewer; @@ -19,44 +21,65 @@ describe('BalsamiqViewer', () => { }); describe('loadFile', () => { - let xhr; - let loadFile; + let bv; const endpoint = 'endpoint'; + const requestSuccess = Promise.resolve({ + data: mockArrayBuffer, + status: 200, + }); beforeEach(() => { - xhr = jasmine.createSpyObj('xhr', ['open', 'send']); + viewer = {}; + bv = new BalsamiqViewer(viewer); + }); - balsamiqViewer = jasmine.createSpyObj('balsamiqViewer', ['renderFile']); + it('should call `axios.get` on `endpoint` param with responseType set to `arraybuffer', () => { + spyOn(axios, 'get').and.returnValue(requestSuccess); + spyOn(bv, 'renderFile').and.stub(); - spyOn(window, 'XMLHttpRequest').and.returnValue(xhr); + bv.loadFile(endpoint); - loadFile = BalsamiqViewer.prototype.loadFile.call(balsamiqViewer, endpoint); + expect(axios.get).toHaveBeenCalledWith( + endpoint, + jasmine.objectContaining({ + responseType: 'arraybuffer', + }), + ); }); - it('should call .open', () => { - expect(xhr.open).toHaveBeenCalledWith('GET', endpoint, true); - }); + it('should call `renderFile` on request success', done => { + spyOn(axios, 'get').and.returnValue(requestSuccess); + spyOn(bv, 'renderFile').and.callFake(() => {}); - it('should set .responseType', () => { - expect(xhr.responseType).toBe('arraybuffer'); + bv.loadFile(endpoint) + .then(() => { + expect(bv.renderFile).toHaveBeenCalledWith(mockArrayBuffer); + }) + .then(done) + .catch(done.fail); }); - it('should call .send', () => { - expect(xhr.send).toHaveBeenCalled(); - }); + it('should not call `renderFile` on request failure', done => { + spyOn(axios, 'get').and.returnValue(Promise.reject()); + spyOn(bv, 'renderFile'); - it('should return a promise', () => { - expect(loadFile).toEqual(jasmine.any(Promise)); + bv.loadFile(endpoint) + .then(() => { + done.fail('Expected loadFile to throw error!'); + }) + .catch(() => { + expect(bv.renderFile).not.toHaveBeenCalled(); + }) + .then(done) + .catch(done.fail); }); }); describe('renderFile', () => { let container; - let loadEvent; let previews; beforeEach(() => { - loadEvent = { target: { response: {} } }; viewer = jasmine.createSpyObj('viewer', ['appendChild']); previews = [document.createElement('ul'), document.createElement('ul')]; @@ -73,11 +96,11 @@ describe('BalsamiqViewer', () => { container = containerElement; }); - BalsamiqViewer.prototype.renderFile.call(balsamiqViewer, loadEvent); + BalsamiqViewer.prototype.renderFile.call(balsamiqViewer, mockArrayBuffer); }); it('should call .initDatabase', () => { - expect(balsamiqViewer.initDatabase).toHaveBeenCalledWith(loadEvent.target.response); + expect(balsamiqViewer.initDatabase).toHaveBeenCalledWith(mockArrayBuffer); }); it('should call .getPreviews', () => { |