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
33f0450a
Commit
33f0450a
authored
Mar 16, 2017
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert `<excerpt>` to a component
parent
7112851f
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
147 additions
and
153 deletions
+147
-153
app.js
src/sidebar/app.js
+1
-1
excerpt.js
src/sidebar/directive/excerpt.js
+126
-132
excerpt-test.js
src/sidebar/directive/test/excerpt-test.js
+20
-20
No files found.
src/sidebar/app.js
View file @
33f0450a
...
...
@@ -140,6 +140,7 @@ module.exports = angular.module('h', [
.
component
(
'annotationShareDialog'
,
require
(
'./components/annotation-share-dialog'
))
.
component
(
'annotationThread'
,
require
(
'./components/annotation-thread'
))
.
component
(
'dropdownMenuBtn'
,
require
(
'./components/dropdown-menu-btn'
))
.
component
(
'excerpt'
,
require
(
'./directive/excerpt'
).
component
)
.
component
(
'groupList'
,
require
(
'./components/group-list'
))
.
component
(
'helpLink'
,
require
(
'./components/help-link'
))
.
component
(
'helpPanel'
,
require
(
'./components/help-panel'
))
...
...
@@ -163,7 +164,6 @@ module.exports = angular.module('h', [
.
directive
(
'markdown'
,
require
(
'./directive/markdown'
))
.
directive
(
'topBar'
,
require
(
'./directive/top-bar'
))
.
directive
(
'excerpt'
,
require
(
'./directive/excerpt'
).
directive
)
.
directive
(
'formInput'
,
require
(
'./directive/form-input'
))
.
directive
(
'formValidate'
,
require
(
'./directive/form-validate'
))
.
directive
(
'hAutofocus'
,
require
(
'./directive/h-autofocus'
))
...
...
src/sidebar/directive/excerpt.js
View file @
33f0450a
This diff is collapsed.
Click to expand it.
src/sidebar/directive/test/excerpt-test.js
View file @
33f0450a
...
...
@@ -5,14 +5,14 @@ var angular = require('angular');
var
util
=
require
(
'./util'
);
var
excerpt
=
require
(
'../excerpt'
);
describe
(
'excerpt
directive
'
,
function
()
{
describe
(
'excerpt'
,
function
()
{
// ExcerptOverflowMonitor fake instance created by the current test
var
fakeOverflowMonitor
;
var
SHORT_DIV
=
'<div id="foo" style="height:5px;"></div>'
;
var
TALL_DIV
=
'<div id="foo" style="height:200px;">foo bar</div>'
;
function
excerpt
Directive
(
attrs
,
content
)
{
function
excerpt
Component
(
attrs
,
content
)
{
var
defaultAttrs
=
{
enabled
:
true
,
contentData
:
'the content'
,
...
...
@@ -25,7 +25,7 @@ describe('excerpt directive', function () {
before
(
function
()
{
angular
.
module
(
'app'
,
[])
.
directive
(
'excerpt'
,
excerpt
.
directive
);
.
component
(
'excerpt'
,
excerpt
.
component
);
});
beforeEach
(
function
()
{
...
...
@@ -45,7 +45,7 @@ describe('excerpt directive', function () {
context
(
'when created'
,
function
()
{
it
(
'schedules an overflow state recalculation'
,
function
()
{
excerpt
Directive
({},
'<span id="foo"></span>'
);
excerpt
Component
({},
'<span id="foo"></span>'
);
assert
.
called
(
fakeOverflowMonitor
.
check
);
});
...
...
@@ -57,7 +57,7 @@ describe('excerpt directive', function () {
inlineControls
:
false
,
overflowHysteresis
:
20
,
};
excerpt
Directive
(
attrs
,
'<span></span>'
);
excerpt
Component
(
attrs
,
'<span></span>'
);
assert
.
deepEqual
(
fakeOverflowMonitor
.
ctrl
.
getState
(),
{
animate
:
attrs
.
animate
,
enabled
:
attrs
.
enabled
,
...
...
@@ -68,14 +68,14 @@ describe('excerpt directive', function () {
});
it
(
'reports the content height to ExcerptOverflowMonitor'
,
function
()
{
excerpt
Directive
({},
TALL_DIV
);
excerpt
Component
({},
TALL_DIV
);
assert
.
deepEqual
(
fakeOverflowMonitor
.
ctrl
.
contentHeight
(),
200
);
});
});
context
(
'input changes'
,
function
()
{
it
(
'schedules an overflow state check when inputs change'
,
function
()
{
var
element
=
excerpt
Directive
({},
'<span></span>'
);
var
element
=
excerpt
Component
({},
'<span></span>'
);
fakeOverflowMonitor
.
check
.
reset
();
element
.
scope
.
contentData
=
'new-content'
;
element
.
scope
.
$digest
();
...
...
@@ -83,7 +83,7 @@ describe('excerpt directive', function () {
});
it
(
'does not schedule a state check if inputs are unchanged'
,
function
()
{
var
element
=
excerpt
Directive
({},
'<span></span>'
);
var
element
=
excerpt
Component
({},
'<span></span>'
);
fakeOverflowMonitor
.
check
.
reset
();
element
.
scope
.
$digest
();
assert
.
notCalled
(
fakeOverflowMonitor
.
check
);
...
...
@@ -92,14 +92,14 @@ describe('excerpt directive', function () {
context
(
'document events'
,
function
()
{
it
(
'schedules an overflow check when media loads'
,
function
()
{
var
element
=
excerpt
Directive
({},
'<img src="https://example.com/foo.jpg">'
);
var
element
=
excerpt
Component
({},
'<img src="https://example.com/foo.jpg">'
);
fakeOverflowMonitor
.
check
.
reset
();
util
.
sendEvent
(
element
[
0
],
'load'
);
assert
.
called
(
fakeOverflowMonitor
.
check
);
});
it
(
'schedules an overflow check when the window is resized'
,
function
()
{
var
element
=
excerpt
Directive
({},
'<span></span>'
);
var
element
=
excerpt
Component
({},
'<span></span>'
);
fakeOverflowMonitor
.
check
.
reset
();
util
.
sendEvent
(
element
[
0
].
ownerDocument
.
defaultView
,
'resize'
);
assert
.
called
(
fakeOverflowMonitor
.
check
);
...
...
@@ -108,7 +108,7 @@ describe('excerpt directive', function () {
context
(
'visibility changes'
,
function
()
{
it
(
'schedules an overflow check when shown'
,
function
()
{
var
element
=
excerpt
Directive
({},
'<span></span>'
);
var
element
=
excerpt
Component
({},
'<span></span>'
);
fakeOverflowMonitor
.
check
.
reset
();
// ng-hide is the class used by the ngShow and ngHide directives
...
...
@@ -126,7 +126,7 @@ describe('excerpt directive', function () {
context
(
'excerpt content style'
,
function
()
{
it
(
'sets the content style using ExcerptOverflowMonitor#contentStyle()'
,
function
()
{
var
element
=
excerpt
Directive
({},
'<span></span>'
);
var
element
=
excerpt
Component
({},
'<span></span>'
);
fakeOverflowMonitor
.
contentStyle
.
returns
({
'max-height'
:
'52px'
});
element
.
scope
.
$digest
();
var
content
=
element
[
0
].
querySelector
(
'.excerpt'
);
...
...
@@ -136,19 +136,19 @@ describe('excerpt directive', function () {
describe
(
'enabled state'
,
function
()
{
it
(
'renders its contents in a .excerpt element by default'
,
function
()
{
var
element
=
excerpt
Directive
({},
'<span id="foo"></span>'
);
var
element
=
excerpt
Component
({},
'<span id="foo"></span>'
);
assert
.
equal
(
element
.
find
(
'.excerpt #foo'
).
length
,
1
);
});
it
(
'when enabled, renders its contents in a .excerpt element'
,
function
()
{
var
element
=
excerpt
Directive
({
enabled
:
true
},
'<span id="foo"></span>'
);
var
element
=
excerpt
Component
({
enabled
:
true
},
'<span id="foo"></span>'
);
assert
.
equal
(
element
.
find
(
'.excerpt #foo'
).
length
,
1
);
});
it
(
'when disabled, renders its contents but not in a .excerpt element'
,
function
()
{
var
element
=
excerpt
Directive
({
enabled
:
false
},
'<span id="foo"></span>'
);
var
element
=
excerpt
Component
({
enabled
:
false
},
'<span id="foo"></span>'
);
assert
.
equal
(
element
.
find
(
'.excerpt #foo'
).
length
,
0
);
assert
.
equal
(
element
.
find
(
'#foo'
).
length
,
1
);
...
...
@@ -175,7 +175,7 @@ describe('excerpt directive', function () {
}
it
(
'displays inline controls if collapsed'
,
function
()
{
var
element
=
excerpt
Directive
({
inlineControls
:
true
},
var
element
=
excerpt
Component
({
inlineControls
:
true
},
TALL_DIV
);
fakeOverflowMonitor
.
ctrl
.
onOverflowChanged
(
true
);
var
expandLink
=
findInlineControl
(
element
[
0
]);
...
...
@@ -184,13 +184,13 @@ describe('excerpt directive', function () {
});
it
(
'does not display inline controls if not collapsed'
,
function
()
{
var
element
=
excerpt
Directive
({
inlineControls
:
true
},
SHORT_DIV
);
var
element
=
excerpt
Component
({
inlineControls
:
true
},
SHORT_DIV
);
var
expandLink
=
findInlineControl
(
element
[
0
]);
assert
.
notOk
(
expandLink
);
});
it
(
'toggles the expanded state when clicked'
,
function
()
{
var
element
=
excerpt
Directive
({
inlineControls
:
true
},
TALL_DIV
);
var
element
=
excerpt
Component
({
inlineControls
:
true
},
TALL_DIV
);
fakeOverflowMonitor
.
ctrl
.
onOverflowChanged
(
true
);
var
expandLink
=
findInlineControl
(
element
[
0
]);
angular
.
element
(
expandLink
.
querySelector
(
'a'
)).
click
();
...
...
@@ -202,7 +202,7 @@ describe('excerpt directive', function () {
describe
(
'bottom area'
,
function
()
{
it
(
'expands the excerpt when clicking at the bottom if collapsed'
,
function
()
{
var
element
=
excerpt
Directive
({
inlineControls
:
true
},
var
element
=
excerpt
Component
({
inlineControls
:
true
},
TALL_DIV
);
element
.
scope
.
$digest
();
assert
.
isTrue
(
element
.
ctrl
.
collapse
);
...
...
@@ -215,7 +215,7 @@ describe('excerpt directive', function () {
describe
(
'#onCollapsibleChanged'
,
function
()
{
it
(
'is called when overflow state changes'
,
function
()
{
var
callback
=
sinon
.
stub
();
excerpt
Directive
({
excerpt
Component
({
onCollapsibleChanged
:
{
args
:
[
'collapsible'
],
callback
:
callback
,
...
...
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