Commit cde3eaf3 authored by Robert Knight's avatar Robert Knight

Add test to verify that post button is enabled when 'can-post' attribute is true

Card 89
parent bc267718
...@@ -130,6 +130,11 @@ describe('publishAnnotationBtn', function () { ...@@ -130,6 +130,11 @@ describe('publishAnnotationBtn', function () {
}); });
var disabledBtns = element.find('button[disabled]'); var disabledBtns = element.find('button[disabled]');
assert.equal(disabledBtns.length, 2); assert.equal(disabledBtns.length, 2);
// check that buttons are enabled when posting is possible
element = element.link({canPost: true});
disabledBtns = element.find('button[disabled]');
assert.equal(disabledBtns.length, 0);
}); });
}); });
...@@ -22,9 +22,6 @@ function hyphenate(name) { ...@@ -22,9 +22,6 @@ function hyphenate(name) {
* *
* { attrA: 'initial-value', scopeProperty: scopeValue } * { attrA: 'initial-value', scopeProperty: scopeValue }
* *
* Attribute values are converted to scope properties of the same
* name as the attribute and t
*
* @param {Document} document - The DOM Document to create the element in * @param {Document} document - The DOM Document to create the element in
* @param {string} name - The name of the directive to instantiate * @param {string} name - The name of the directive to instantiate
* @param {Object} attrs - A map of attribute names (in camelCase) to initial values. * @param {Object} attrs - A map of attribute names (in camelCase) to initial values.
...@@ -32,6 +29,8 @@ function hyphenate(name) { ...@@ -32,6 +29,8 @@ function hyphenate(name) {
* scope when the element is linked * scope when the element is linked
* *
* @return {DOMElement} The Angular jqLite-wrapped DOM element for the component. * @return {DOMElement} The Angular jqLite-wrapped DOM element for the component.
* The returned object has a link(scope) method which will
* re-link the component with new properties.
*/ */
function createDirective(document, name, attrs, initialScope) { function createDirective(document, name, attrs, initialScope) {
attrs = attrs || {}; attrs = attrs || {};
...@@ -56,18 +55,28 @@ function createDirective(document, name, attrs, initialScope) { ...@@ -56,18 +55,28 @@ function createDirective(document, name, attrs, initialScope) {
}); });
// setup initial scope // setup initial scope
Object.keys(initialScope).forEach(function (key) {
$scope[key] = initialScope[key];
});
Object.keys(attrs).forEach(function (key) { Object.keys(attrs).forEach(function (key) {
$scope[key] = attrs[key]; $scope[key] = attrs[key];
}); });
// instantiate component // compile the template
var element = $compile(templateElement)($scope); var linkFn = $compile(templateElement);
element.scope = $scope;
$scope.$digest(); // link the component, passing in the initial
return element; // scope values. The caller can then re-render/link
// the template passing in different properties
// and verify the output
var linkDirective = function(props) {
var childScope = $scope.$new();
angular.extend(childScope, props);
var element = linkFn(childScope);
element.link = linkDirective;
element.scope = childScope;
childScope.$digest();
return element;
}
return linkDirective(initialScope);
} }
module.exports = { module.exports = {
......
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