Refactor how cards are recieved

This commit is contained in:
Blade Barringer
2015-08-12 08:36:57 -05:00
parent 60f92a8997
commit 203a26b6df
7 changed files with 121 additions and 61 deletions

View File

@@ -1,7 +1,7 @@
'use strict';
describe('Inventory Controller', function() {
var scope, ctrl, user, $rootScope;
var scope, ctrl, user, rootScope;
beforeEach(function() {
module(function($provide) {
@@ -23,6 +23,7 @@ describe('Inventory Controller', function() {
}
};
scope = $rootScope.$new();
rootScope = $rootScope;
// Load RootCtrl to ensure shared behaviors are loaded
$controller('RootCtrl', {$scope: scope, User: {user: user}, $window: mockWindow});
@@ -109,4 +110,45 @@ describe('Inventory Controller', function() {
expect(scope.selectedEgg).to.eql(null);
});
});
describe('openCardsModal', function(type, numberOfVariations) {
var cardsModalScope;
beforeEach(function() {
cardsModalScope = {};
sandbox.stub(rootScope, 'openModal');
sandbox.stub(rootScope, '$new').returns(cardsModalScope);
});
it('opens cards modal', function() {
scope.openCardsModal('valentine', 4);
expect(rootScope.openModal).to.be.calledOnce;
expect(rootScope.openModal).to.be.calledWith(
'cards'
);
});
it('instantiates a new scope for the modal', function() {
scope.openCardsModal('valentine', 4);
expect(rootScope.$new).to.be.calledOnce;
expect(cardsModalScope.cardType).to.eql('valentine');
expect(cardsModalScope.cardMessage).to.exist;
});
it('provides a card message', function() {
scope.openCardsModal('valentine', 1);
expect(cardsModalScope.cardMessage).to.eql(env.t('valentine0'));
});
it('randomly generates message from x number of messages', function() {
var possibleValues = [env.t('valentine0'), env.t('valentine1')];
scope.openCardsModal('valentine', 2);
expect(possibleValues).to.contain(cardsModalScope.cardMessage);
});
});
});