mirror of
https://github.com/wekan/wekan.git
synced 2025-12-22 02:10:12 +01:00
initial tests added
This commit is contained in:
parent
7daa67c792
commit
20452d7296
5 changed files with 252 additions and 7 deletions
101
client/lib/tests/Utils.tests.js
Normal file
101
client/lib/tests/Utils.tests.js
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
/* eslint-env mocha */
|
||||
import sinon from 'sinon';
|
||||
import { expect } from 'chai';
|
||||
import { Random } from 'meteor/random';
|
||||
import '../utils';
|
||||
|
||||
|
||||
describe('Utils', function() {
|
||||
beforeEach(function() {
|
||||
sinon.stub(Utils, 'reload').callsFake(() => {});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
window.localStorage.removeItem(boardView);
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
const boardView = 'boardView';
|
||||
|
||||
describe(Utils.setBoardView.name, function() {
|
||||
it('sets the board view if the user exists', function(done) {
|
||||
const viewId = Random.id();
|
||||
const user = {
|
||||
setBoardView: (view) => {
|
||||
expect(view).to.equal(viewId);
|
||||
done();
|
||||
},
|
||||
};
|
||||
sinon.stub(Meteor, 'user').callsFake(() => user);
|
||||
Utils.setBoardView(viewId);
|
||||
|
||||
expect(window.localStorage.getItem(boardView)).to.equal(viewId);
|
||||
});
|
||||
|
||||
it('sets a specific view if no user exists but a view is defined', function() {
|
||||
const views = [
|
||||
'board-view-swimlanes',
|
||||
'board-view-lists',
|
||||
'board-view-cal'
|
||||
];
|
||||
|
||||
sinon.stub(Meteor, 'user').callsFake(() => {});
|
||||
|
||||
views.forEach(viewName => {
|
||||
Utils.setBoardView(viewName);
|
||||
expect(window.localStorage.getItem(boardView)).to.equal(viewName);
|
||||
});
|
||||
});
|
||||
|
||||
it('sets a default view if no user and no view are given', function() {
|
||||
sinon.stub(Meteor, 'user').callsFake(() => {});
|
||||
Utils.setBoardView();
|
||||
expect(window.localStorage.getItem(boardView)).to.equal('board-view-swimlanes');
|
||||
});
|
||||
});
|
||||
|
||||
describe(Utils.unsetBoardView.name, function() {
|
||||
it('removes the boardview from localStoage', function() {
|
||||
window.localStorage.setItem(boardView, Random.id());
|
||||
window.localStorage.setItem('collapseSwimlane', Random.id());
|
||||
|
||||
Utils.unsetBoardView();
|
||||
|
||||
expect(window.localStorage.getItem(boardView)).to.equal(null);
|
||||
expect(window.localStorage.getItem('collapseSwimlane')).to.equal(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe(Utils.boardView.name, function() {
|
||||
it('returns the user\'s board view if a user exists', function() {
|
||||
const viewId = Random.id();
|
||||
const user = {};
|
||||
sinon.stub(Meteor, 'user').callsFake(() => user);
|
||||
expect(Utils.boardView()).to.equal(undefined);
|
||||
|
||||
const boardView = Random.id();
|
||||
user.profile = { boardView };
|
||||
|
||||
expect(Utils.boardView()).to.equal(boardView);
|
||||
});
|
||||
it('returns the current defined view', function() {
|
||||
const views = [
|
||||
'board-view-swimlanes',
|
||||
'board-view-lists',
|
||||
'board-view-cal'
|
||||
];
|
||||
|
||||
sinon.stub(Meteor, 'user').callsFake(() => {});
|
||||
|
||||
views.forEach(viewName => {
|
||||
window.localStorage.setItem(boardView, viewName);
|
||||
expect(Utils.boardView()).to.equal(viewName);
|
||||
});
|
||||
});
|
||||
it('returns a default if nothing is set', function() {
|
||||
sinon.stub(Meteor, 'user').callsFake(() => {});
|
||||
expect(Utils.boardView()).to.equal('board-view-swimlanes');
|
||||
expect(window.localStorage.getItem(boardView)).to.equal('board-view-swimlanes');
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue