Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
797bf070
Commit
797bf070
authored
Jul 19, 2015
by
Randall Leeds
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
4 space -> 2 space
parent
e5a03975
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
238 additions
and
238 deletions
+238
-238
spinner.js
h/static/scripts/directive/spinner.js
+8
-8
spinner-test.js
h/static/scripts/directive/test/spinner-test.js
+20
-20
features.js
h/static/scripts/features.js
+31
-31
converter.js
h/static/scripts/filter/converter.js
+8
-8
moment.js
h/static/scripts/filter/moment.js
+15
-15
persona.js
h/static/scripts/filter/persona.js
+15
-15
persona-test.js
h/static/scripts/filter/test/persona-test.js
+34
-34
urlencode-test.js
h/static/scripts/filter/test/urlencode-test.js
+11
-11
urlencode.js
h/static/scripts/filter/urlencode.js
+3
-3
features-test.js
h/static/scripts/test/features-test.js
+93
-93
No files found.
h/static/scripts/directive/spinner.js
View file @
797bf070
module
.
exports
=
[
'$animate'
,
function
(
$animate
)
{
module
.
exports
=
[
'$animate'
,
function
(
$animate
)
{
return
{
return
{
link
:
function
(
scope
,
elem
,
attrs
)
{
link
:
function
(
scope
,
elem
,
attrs
)
{
// ngAnimate conflicts with the spinners own CSS
// ngAnimate conflicts with the spinners own CSS
$animate
.
enabled
(
false
,
elem
);
$animate
.
enabled
(
false
,
elem
);
},
},
restrict
:
'C'
,
restrict
:
'C'
,
template
:
'<span><span></span></span>'
template
:
'<span><span></span></span>'
}
}
}];
}];
h/static/scripts/directive/test/spinner-test.js
View file @
797bf070
...
@@ -6,31 +6,31 @@ var assert = chai.assert;
...
@@ -6,31 +6,31 @@ var assert = chai.assert;
sinon
.
assert
.
expose
(
assert
,
{
prefix
:
null
});
sinon
.
assert
.
expose
(
assert
,
{
prefix
:
null
});
describe
(
'spinner'
,
function
()
{
describe
(
'spinner'
,
function
()
{
var
$animate
=
null
;
var
$animate
=
null
;
var
$element
=
null
var
$element
=
null
var
sandbox
=
null
;
var
sandbox
=
null
;
before
(
function
()
{
before
(
function
()
{
angular
.
module
(
'h'
,
[]).
directive
(
'spinner'
,
require
(
'../spinner'
));
angular
.
module
(
'h'
,
[]).
directive
(
'spinner'
,
require
(
'../spinner'
));
});
});
beforeEach
(
module
(
'h'
));
beforeEach
(
module
(
'h'
));
beforeEach
(
inject
(
function
(
_$animate_
,
$compile
,
$rootScope
)
{
beforeEach
(
inject
(
function
(
_$animate_
,
$compile
,
$rootScope
)
{
sandbox
=
sinon
.
sandbox
.
create
();
sandbox
=
sinon
.
sandbox
.
create
();
$animate
=
_$animate_
;
$animate
=
_$animate_
;
sandbox
.
spy
(
$animate
,
'enabled'
);
sandbox
.
spy
(
$animate
,
'enabled'
);
$element
=
angular
.
element
(
'<span class="spinner"></span>'
);
$element
=
angular
.
element
(
'<span class="spinner"></span>'
);
$compile
(
$element
)(
$rootScope
.
$new
());
$compile
(
$element
)(
$rootScope
.
$new
());
}));
}));
afterEach
(
function
()
{
afterEach
(
function
()
{
sandbox
.
restore
();
sandbox
.
restore
();
});
});
it
(
'disables ngAnimate animations for itself'
,
function
()
{
it
(
'disables ngAnimate animations for itself'
,
function
()
{
assert
.
calledWith
(
$animate
.
enabled
,
false
,
sinon
.
match
(
$element
));
assert
.
calledWith
(
$animate
.
enabled
,
false
,
sinon
.
match
(
$element
));
});
});
});
});
h/static/scripts/features.js
View file @
797bf070
...
@@ -24,42 +24,42 @@
...
@@ -24,42 +24,42 @@
var
CACHE_TTL
=
5
*
60
*
1000
;
// 5 minutes
var
CACHE_TTL
=
5
*
60
*
1000
;
// 5 minutes
function
features
(
$document
,
$http
,
$log
)
{
function
features
(
$document
,
$http
,
$log
)
{
var
cache
=
null
;
var
cache
=
null
;
var
featuresURL
=
new
URL
(
'/app/features'
,
$document
.
prop
(
'baseURI'
));
var
featuresURL
=
new
URL
(
'/app/features'
,
$document
.
prop
(
'baseURI'
));
function
fetch
()
{
function
fetch
()
{
$http
.
get
(
featuresURL
)
$http
.
get
(
featuresURL
)
.
success
(
function
(
data
)
{
.
success
(
function
(
data
)
{
cache
=
[
Date
.
now
(),
data
];
cache
=
[
Date
.
now
(),
data
];
})
})
.
error
(
function
()
{
.
error
(
function
()
{
$log
.
warn
(
'features service: failed to load features data'
);
$log
.
warn
(
'features service: failed to load features data'
);
});
});
}
}
function
flagEnabled
(
name
)
{
function
flagEnabled
(
name
)
{
// Trigger a fetch if the cache is more than CACHE_TTL milliseconds old.
// 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
// We don't wait for the fetch to complete, so it's not this call that
// will see new data.
// will see new data.
if
(
cache
===
null
||
(
Date
.
now
()
-
cache
[
0
])
>
CACHE_TTL
)
{
if
(
cache
===
null
||
(
Date
.
now
()
-
cache
[
0
])
>
CACHE_TTL
)
{
fetch
();
fetch
();
}
}
if
(
cache
===
null
)
{
if
(
cache
===
null
)
{
return
false
;
return
false
;
}
}
var
flags
=
cache
[
1
];
var
flags
=
cache
[
1
];
if
(
!
flags
.
hasOwnProperty
(
name
))
{
if
(
!
flags
.
hasOwnProperty
(
name
))
{
$log
.
warn
(
'features service: looked up unknown feature:'
,
name
);
$log
.
warn
(
'features service: looked up unknown feature:'
,
name
);
return
false
;
return
false
;
}
return
flags
[
name
];
}
}
return
flags
[
name
];
}
return
{
return
{
fetch
:
fetch
,
fetch
:
fetch
,
flagEnabled
:
flagEnabled
flagEnabled
:
flagEnabled
};
};
}
}
module
.
exports
=
[
'$document'
,
'$http'
,
'$log'
,
features
];
module
.
exports
=
[
'$document'
,
'$http'
,
'$log'
,
features
];
h/static/scripts/filter/converter.js
View file @
797bf070
var
Markdown
=
require
(
'../vendor/Markdown.Converter'
);
var
Markdown
=
require
(
'../vendor/Markdown.Converter'
);
function
Converter
()
{
function
Converter
()
{
Markdown
.
Converter
.
call
(
this
);
Markdown
.
Converter
.
call
(
this
);
this
.
hooks
.
chain
(
'preConversion'
,
function
(
text
)
{
this
.
hooks
.
chain
(
'preConversion'
,
function
(
text
)
{
return
text
||
''
;
return
text
||
''
;
});
});
this
.
hooks
.
chain
(
'postConversion'
,
function
(
text
)
{
this
.
hooks
.
chain
(
'postConversion'
,
function
(
text
)
{
return
text
.
replace
(
/<a href=/g
,
"<a target=
\"
_blank
\"
href="
);
return
text
.
replace
(
/<a href=/g
,
"<a target=
\"
_blank
\"
href="
);
});
});
}
}
module
.
exports
=
function
()
{
module
.
exports
=
function
()
{
return
(
new
Converter
()).
makeHtml
;
return
(
new
Converter
()).
makeHtml
;
};
};
h/static/scripts/filter/moment.js
View file @
797bf070
module
.
exports
=
[
'$window'
,
function
(
$window
)
{
module
.
exports
=
[
'$window'
,
function
(
$window
)
{
return
function
(
value
,
format
)
{
return
function
(
value
,
format
)
{
// Determine the timezone name and browser language.
// Determine the timezone name and browser language.
var
timezone
=
jstz
.
determine
().
name
();
var
timezone
=
jstz
.
determine
().
name
();
var
userLang
=
$window
.
navigator
.
language
||
$window
.
navigator
.
userLanguage
;
var
userLang
=
$window
.
navigator
.
language
||
$window
.
navigator
.
userLanguage
;
// Now make a localized date and set the language.
// Now make a localized date and set the language.
var
momentDate
=
moment
(
value
);
var
momentDate
=
moment
(
value
);
momentDate
.
lang
(
userLang
);
momentDate
.
lang
(
userLang
);
// Try to localize to the browser's timezone.
// Try to localize to the browser's timezone.
try
{
try
{
return
momentDate
.
tz
(
timezone
).
format
(
'LLLL'
);
return
momentDate
.
tz
(
timezone
).
format
(
'LLLL'
);
}
catch
(
error
)
{
}
catch
(
error
)
{
// For an invalid timezone, use the default.
// For an invalid timezone, use the default.
return
momentDate
.
format
(
'LLLL'
);
return
momentDate
.
format
(
'LLLL'
);
}
}
};
};
}];
}];
h/static/scripts/filter/persona.js
View file @
797bf070
module
.
exports
=
function
()
{
module
.
exports
=
function
()
{
return
function
(
user
,
part
)
{
return
function
(
user
,
part
)
{
if
(
typeof
(
part
)
===
'undefined'
)
{
if
(
typeof
(
part
)
===
'undefined'
)
{
part
=
'username'
;
part
=
'username'
;
}
}
var
index
=
[
'term'
,
'username'
,
'provider'
].
indexOf
(
part
);
var
index
=
[
'term'
,
'username'
,
'provider'
].
indexOf
(
part
);
var
groups
=
null
;
var
groups
=
null
;
if
(
typeof
(
user
)
!==
'undefined'
&&
user
!==
null
)
{
if
(
typeof
(
user
)
!==
'undefined'
&&
user
!==
null
)
{
groups
=
user
.
match
(
/^acct:
([^
@
]
+
)
@
(
.+
)
/
);
groups
=
user
.
match
(
/^acct:
([^
@
]
+
)
@
(
.+
)
/
);
}
}
if
(
groups
)
{
if
(
groups
)
{
return
groups
[
index
];
return
groups
[
index
];
}
else
if
(
part
!==
'provider'
)
{
}
else
if
(
part
!==
'provider'
)
{
return
user
;
return
user
;
}
}
};
};
};
};
h/static/scripts/filter/test/persona-test.js
View file @
797bf070
...
@@ -6,38 +6,38 @@ var assert = chai.assert;
...
@@ -6,38 +6,38 @@ var assert = chai.assert;
sinon
.
assert
.
expose
(
assert
,
{
prefix
:
null
});
sinon
.
assert
.
expose
(
assert
,
{
prefix
:
null
});
describe
(
'persona'
,
function
()
{
describe
(
'persona'
,
function
()
{
var
filter
=
null
;
var
filter
=
null
;
var
term
=
'acct:hacker@example.com'
;
var
term
=
'acct:hacker@example.com'
;
before
(
function
()
{
before
(
function
()
{
angular
.
module
(
'h'
,
[]).
filter
(
'persona'
,
require
(
'../persona'
));
angular
.
module
(
'h'
,
[]).
filter
(
'persona'
,
require
(
'../persona'
));
});
});
beforeEach
(
module
(
'h'
));
beforeEach
(
module
(
'h'
));
beforeEach
(
inject
(
function
(
$filter
)
{
beforeEach
(
inject
(
function
(
$filter
)
{
filter
=
$filter
(
'persona'
);
filter
=
$filter
(
'persona'
);
}));
}));
it
(
'should return the whole term by request'
,
function
()
{
it
(
'should return the whole term by request'
,
function
()
{
var
result
=
filter
(
'acct:hacker@example.com'
,
'term'
);
var
result
=
filter
(
'acct:hacker@example.com'
,
'term'
);
assert
.
equal
(
result
,
'acct:hacker@example.com'
);
assert
.
equal
(
result
,
'acct:hacker@example.com'
);
});
});
it
(
'should return the requested part'
,
function
()
{
it
(
'should return the requested part'
,
function
()
{
assert
.
equal
(
filter
(
term
),
'hacker'
);
assert
.
equal
(
filter
(
term
),
'hacker'
);
assert
.
equal
(
filter
(
term
,
'term'
),
term
);
assert
.
equal
(
filter
(
term
,
'term'
),
term
);
assert
.
equal
(
filter
(
term
,
'username'
),
'hacker'
);
assert
.
equal
(
filter
(
term
,
'username'
),
'hacker'
);
assert
.
equal
(
filter
(
term
,
'provider'
),
'example.com'
);
assert
.
equal
(
filter
(
term
,
'provider'
),
'example.com'
);
});
});
it
(
'should pass unrecognized terms as username or term'
,
function
()
{
it
(
'should pass unrecognized terms as username or term'
,
function
()
{
assert
.
equal
(
filter
(
'bogus'
),
'bogus'
);
assert
.
equal
(
filter
(
'bogus'
),
'bogus'
);
assert
.
equal
(
filter
(
'bogus'
,
'username'
),
'bogus'
);
assert
.
equal
(
filter
(
'bogus'
,
'username'
),
'bogus'
);
});
});
it
(
'should handle error cases'
,
function
()
{
it
(
'should handle error cases'
,
function
()
{
assert
.
notOk
(
filter
());
assert
.
notOk
(
filter
());
assert
.
notOk
(
filter
(
'bogus'
,
'provider'
));
assert
.
notOk
(
filter
(
'bogus'
,
'provider'
));
});
});
});
});
h/static/scripts/filter/test/urlencode-test.js
View file @
797bf070
...
@@ -6,19 +6,19 @@ var assert = chai.assert;
...
@@ -6,19 +6,19 @@ var assert = chai.assert;
sinon
.
assert
.
expose
(
assert
,
{
prefix
:
null
});
sinon
.
assert
.
expose
(
assert
,
{
prefix
:
null
});
describe
(
'urlencode'
,
function
()
{
describe
(
'urlencode'
,
function
()
{
var
filter
=
null
;
var
filter
=
null
;
before
(
function
()
{
before
(
function
()
{
angular
.
module
(
'h'
,
[]).
filter
(
'urlencode'
,
require
(
'../urlencode'
));
angular
.
module
(
'h'
,
[]).
filter
(
'urlencode'
,
require
(
'../urlencode'
));
});
});
beforeEach
(
module
(
'h'
));
beforeEach
(
module
(
'h'
));
beforeEach
(
inject
(
function
(
$filter
)
{
beforeEach
(
inject
(
function
(
$filter
)
{
filter
=
$filter
(
'urlencode'
);
filter
=
$filter
(
'urlencode'
);
}));
}));
it
(
'encodes reserved characters in the term'
,
function
()
{
it
(
'encodes reserved characters in the term'
,
function
()
{
assert
.
equal
(
filter
(
'#hello world'
),
'%23hello%20world'
);
assert
.
equal
(
filter
(
'#hello world'
),
'%23hello%20world'
);
});
});
});
});
h/static/scripts/filter/urlencode.js
View file @
797bf070
module
.
exports
=
function
()
{
module
.
exports
=
function
()
{
return
function
(
value
)
{
return
function
(
value
)
{
return
encodeURIComponent
(
value
);
return
encodeURIComponent
(
value
);
};
};
};
};
h/static/scripts/test/features-test.js
View file @
797bf070
...
@@ -7,97 +7,97 @@ sinon.assert.expose(assert, {prefix: null});
...
@@ -7,97 +7,97 @@ sinon.assert.expose(assert, {prefix: null});
describe
(
'h:features'
,
function
()
{
describe
(
'h:features'
,
function
()
{
var
$httpBackend
;
var
$httpBackend
;
var
httpHandler
;
var
httpHandler
;
var
features
;
var
features
;
var
sandbox
;
var
sandbox
;
before
(
function
()
{
before
(
function
()
{
angular
.
module
(
'h'
,
[])
angular
.
module
(
'h'
,
[])
.
service
(
'features'
,
require
(
'../features'
));
.
service
(
'features'
,
require
(
'../features'
));
});
});
beforeEach
(
mock
.
module
(
'h'
));
beforeEach
(
mock
.
module
(
'h'
));
beforeEach
(
mock
.
module
(
function
(
$provide
)
{
beforeEach
(
mock
.
module
(
function
(
$provide
)
{
sandbox
=
sinon
.
sandbox
.
create
();
sandbox
=
sinon
.
sandbox
.
create
();
var
fakeDocument
=
{
var
fakeDocument
=
{
prop
:
sandbox
.
stub
()
prop
:
sandbox
.
stub
()
};
};
fakeDocument
.
prop
.
withArgs
(
'baseURI'
).
returns
(
'http://foo.com/'
);
fakeDocument
.
prop
.
withArgs
(
'baseURI'
).
returns
(
'http://foo.com/'
);
$provide
.
value
(
'$document'
,
fakeDocument
);
$provide
.
value
(
'$document'
,
fakeDocument
);
}));
}));
beforeEach
(
mock
.
inject
(
function
(
$injector
)
{
beforeEach
(
mock
.
inject
(
function
(
$injector
)
{
$httpBackend
=
$injector
.
get
(
'$httpBackend'
);
$httpBackend
=
$injector
.
get
(
'$httpBackend'
);
features
=
$injector
.
get
(
'features'
);
features
=
$injector
.
get
(
'features'
);
httpHandler
=
$httpBackend
.
when
(
'GET'
,
'http://foo.com/app/features'
);
httpHandler
=
$httpBackend
.
when
(
'GET'
,
'http://foo.com/app/features'
);
httpHandler
.
respond
(
200
,
{
foo
:
true
,
bar
:
false
});
httpHandler
.
respond
(
200
,
{
foo
:
true
,
bar
:
false
});
}));
}));
afterEach
(
function
()
{
afterEach
(
function
()
{
$httpBackend
.
verifyNoOutstandingExpectation
();
$httpBackend
.
verifyNoOutstandingExpectation
();
$httpBackend
.
verifyNoOutstandingRequest
();
$httpBackend
.
verifyNoOutstandingRequest
();
sandbox
.
restore
();
sandbox
.
restore
();
});
});
it
(
'fetch should retrieve features data'
,
function
()
{
it
(
'fetch should retrieve features data'
,
function
()
{
$httpBackend
.
expect
(
'GET'
,
'http://foo.com/app/features'
);
$httpBackend
.
expect
(
'GET'
,
'http://foo.com/app/features'
);
features
.
fetch
();
features
.
fetch
();
$httpBackend
.
flush
();
$httpBackend
.
flush
();
});
});
it
(
'fetch should not explode for errors fetching features data'
,
function
()
{
it
(
'fetch should not explode for errors fetching features data'
,
function
()
{
httpHandler
.
respond
(
500
,
"ASPLODE!"
);
httpHandler
.
respond
(
500
,
"ASPLODE!"
);
features
.
fetch
();
features
.
fetch
();
$httpBackend
.
flush
();
$httpBackend
.
flush
();
});
});
it
(
'flagEnabled should retrieve features data'
,
function
()
{
it
(
'flagEnabled should retrieve features data'
,
function
()
{
$httpBackend
.
expect
(
'GET'
,
'http://foo.com/app/features'
);
$httpBackend
.
expect
(
'GET'
,
'http://foo.com/app/features'
);
features
.
flagEnabled
(
'foo'
);
features
.
flagEnabled
(
'foo'
);
$httpBackend
.
flush
();
$httpBackend
.
flush
();
});
});
it
(
'flagEnabled should return false initially'
,
function
()
{
it
(
'flagEnabled should return false initially'
,
function
()
{
var
result
=
features
.
flagEnabled
(
'foo'
);
var
result
=
features
.
flagEnabled
(
'foo'
);
$httpBackend
.
flush
();
$httpBackend
.
flush
();
assert
.
isFalse
(
result
);
assert
.
isFalse
(
result
);
});
});
it
(
'flagEnabled should return flag values when data is loaded'
,
function
()
{
it
(
'flagEnabled should return flag values when data is loaded'
,
function
()
{
features
.
fetch
();
features
.
fetch
();
$httpBackend
.
flush
();
$httpBackend
.
flush
();
var
foo
=
features
.
flagEnabled
(
'foo'
);
var
foo
=
features
.
flagEnabled
(
'foo'
);
assert
.
isTrue
(
foo
);
assert
.
isTrue
(
foo
);
var
bar
=
features
.
flagEnabled
(
'bar'
);
var
bar
=
features
.
flagEnabled
(
'bar'
);
assert
.
isFalse
(
bar
);
assert
.
isFalse
(
bar
);
});
});
it
(
'flagEnabled should return false for unknown flags'
,
function
()
{
it
(
'flagEnabled should return false for unknown flags'
,
function
()
{
features
.
fetch
();
features
.
fetch
();
$httpBackend
.
flush
();
$httpBackend
.
flush
();
var
baz
=
features
.
flagEnabled
(
'baz'
);
var
baz
=
features
.
flagEnabled
(
'baz'
);
assert
.
isFalse
(
baz
);
assert
.
isFalse
(
baz
);
});
});
it
(
'flagEnabled should trigger a new fetch after cache expiry'
,
function
()
{
it
(
'flagEnabled should trigger a new fetch after cache expiry'
,
function
()
{
var
clock
=
sandbox
.
useFakeTimers
();
var
clock
=
sandbox
.
useFakeTimers
();
$httpBackend
.
expect
(
'GET'
,
'http://foo.com/app/features'
);
$httpBackend
.
expect
(
'GET'
,
'http://foo.com/app/features'
);
features
.
flagEnabled
(
'foo'
);
features
.
flagEnabled
(
'foo'
);
$httpBackend
.
flush
();
$httpBackend
.
flush
();
clock
.
tick
(
301
*
1000
);
clock
.
tick
(
301
*
1000
);
$httpBackend
.
expect
(
'GET'
,
'http://foo.com/app/features'
);
$httpBackend
.
expect
(
'GET'
,
'http://foo.com/app/features'
);
features
.
flagEnabled
(
'foo'
);
features
.
flagEnabled
(
'foo'
);
$httpBackend
.
flush
();
$httpBackend
.
flush
();
});
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment