Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions client/app/common/navbar/navbar.spec.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import NavbarModule from './navbar'
import NavbarController from './navbar.controller';
import NavbarComponent from './navbar.component';
import NavbarTemplate from './navbar.html';

describe('Navbar', () => {
let $rootScope, makeController;
let $rootScope, $state, $location, $componentController, $compile;

beforeEach(window.module(NavbarModule));
beforeEach(inject((_$rootScope_) => {
$rootScope = _$rootScope_;
makeController = () => {
return new NavbarController();
};

beforeEach(inject(($injector) => {
$rootScope = $injector.get('$rootScope');
$componentController = $injector.get('$componentController');
$state = $injector.get('$state');
$location = $injector.get('$location');
$compile = $injector.get('$compile');
}));

describe('Module', () => {
Expand All @@ -20,30 +19,31 @@ describe('Navbar', () => {

describe('Controller', () => {
// controller specs
it('has a name property [REMOVE]', () => { // erase if removing this.name from the controller
let controller = makeController();
expect(controller).to.have.property('name');
let controller;
beforeEach(() => {
controller = $componentController('navbar', {
$scope: $rootScope.$new()
});
});
});

describe('Template', () => {
// template specs
// tip: use regex to ensure correct bindings are used e.g., {{ }}
it('has name in template [REMOVE]', () => {
expect(NavbarTemplate).to.match(/{{\s?\$ctrl\.name\s?}}/g);
it('has a name property', () => { // erase if removing this.name from the controller
expect(controller).to.have.property('name');
});
});

describe('Component', () => {
// component/directive specs
let component = NavbarComponent;
describe('View', () => {
// view layer specs.
let scope, template;

it('includes the intended template',() => {
expect(component.template).to.equal(NavbarTemplate);
});
beforeEach(() => {
scope = $rootScope.$new();
template = $compile('<navbar></navbar>')(scope);
scope.$apply();
});

it('has name in template', () => {
expect(template.find('h1').find('a').html()).to.eq('navbar');
});

it('invokes the right controller', () => {
expect(component.controller).to.equal(NavbarController);
});
});
});
2 changes: 1 addition & 1 deletion client/app/components/about/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let aboutModule = angular.module('about', [
$stateProvider
.state('about', {
url: '/about',
template: '<about></about>'
component: 'about'
});
})

Expand Down
59 changes: 32 additions & 27 deletions client/app/components/about/about.spec.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,54 @@
import AboutModule from './about'
import AboutController from './about.controller';
import AboutComponent from './about.component';
import AboutTemplate from './about.html';

describe('About', () => {
let $rootScope, makeController;
let $rootScope, $state, $location, $componentController, $compile;

beforeEach(window.module(AboutModule));
beforeEach(inject((_$rootScope_) => {
$rootScope = _$rootScope_;
makeController = () => {
return new AboutController();
};

beforeEach(inject(($injector) => {
$rootScope = $injector.get('$rootScope');
$componentController = $injector.get('$componentController');
$state = $injector.get('$state');
$location = $injector.get('$location');
$compile = $injector.get('$compile');
}));

describe('Module', () => {
// top-level specs: i.e., routes, injection, naming
it('About component should be visible when navigates to /about', () => {
$location.url('/about');
$rootScope.$digest();
expect($state.current.component).to.eq('about');
});
});

describe('Controller', () => {
// controller specs
it('has a name property [REMOVE]', () => { // erase if removing this.name from the controller
let controller = makeController();
expect(controller).to.have.property('name');
let controller;
beforeEach(() => {
controller = $componentController('about', {
$scope: $rootScope.$new()
});
});
});

describe('Template', () => {
// template specs
// tip: use regex to ensure correct bindings are used e.g., {{ }}
it('has name in template [REMOVE]', () => {
expect(AboutTemplate).to.match(/{{\s?\$ctrl\.name\s?}}/g);
it('has a name property', () => { // erase if removing this.name from the controller
expect(controller).to.have.property('name');
});
});

describe('Component', () => {
// component/directive specs
let component = AboutComponent;
describe('View', () => {
// view layer specs.
let scope, template;

it('includes the intended template',() => {
expect(component.template).to.equal(AboutTemplate);
});
beforeEach(() => {
scope = $rootScope.$new();
template = $compile('<about></about>')(scope);
scope.$apply();
});

it('has name in template', () => {
expect(template.find('h1').html()).to.eq('about');
});

it('invokes the right controller', () => {
expect(component.controller).to.equal(AboutController);
});
});
});
2 changes: 1 addition & 1 deletion client/app/components/home/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let homeModule = angular.module('home', [
$stateProvider
.state('home', {
url: '/',
template: '<home></home>'
component: 'home'
});
})

Expand Down
59 changes: 32 additions & 27 deletions client/app/components/home/home.spec.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,54 @@
import HomeModule from './home'
import HomeController from './home.controller';
import HomeComponent from './home.component';
import HomeTemplate from './home.html';

describe('Home', () => {
let $rootScope, makeController;
let $rootScope, $state, $location, $componentController, $compile;

beforeEach(window.module(HomeModule));
beforeEach(inject((_$rootScope_) => {
$rootScope = _$rootScope_;
makeController = () => {
return new HomeController();
};

beforeEach(inject(($injector) => {
$rootScope = $injector.get('$rootScope');
$componentController = $injector.get('$componentController');
$state = $injector.get('$state');
$location = $injector.get('$location');
$compile = $injector.get('$compile');
}));

describe('Module', () => {
// top-level specs: i.e., routes, injection, naming
it('default component should be home', () => {
$location.url('/');
$rootScope.$digest();
expect($state.current.component).to.eq('home');
});
});

describe('Controller', () => {
// controller specs
it('has a name property [REMOVE]', () => { // erase if removing this.name from the controller
let controller = makeController();
expect(controller).to.have.property('name');
let controller;
beforeEach(() => {
controller = $componentController('home', {
$scope: $rootScope.$new()
});
});
});

describe('Template', () => {
// template specs
// tip: use regex to ensure correct bindings are used e.g., {{ }}
it('has name in template [REMOVE]', () => {
expect(HomeTemplate).to.match(/{{\s?\$ctrl\.name\s?}}/g);
it('has a name property', () => { // erase if removing this.name from the controller
expect(controller).to.have.property('name');
});
});

describe('Component', () => {
// component/directive specs
let component = HomeComponent;
describe('View', () => {
// view layer specs.
let scope, template;

it('includes the intended template',() => {
expect(component.template).to.equal(HomeTemplate);
});
beforeEach(() => {
scope = $rootScope.$new();
template = $compile('<home></home>')(scope);
scope.$apply();
});

it('has name in template', () => {
expect(template.find('h1').html()).to.eq('Found in home.html');
});

it('invokes the right controller', () => {
expect(component.controller).to.equal(HomeController);
});
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"dependencies": {
"angular": "^1.5.0",
"angular-ui-router": "^0.2.15",
"angular-ui-router": "^1.0.0-beta.1",
"normalize.css": "^3.0.3"
},
"devDependencies": {
Expand Down