-
Notifications
You must be signed in to change notification settings - Fork 28
/
logging-spec.js
174 lines (129 loc) · 5.67 KB
/
logging-spec.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
describe('Mechanic Logging Module', function() {
it('suppresses message and debug logs when isVerbose is false', function() {
spyOn(UIALogger, 'logError');
spyOn(UIALogger, 'logWarning');
spyOn(UIALogger, 'logDebug');
spyOn(UIALogger, 'logMessage');
$.isVerbose = false;
$.log('error', 'error');
$.log('warn', 'warn');
$.log('debug', 'debug');
$.log('message', 'message');
expect(UIALogger.logError).toHaveBeenCalledWith('error');
expect(UIALogger.logWarning).toHaveBeenCalledWith('warn');
expect(UIALogger.logDebug).not.toHaveBeenCalled();
expect(UIALogger.logMessage).not.toHaveBeenCalled();
});
it('delegates to UIALogger when logging', function() {
spyOn(UIALogger, 'logError');
spyOn(UIALogger, 'logWarning');
spyOn(UIALogger, 'logDebug');
spyOn(UIALogger, 'logMessage');
$.isVerbose = true;
$.error('error');
$.warn('warn');
$.debug('debug');
$.message('message');
expect(UIALogger.logError).toHaveBeenCalledWith('error');
expect(UIALogger.logWarning).toHaveBeenCalledWith('warn');
expect(UIALogger.logDebug).toHaveBeenCalledWith('debug');
expect(UIALogger.logMessage).toHaveBeenCalledWith('message');
});
it('defaults log level to \'message\' level when none is given to log function', function() {
spyOn(UIALogger, 'logMessage');
spyOn(UIALogger, 'logError');
$.isVerbose = true;
$.log('hello!');
expect(UIALogger.logMessage).toHaveBeenCalledWith('hello!');
expect(UIALogger.logError).not.toHaveBeenCalled();
})
it('defaults log level to \'message\' when an unknown log level is given to log function', function() {
spyOn(UIALogger, 'logMessage');
spyOn(UIALogger, 'logError');
$.isVerbose = true;
$.log('hello!', 'fakelevel');
expect(UIALogger.logMessage).toHaveBeenCalledWith('hello!');
expect(UIALogger.logError).not.toHaveBeenCalled();
});
it('calls appropriate UIALogger method based on log level passed', function() {
spyOn(UIALogger, 'logError');
spyOn(UIALogger, 'logWarning');
spyOn(UIALogger, 'logDebug');
spyOn(UIALogger, 'logMessage');
$.isVerbose = true;
$.log('error', 'error');
$.log('warn', 'warn');
$.log('debug', 'debug');
$.log('message', 'message');
expect(UIALogger.logError).toHaveBeenCalledWith('error');
expect(UIALogger.logWarning).toHaveBeenCalledWith('warn');
expect(UIALogger.logDebug).toHaveBeenCalledWith('debug');
expect(UIALogger.logMessage).toHaveBeenCalledWith('message');
});
it('calls captureScreenWithName when no rect given to capture', function() {
spyOn(UIATarget.localTarget(), 'captureScreenWithName');
$.capture('image');
expect(UIATarget.localTarget().captureScreenWithName).toHaveBeenCalledWith('image');
});
it('uses date as image name when no image name is passed to capture.', function() {
spyOn(UIATarget.localTarget(), 'captureScreenWithName');
var date = new Date();
$.capture();
expect(UIATarget.localTarget().captureScreenWithName).toHaveBeenCalledWith(date.toString());
});
it('calls captureRectWithName when an image name and rect is passed to capture.', function() {
spyOn(UIATarget.localTarget(), 'captureRectWithName');
var rect = {x:1, y:2};
$.capture("name", rect);
expect(UIATarget.localTarget().captureRectWithName).toHaveBeenCalledWith(rect, "name");
});
it('allows chaining when log function is called', function() {
var win = new UIAWindow();
var sel = $(win);
expect(sel.log()).toBe(sel);
});
it('calls logElement on each element in the selector when log is called', function() {
var text = new UIAStaticText();
spyOn(text, 'logElement');
var image = new UIAImage();
spyOn(image, 'logElement');
var sel = $([text, image]);
sel.log();
expect(text.logElement).toHaveBeenCalled();
expect(image.logElement).toHaveBeenCalled();
});
it('allows chaining when logTree function is called', function() {
var win = new UIAWindow();
var sel = $(win);
expect(sel.logTree()).toBe(sel);
});
it('calls logElementTree on each element in the selector when logTree is called', function() {
var text = new UIAStaticText();
spyOn(text, 'logElementTree');
var image = new UIAImage();
spyOn(image, 'logElementTree');
var sel = $([text, image]);
sel.logTree();
expect(text.logElementTree).toHaveBeenCalled();
expect(image.logElementTree).toHaveBeenCalled();
});
it('allows chaining when capture is called', function() {
var win = new UIAWindow();
var sel = $(win);
expect(sel.capture()).toBe(sel);
});
it('calls captureRectWithName for each element in select when capture is called', function() {
rect1 = {x:1, y:1};
var win = new UIAWindow();
spyOn(win, 'rect').andReturn(rect1);
rect2 = {x:2, y:2};
var text = new UIAStaticText();
spyOn(text, 'rect').andReturn(rect2);
spyOn(UIATarget.localTarget(), 'captureRectWithName');
var sel = $([win, text]);
sel.capture();
expect(sel.capture()).toBe(sel);
expect(UIATarget.localTarget().captureRectWithName).toHaveBeenCalledWith(rect1, jasmine.any(String));
expect(UIATarget.localTarget().captureRectWithName).toHaveBeenCalledWith(rect2, jasmine.any(String));
});
});