Skip to content

Commit

Permalink
Step 13.17: Tests of PartyCreator
Browse files Browse the repository at this point in the history
  • 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.
81 changes: 81 additions & 0 deletions imports/ui/components/partyCreator/client/partyCreator.tests.js
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');
});
});
});

0 comments on commit d22cc28

Please sign in to comment.