Commit 797bf070 authored by Randall Leeds's avatar Randall Leeds

4 space -> 2 space

parent e5a03975
module.exports = ['$animate', function ($animate) {
return {
link: function (scope, elem, attrs) {
// ngAnimate conflicts with the spinners own CSS
$animate.enabled(false, elem);
},
restrict: 'C',
template: '<span><span></span></span>'
}
return {
link: function (scope, elem, attrs) {
// ngAnimate conflicts with the spinners own CSS
$animate.enabled(false, elem);
},
restrict: 'C',
template: '<span><span></span></span>'
}
}];
......@@ -6,31 +6,31 @@ var assert = chai.assert;
sinon.assert.expose(assert, {prefix: null});
describe('spinner', function () {
var $animate = null;
var $element = null
var sandbox = null;
var $animate = null;
var $element = null
var sandbox = null;
before(function () {
angular.module('h', []).directive('spinner', require('../spinner'));
});
before(function () {
angular.module('h', []).directive('spinner', require('../spinner'));
});
beforeEach(module('h'));
beforeEach(module('h'));
beforeEach(inject(function (_$animate_, $compile, $rootScope) {
sandbox = sinon.sandbox.create();
beforeEach(inject(function (_$animate_, $compile, $rootScope) {
sandbox = sinon.sandbox.create();
$animate = _$animate_;
sandbox.spy($animate, 'enabled');
$animate = _$animate_;
sandbox.spy($animate, 'enabled');
$element = angular.element('<span class="spinner"></span>');
$compile($element)($rootScope.$new());
}));
$element = angular.element('<span class="spinner"></span>');
$compile($element)($rootScope.$new());
}));
afterEach(function () {
sandbox.restore();
});
afterEach(function () {
sandbox.restore();
});
it('disables ngAnimate animations for itself', function () {
assert.calledWith($animate.enabled, false, sinon.match($element));
});
it('disables ngAnimate animations for itself', function () {
assert.calledWith($animate.enabled, false, sinon.match($element));
});
});
......@@ -24,42 +24,42 @@
var CACHE_TTL = 5 * 60 * 1000; // 5 minutes
function features ($document, $http, $log) {
var cache = null;
var featuresURL = new URL('/app/features', $document.prop('baseURI'));
var cache = null;
var featuresURL = new URL('/app/features', $document.prop('baseURI'));
function fetch() {
$http.get(featuresURL)
.success(function(data) {
cache = [Date.now(), data];
})
.error(function() {
$log.warn('features service: failed to load features data');
});
}
function fetch() {
$http.get(featuresURL)
.success(function(data) {
cache = [Date.now(), data];
})
.error(function() {
$log.warn('features service: failed to load features data');
});
}
function flagEnabled(name) {
// Trigger a fetch if the cache is more than CACHE_TTL milliseconds old.
// We don't wait for the fetch to complete, so it's not this call that
// will see new data.
if (cache === null || (Date.now() - cache[0]) > CACHE_TTL) {
fetch();
}
function flagEnabled(name) {
// Trigger a fetch if the cache is more than CACHE_TTL milliseconds old.
// We don't wait for the fetch to complete, so it's not this call that
// will see new data.
if (cache === null || (Date.now() - cache[0]) > CACHE_TTL) {
fetch();
}
if (cache === null) {
return false;
}
var flags = cache[1];
if (!flags.hasOwnProperty(name)) {
$log.warn('features service: looked up unknown feature:', name);
return false;
}
return flags[name];
if (cache === null) {
return false;
}
var flags = cache[1];
if (!flags.hasOwnProperty(name)) {
$log.warn('features service: looked up unknown feature:', name);
return false;
}
return flags[name];
}
return {
fetch: fetch,
flagEnabled: flagEnabled
};
return {
fetch: fetch,
flagEnabled: flagEnabled
};
}
module.exports = ['$document', '$http', '$log', features];
var Markdown = require('../vendor/Markdown.Converter');
function Converter() {
Markdown.Converter.call(this);
this.hooks.chain('preConversion', function (text) {
return text || '';
});
this.hooks.chain('postConversion', function (text) {
return text.replace(/<a href=/g, "<a target=\"_blank\" href=");
});
Markdown.Converter.call(this);
this.hooks.chain('preConversion', function (text) {
return text || '';
});
this.hooks.chain('postConversion', function (text) {
return text.replace(/<a href=/g, "<a target=\"_blank\" href=");
});
}
module.exports = function () {
return (new Converter()).makeHtml;
return (new Converter()).makeHtml;
};
module.exports = ['$window', function ($window) {
return function (value, format) {
// Determine the timezone name and browser language.
var timezone = jstz.determine().name();
var userLang = $window.navigator.language || $window.navigator.userLanguage;
return function (value, format) {
// Determine the timezone name and browser language.
var timezone = jstz.determine().name();
var userLang = $window.navigator.language || $window.navigator.userLanguage;
// Now make a localized date and set the language.
var momentDate = moment(value);
momentDate.lang(userLang);
// Now make a localized date and set the language.
var momentDate = moment(value);
momentDate.lang(userLang);
// Try to localize to the browser's timezone.
try {
return momentDate.tz(timezone).format('LLLL');
} catch (error) {
// For an invalid timezone, use the default.
return momentDate.format('LLLL');
}
};
// Try to localize to the browser's timezone.
try {
return momentDate.tz(timezone).format('LLLL');
} catch (error) {
// For an invalid timezone, use the default.
return momentDate.format('LLLL');
}
};
}];
module.exports = function () {
return function (user, part) {
if (typeof(part) === 'undefined') {
part = 'username';
}
var index = ['term', 'username', 'provider'].indexOf(part);
var groups = null;
return function (user, part) {
if (typeof(part) === 'undefined') {
part = 'username';
}
var index = ['term', 'username', 'provider'].indexOf(part);
var groups = null;
if (typeof(user) !== 'undefined' && user !== null) {
groups = user.match(/^acct:([^@]+)@(.+)/);
}
if (typeof(user) !== 'undefined' && user !== null) {
groups = user.match(/^acct:([^@]+)@(.+)/);
}
if (groups) {
return groups[index];
} else if (part !== 'provider') {
return user;
}
};
if (groups) {
return groups[index];
} else if (part !== 'provider') {
return user;
}
};
};
......@@ -6,38 +6,38 @@ var assert = chai.assert;
sinon.assert.expose(assert, {prefix: null});
describe('persona', function () {
var filter = null;
var term = 'acct:hacker@example.com';
before(function () {
angular.module('h', []).filter('persona', require('../persona'));
});
beforeEach(module('h'));
beforeEach(inject(function ($filter) {
filter = $filter('persona');
}));
it('should return the whole term by request', function () {
var result = filter('acct:hacker@example.com', 'term');
assert.equal(result, 'acct:hacker@example.com');
});
it('should return the requested part', function () {
assert.equal(filter(term), 'hacker');
assert.equal(filter(term, 'term'), term);
assert.equal(filter(term, 'username'), 'hacker');
assert.equal(filter(term, 'provider'), 'example.com');
});
it('should pass unrecognized terms as username or term', function () {
assert.equal(filter('bogus'), 'bogus');
assert.equal(filter('bogus', 'username'), 'bogus');
});
it('should handle error cases', function () {
assert.notOk(filter());
assert.notOk(filter('bogus', 'provider'));
});
var filter = null;
var term = 'acct:hacker@example.com';
before(function () {
angular.module('h', []).filter('persona', require('../persona'));
});
beforeEach(module('h'));
beforeEach(inject(function ($filter) {
filter = $filter('persona');
}));
it('should return the whole term by request', function () {
var result = filter('acct:hacker@example.com', 'term');
assert.equal(result, 'acct:hacker@example.com');
});
it('should return the requested part', function () {
assert.equal(filter(term), 'hacker');
assert.equal(filter(term, 'term'), term);
assert.equal(filter(term, 'username'), 'hacker');
assert.equal(filter(term, 'provider'), 'example.com');
});
it('should pass unrecognized terms as username or term', function () {
assert.equal(filter('bogus'), 'bogus');
assert.equal(filter('bogus', 'username'), 'bogus');
});
it('should handle error cases', function () {
assert.notOk(filter());
assert.notOk(filter('bogus', 'provider'));
});
});
......@@ -6,19 +6,19 @@ var assert = chai.assert;
sinon.assert.expose(assert, {prefix: null});
describe('urlencode', function () {
var filter = null;
var filter = null;
before(function () {
angular.module('h', []).filter('urlencode', require('../urlencode'));
});
before(function () {
angular.module('h', []).filter('urlencode', require('../urlencode'));
});
beforeEach(module('h'));
beforeEach(module('h'));
beforeEach(inject(function ($filter) {
filter = $filter('urlencode');
}));
beforeEach(inject(function ($filter) {
filter = $filter('urlencode');
}));
it('encodes reserved characters in the term', function () {
assert.equal(filter('#hello world'), '%23hello%20world');
});
it('encodes reserved characters in the term', function () {
assert.equal(filter('#hello world'), '%23hello%20world');
});
});
module.exports = function () {
return function (value) {
return encodeURIComponent(value);
};
return function (value) {
return encodeURIComponent(value);
};
};
......@@ -7,97 +7,97 @@ sinon.assert.expose(assert, {prefix: null});
describe('h:features', function () {
var $httpBackend;
var httpHandler;
var features;
var sandbox;
before(function () {
angular.module('h', [])
.service('features', require('../features'));
});
beforeEach(mock.module('h'));
beforeEach(mock.module(function ($provide) {
sandbox = sinon.sandbox.create();
var fakeDocument = {
prop: sandbox.stub()
};
fakeDocument.prop.withArgs('baseURI').returns('http://foo.com/');
$provide.value('$document', fakeDocument);
}));
beforeEach(mock.inject(function ($injector) {
$httpBackend = $injector.get('$httpBackend');
features = $injector.get('features');
httpHandler = $httpBackend.when('GET', 'http://foo.com/app/features');
httpHandler.respond(200, {foo: true, bar: false});
}));
afterEach(function () {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
sandbox.restore();
});
it('fetch should retrieve features data', function () {
$httpBackend.expect('GET', 'http://foo.com/app/features');
features.fetch();
$httpBackend.flush();
});
it('fetch should not explode for errors fetching features data', function () {
httpHandler.respond(500, "ASPLODE!");
features.fetch();
$httpBackend.flush();
});
it('flagEnabled should retrieve features data', function () {
$httpBackend.expect('GET', 'http://foo.com/app/features');
features.flagEnabled('foo');
$httpBackend.flush();
});
it('flagEnabled should return false initially', function () {
var result = features.flagEnabled('foo');
$httpBackend.flush();
assert.isFalse(result);
});
it('flagEnabled should return flag values when data is loaded', function () {
features.fetch();
$httpBackend.flush();
var foo = features.flagEnabled('foo');
assert.isTrue(foo);
var bar = features.flagEnabled('bar');
assert.isFalse(bar);
});
it('flagEnabled should return false for unknown flags', function () {
features.fetch();
$httpBackend.flush();
var baz = features.flagEnabled('baz');
assert.isFalse(baz);
});
it('flagEnabled should trigger a new fetch after cache expiry', function () {
var clock = sandbox.useFakeTimers();
$httpBackend.expect('GET', 'http://foo.com/app/features');
features.flagEnabled('foo');
$httpBackend.flush();
clock.tick(301 * 1000);
$httpBackend.expect('GET', 'http://foo.com/app/features');
features.flagEnabled('foo');
$httpBackend.flush();
});
var $httpBackend;
var httpHandler;
var features;
var sandbox;
before(function () {
angular.module('h', [])
.service('features', require('../features'));
});
beforeEach(mock.module('h'));
beforeEach(mock.module(function ($provide) {
sandbox = sinon.sandbox.create();
var fakeDocument = {
prop: sandbox.stub()
};
fakeDocument.prop.withArgs('baseURI').returns('http://foo.com/');
$provide.value('$document', fakeDocument);
}));
beforeEach(mock.inject(function ($injector) {
$httpBackend = $injector.get('$httpBackend');
features = $injector.get('features');
httpHandler = $httpBackend.when('GET', 'http://foo.com/app/features');
httpHandler.respond(200, {foo: true, bar: false});
}));
afterEach(function () {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
sandbox.restore();
});
it('fetch should retrieve features data', function () {
$httpBackend.expect('GET', 'http://foo.com/app/features');
features.fetch();
$httpBackend.flush();
});
it('fetch should not explode for errors fetching features data', function () {
httpHandler.respond(500, "ASPLODE!");
features.fetch();
$httpBackend.flush();
});
it('flagEnabled should retrieve features data', function () {
$httpBackend.expect('GET', 'http://foo.com/app/features');
features.flagEnabled('foo');
$httpBackend.flush();
});
it('flagEnabled should return false initially', function () {
var result = features.flagEnabled('foo');
$httpBackend.flush();
assert.isFalse(result);
});
it('flagEnabled should return flag values when data is loaded', function () {
features.fetch();
$httpBackend.flush();
var foo = features.flagEnabled('foo');
assert.isTrue(foo);
var bar = features.flagEnabled('bar');
assert.isFalse(bar);
});
it('flagEnabled should return false for unknown flags', function () {
features.fetch();
$httpBackend.flush();
var baz = features.flagEnabled('baz');
assert.isFalse(baz);
});
it('flagEnabled should trigger a new fetch after cache expiry', function () {
var clock = sandbox.useFakeTimers();
$httpBackend.expect('GET', 'http://foo.com/app/features');
features.flagEnabled('foo');
$httpBackend.flush();
clock.tick(301 * 1000);
$httpBackend.expect('GET', 'http://foo.com/app/features');
features.flagEnabled('foo');
$httpBackend.flush();
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment