[Imagery] Test mct-background-image filters

This commit is contained in:
Victor Woeltjen
2016-11-15 13:50:28 -08:00
parent 2f5dc8a887
commit 2dfde9a612

View File

@@ -35,7 +35,10 @@ define(
mockDocument = [ mockDocument = [
jasmine.createSpyObj('document', ['createElement']) jasmine.createSpyObj('document', ['createElement'])
]; ];
mockScope = jasmine.createSpyObj('scope', ['$watch']); mockScope = jasmine.createSpyObj('scope', [
'$watch',
'$watchCollection'
]);
mockElement = jasmine.createSpyObj('element', ['css']); mockElement = jasmine.createSpyObj('element', ['css']);
testImage = {}; testImage = {};
@@ -52,8 +55,12 @@ define(
expect(directive.scope.mctBackgroundImage).toEqual("="); expect(directive.scope.mctBackgroundImage).toEqual("=");
}); });
it("watches for changes to the URL", function () { describe("once linked", function () {
beforeEach(function () {
directive.link(mockScope, mockElement, {}); directive.link(mockScope, mockElement, {});
});
it("watches for changes to the URL", function () {
expect(mockScope.$watch).toHaveBeenCalledWith( expect(mockScope.$watch).toHaveBeenCalledWith(
'mctBackgroundImage', 'mctBackgroundImage',
jasmine.any(Function) jasmine.any(Function)
@@ -63,8 +70,6 @@ define(
it("updates images in-order, even when they load out-of-order", function () { it("updates images in-order, even when they load out-of-order", function () {
var firstOnload; var firstOnload;
directive.link(mockScope, mockElement);
mockScope.$watch.mostRecentCall.args[1]("some/url/0"); mockScope.$watch.mostRecentCall.args[1]("some/url/0");
firstOnload = testImage.onload; firstOnload = testImage.onload;
@@ -82,8 +87,6 @@ define(
}); });
it("clears the background image when undefined is passed in", function () { it("clears the background image when undefined is passed in", function () {
directive.link(mockScope, mockElement);
mockScope.$watch.mostRecentCall.args[1]("some/url/0"); mockScope.$watch.mostRecentCall.args[1]("some/url/0");
testImage.onload(); testImage.onload();
mockScope.$watch.mostRecentCall.args[1](undefined); mockScope.$watch.mostRecentCall.args[1](undefined);
@@ -93,6 +96,30 @@ define(
"none" "none"
]); ]);
}); });
it("updates filters on change", function () {
var filters = { brightness: 123, contrast: 21 };
mockScope.$watchCollection.calls.forEach(function (call) {
if (call.args[0] === 'filters') {
call.args[1](filters);
}
});
expect(mockElement.css).toHaveBeenCalledWith(
'filter',
'brightness(123%) contrast(21%)'
);
});
it("clears filters when none are present", function () {
mockScope.$watchCollection.calls.forEach(function (call) {
if (call.args[0] === 'filters') {
call.args[1](undefined);
}
});
expect(mockElement.css)
.toHaveBeenCalledWith('filter', '');
});
});
}); });
} }
); );