-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtests.js
101 lines (86 loc) · 2.78 KB
/
tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
(c) 2015 Massimiliano Sartoretto <[email protected]>
License: MIT
*/
describe('module ngAviary', function () {
var $rootScope, $compile, $window, AdobeAviary, ngAviary, mockEditor;
var imageElement = document.createElement('img');
mockEditor = {
launch: function(a){return false;}
};
beforeEach(module('ngAviary', function(ngAviaryProvider){
ngAviaryProvider.configure({
apiKey: 'my-awesome-api-key',
theme: 'light'
});
}));
beforeEach(function(){
module(function($provide) {
$provide.constant('Aviary', {
Feather: jasmine.createSpy('Feather')
});
});
});
beforeEach(inject(function ($injector, $window) {
$rootScope = $injector.get('$rootScope');
$compile = $injector.get('$compile');
$window = $injector.get('$window');
ngAviary = $injector.get('ngAviary');
// Mocking Aviary Global Object
(function($window) {
window = $window;
spyOn(window.Aviary, 'Feather').and.returnValue(mockEditor);
spyOn(window.document, 'querySelector').and.returnValue(imageElement);
spyOn(mockEditor, 'launch');
})();
}));
afterEach(function () {
jasmine.clock().uninstall();
});
describe('ngAviary configuration', function () {
it('should has an awesome api key', function () {
expect(ngAviary.configuration.apiKey).toEqual('my-awesome-api-key');
});
it('should has the light theme active', function () {
expect(ngAviary.configuration.theme).toEqual('light');
});
});
describe('ngAviary directive', function() {
var element, scope;
function compileElementAndClick(el, click) {
el = el ? el : angular.element('<a target-selector="42" ng-aviary></a>');
scope = $rootScope.$new();
element = $compile(el)(scope);
scope.$digest();
if(click) {
element.triggerHandler('click');
}
}
beforeEach(function() {
spyOn(document, 'getElementById').and.returnValue(imageElement);
});
describe('should launch the Feather editor', function() {
it('when clicked', function(){
compileElementAndClick(null, true);
expect(mockEditor.launch).toHaveBeenCalled();
});
it('with target-selector by default', function() {
compileElementAndClick(
angular.element('<a target-selector="#42" ng-aviary></a>'), true
);
var paramsObj = {image: imageElement, url: imageElement.src};
expect(mockEditor.launch).toHaveBeenCalledWith(paramsObj);
});
it('with target-src if provided', function(){
compileElementAndClick(
angular.element('<a target-selector=\'#42\'' +
'target-src=\'towel.png\'' +
'ng-aviary></a>'),
true
);
var paramsObj = {image: imageElement, url: 'towel.png'};
expect(mockEditor.launch).toHaveBeenCalledWith(paramsObj);
});
});
});
});