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
5d62b7cf
Unverified
Commit
5d62b7cf
authored
Dec 06, 2017
by
Sean Hammond
Committed by
GitHub
Dec 06, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #620 from hypothesis/dont-show-page-share-link-on-elife
Don't show page share button on eLife pages
parents
05763de5
d11be3fb
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
126 additions
and
1 deletion
+126
-1
top-bar-test.js
src/sidebar/components/test/top-bar-test.js
+42
-1
top-bar.js
src/sidebar/components/top-bar.js
+6
-0
top-bar.html
src/sidebar/templates/top-bar.html
+1
-0
is-third-party-service.js
src/sidebar/util/is-third-party-service.js
+30
-0
is-third-party-service-test.js
src/sidebar/util/test/is-third-party-service-test.js
+47
-0
No files found.
src/sidebar/components/test/top-bar-test.js
View file @
5d62b7cf
'use strict'
;
var
angular
=
require
(
'angular'
);
var
proxyquire
=
require
(
'proxyquire'
);
var
util
=
require
(
'../../directive/test/util'
);
describe
(
'topBar'
,
function
()
{
var
fakeSettings
=
{};
var
fakeIsThirdPartyService
=
sinon
.
stub
();
before
(
function
()
{
angular
.
module
(
'app'
,
[])
.
component
(
'topBar'
,
require
(
'../top-bar'
))
.
component
(
'topBar'
,
proxyquire
(
'../top-bar'
,
{
'../util/is-third-party-service'
:
fakeIsThirdPartyService
,
'@noCallThru'
:
true
,
}))
.
component
(
'loginControl'
,
{
bindings
:
require
(
'../login-control'
).
bindings
,
})
...
...
@@ -25,6 +30,9 @@ describe('topBar', function () {
angular
.
mock
.
module
(
'app'
,
{
settings
:
fakeSettings
,
});
fakeIsThirdPartyService
.
reset
();
fakeIsThirdPartyService
.
returns
(
false
);
});
function
applyUpdateBtn
(
el
)
{
...
...
@@ -87,6 +95,39 @@ describe('topBar', function () {
assert
.
called
(
onLogout
);
});
it
(
"checks whether we're using a third-party service"
,
function
()
{
createTopBar
();
assert
.
called
(
fakeIsThirdPartyService
);
assert
.
alwaysCalledWithExactly
(
fakeIsThirdPartyService
,
fakeSettings
);
});
context
(
'when using a first-party service'
,
function
()
{
it
(
'shows the share page button'
,
function
()
{
var
el
=
createTopBar
();
// I want the DOM element, not AngularJS's annoying angular.element
// wrapper object.
el
=
el
[
0
];
assert
.
isNotNull
(
el
.
querySelector
(
'[title="Share this page"]'
));
});
});
context
(
'when using a third-party service'
,
function
()
{
beforeEach
(
function
()
{
fakeIsThirdPartyService
.
returns
(
true
);
});
it
(
"doesn't show the share page button"
,
function
()
{
var
el
=
createTopBar
();
// I want the DOM element, not AngularJS's annoying angular.element
// wrapper object.
el
=
el
[
0
];
assert
.
isNull
(
el
.
querySelector
(
'[title="Share this page"]'
));
});
});
it
(
'displays the share page when "Share this page" is clicked'
,
function
()
{
var
onSharePage
=
sinon
.
stub
();
var
el
=
createTopBar
({
onSharePage
:
onSharePage
});
...
...
src/sidebar/components/top-bar.js
View file @
5d62b7cf
'use strict'
;
var
isThirdPartyService
=
require
(
'../util/is-third-party-service'
);
module
.
exports
=
{
controllerAs
:
'vm'
,
//@ngInject
...
...
@@ -9,6 +11,10 @@ module.exports = {
}
else
{
this
.
isThemeClean
=
false
;
}
this
.
showSharePageButton
=
function
()
{
return
!
isThirdPartyService
(
settings
);
};
},
bindings
:
{
auth
:
'<'
,
...
...
src/sidebar/templates/top-bar.html
View file @
5d62b7cf
...
...
@@ -48,6 +48,7 @@
</sort-dropdown>
<a
class=
"top-bar__btn"
ng-click=
"vm.onSharePage()"
ng-if=
"vm.showSharePageButton()"
title=
"Share this page"
>
<i
class=
"h-icon-annotation-share"
></i>
</a>
...
...
src/sidebar/util/is-third-party-service.js
0 → 100644
View file @
5d62b7cf
'use strict'
;
const
serviceConfig
=
require
(
'../service-config'
);
/**
* Return `true` if the first configured service is a "third-party" service.
*
* Return `true` if the first custom annotation service configured in the
* services array in the host page is a third-party service, `false` otherwise.
*
* If no custom annotation services are configured then return `false`.
*
* @param {Object} settings - the sidebar settings object
*
*/
function
isThirdPartyService
(
settings
)
{
const
service
=
serviceConfig
(
settings
);
if
(
service
===
null
)
{
return
false
;
}
if
(
!
service
.
hasOwnProperty
(
'authority'
))
{
return
false
;
}
return
(
service
.
authority
!==
settings
.
authDomain
);
}
module
.
exports
=
isThirdPartyService
;
src/sidebar/util/test/is-third-party-service-test.js
0 → 100644
View file @
5d62b7cf
'use strict'
;
const
proxyquire
=
require
(
'proxyquire'
);
describe
(
'sidebar.util.isThirdPartyService'
,
()
=>
{
let
fakeServiceConfig
;
let
fakeSettings
;
let
isThirdPartyService
;
beforeEach
(()
=>
{
fakeServiceConfig
=
sinon
.
stub
();
fakeSettings
=
{
authDomain
:
'hypothes.is'
};
isThirdPartyService
=
proxyquire
(
'../is-third-party-service'
,
{
'../service-config'
:
fakeServiceConfig
,
'@noCallThru'
:
true
,
});
});
it
(
'returns false for first-party services'
,
()
=>
{
fakeServiceConfig
.
returns
({
authority
:
'hypothes.is'
});
assert
.
isFalse
(
isThirdPartyService
(
fakeSettings
));
});
it
(
'returns true for third-party services'
,
()
=>
{
fakeServiceConfig
.
returns
({
authority
:
'elifesciences.org'
});
assert
.
isTrue
(
isThirdPartyService
(
fakeSettings
));
});
it
(
"returns false if there's no service config"
,
()
=>
{
fakeServiceConfig
.
returns
(
null
);
assert
.
isFalse
(
isThirdPartyService
(
fakeSettings
));
});
// It's not valid for a service config object to not contain an authority
// (authority is a required field) but at the time of writing the config
// isn't validated when it's read in, so make sure that isThirdPartyService()
// handles invalid configs.
it
(
"returns false if the service config doesn't contain an authority"
,
()
=>
{
fakeServiceConfig
.
returns
({});
assert
.
isFalse
(
isThirdPartyService
(
fakeSettings
));
});
});
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