@@ -7,62 +7,159 @@ describe('AddSubItem', ()=>{
let $rootScope,
makeController,
compile,
injector,
scope,
onAddUser,
onRemoveUser,
directiveElem;

beforeEach(window.module(addSubItem.name));
beforeEach(inject((_$rootScope_)=>{
$rootScope = _$rootScope_;
makeController = ()=>{
return new AddSubItemController();
q,
deferred,
directiveElem,
mockFactory;

beforeEach(function(){

mockFactory = {
createNew: () => {},
getAll: () => {}
};
}));

// Mock directive scope props
beforeEach(function() {
// Register the mock factory on the module
window.module(addSubItem.name, ($provide) => {
$provide.value('MockFactory', mockFactory);
});

inject(function ($compile, $rootScope) {
// Inject the dependencies
inject(($compile, $rootScope, $injector, _$q_) => {

compile=$compile;
injector=$injector;
scope=$rootScope.$new();

// Mock out $q
q = _$q_;

deferred = q.defer();

// Stub out factoryFunctions
sinon.stub(mockFactory, 'createNew', () => { return deferred.promise});

makeController = (scope, injector)=>{
return new AddSubItemController(scope, injector);
};
});
});

directiveElem = getCompiledElement();
// Restore mockFactory stubs
afterEach(() => {
mockFactory.createNew.restore();
});

function getCompiledElement(){
var compiledDirective = compile(angular.element(
// directive
))(scope);
scope.$digest();
return compiledDirective;
}
describe('Controller', ()=>{

describe('handleSubmit', () => {
it('should call factory createNew function on handleSubmit when a parent id is present', () => {
scope.factoryName = 'MockFactory';
scope.parentId = 'fakestreet';

describe('Controller', ()=>{
let ctrl = makeController(scope, injector);

ctrl.handleSubmit();
expect(mockFactory.createNew.called).to.equal(true);
});

it('should not call factory createNew function on handleSubmit when a parent id is present', () => {
scope.factoryName = 'MockFactory';
scope.parentId = undefined;

let ctrl = makeController(scope, injector);

ctrl.handleSubmit();
expect(mockFactory.createNew.called).to.equal(false);
});

it('should pass the current item to createNew factory function', () => {
scope.factoryName = 'MockFactory';
scope.parentId = 'fakestreet';
let ctrl = makeController(scope, injector);

ctrl.currentItem = {
name:'fake town',
description: 'not realsville'
};

ctrl.handleSubmit();
expect(mockFactory.createNew.calledWith(ctrl.currentItem)).to.equal(true);
expect(ctrl.parentId).to.equal('fakestreet');
});
});
});

describe('Template', ()=>{
it('should have addSubItem class on a section tag', () => {
expect(template).match(/^<section.*class="addSubItem/);
});

});
it('should have button that calls handleSubmit', () => {
expect(template).match(/<button.*ng-click="vm\.handleSubmit\(\)"/);
});

it('should have a transclusion container', () => {
expect(template).match(/class="item-form-container"/);
});
});

describe('Directive', ()=>{
// test the component/directive itself
let directive = addSubItemDirective();

it('should use the right template',()=>{
expect(directive.template).to.equal(template);
});
beforeEach(() => {
scope.parentId = 'parentId';
scope.MockFactory = 'MockFactory';
directiveElem = getCompiledElement();
});

it('should use controllerAs', ()=>{
expect(directive).to.have.property('controllerAs');
});
// Create mocked out directive by creating fake element
function getCompiledElement(){
let compiledDirective = compile(angular.element(
`<add-sub-item
parent-id="parentId"
factory-name="MockFactory"
>
<div>
transcludedContent
</div>
</add-sub-item>`
))(scope);
scope.$digest();
return compiledDirective;
}

// test the component/directive itself
let directive = addSubItemDirective();

it('should use the right template',()=>{
expect(directive.template).to.equal(template);
});

it('should use controllerAs', ()=>{
expect(directive).to.have.property('controllerAs');
});

it('should use the right controller', ()=>{
expect(directive.controller).to.equal(AddSubItemController);
});

it('should have factory name, parent id, and current item properties', () => {
const isolateScope = directiveElem.isolateScope();
expect(isolateScope.factoryName).to.equal('MockFactory');
expect(isolateScope.parentId).to.equal('parentId');
});

it('should have factory name, parent id, and current item properties', () => {
const isolateScope = directiveElem.isolateScope();
expect(isolateScope.factoryName).to.equal('MockFactory');
expect(isolateScope.parentId).to.equal('parentId');
});

it('should have transcluded content', () => {
expect(directiveElem.html()).match(/transcludedContent/);
});

it('should use the right controller', ()=>{
expect(directive.controller).to.equal(AddSubItemController);
});
});
});
@@ -3,102 +3,154 @@ import {AssignUserController} from './assignUser.controller';
import {assignUserDirective} from './assignUser.directive';
import template from './assignUser.html';

describe('AssignUser', ()=>{
describe('assignUser', ()=>{
let $rootScope,
makeController,
compile,
injector,
scope,
onAddUser,
onRemoveUser,
directiveElem;
q,
deferred,
directiveElem,
mockFactory;

beforeEach(window.module('assignUser'));
beforeEach(function(){

// Set up Controller
beforeEach(inject((_$rootScope_)=>{
$rootScope = _$rootScope_;
makeController = ()=>{
return new AssignUserController();
mockFactory = {
createNew: () => {},
getAll: () => {}
};
}));

// Mock directive scope props
beforeEach(function() {
// Register the mock factory on the module
window.module(assignUser.name, ($provide) => {
$provide.value('MockFactory', mockFactory);
});

// Inject the dependencies
inject((_$compile_, $rootScope, $injector, _$q_) => {

inject(function ($compile, $rootScope) {
compile=$compile;
compile=_$compile_;
injector=$injector;
scope=$rootScope.$new();

// Mock out $q
q = _$q_;

onAddUser = sinon.spy();
onRemoveUser = sinon.spy();
deferred = q.defer();

scope.currentUsers = ['user1', 'user2'];
scope.allUsers = ['user3', 'user4'];
scope.onAddUser = onAddUser;
scope.onRemoveUser = onRemoveUser;
// Stub out factoryFunctions
sinon.stub(mockFactory, 'createNew', () => { return deferred.promise});
});

directiveElem = getCompiledElement();
makeController = (scope, injector)=>{
return new AssignUserController(scope, injector);
};
});

function getCompiledElement(){
let compiledDirective = compile(angular.element(
`<assign-user
current-users="currentUsers"
all-users="allUsers"
on-add-user="onAddUser()"
on-remove-user="onRemoveUser()">
</assign-user>`))(scope);
scope.$apply();
return compiledDirective;
}

// test the component/directive itself
let directive = assignUserDirective();

// it('should use the right template',()=>{
// expect(directive.template).to.equal(template);
// });

// it('should use controllerAs', ()=>{
// expect(directive).to.have.property('controllerAs');
// });

// it('should use the right controller', ()=>{
// expect(directive.controller).to.equal(AssignUserController);
// });

describe('Properties', () => {

// it('should have a list of all users', () => {
// const isolatedScope = directiveElem.isolateScope();
// expect(isolatedScope.allUsers).to.be.a('array')
// });

// it('should have a list of current users', () => {
// const isolatedScope = directiveElem.isolateScope();
// expect(isolatedScope.currentUsers).to.be.a('array')
// });

// it('should have an onAddUser Callback', () => {
// const isolatedScope = directiveElem.isolateScope();
// expect(isolatedScope.onAddUser).to.be.a('function');
// isolatedScope.onAddUser();
// expect(onAddUser.calledOnce);
// });

// it('should have an onRemoveUser Callback', () => {
// const isolatedScope = directiveElem.isolateScope();
// expect(isolatedScope.onRemoveUser).to.be.a('function');
// isolatedScope.onRemoveUser();
// expect(onRemoveUser.calledOnce);
// });

it('should no be a piece of shit', () => {
let el = directiveElem.find('li');
el.triggerHandler('click');
expect()
// Restore mockFactory stubs
afterEach(() => {
mockFactory.createNew.restore();
});

describe('Controller', ()=>{

describe('filterAllUserList', () => {
it('should filter out current users from filteredAllUsers', () => {
scope.allUsers = [{_id:'user1'}, {_id:'user2'}];
scope.currentUsers = [{_id:'user1'}];

let ctrl = makeController(scope, injector);

ctrl.filterAllUserList();

expect(ctrl.filteredAllUsers).to.eql([{_id:'user2'}]);
expect(ctrl.allUsers).to.equal(scope.allUsers);
expect(ctrl.currentUsers).to.equal(scope.currentUsers);
});
});

describe('adding and removing users', () => {
it('should call onAddUser function with user at passed index', () => {
scope.allUsers = [{_id:'user1'}, {_id:'user2'}];
scope.currentUsers = [{_id:'user1'}];
scope.onAddUser = sinon.spy();

let ctrl = makeController(scope, injector);
ctrl.filteredAllUsers = [{_id:'user2'}];
ctrl.handleAddUser(0);

expect(ctrl.onAddUser.args[0][0]).to.eql({user:{_id:'user2'}});
});

it('should call onRemoveUser function with user at passed index', () => {
scope.allUsers = [{_id:'user1'}, {_id:'user2'}];
scope.currentUsers = [{_id:'user1'}];
scope.onRemoveUser = sinon.spy();

let ctrl = makeController(scope, injector);

ctrl.handleRemoveUser(0);
expect(scope.onRemoveUser.args[0][0]).to.eql({user: {_id:'user1'}});
});
});
});

describe('Template', ()=>{

});

describe('Directive', ()=>{
let ctrl;

beforeEach(() => {
scope.allUsers = [{username:'user1'}, {username:'user2'}];
scope.currentUsers = [{username:'user3'}, {username:'user4'}];
scope.onAddUser = sinon.spy();
scope.onRemoveUser = sinon.spy();

directiveElem = getCompiledElement();
});

// Create mocked out directive by creating fake element
function getCompiledElement(){
let compiledDirective = compile(angular.element(
`<assign-user
all-users="allUsers"
current-users="currentUsers"
on-add-user="onAddUser"
on-remove-user="onRemoveUser"
>
</assign-user>`
))(scope);
scope.$digest();
return compiledDirective;
}

// test the component/directive itself
let directive = assignUserDirective();

it('should use the right template',()=>{
expect(directive.template).to.equal(template);
});

it('should use controllerAs', ()=>{
expect(directive).to.have.property('controllerAs');
});

it('should use the right controller', ()=>{
expect(directive.controller).to.equal(AssignUserController);
});

it('should have correct properties on isolate scope', () => {
const isolateScope = directiveElem.isolateScope();
expect(isolateScope.allUsers).to.be.a('array');
expect(isolateScope.currentUsers).to.be.a('array');
expect(isolateScope.onAddUser).to.be.a('function');
expect(isolateScope.onRemoveUser).to.be.a('function');
});

it('should render users from currentUsers', () => {
expect(directiveElem.html()).match(/user3/);
});
});
});
@@ -23,39 +23,28 @@ describe('Navbar', ()=>{
});

describe('Controller', ()=>{
// test your controller here

it('should have a name property [REMOVE]', ()=>{ // erase me if you remove this.name from the controller
// let controller = makeController();

// expect(controller).to.have.property('greeting');
});

});

describe('Template', ()=>{
// test the template
// use Regexes to test that you are using the right bindings {{ }}

// it('should have name in template [REMOVE]', ()=>{
// expect(template).to.match(/{{\s?vm\.greeting\s?}}/g);
// });

});


describe('Directive', ()=>{
// test the component/directive itself
let directive = navbarDirective();
// // test the component/directive itself
// let directive = navbarDirective();

it('should use the right template',()=>{
expect(directive.template).to.equal(template);
});
// it('should use the right template',()=>{
// expect(directive.template).to.equal(template);
// });

it('should use controllerAs', ()=>{
expect(directive).to.have.property('controllerAs');
});
// it('should use controllerAs', ()=>{
// expect(directive).to.have.property('controllerAs');
// });

it('should use the right controller', ()=>{
expect(directive.controller).to.equal(NavbarController);
});
// it('should use the right controller', ()=>{
// expect(directive.controller).to.equal(NavbarController);
// });
});
});
@@ -5,57 +5,106 @@ import template from './<%= name %>.html';

describe('<%= upCaseName %>', ()=>{
let $rootScope,
makeController;
makeController,
compile,
injector,
scope,
q,
deferred,
directiveElem,
mockFactory;

beforeEach(window.module(<%= name %>.name));
beforeEach(inject((_$rootScope_)=>{
$rootScope = _$rootScope_;
makeController = ()=>{
return new <%= upCaseName %>Controller();
beforeEach(function(){

mockFactory = {
createNew: () => {},
getAll: () => {}
};
}));

describe('Module', ()=>{
// test things about the component module
// checking to see if it registers certain things and what not
// test for best practices with naming too
// test for routing
});
// Register the mock factory on the module
window.module(<%= name %>.name, ($provide) => {
$provide.value('MockFactory', mockFactory);
});

describe('Controller', ()=>{
// test your controller here
// Inject the dependencies
inject(($compile, $rootScope, $injector, _$q_) => {

compile=$compile;
injector=$injector;
scope=$rootScope.$new();

// Mock out $q
q = _$q_;

it('should have a name property [REMOVE]', ()=>{ // erase me if you remove this.name from the controller
let controller = makeController();
deferred = q.defer();

expect(controller).to.have.property('greeting');
// Stub out factoryFunctions
sinon.stub(mockFactory, 'createNew', () => { return deferred.promise});
});
});

// Restore mockFactory stubs
afterEach(() => {
mockFactory.createNew.restore();
});

describe('Module', ()=>{

});

describe('Controller', ()=>{
beforeEach(inject((_$rootScope_)=>{
$rootScope = _$rootScope_;
makeController = (scope, injector)=>{
return new AddSubItemController(scope, injector);
};
}));
});

describe('Template', ()=>{
// test the template
// use Regexes to test that you are using the right bindings {{ }}

it('should have name in template [REMOVE]', ()=>{
expect(template).to.match(/{{\s?vm\.greeting\s?}}/g);
});
});


describe('Directive', ()=>{
// test the component/directive itself
let directive = <%= name %>Directive();
describe('Directive', ()=>{

it('should use the right template',()=>{
expect(directive.template).to.equal(template);
beforeEach(() => {
scope.parentId = 'parentId';
scope.MockFactory = 'MockFactory';
directiveElem = getCompiledElement();
});

it('should use controllerAs', ()=>{
expect(directive).to.have.property('controllerAs');
});
// Create mocked out directive by creating fake element
function getCompiledElement(){
let compiledDirective = compile(angular.element(
`<<%= name =>
parent-id="parentId"
factory-name="MockFactory"
>
<div>
transcludedContent
</div>
</<%= name %>>`
))(scope);
scope.$digest();
return compiledDirective;
}

it('should use the right controller', ()=>{
expect(directive.controller).to.equal(<%= upCaseName %>Controller);
});
let directive = <%= name %>Directive();

it('should use the right template',()=>{
expect(directive.template).to.equal(template);
});

it('should use controllerAs', ()=>{
expect(directive).to.have.property('controllerAs');
});

it('should use the right controller', ()=>{
expect(directive.controller).to.equal(<%= upCaseName %>Controller);
});
});
});


@@ -7,73 +7,103 @@ describe('<%= upCaseName %>', ()=>{
let $rootScope,
makeController,
compile,
injector,
scope,
onAddUser,
onRemoveUser,
directiveElem;

beforeEach(window.module(<%= name %>.name));
beforeEach(inject((_$rootScope_)=>{
$rootScope = _$rootScope_;
makeController = ()=>{
return new <%= upCaseName %>Controller();
q,
deferred,
directiveElem,
mockFactory;

beforeEach(function(){

mockFactory = {
createNew: () => {},
getAll: () => {}
};
}));

// Mock directive scope props
beforeEach(function() {
// Register the mock factory on the module
window.module(<%= name %>.name, ($provide) => {
$provide.value('MockFactory', mockFactory);
});

// Inject the dependencies
inject(($compile, $rootScope, $injector, _$q_) => {

inject(function ($compile, $rootScope) {
compile=$compile;
injector=$injector;
scope=$rootScope.$new();
});

// Mock out $q
q = _$q_;

directiveElem = getCompiledElement();
});
deferred = q.defer();

function getCompiledElement(){
var compiledDirective = compile(angular.element(
// directive
))(scope);
scope.$digest();
return compiledDirective;
}
// Stub out factoryFunctions
sinon.stub(mockFactory, 'createNew', () => { return deferred.promise});
});
});

// Restore mockFactory stubs
afterEach(() => {
mockFactory.createNew.restore();
});

describe('Controller', ()=>{
// test your controller here

it('should have a name property [REMOVE]', ()=>{ // erase me if you remove this.name from the controller
let controller = makeController();

expect(controller).to.have.property('greeting');
});
beforeEach(inject((_$rootScope_)=>{
$rootScope = _$rootScope_;
makeController = (scope, injector)=>{
return new AddSubItemController(scope, injector);
};
}));
});

describe('Template', ()=>{
// test the template
// use Regexes to test that you are using the right bindings {{ }}

it('should have name in template [REMOVE]', ()=>{
expect(template).to.match(/{{\s?vm\.greeting\s?}}/g);
});
// it('should have name in template [REMOVE]', ()=>{
// expect(template).to.match(/{{\s?vm\.greeting\s?}}/g);
// });
});


describe('Directive', ()=>{
// test the component/directive itself
let directive = <%= name %>Directive();
describe('Directive', ()=>{

it('should use the right template',()=>{
expect(directive.template).to.equal(template);
beforeEach(() => {
scope.parentId = 'parentId';
scope.MockFactory = 'MockFactory';
directiveElem = getCompiledElement();
});

it('should use controllerAs', ()=>{
expect(directive).to.have.property('controllerAs');
});
// Create mocked out directive by creating fake element
function getCompiledElement(){
let compiledDirective = compile(angular.element(
`<<%= name =>
parent-id="parentId"
factory-name="MockFactory"
>
<div>
transcludedContent
</div>
</<%= name %>>`
))(scope);
scope.$digest();
return compiledDirective;
}

// test the component/directive itself
let directive = <%= name %>Directive();

it('should use the right template',()=>{
expect(directive.template).to.equal(template);
});

it('should use the right controller', ()=>{
expect(directive.controller).to.equal(<%= upCaseName %>Controller);
});
it('should use controllerAs', ()=>{
expect(directive).to.have.property('controllerAs');
});

it('should use the right controller', ()=>{
expect(directive.controller).to.equal(<%= upCaseName %>Controller);
});
});
});