summaryrefslogtreecommitdiffstats
path: root/polygerrit-ui/app/elements/core/gr-reporting/gr-reporting_test.html
diff options
context:
space:
mode:
Diffstat (limited to 'polygerrit-ui/app/elements/core/gr-reporting/gr-reporting_test.html')
-rw-r--r--polygerrit-ui/app/elements/core/gr-reporting/gr-reporting_test.html101
1 files changed, 57 insertions, 44 deletions
diff --git a/polygerrit-ui/app/elements/core/gr-reporting/gr-reporting_test.html b/polygerrit-ui/app/elements/core/gr-reporting/gr-reporting_test.html
index 2720ebd02d..e88096b25e 100644
--- a/polygerrit-ui/app/elements/core/gr-reporting/gr-reporting_test.html
+++ b/polygerrit-ui/app/elements/core/gr-reporting/gr-reporting_test.html
@@ -20,7 +20,7 @@ limitations under the License.
<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<script src="../../../bower_components/web-component-tester/browser.js"></script>
-
+<link rel="import" href="../../../test/common-test-setup.html"/>
<link rel="import" href="gr-reporting.html">
<script>void(0);</script>
@@ -32,15 +32,15 @@ limitations under the License.
</test-fixture>
<script>
- suite('gr-reporting tests', function() {
- var element;
- var sandbox;
- var clock;
- var fakePerformance;
+ suite('gr-reporting tests', () => {
+ let element;
+ let sandbox;
+ let clock;
+ let fakePerformance;
- var NOW_TIME = 100;
+ const NOW_TIME = 100;
- setup(function() {
+ setup(() => {
sandbox = sinon.sandbox.create();
clock = sinon.useFakeTimers(NOW_TIME);
element = fixture('basic');
@@ -49,15 +49,15 @@ limitations under the License.
loadEventEnd: 2,
};
sinon.stub(element, 'performanceTiming',
- {get: function() {return fakePerformance;}});
+ {get() { return fakePerformance; }});
sandbox.stub(element, 'reporter');
});
- teardown(function() {
+ teardown(() => {
sandbox.restore();
clock.restore();
});
- test('appStarted', function() {
+ test('appStarted', () => {
element.appStarted();
assert.isTrue(
element.reporter.calledWithExactly(
@@ -66,7 +66,7 @@ limitations under the License.
));
});
- test('pageLoaded', function() {
+ test('pageLoaded', () => {
element.pageLoaded();
assert.isTrue(
element.reporter.calledWithExactly(
@@ -75,8 +75,8 @@ limitations under the License.
);
});
- test('time and timeEnd', function() {
- var nowStub = sandbox.stub(element, 'now').returns(0);
+ test('time and timeEnd', () => {
+ const nowStub = sandbox.stub(element, 'now').returns(0);
element.time('foo');
nowStub.returns(1);
element.time('bar');
@@ -85,42 +85,42 @@ limitations under the License.
nowStub.returns(3.123);
element.timeEnd('foo');
assert.isTrue(element.reporter.calledWithExactly(
- 'timing-report', 'UI Latency', 'foo', 3.123
+ 'timing-report', 'UI Latency', 'foo', '3ms'
));
assert.isTrue(element.reporter.calledWithExactly(
- 'timing-report', 'UI Latency', 'bar', 1
+ 'timing-report', 'UI Latency', 'bar', '1ms'
));
});
- suite('plugins', function() {
- setup(function() {
+ suite('plugins', () => {
+ setup(() => {
element.reporter.restore();
sandbox.stub(element, 'defaultReporter');
sandbox.stub(Gerrit, '_arePluginsLoaded');
});
- test('pluginsLoaded reports time', function() {
+ test('pluginsLoaded reports time', () => {
Gerrit._arePluginsLoaded.returns(true);
sandbox.stub(element, 'now').returns(42);
element.pluginsLoaded();
assert.isTrue(element.defaultReporter.calledWithExactly(
- 'timing-report', 'UI Latency', 'PluginsLoaded', 42
+ 'timing-report', 'UI Latency', 'PluginsLoaded', '42ms'
));
});
- test('caches reports if plugins are not loaded', function() {
+ test('caches reports if plugins are not loaded', () => {
Gerrit._arePluginsLoaded.returns(false);
element.timeEnd('foo');
assert.isFalse(element.defaultReporter.called);
});
- test('reports if plugins are loaded', function() {
+ test('reports if plugins are loaded', () => {
Gerrit._arePluginsLoaded.returns(true);
element.timeEnd('foo');
assert.isTrue(element.defaultReporter.called);
});
- test('reports cached events preserving order', function() {
+ test('reports cached events preserving order', () => {
Gerrit._arePluginsLoaded.returns(false);
element.timeEnd('foo');
Gerrit._arePluginsLoaded.returns(true);
@@ -134,38 +134,38 @@ limitations under the License.
});
});
- suite('location changed', function() {
- var pathnameStub;
- setup(function() {
+ suite('location changed', () => {
+ let pathnameStub;
+ setup(() => {
pathnameStub = sinon.stub(element, '_getPathname');
});
- teardown(function() {
+ teardown(() => {
pathnameStub.restore();
});
- test('search', function() {
+ test('search', () => {
pathnameStub.returns('/q/foo');
element.locationChanged();
assert.isTrue(element.reporter.calledWithExactly(
'nav-report', 'Location Changed', 'Page', '/q/'));
});
- test('change view', function() {
+ test('change view', () => {
pathnameStub.returns('/c/42/');
element.locationChanged();
assert.isTrue(element.reporter.calledWithExactly(
'nav-report', 'Location Changed', 'Page', '/c/'));
});
- test('change view', function() {
+ test('change view', () => {
pathnameStub.returns('/c/41/2');
element.locationChanged();
assert.isTrue(element.reporter.calledWithExactly(
'nav-report', 'Location Changed', 'Page', '/c/'));
});
- test('diff view', function() {
+ test('diff view', () => {
pathnameStub.returns('/c/41/2/file.txt');
element.locationChanged();
assert.isTrue(element.reporter.calledWithExactly(
@@ -173,38 +173,51 @@ limitations under the License.
});
});
- suite('exception logging', function() {
- var fakeWindow;
- var reporter;
+ suite('exception logging', () => {
+ let fakeWindow;
+ let reporter;
- var emulateThrow = function(msg, url, line, column, error) {
+ const emulateThrow = function(msg, url, line, column, error) {
return fakeWindow.onerror(msg, url, line, column, error);
};
- setup(function() {
+ setup(() => {
reporter = sandbox.stub(GrReporting.prototype, 'reporter');
- fakeWindow = {};
+ fakeWindow = {
+ handlers: {},
+ addEventListener(type, handler) {
+ this.handlers[type] = handler;
+ },
+ };
sandbox.stub(console, 'error');
window.GrReporting._catchErrors(fakeWindow);
});
- test('is reported', function() {
- var error = new Error('bar');
+ test('is reported', () => {
+ const error = new Error('bar');
emulateThrow('bar', 'http://url', 4, 2, error);
- assert.isTrue(
- reporter.calledWith('error', 'exception', 'bar'));
- var payload = reporter.lastCall.args[3];
+ assert.isTrue(reporter.calledWith('error', 'exception', 'bar'));
+ const payload = reporter.lastCall.args[3];
assert.deepEqual(payload, {
url: 'http://url',
line: 4,
column: 2,
- error: error,
+ error,
});
});
- test('prevent default event handler', function() {
+ test('prevent default event handler', () => {
assert.isTrue(emulateThrow());
});
+
+ test('unhandled rejection', () => {
+ fakeWindow.handlers['unhandledrejection']({
+ reason: {
+ message: 'bar',
+ },
+ });
+ assert.isTrue(reporter.calledWith('error', 'exception', 'bar'));
+ });
});
});
</script>