Skip to content
This repository has been archived by the owner on Jun 16, 2018. It is now read-only.

Commit

Permalink
Merge branch 'master' into periodic_scores_refresh
Browse files Browse the repository at this point in the history
Conflicts:
	src/js/services/ng-scores.js
  • Loading branch information
poelstra committed Oct 27, 2017
2 parents 97e09a7 + a243e4a commit eb4582b
Show file tree
Hide file tree
Showing 30 changed files with 401 additions and 155 deletions.
6 changes: 2 additions & 4 deletions spec/controllers/DescriptionDialogControllerSpec.js
@@ -1,12 +1,10 @@
describe('DescriptionDialogController',function() {

var module = factory('controllers/DescriptionDialogController',{
// 'services/log': logMock,
});

var module;
var $scope, controller, handshakeMock;

beforeEach(function() {
module = factory('controllers/DescriptionDialogController');
angular.mock.module(module.name);
angular.mock.inject(function($controller,$rootScope,$q) {
$scope = $rootScope.$new();
Expand Down
9 changes: 5 additions & 4 deletions spec/controllers/ExportRankingDialiogControllerSpec.js
@@ -1,15 +1,16 @@
describe('ExportRankingDialogController',function() {

var module = factory('controllers/ExportRankingDialogController',{
'services/log': logMock,
});

var module;
var $scope, $timeout, stagesMock, scoresMock, handshakeMock;
var fakeScoreboard = {
"1": [1,2,3,4]
};

beforeEach(function() {
module = factory('controllers/ExportRankingDialogController',{
'services/log': logMock,
'services/fs': {},
});
angular.mock.module(module.name);
angular.mock.inject(function($controller,$rootScope,$q,_$timeout_) {
$scope = $rootScope.$new();
Expand Down
8 changes: 4 additions & 4 deletions spec/controllers/NewStageDialogControllerSpec.js
@@ -1,12 +1,12 @@
describe('NewStageDialogController',function() {

var module = factory('controllers/NewStageDialogController',{
'services/log': logMock,
});

var module;
var $scope, controller, handshakeMock;

beforeEach(function() {
module = factory('controllers/NewStageDialogController',{
'services/log': logMock,
});
angular.mock.module(module.name);
angular.mock.inject(function($controller,$rootScope,$q) {
$scope = $rootScope.$new();
Expand Down
8 changes: 4 additions & 4 deletions spec/controllers/RoundDialogControllerSpec.js
@@ -1,12 +1,12 @@
describe('RoundDialogController',function() {

var module = factory('controllers/RoundDialogController',{
'services/log': logMock,
});

var module;
var $scope, controller, handshakeMock;

beforeEach(function() {
module = factory('controllers/RoundDialogController',{
'services/log': logMock,
});
angular.mock.module(module.name);
angular.mock.inject(function($controller,$rootScope,$q) {
$scope = $rootScope.$new();
Expand Down
9 changes: 5 additions & 4 deletions spec/controllers/TeamDialogControllerSpec.js
@@ -1,12 +1,13 @@
describe('TeamDialogController',function() {

var module = factory('controllers/TeamDialogController',{
'services/log': logMock,
});

var module;
var $scope, controller, settingsMock, handshakeMock;

beforeEach(function() {
module = factory('controllers/TeamDialogController',{
'services/log': logMock,
'services/fs': {},
});
angular.mock.module(module.name);
angular.mock.inject(function($controller,$rootScope,$q) {
$scope = $rootScope.$new();
Expand Down
8 changes: 4 additions & 4 deletions spec/controllers/TeamImportDialogControllerSpec.js
@@ -1,12 +1,12 @@
describe('TeamImportDialogController',function() {

var module = factory('controllers/TeamImportDialogController',{
'services/log': logMock,
});

var module;
var $scope, controller, handshakeMock;

beforeEach(function() {
module = factory('controllers/TeamImportDialogController',{
'services/log': logMock,
});
angular.mock.module(module.name);
angular.mock.inject(function($controller,$rootScope,$q) {
$scope = $rootScope.$new();
Expand Down
7 changes: 4 additions & 3 deletions spec/directives/reallySpec.js
@@ -1,7 +1,8 @@
describe('really',function() {
var ngDirectives = factory('directives/ng-directives');
var module = factory('directives/really',{
'directives/ng-directives': ngDirectives
var module;

beforeEach(function() {
module = factory('directives/really');
});

var $compile,$rootScope,windowMock = {
Expand Down
10 changes: 4 additions & 6 deletions spec/directives/sigpadSpec.js
@@ -1,15 +1,13 @@
describe('sigpad',function() {
var ngDirectives = factory('directives/ng-directives');
var module = factory('directives/sigpad',{
'directives/ng-directives': ngDirectives
});


var module;
var $compile,$rootScope,
regenerateSpy,
drawEnd;

beforeEach(function() {
module = factory('directives/sigpad',{
'signaturepad': {},
});
angular.mock.module(module.name);
inject(function(_$compile_,_$rootScope_) {
$compile = _$compile_;
Expand Down
7 changes: 2 additions & 5 deletions spec/directives/sizeSpec.js
@@ -1,12 +1,9 @@
describe('size',function() {
var ngDirectives = factory('directives/ng-directives');
var module = factory('directives/size',{
'directives/ng-directives': ngDirectives
});

var module;
var $compile,$rootScope;

beforeEach(function() {
module = factory('directives/size');
angular.mock.module(module.name);
inject(function(_$compile_,_$rootScope_) {
$compile = _$compile_;
Expand Down
7 changes: 2 additions & 5 deletions spec/directives/spinnerSpec.js
@@ -1,12 +1,9 @@
xdescribe('spinner',function() {
var ngDirectives = factory('directives/ng-directives');
var module = factory('directives/spinner',{
'directives/ng-directives': ngDirectives
});

var module;
var $compile, $scope, $timeout, element, container, frame, prev, next;

beforeEach(function() {
module = factory('directives/spinner');
//add some styling to make it work
var style = angular.element(multiline(function() {/*
<style id="spinnerStyle">
Expand Down
7 changes: 2 additions & 5 deletions spec/filters/indexSpec.js
@@ -1,12 +1,9 @@
describe('indexFilter',function() {
var ngFilters = factory('filters/ng-filters');
var module = factory('filters/index',{
'filters/ng-filters': ngFilters
});

var module;
var index;

beforeEach(function() {
module = factory('filters/index');
angular.mock.module(module.name);
angular.mock.inject(function(indexFilter) {
index = indexFilter;
Expand Down
181 changes: 156 additions & 25 deletions spec/helpers/defineShim.js
@@ -1,27 +1,158 @@
/**
* This shim replaces RequireJS (which is used outside the tests), and allows
* modules to be injected with e.g. mocks instead of the 'real deal', if necessary.
*
* It adds two functions to the global namespace: define() and factory().
*/
!function() {
var store = {};
var inited = {};
this.factory = function(name,deps,force) {
if (inited[name] && !force) {
return inited[name];
}
if (!store[name]) {
console.log('unable to find module',name,'in store');
console.log(JSON.stringify(store,null,2));
return;
}
deps = deps||{};
var resolvedDeps = store[name].deps.map(function(dep) {
return deps[dep]||undefined;
});
inited[name] = store[name].factory.apply(this,resolvedDeps);
return inited[name];
};
this.define = function(name,deps,factory) {
//store factories in a global store
store[name] = {
factory: factory,
deps: deps
};
};
var store = {};

/**
* Resolve the relative path of the require'd module
* to the current module's basename.
* e.g. if name = "common/foo" and dep = "./bar",
* result will be "common/bar".
*/
function resolveRelativeDependency(name, dep) {
var base = name.split("/");
var relative = dep.split("/");
base.pop(); // take the 'filename' off, leaving the 'current folder'
if (relative[0] !== "." && relative[0] !== "..") {
throw new Error("invalid dependency '" + dep + "' in module '" + name + "': relative path expected");
}
while (relative.length > 0) {
var part = relative.shift();
if (part === "" || part === ".") {
continue;
} else if (part === "..") {
if (base.length === 0) {
throw new Error("invalid dependency '" + dep + "' in module '" + name + "': cannot go up this far");
}
base.pop();
} else {
base.push(part);
}
}
return base.join("/");
}

function resolve(name, deps, cache) {
if (typeof name !== "string") {
throw new Error("factory(): invalid module name: " + name);
}

if (cache[name]) {
return cache[name];
}

if (!store[name]) {
throw new Error("factory(): module " + name + " is not yet define()'ed");
}

if (store[name].deps !== undefined) {
// 'Normal' AMD module, as used in all of our front-end code.

// Resolve dependencies of this module to either the
// passed in custom dependencies, or the 'real' ones.
var resolvedDeps = store[name].deps.map(function(dep) {
// Use custom deps, if passed
if (deps && dep in deps) {
return deps[dep];
}
// Use the 'real' module instead, but make sure that if
// that real module uses a dependency that we want to
// override, we use that instead.
return resolve(dep, deps, cache);
});

// Instantiate module
cache[name] = store[name].factory.apply(this, resolvedDeps);
} else {
// UMD style module, as used in our common (client+server) code.

function require(dep) {
if (typeof dep !== "string" || dep === "") {
throw new Error("invalid dependency '" + dep + "' in module '" + name + "'");
}
return resolve(resolveRelativeDependency(name, dep), deps, cache);
}
var module = { exports: {} };
var exports = module.exports;

// Instantiate module
store[name].factory.call(this, require, exports, module);
cache[name] = module.exports;
}

return cache[name];
}

/**
* Instantiate module including dependencies.
*
* Obtain reference to module, optionally passing in an object of dependencyName => object pairs to
* instantiate a version of the module using any 'custom' dependency (e.g. mocked versions).
*
* All modules (including dependencies) created during the call to factory() are guaranteed to be
* instantiated just once within this call to factory(), but the next call to factory() will
* use a new module cache.
*
* Note that the angular and jquery modules behave special, in that they are global instances
* that are not (re)created for each call to factory().
* This means that every factory call for a module using e.g. ng-services will create a new instance
* of the ng-services angular module (angular.module('ng-services', [])), so later calls to
* factory() will 'disconnect' that earlier module.
* Thus, you must make sure that any call to factory() immediately precedes the tests you're
* running, e.g. by placing it in a beforeEach() (not directly in the body of e.g. describe()).
*
* Shim for RequireJS functionality.
*
* @param name {string} Name of module to instantiate
* @param deps {Object} Optional key-value pairs of dependencies to override
*/
this.factory = function(name, deps) {
return resolve(name, deps, {});
};

/**
* Define a module to be instantiated later using `factory()`.
*
* Shim for RequireJS define functionality.
*
* @see documentation of `factory()` for caveats.
*
* @param name {string} Name of module, e.g. "services/ng-scores"
* @param deps {Array<string>} Optional array of dependencies. @see `factory`
* @param factory {Function} When deps are given, function receiving deps as args, returning the module, when
* no deps are given, function receiving `require`, `exports`, `module`, returning nothing
* (setting its exports through `exports` or `module.exports`).
*/
this.define = function(name, deps, factory) {
if (typeof name !== "string") {
throw new Error("factory(): invalid module name: " + name);
}
if (store[name]) {
throw new Error("factory(): duplicate module name: " + name);
}
if (typeof deps === "function") {
// This is a UMD-style call, which only passes the module name
// and a factory function which expects to receive
// `require`, `exports`, and `module`.
factory = deps;
deps = undefined;
} else {
if (!Array.isArray(deps)) {
throw new Error("factory(): invalid dependencies (expected an array): " + deps);
}
}
//store factories in a global store
store[name] = {
factory: factory,
deps: deps
};
};
}();

// Pre-register 'well-known' modules
define("jquery", [], function() { return $; });
define("angular", [], function () { return angular; });

0 comments on commit eb4582b

Please sign in to comment.