-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kamil Kisiela
authored and
Dotan Simha
committed
Nov 22, 2016
1 parent
44130e4
commit d22cc28
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
imports/ui/components/partyCreator/client/partyCreator.tests.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { name as PartyCreator } from '../partyCreator'; | ||
import { Meteor } from 'meteor/meteor'; | ||
import 'angular-mocks'; | ||
|
||
describe('PartyCreator', () => { | ||
beforeEach(() => { | ||
window.module(PartyCreator); | ||
}); | ||
|
||
describe('controller', () => { | ||
let $rootScope; | ||
let $componentController; | ||
const party = { | ||
_id: 'partyId' | ||
}; | ||
|
||
beforeEach(() => { | ||
inject((_$rootScope_, _$componentController_) => { | ||
$rootScope = _$rootScope_; | ||
$componentController = _$componentController_; | ||
}); | ||
}); | ||
|
||
function component(bindings) { | ||
return $componentController(PartyCreator, { | ||
$scope: $rootScope.$new(true) | ||
}, bindings); | ||
} | ||
|
||
it('should return an empty string if there is no party', () => { | ||
const controller = component({ | ||
party: undefined | ||
}); | ||
|
||
expect(controller.creator).toEqual(''); | ||
}); | ||
|
||
it('should say `me` if logged in is the owner', () => { | ||
const owner = 'userId'; | ||
// logged in | ||
spyOn(Meteor, 'userId').and.returnValue(owner); | ||
const controller = component({ | ||
party: { | ||
owner | ||
} | ||
}); | ||
|
||
expect(controller.creator).toEqual('me'); | ||
}); | ||
|
||
it('should say `nobody` if user does not exist', () => { | ||
const owner = 'userId'; | ||
// not logged in | ||
spyOn(Meteor, 'userId').and.returnValue(null); | ||
// no user found | ||
spyOn(Meteor.users, 'findOne').and.returnValue(undefined); | ||
const controller = component({ | ||
party: { | ||
owner | ||
} | ||
}); | ||
|
||
expect(controller.creator).toEqual('nobody'); | ||
}); | ||
|
||
it('should return user data if user exists and it is not logged one', () => { | ||
const owner = 'userId'; | ||
// not logged in | ||
spyOn(Meteor, 'userId').and.returnValue(null); | ||
// user found | ||
spyOn(Meteor.users, 'findOne').and.returnValue('found'); | ||
const controller = component({ | ||
party: { | ||
owner | ||
} | ||
}); | ||
|
||
expect(controller.creator).toEqual('found'); | ||
}); | ||
}); | ||
}); |