diff options
author | Phil Hughes <me@iamphill.com> | 2017-04-26 12:19:09 +0300 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-04-27 20:23:27 +0300 |
commit | 88380a04c629d21d39e59a6066cec63b8db89126 (patch) | |
tree | a44799e989a79874bf51097894beab776839b257 /spec/javascripts | |
parent | 95658fb62a955a40260d5b7c4ccd51ce72ae1fb9 (diff) |
Added specs for JS method to switch views
Diffstat (limited to 'spec/javascripts')
-rw-r--r-- | spec/javascripts/blob/viewer/index_spec.js | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/spec/javascripts/blob/viewer/index_spec.js b/spec/javascripts/blob/viewer/index_spec.js index 2031898cf54..13f122b68b2 100644 --- a/spec/javascripts/blob/viewer/index_spec.js +++ b/spec/javascripts/blob/viewer/index_spec.js @@ -1,14 +1,15 @@ /* eslint-disable no-new */ import BlobViewer from '~/blob/viewer/index'; -fdescribe('Blob viewer', () => { +describe('Blob viewer', () => { + let blob; preloadFixtures('blob/show.html.raw'); beforeEach(() => { loadFixtures('blob/show.html.raw'); $('#modal-upload-blob').remove(); - new BlobViewer(); + blob = new BlobViewer(); spyOn($, 'ajax').and.callFake(() => { const d = $.Deferred(); @@ -121,4 +122,40 @@ fdescribe('Blob viewer', () => { }); }); }); + + describe('switchToViewer', () => { + it('removes active class from old viewer button', () => { + blob.switchToViewer('simple'); + + expect( + document.querySelector('.js-blob-viewer-switch-btn.active[data-viewer="rich"]'), + ).toBeNull(); + }); + + it('adds active class to new viewer button', () => { + const simpleBtn = document.querySelector('.js-blob-viewer-switch-btn[data-viewer="simple"]'); + + spyOn(simpleBtn, 'blur'); + + blob.switchToViewer('simple'); + + expect( + simpleBtn.classList.contains('active'), + ).toBeTruthy(); + expect(simpleBtn.blur).toHaveBeenCalled(); + }); + + it('sends AJAX request when switching to simple view', () => { + blob.switchToViewer('simple'); + + expect($.ajax).toHaveBeenCalled(); + }); + + it('does not send AJAX request when switching to rich view', () => { + blob.switchToViewer('simple'); + blob.switchToViewer('rich'); + + expect($.ajax.calls.count()).toBe(1); + }); + }); }); |