ES6ify /gr-diff-preferences/*

Bug: Issue 6179
Change-Id: I5a68c4db6d196f5724a5702f7433c41c3cf7b7fd
This commit is contained in:
Kasper Nilsson
2017-05-16 14:21:31 -07:00
parent 858f5bee35
commit 90111b882a
2 changed files with 38 additions and 40 deletions

View File

@@ -41,20 +41,19 @@
'_localPrefsChanged(localPrefs.*)',
],
getFocusStops: function() {
getFocusStops() {
return {
start: this.$.contextSelect,
end: this.$.cancelButton,
};
},
resetFocus: function() {
resetFocus() {
this.$.contextSelect.focus();
},
_prefsChanged: function(changeRecord) {
var prefs = changeRecord.base;
// TODO(andybons): This is not supported in IE. Implement a polyfill.
_prefsChanged(changeRecord) {
const prefs = changeRecord.base;
// NOTE: Object.assign is NOT automatically a deep copy. If prefs adds
// an object as a value, it must be marked enumerable.
this._newPrefs = Object.assign({}, prefs);
@@ -65,71 +64,70 @@
this.$.syntaxHighlightInput.checked = prefs.syntax_highlighting;
},
_localPrefsChanged: function(changeRecord) {
var localPrefs = changeRecord.base || {};
// TODO(viktard): This is not supported in IE. Implement a polyfill.
_localPrefsChanged(changeRecord) {
const localPrefs = changeRecord.base || {};
this._newLocalPrefs = Object.assign({}, localPrefs);
},
_handleContextSelectChange: function(e) {
var selectEl = Polymer.dom(e).rootTarget;
_handleContextSelectChange(e) {
const selectEl = Polymer.dom(e).rootTarget;
this.set('_newPrefs.context', parseInt(selectEl.value, 10));
},
_handleShowTabsTap: function(e) {
_handleShowTabsTap(e) {
this.set('_newPrefs.show_tabs', Polymer.dom(e).rootTarget.checked);
},
_handleShowTrailingWhitespaceTap: function(e) {
_handleShowTrailingWhitespaceTap(e) {
this.set('_newPrefs.show_whitespace_errors',
Polymer.dom(e).rootTarget.checked);
},
_handleSyntaxHighlightTap: function(e) {
_handleSyntaxHighlightTap(e) {
this.set('_newPrefs.syntax_highlighting',
Polymer.dom(e).rootTarget.checked);
},
_handlelineWrappingTap: function(e) {
_handlelineWrappingTap(e) {
this.set('_newPrefs.line_wrapping', Polymer.dom(e).rootTarget.checked);
},
_handleSave: function(e) {
_handleSave(e) {
e.stopPropagation();
this.prefs = this._newPrefs;
this.localPrefs = this._newLocalPrefs;
var el = Polymer.dom(e).rootTarget;
const el = Polymer.dom(e).rootTarget;
el.disabled = true;
this.$.storage.savePreferences(this._localPrefs);
this._saveDiffPreferences().then(function(response) {
this._saveDiffPreferences().then(response => {
el.disabled = false;
if (!response.ok) { return response; }
this.$.prefsOverlay.close();
}.bind(this)).catch(function(err) {
}).catch(err => {
el.disabled = false;
}.bind(this));
});
},
_handleCancel: function(e) {
_handleCancel(e) {
e.stopPropagation();
this.$.prefsOverlay.close();
},
_handlePrefsTap: function(e) {
_handlePrefsTap(e) {
e.preventDefault();
this._openPrefs();
},
open: function() {
this.$.prefsOverlay.open().then(function() {
var focusStops = this.getFocusStops();
open() {
this.$.prefsOverlay.open().then(() => {
const focusStops = this.getFocusStops();
this.$.prefsOverlay.setFocusStops(focusStops);
this.resetFocus();
}.bind(this));
});
},
_saveDiffPreferences: function() {
_saveDiffPreferences() {
return this.$.restAPI.saveDiffPreferences(this.prefs);
},
});

View File

@@ -33,20 +33,20 @@ limitations under the License.
</test-fixture>
<script>
suite('gr-diff-preferences tests', function() {
var element;
var sandbox;
suite('gr-diff-preferences tests', () => {
let element;
let sandbox;
setup(function() {
setup(() => {
sandbox = sinon.sandbox.create();
element = fixture('basic');
});
teardown(function() {
teardown(() => {
sandbox.restore();
});
test('model changes', function() {
test('model changes', () => {
element.prefs = {
context: 10,
font_size: 12,
@@ -78,7 +78,7 @@ limitations under the License.
assert.isFalse(element._newPrefs.syntax_highlighting);
});
test('clicking fit to screen hides line length input', function() {
test('clicking fit to screen hides line length input', () => {
element.prefs = {line_wrapping: false};
assert.isFalse(element.$.columnsPref.hidden);
@@ -90,31 +90,31 @@ limitations under the License.
assert.isFalse(element.$.columnsPref.hidden);
});
test('clicking save button calls _handleSave function', function() {
var savePrefs = sinon.stub(element, '_handleSave');
test('clicking save button calls _handleSave function', () => {
const savePrefs = sinon.stub(element, '_handleSave');
MockInteractions.tap(element.$.saveButton);
flushAsynchronousOperations();
assert(savePrefs.calledOnce);
savePrefs.restore();
});
test('save button', function() {
test('save button', () => {
element.prefs = {
font_size: '11',
};
element._newPrefs = {
font_size: '12',
};
var saveStub = sandbox.stub(element.$.restAPI, 'saveDiffPreferences',
function() { return Promise.resolve(); });
const saveStub = sandbox.stub(element.$.restAPI, 'saveDiffPreferences',
() => { return Promise.resolve(); });
MockInteractions.tap(element.$$('gr-button[primary]'));
assert.deepEqual(element.prefs, element._newPrefs);
assert.deepEqual(saveStub.lastCall.args[0], element._newPrefs);
});
test('cancel button', function() {
var closeStub = sandbox.stub(element.$.prefsOverlay, 'close');
test('cancel button', () => {
const closeStub = sandbox.stub(element.$.prefsOverlay, 'close');
MockInteractions.tap(element.$$('gr-button:not([primary])'));
assert.isTrue(closeStub.called);
});