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
f8a0eeb0
Commit
f8a0eeb0
authored
Jul 18, 2019
by
Kyle Keating
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert new-note-btn to preact
parent
b0dfce31
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
97 additions
and
59 deletions
+97
-59
new-note-btn.js
src/sidebar/components/new-note-btn.js
+36
-14
new-note-btn-test.js
src/sidebar/components/test/new-note-btn-test.js
+57
-44
index.js
src/sidebar/index.js
+4
-1
No files found.
src/sidebar/components/new-note-btn.js
View file @
f8a0eeb0
'use strict'
;
const
{
createElement
}
=
require
(
'preact'
);
const
propTypes
=
require
(
'prop-types'
);
const
events
=
require
(
'../events'
);
const
useStore
=
require
(
'../store/use-store'
);
const
{
applyTheme
}
=
require
(
'../util/theme'
);
const
{
withServices
}
=
require
(
'../util/service-context'
);
module
.
exports
=
{
controllerAs
:
'vm'
,
//@ngInject
controller
:
function
(
$rootScope
,
store
)
{
this
.
onNewNoteBtnClick
=
function
()
{
const
topLevelFrame
=
store
.
frames
().
find
(
f
=>
!
f
.
id
);
const
annot
=
{
target
:
[],
uri
:
topLevelFrame
.
uri
,
};
function
NewNoteButton
({
$rootScope
,
settings
})
{
const
store
=
useStore
(
store
=>
({
frames
:
store
.
frames
(),
}));
$rootScope
.
$broadcast
(
events
.
BEFORE_ANNOTATION_CREATED
,
annot
);
const
onNewNoteBtnClick
=
function
()
{
const
topLevelFrame
=
store
.
frames
.
find
(
f
=>
!
f
.
id
);
const
annot
=
{
target
:
[],
uri
:
topLevelFrame
.
uri
,
};
},
bindings
:
{},
template
:
require
(
'../templates/new-note-btn.html'
),
$rootScope
.
$broadcast
(
events
.
BEFORE_ANNOTATION_CREATED
,
annot
);
};
return
(
<
button
style
=
{
applyTheme
([
'ctaBackgroundColor'
],
settings
)}
className
=
"new-note__create"
onClick
=
{
onNewNoteBtnClick
}
>
+
New
note
<
/button
>
);
}
NewNoteButton
.
propTypes
=
{
// Injected services.
$rootScope
:
propTypes
.
object
.
isRequired
,
settings
:
propTypes
.
object
.
isRequired
,
};
NewNoteButton
.
injectedProps
=
[
'$rootScope'
,
'settings'
];
module
.
exports
=
withServices
(
NewNoteButton
);
src/sidebar/components/test/new-note-btn-test.js
View file @
f8a0eeb0
'use strict'
;
const
angular
=
require
(
'angular'
);
const
{
shallow
}
=
require
(
'enzyme'
);
const
{
createElement
}
=
require
(
'preact'
);
const
events
=
require
(
'../../events'
);
const
util
=
require
(
'../../directive/test/util
'
);
const
NewNoteButton
=
require
(
'../new-note-btn
'
);
describe
(
'newNoteBtn'
,
function
()
{
let
$rootScope
;
const
sandbox
=
sinon
.
sandbox
.
create
();
const
fakeStore
=
{
frames
:
sinon
.
stub
()
.
returns
([
{
id
:
null
,
uri
:
'www.example.org'
},
{
id
:
'1'
,
uri
:
'www.example.org'
},
]),
};
describe
(
'NewNoteButton'
,
function
()
{
let
fakeStore
;
let
fakeSettings
;
let
fakeRootScope
;
before
(
function
()
{
angular
.
module
(
'app'
,
[])
.
component
(
'selectionTabs'
,
require
(
'../selection-tabs'
))
.
component
(
'newNoteBtn'
,
require
(
'../new-note-btn'
));
});
function
createComponent
()
{
return
shallow
(
<
NewNoteButton
$rootScope
=
{
fakeRootScope
}
settings
=
{
fakeSettings
}
store
=
{
fakeStore
}
/
>
).
dive
();
// dive() needed because this component uses `withServices`
}
beforeEach
(
function
()
{
const
fakeFeatures
=
{
flagEnabled
:
sinon
.
stub
().
returns
(
true
),
fakeRootScope
=
{
$broadcast
:
sinon
.
stub
(
),
};
const
fakeSettings
=
{
theme
:
'clean'
};
angular
.
mock
.
module
(
'app'
,
{
store
:
fakeStore
,
features
:
fakeFeatures
,
settings
:
fakeSettings
,
fakeSettings
=
{
branding
:
{
ctaBackgroundColor
:
'#00f'
,
},
};
fakeStore
=
{
createAnnotation
:
sinon
.
stub
(),
frames
:
sinon
.
stub
()
.
returns
([
{
id
:
null
,
uri
:
'www.example.org'
},
{
id
:
'1'
,
uri
:
'www.example.org'
},
]),
};
NewNoteButton
.
$imports
.
$mock
({
'../store/use-store'
:
callback
=>
callback
(
fakeStore
),
});
});
angular
.
mock
.
inject
(
function
(
_$componentController_
,
_$rootScope_
)
{
$rootScope
=
_$rootScope_
;
});
afterEach
(()
=>
{
NewNoteButton
.
$imports
.
$restore
();
});
afterEach
(
function
()
{
sandbox
.
restore
();
it
(
'creates the component'
,
()
=>
{
const
wrapper
=
createComponent
();
assert
.
include
(
wrapper
.
text
(),
'New note'
);
});
it
(
'should broadcast BEFORE_ANNOTATION_CREATED event when the new note button is clicked'
,
function
()
{
const
annot
=
{
target
:
[],
uri
:
'www.example.org'
,
};
const
elem
=
util
.
createDirective
(
document
,
'newNoteBtn'
,
{
store
:
fakeStore
,
});
sandbox
.
spy
(
$rootScope
,
'$broadcast'
);
elem
.
ctrl
.
onNewNoteBtnClick
();
it
(
"has a backgroundColor equal to the setting's ctaBackgroundColor color"
,
()
=>
{
const
wrapper
=
createComponent
();
assert
.
equal
(
wrapper
.
prop
(
'style'
).
backgroundColor
,
fakeSettings
.
branding
.
ctaBackgroundColor
);
});
it
(
'should broadcast BEFORE_ANNOTATION_CREATED event when the new note button is clicked'
,
()
=>
{
const
wrapper
=
createComponent
();
wrapper
.
find
(
'button'
).
simulate
(
'click'
);
const
topLevelFrame
=
fakeStore
.
frames
().
find
(
f
=>
!
f
.
id
);
assert
.
calledWith
(
$r
ootScope
.
$broadcast
,
fakeR
ootScope
.
$broadcast
,
events
.
BEFORE_ANNOTATION_CREATED
,
annot
{
target
:
[],
uri
:
topLevelFrame
.
uri
,
}
);
});
});
src/sidebar/index.js
View file @
f8a0eeb0
...
...
@@ -180,11 +180,14 @@ function startAngularApp(config) {
'moderationBanner'
,
wrapReactComponent
(
require
(
'./components/moderation-banner'
))
)
.
component
(
'newNoteBtn'
,
require
(
'./components/new-note-btn'
))
.
component
(
'searchStatusBar'
,
wrapReactComponent
(
require
(
'./components/search-status-bar'
))
)
.
component
(
'newNoteBtn'
,
wrapReactComponent
(
require
(
'./components/new-note-btn'
))
)
.
component
(
'selectionTabs'
,
require
(
'./components/selection-tabs'
))
.
component
(
'sidebarContent'
,
require
(
'./components/sidebar-content'
))
.
component
(
...
...
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