BigW Consortium Gitlab

Added unit tests

parent 75d3ed9a
/* global Flash */
import Spinner from '../../spinner';
import sqljs from 'sql.js';
import Spinner from '../../spinner';
class BalsamiqViewer {
constructor(viewer) {
......@@ -32,7 +32,7 @@ class BalsamiqViewer {
this.initDatabase(loadEvent.target.response);
const previews = this.getPreviews();
const renderedPreviews = previews.map(preview => this.renderPreview(preview, container));
const renderedPreviews = previews.map(preview => this.renderPreview(preview));
container.innerHTML = renderedPreviews.join('');
container.classList.add('list-inline', 'previews');
......@@ -68,7 +68,7 @@ class BalsamiqViewer {
const name = JSON.parse(title[0].values[0][2]).name;
const image = preview.image;
template = template.replace(/{{name}}/, name).replace(/{{image}}/, image);
template = template.replace(/{{name}}/g, name).replace(/{{image}}/g, image);
return template;
}
......
import Spinner from '~/spinner';
import ClassSpecHelper from './helpers/class_spec_helper';
describe('Spinner', () => {
let renderable;
let container;
let spinner;
describe('class constructor', () => {
beforeEach(() => {
renderable = {};
container = {};
spyOn(Spinner, 'createContainer').and.returnValue(container);
spinner = new Spinner(renderable);
});
it('should set .renderable', () => {
expect(spinner.renderable).toBe(renderable);
});
it('should call Spinner.createContainer', () => {
expect(Spinner.createContainer).toHaveBeenCalled();
});
it('should set .container', () => {
expect(spinner.container).toBe(container);
});
});
describe('start', () => {
beforeEach(() => {
renderable = jasmine.createSpyObj('renderable', ['prepend']);
container = {};
spinner = {
renderable,
container,
};
Spinner.prototype.start.call(spinner);
});
it('should call .prepend', () => {
expect(renderable.prepend).toHaveBeenCalledWith(container);
});
});
describe('stop', () => {
beforeEach(() => {
container = jasmine.createSpyObj('container', ['remove']);
spinner = {
container,
};
Spinner.prototype.stop.call(spinner);
});
it('should call .remove', () => {
expect(container.remove).toHaveBeenCalled();
});
});
describe('createContainer', () => {
let createContainer;
beforeEach(() => {
container = {
classList: jasmine.createSpyObj('classList', ['add']),
};
spyOn(document, 'createElement').and.returnValue(container);
createContainer = Spinner.createContainer();
});
ClassSpecHelper.itShouldBeAStaticMethod(Spinner, 'createContainer');
it('should call document.createElement', () => {
expect(document.createElement).toHaveBeenCalledWith('div');
});
it('should call classList.add', () => {
expect(container.classList.add).toHaveBeenCalledWith('loading');
});
it('should return the container element', () => {
expect(createContainer).toBe(container);
});
it('should set the container .innerHTML to Spinner.TEMPLATE', () => {
expect(container.innerHTML).toBe(Spinner.TEMPLATE);
});
});
});
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