Fix null view mode for expanding diffs

Previously, when _resetFileListViewState was called, the diff view mode
was reset to null and the file list handled determining the view mode.

After change Iadb939643087589e16d7d90e77fde8f62a457f0a, the
change view handles determining the view mode, but was not updated to
reset to the correct value upon calling _resetFileListViewState.

This change no longer sets the view mode to null when
_resetFileListViewState is called, but rather resets it to the 'default'
value.

Change-Id: Ic7e11fba6bdc3b9d52b92a7dc6eefee011c69db7
This commit is contained in:
Becky Siegel
2017-09-12 11:36:22 -07:00
parent cc150c8aaa
commit e2ba063528
2 changed files with 27 additions and 14 deletions

View File

@@ -260,18 +260,21 @@
}
},
_setDiffViewMode() {
if (!this.viewState.diffViewMode) {
return this.$.restAPI.getPreferences().then( prefs => {
if (!this.viewState.diffMode) {
this.set('viewState.diffMode', prefs.default_diff_view);
}
}).then(() => {
if (!this.viewState.diffMode) {
this.set('viewState.diffMode', 'SIDE_BY_SIDE');
}
});
}
/**
* @param {boolean=} opt_reset
*/
_setDiffViewMode(opt_reset) {
if (!opt_reset && this.viewState.diffViewMode) { return; }
return this.$.restAPI.getPreferences().then( prefs => {
if (!this.viewState.diffMode) {
this.set('viewState.diffMode', prefs.default_diff_view);
}
}).then(() => {
if (!this.viewState.diffMode) {
this.set('viewState.diffMode', 'SIDE_BY_SIDE');
}
});
},
_updateSortedRevisions(revisionsRecord) {
@@ -619,7 +622,7 @@
this.viewState.changeNum !== this._changeNum) {
// Reset the diff mode to null when navigating from one change to
// another, so that the user's preference is restored.
this.set('viewState.diffMode', null);
this._setDiffViewMode(true);
this.set('_numFilesShown', DEFAULT_NUM_FILES_SHOWN);
}
this.set('viewState.changeNum', this._changeNum);

View File

@@ -440,12 +440,22 @@ limitations under the License.
element.params = {changeNum: '2'};
element._change.newProp = '2';
flushAsynchronousOperations();
assert.isNull(element.viewState.diffMode);
assert.equal(element.viewState.diffMode, 'UNIFIED');
assert.equal(element.viewState.changeNum, '2');
assert.equal(element.viewState.numFilesShown, 200);
assert.equal(element._numFilesShown, 200);
});
test('_setDiffViewMode is called with reset when new change is loaded',
() => {
sandbox.stub(element, '_setDiffViewMode');
element.viewState = {changeNum: 1};
element._changeNum = 2;
element._resetFileListViewState();
assert.isTrue(
element._setDiffViewMode.lastCall.calledWithExactly(true));
});
test('diffMode defaults to side by side without preferences', done => {
sandbox.stub(element.$.restAPI, 'getPreferences').returns(
Promise.resolve({}));