ES6ify /gr-storage/*
Bug: Issue 6179
Change-Id: I456468d84472328d0ceb7a2db480c631e8cbf95d
diff --git a/polygerrit-ui/app/elements/shared/gr-storage/gr-storage_test.html b/polygerrit-ui/app/elements/shared/gr-storage/gr-storage_test.html
index 6d77c55..4171939 100644
--- a/polygerrit-ui/app/elements/shared/gr-storage/gr-storage_test.html
+++ b/polygerrit-ui/app/elements/shared/gr-storage/gr-storage_test.html
@@ -31,43 +31,44 @@
</test-fixture>
<script>
- suite('gr-storage tests', function() {
- var element;
+ suite('gr-storage tests', () => {
+ let element;
function mockStorage(opt_quotaExceeded) {
return {
- getItem: function(key) { return this[key]; },
- removeItem: function(key) { delete this[key]; },
- setItem: function(key, value) {
+ getItem(key) { return this[key]; },
+ removeItem(key) { delete this[key]; },
+ setItem(key, value) {
+ // eslint-disable-next-line no-throw-literal
if (opt_quotaExceeded) { throw {code: 22}; /* Quota exceeded */ }
this[key] = value;
},
};
}
- setup(function() {
+ setup(() => {
element = fixture('basic');
element._storage = mockStorage();
});
- test('storing, retrieving and erasing drafts', function() {
- var changeNum = 1234;
- var patchNum = 5;
- var path = 'my_source_file.js';
- var line = 123;
- var location = {
- changeNum: changeNum,
- patchNum: patchNum,
- path: path,
- line: line,
+ test('storing, retrieving and erasing drafts', () => {
+ const changeNum = 1234;
+ const patchNum = 5;
+ const path = 'my_source_file.js';
+ const line = 123;
+ const location = {
+ changeNum,
+ patchNum,
+ path,
+ line,
};
// The key is in the expected format.
- var key = element._getDraftKey(location);
+ const key = element._getDraftKey(location);
assert.equal(key, ['draft', changeNum, patchNum, path, line].join(':'));
// There should be no draft initially.
- var draft = element.getDraftComment(location);
+ const draft = element.getDraftComment(location);
assert.isNotOk(draft);
// Setting the draft stores it under the expected key.
@@ -82,24 +83,24 @@
assert.isNotOk(element._storage.getItem(key));
});
- test('automatically removes old drafts', function() {
- var changeNum = 1234;
- var patchNum = 5;
- var path = 'my_source_file.js';
- var line = 123;
- var location = {
- changeNum: changeNum,
- patchNum: patchNum,
- path: path,
- line: line,
+ test('automatically removes old drafts', () => {
+ const changeNum = 1234;
+ const patchNum = 5;
+ const path = 'my_source_file.js';
+ const line = 123;
+ const location = {
+ changeNum,
+ patchNum,
+ path,
+ line,
};
- var key = element._getDraftKey(location);
+ const key = element._getDraftKey(location);
// Make sure that the call to cleanup doesn't get throttled.
element._lastCleanup = 0;
- var cleanupSpy = sinon.spy(element, '_cleanupDrafts');
+ const cleanupSpy = sinon.spy(element, '_cleanupDrafts');
// Create a message with a timestamp that is a second behind the max age.
element._storage.setItem(key, JSON.stringify({
@@ -108,7 +109,7 @@
}));
// Getting the draft should cause it to be removed.
- var draft = element.getDraftComment(location);
+ const draft = element.getDraftComment(location);
assert.isTrue(cleanupSpy.called);
assert.isNotOk(draft);
@@ -117,18 +118,18 @@
cleanupSpy.restore();
});
- test('_getDraftKey', function() {
- var changeNum = 1234;
- var patchNum = 5;
- var path = 'my_source_file.js';
- var line = 123;
- var location = {
- changeNum: changeNum,
- patchNum: patchNum,
- path: path,
- line: line,
+ test('_getDraftKey', () => {
+ const changeNum = 1234;
+ const patchNum = 5;
+ const path = 'my_source_file.js';
+ const line = 123;
+ const location = {
+ changeNum,
+ patchNum,
+ path,
+ line,
};
- var expectedResult = 'draft:1234:5:my_source_file.js:123';
+ let expectedResult = 'draft:1234:5:my_source_file.js:123';
assert.equal(element._getDraftKey(location), expectedResult);
location.range = {
start_character: 1,
@@ -140,21 +141,21 @@
assert.equal(element._getDraftKey(location), expectedResult);
});
- test('exceeded quota disables storage', function() {
+ test('exceeded quota disables storage', () => {
element._storage = mockStorage(true);
assert.isFalse(element._exceededQuota);
- var changeNum = 1234;
- var patchNum = 5;
- var path = 'my_source_file.js';
- var line = 123;
- var location = {
- changeNum: changeNum,
- patchNum: patchNum,
- path: path,
- line: line,
+ const changeNum = 1234;
+ const patchNum = 5;
+ const path = 'my_source_file.js';
+ const line = 123;
+ const location = {
+ changeNum,
+ patchNum,
+ path,
+ line,
};
- var key = element._getDraftKey(location);
+ const key = element._getDraftKey(location);
element.setDraftComment(location, 'my comment');
assert.isTrue(element._exceededQuota);
assert.isNotOk(element._storage.getItem(key));