Don't show page share button on eLife pages

Don't show the "Share this page" button in the top-right of the sidebar
on pages, such as eLife's, that have both an embedded Hypothesis client
and a services config including their own `authority` string.

The "Share this page" button is a Via link, and Via doesn't work with
pages using a third-party authority config.

Fixes https://github.com/hypothesis/client/issues/615
parent 0315976d
'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 });
......
'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: '<',
......
......@@ -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>
......
'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;
'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));
});
});
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