Skip to content

Commit

Permalink
Merge e2fabc4 into a989b6a
Browse files Browse the repository at this point in the history
  • Loading branch information
dinoboff committed Jul 3, 2016
2 parents a989b6a + e2fabc4 commit 8dab72a
Show file tree
Hide file tree
Showing 13 changed files with 3,336 additions and 3,693 deletions.
51 changes: 12 additions & 39 deletions src/classmentors/components/ace/ace.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,50 +28,23 @@ export const component = {
controller: AceController
};

/**
* Configure ace of coders route
*
* @param {$routeProvider} $routeProvider
* @param {Object} routes
*/
export function configRoute($routeProvider, routes) {
$routeProvider.when(routes.aceOfCoders, {
template: '<ace stats="$resolve.stats"></ace>',
resolve: {
// ngRoute will wait for the promise aceStats to resolve before assigning
// it to $resolve.stats. Once, it's resolved, the template will be run.
stats: ['aceStats', aceStats => aceStats()]
}
});
}

configRoute.$inject = ['$routeProvider', 'routes'];

export const ACE_STATS_URL = 'https://dl.dropboxusercontent.com/u/4972572/ace_of_coders_stats.json';

/**
* aceStats factory
* Route resolver helper.
*
* return the aceStats function.
* This is not a service; this is not generating a singleton. If used in a route
* configuration "resolve" map, the function will be run on each resolution of
* that route.
*
* @param {$http} $http
* @return {function}
* @param {Object} $http $http service.
* @param {string} aceStatsUrl URL to fetch stats from
* @return {Promise}
*/
export function factory($http, aceStatsUrl) {

/**
* aceStats service
*
* Resolve to the Ace stats
*
* @return {Promise}
*/
return function aceStats() {
return $http.get(aceStatsUrl).then(
response => response.data
);
};
export function getStats($http, aceStatsUrl) {
return $http.get(aceStatsUrl).then(
response => response.data
);
}

factory.$inject = ['$http', 'aceStatsUrl'];
getStats.$inject = ['$http', 'aceStatsUrl'];

11 changes: 5 additions & 6 deletions src/classmentors/components/ace/ace.specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {expect} from 'chai';
import sinon from 'sinon';

import tmpl from './2015-ace-view.html!text';
import {component, factory, ACE_STATS_URL} from './ace.js';
import {component, getStats, ACE_STATS_URL} from './ace.js';

describe('ace component', function() {

Expand Down Expand Up @@ -39,19 +39,18 @@ describe('aceStatsUrl constant', function() {

});

describe('aceStats service', function() {
describe('getStats resolver helper', function() {
const aceStatsUrl = 'http://ace.stats/';
let aceStats, http;
let http;

beforeEach(function() {
http = {
get: sinon.stub().returns(Promise.reject())
};
aceStats = factory(http, aceStatsUrl);
});

it('should fetch the ace stats', function() {
aceStats();
getStats(http, aceStatsUrl);
expect(http.get).to.have.been.calledOnce;
expect(http.get).to.have.been.calledWithExactly(aceStatsUrl);
});
Expand All @@ -63,7 +62,7 @@ describe('aceStats service', function() {

// By returning a promise, the test runner knows the test asynchronous
// and will wait for it resolve.
return aceStats().then(
return getStats(http, aceStatsUrl).then(
data => expect(data).to.equal(resp.data)
);
});
Expand Down
26 changes: 4 additions & 22 deletions src/classmentors/components/cohort/cohort.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
// import module from 'classmentors/module.js';
/**
* - define cohort component.
*/
import cohortTmpl from './cohort-view.html!text';
// import './cohort.css!';

// This here didn't work, not sure why - Amos
export const component = {
cohortTmpl
};
//
export function configRoute($routeProvider, routes){
$routeProvider.when(routes.cohort, {
template: cohortTmpl
});
}
configRoute.$inject = ['$routeProvider', 'routes'];
//
// module.config([
// '$routeProvider',
// 'routes',
// function($routeProvider, routes){
// console.log('SOMETHING HAPPENS HERE');
// $routeProvider
// .when(routes.cohort, {template: cohortTmpl})
// }
// ]);
export const component = {template: cohortTmpl};
Loading

0 comments on commit 8dab72a

Please sign in to comment.