mirror of https://github.com/wekan/wekan
parent
7daa67c792
commit
20452d7296
@ -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'); |
||||
}); |
||||
}); |
||||
}); |
@ -0,0 +1 @@ |
||||
import './Utils.tests'; |
@ -0,0 +1,106 @@ |
||||
/* eslint-env mocha */ |
||||
import { Random } from 'meteor/random'; |
||||
import { expect } from 'chai'; |
||||
import './utils'; |
||||
|
||||
describe('utils', function() { |
||||
describe(allowIsBoardAdmin.name, function() { |
||||
it('returns if a board has an admin', function() { |
||||
const userId = Random.id(); |
||||
const board = { |
||||
hasAdmin: id => { |
||||
return id === userId; |
||||
} |
||||
}; |
||||
|
||||
expect(allowIsBoardAdmin(userId, board)).to.equal(true); |
||||
expect(allowIsBoardAdmin(Random.id(), board)).to.equal(false); |
||||
}); |
||||
}); |
||||
|
||||
describe(allowIsBoardMember.name, function() { |
||||
it('returns if a board has a member', function() { |
||||
const userId = Random.id(); |
||||
const board = { |
||||
hasMember: id => { |
||||
return id === userId; |
||||
} |
||||
}; |
||||
|
||||
expect(allowIsBoardMember(userId, board)).to.equal(true); |
||||
expect(allowIsBoardMember(Random.id(), board)).to.equal(false); |
||||
}); |
||||
}); |
||||
|
||||
describe(allowIsAnyBoardMember.name, function() { |
||||
it('returns if any board has a member', function() { |
||||
const userId = Random.id(); |
||||
const boardsExpectedTrue = [{ |
||||
hasMember: id => { |
||||
return id === userId; |
||||
} |
||||
}]; |
||||
|
||||
expect(allowIsAnyBoardMember(userId, boardsExpectedTrue)).to.equal(true); |
||||
expect(allowIsAnyBoardMember(Random.id(), boardsExpectedTrue)).to.equal(false); |
||||
|
||||
const boardsExpectedFalse = [{ |
||||
hasMember: () => false |
||||
}]; |
||||
|
||||
expect(allowIsAnyBoardMember(userId, boardsExpectedFalse)).to.equal(false); |
||||
expect(allowIsAnyBoardMember(Random.id(), boardsExpectedFalse)).to.equal(false); |
||||
}); |
||||
}); |
||||
|
||||
describe(allowIsBoardMemberCommentOnly.name, function() { |
||||
it('returns if a board has a member that is not comment-only member', function() { |
||||
const userId = Random.id(); |
||||
const board = { |
||||
hasMember: id => { |
||||
return id === userId; |
||||
}, |
||||
hasCommentOnly: id => { |
||||
return id !== userId; |
||||
} |
||||
}; |
||||
|
||||
expect(allowIsBoardMemberCommentOnly(userId, board)).to.equal(true); |
||||
expect(allowIsBoardMemberCommentOnly(Random.id(), board)).to.equal(false); |
||||
}); |
||||
}); |
||||
|
||||
describe(allowIsBoardMemberNoComments.name, function() { |
||||
it('returns if a board has a member that has comment any comments', function() { |
||||
const userId = Random.id(); |
||||
const board = { |
||||
hasMember: id => { |
||||
return id === userId; |
||||
}, |
||||
hasNoComments: id => { |
||||
return id !== userId; |
||||
} |
||||
}; |
||||
|
||||
expect(allowIsBoardMemberNoComments(userId, board)).to.equal(true); |
||||
expect(allowIsBoardMemberNoComments(Random.id(), board)).to.equal(false); |
||||
}); |
||||
}); |
||||
|
||||
describe(allowIsBoardMemberByCard.name, function() { |
||||
it('returns if the board for a given card has a member', function() { |
||||
const userId = Random.id(); |
||||
const board = { |
||||
hasMember: id => { |
||||
return id === userId; |
||||
} |
||||
}; |
||||
const card = { |
||||
board: () => board |
||||
}; |
||||
|
||||
expect(allowIsBoardMemberByCard(userId, card)).to.equal(true); |
||||
expect(allowIsBoardMemberByCard(Random.id(), card)).to.equal(false); |
||||
}); |
||||
}); |
||||
}); |
@ -0,0 +1,30 @@ |
||||
/* eslint-env mocha */ |
||||
|
||||
// This is the main test file from which all tests can be imported top-down,
|
||||
// creating a directed sequence for tests that sums up to our test-suite.
|
||||
//
|
||||
// You propably want to start with low-level code and follow up to higher-level
|
||||
// code, like for example:
|
||||
//
|
||||
// infrastructure
|
||||
// utils / helpers
|
||||
// contexts
|
||||
// api
|
||||
// components
|
||||
// ui
|
||||
|
||||
// If you want to run tests on both, server AND client, simply import them as
|
||||
// they are. However, if you want to restict tests to server-only or client-only
|
||||
// you need to wrap them inside a new describe-block
|
||||
|
||||
if (Meteor.isServer) { |
||||
describe('server', function() { |
||||
import '../server/lib/utils.tests'; |
||||
}); |
||||
} |
||||
|
||||
if (Meteor.isClient) { |
||||
describe('lib', function() { |
||||
import '../client/lib/tests'; |
||||
}); |
||||
} |
Loading…
Reference in new issue