Skip to content

Commit

Permalink
Merge pull request #3049 from hypothesis/direct-link-feature-flag
Browse files Browse the repository at this point in the history
Add direct linking feature flag
  • Loading branch information
nickstenning committed Mar 14, 2016
2 parents 5b87a42 + 0d2c4dc commit a4d2ad2
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 21 deletions.
15 changes: 11 additions & 4 deletions h/static/scripts/directive/annotation.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* jshint node: true */
'use strict';

var Promise = require('core-js/library/es6/promise');

var annotationMetadata = require('../annotation-metadata');
var dateUtil = require('../date-util');
var documentDomain = require('../filter/document-domain');
Expand Down Expand Up @@ -111,13 +109,22 @@ function updateDomainModel(domainModel, vm, permissions) {
}

/** Update the view model from the domain model changes. */
function updateViewModel($scope, time, domainModel, vm, permissions) {
function updateViewModel($scope, time, domainModel,
vm, permissions) {

vm.form = {
text: domainModel.text,
tags: viewModelTagsFromDomainModelTags(domainModel.tags),
};
vm.annotationURI = new URL('/a/' + domainModel.id, vm.serviceUrl).href;

if (domainModel.links) {
vm.annotationURI = domainModel.links.incontext ||
domainModel.links.html ||
'';
} else {
vm.annotationURI = '';
}

vm.isPrivate = permissions.isPrivate(
domainModel.permissions, domainModel.user);

Expand Down
61 changes: 45 additions & 16 deletions h/static/scripts/directive/test/annotation-test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/* jshint node: true */
'use strict';

var angular = require('angular');
var proxyquire = require('proxyquire');

var events = require('../../events');
var fixtures = require('../../test/annotation-fixtures');
var util = require('./util');

var module = angular.mock.module;
var inject = angular.mock.inject;

/**
* Returns the annotation directive with helpers stubbed out.
*/
function annotationDirective() {
var noop = function () { return '' };
var noop = function () { return ''; };

var annotation = proxyquire('../annotation', {
'../filter/document-domain': noop,
Expand Down Expand Up @@ -321,11 +321,9 @@ describe('annotation', function() {
.directive('annotation', annotationDirective());
});

beforeEach(module('h'));

beforeEach(module('h.templates'));

beforeEach(module(function($provide) {
beforeEach(angular.mock.module('h'));
beforeEach(angular.mock.module('h.templates'));
beforeEach(angular.mock.module(function($provide) {
sandbox = sinon.sandbox.create();

fakeAnnotationMapper = {
Expand All @@ -349,7 +347,7 @@ describe('annotation', function() {
};

var fakeFeatures = {
flagEnabled: sandbox.stub().returns(true)
flagEnabled: sandbox.stub().returns(true),
};

fakeFlash = {
Expand Down Expand Up @@ -927,7 +925,7 @@ describe('annotation', function() {

annotation.updated = null;
annotation.$create = function () {
annotation.updated = (new Date).toString();
annotation.updated = (new Date()).toString();
return Promise.resolve(annotation);
};
var controller = createDirective(annotation).controller;
Expand All @@ -952,9 +950,9 @@ describe('annotation', function() {
clock.tick(10 * 60 * 1000);

annotation.$update = function () {
this.updated = (new Date).toString();
this.updated = (new Date()).toString();
return Promise.resolve(this);
}
};
var controller = createDirective(annotation).controller;
assert.equal(controller.relativeTimestamp, 'ages ago');
controller.edit();
Expand Down Expand Up @@ -983,7 +981,7 @@ describe('annotation', function() {
});

it('is no longer updated after the scope is destroyed', function() {
var controller = createDirective(annotation).controller;
createDirective(annotation);
$scope.$digest();
$scope.$destroy();
$timeout.flush();
Expand Down Expand Up @@ -1038,10 +1036,14 @@ describe('annotation', function() {

it(
'doesn\'t call annotationMapper.delete() if the delete is cancelled',
function() {
var controller = createDirective().controller;
function(done) {
var parts = createDirective();
sandbox.stub($window, 'confirm').returns(false);
assert(fakeAnnotationMapper.deleteAnnotation.notCalled);
parts.controller['delete']().then(function() {
assert.notCalled(fakeAnnotationMapper.deleteAnnotation);
done();
});
$timeout.flush();
}
);

Expand Down Expand Up @@ -1194,7 +1196,7 @@ describe('annotation', function() {
'Passes group:<id> to the server when saving a new annotation',
function() {
fakeGroups.focused = function () {
return { id: 'test-id' }
return { id: 'test-id' };
};
var annotation = {
user: 'acct:fred@hypothes.is',
Expand Down Expand Up @@ -1494,5 +1496,32 @@ describe('annotation', function() {
'https://test.hypothes.is/stream?q=tag:atag');
});
});

describe('annotation metadata', function () {
function findLink(directive) {
var links = directive.element[0]
.querySelectorAll('header .annotation-link');
return links[links.length-1];
}

it('displays HTML links when in-context links are not available', function () {
var annotation = Object.assign({}, fixtures.defaultAnnotation(), {
links: {html: 'https://test.hypothes.is/a/deadbeef'},
});
var directive = createDirective(annotation);
assert.equal(findLink(directive).href, annotation.links.html);
});

it('displays in-context links when available', function () {
var annotation = Object.assign({}, fixtures.defaultAnnotation(), {
links: {
html: 'https://test.hypothes.is/a/deadbeef',
incontext: 'https://hpt.is/deadbeef'
},
});
var directive = createDirective(annotation);
assert.equal(findLink(directive).href, annotation.links.incontext);
});
});
});
});
2 changes: 2 additions & 0 deletions h/static/scripts/test/annotation-fixtures.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Return a fake annotation with the basic properties filled in.
*/
Expand Down
2 changes: 1 addition & 1 deletion h/templates/client/annotation.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
target="_blank"
title="{{vm.absoluteTimestamp}}"
ng-if="!vm.editing() && vm.updated()"
ng-href="{{::vm.serviceUrl}}a/{{vm.id()}}"
ng-href="{{vm.annotationURI}}"
>{{vm.relativeTimestamp}}</a>
</header>

Expand Down

0 comments on commit a4d2ad2

Please sign in to comment.