Commit 88380a04 authored by Phil Hughes's avatar Phil Hughes Committed by Douwe Maan

Added specs for JS method to switch views

parent 95658fb6
/* eslint-disable no-new */ /* eslint-disable no-new */
import BlobViewer from '~/blob/viewer/index'; import BlobViewer from '~/blob/viewer/index';
fdescribe('Blob viewer', () => { describe('Blob viewer', () => {
let blob;
preloadFixtures('blob/show.html.raw'); preloadFixtures('blob/show.html.raw');
beforeEach(() => { beforeEach(() => {
loadFixtures('blob/show.html.raw'); loadFixtures('blob/show.html.raw');
$('#modal-upload-blob').remove(); $('#modal-upload-blob').remove();
new BlobViewer(); blob = new BlobViewer();
spyOn($, 'ajax').and.callFake(() => { spyOn($, 'ajax').and.callFake(() => {
const d = $.Deferred(); const d = $.Deferred();
...@@ -121,4 +122,40 @@ fdescribe('Blob viewer', () => { ...@@ -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);
});
});
}); });
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