Merge "Fetch more info about edit files"
This commit is contained in:
@@ -97,10 +97,9 @@ limitations under the License.
|
|||||||
</gr-fixed-panel>
|
</gr-fixed-panel>
|
||||||
<div class="textareaWrapper">
|
<div class="textareaWrapper">
|
||||||
<gr-endpoint-decorator name="editor">
|
<gr-endpoint-decorator name="editor">
|
||||||
<gr-endpoint-param name="fileContent" value="[[_newContent]]">
|
<gr-endpoint-param name="fileContent" value="[[_newContent]]"></gr-endpoint-param>
|
||||||
</gr-endpoint-param>
|
<gr-endpoint-param name="prefs" value="[[_prefs]]"></gr-endpoint-param>
|
||||||
<gr-endpoint-param name="prefs" value="[[_prefs]]">
|
<gr-endpoint-param name="fileType" value="[[_type]]"></gr-endpoint-param>
|
||||||
</gr-endpoint-param>
|
|
||||||
<textarea value="{{_newContent::input}}" id="file"></textarea>
|
<textarea value="{{_newContent::input}}" id="file"></textarea>
|
||||||
</gr-endpoint-decorator>
|
</gr-endpoint-decorator>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
_changeEditDetail: Object,
|
_changeEditDetail: Object,
|
||||||
_changeNum: String,
|
_changeNum: String,
|
||||||
_path: String,
|
_path: String,
|
||||||
|
_type: String,
|
||||||
_content: String,
|
_content: String,
|
||||||
_newContent: String,
|
_newContent: String,
|
||||||
_saveDisabled: {
|
_saveDisabled: {
|
||||||
@@ -81,11 +82,7 @@
|
|||||||
const promises = [];
|
const promises = [];
|
||||||
|
|
||||||
promises.push(this._getChangeDetail(this._changeNum));
|
promises.push(this._getChangeDetail(this._changeNum));
|
||||||
promises.push(this._getFileContent(this._changeNum, this._path)
|
promises.push(this._getFileData(this._changeNum, this._path));
|
||||||
.then(fileContent => {
|
|
||||||
this._content = fileContent;
|
|
||||||
this._newContent = fileContent;
|
|
||||||
}));
|
|
||||||
return Promise.all(promises);
|
return Promise.all(promises);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -109,8 +106,14 @@
|
|||||||
Gerrit.Nav.navigateToChange(this._change, this.EDIT_NAME);
|
Gerrit.Nav.navigateToChange(this._change, this.EDIT_NAME);
|
||||||
},
|
},
|
||||||
|
|
||||||
_getFileContent(changeNum, path) {
|
_getFileData(changeNum, path) {
|
||||||
return this.$.restAPI.getFileInChangeEdit(changeNum, path);
|
return this.$.restAPI.getFileInChangeEdit(changeNum, path).then(res => {
|
||||||
|
if (!res.ok) { return; }
|
||||||
|
|
||||||
|
this._type = res.type;
|
||||||
|
this._newContent = res.content;
|
||||||
|
this._content = res.content;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_saveEdit() {
|
_saveEdit() {
|
||||||
|
|||||||
@@ -67,8 +67,11 @@ suite('gr-editor-view tests', () => {
|
|||||||
|
|
||||||
test('good params proceed', () => {
|
test('good params proceed', () => {
|
||||||
changeDetailStub.returns(Promise.resolve({}));
|
changeDetailStub.returns(Promise.resolve({}));
|
||||||
const fileStub = sandbox.stub(element, '_getFileContent')
|
const fileStub = sandbox.stub(element, '_getFileData', () => {
|
||||||
.returns(Promise.resolve('text'));
|
element._content = 'text';
|
||||||
|
element._newContent = 'text';
|
||||||
|
element._type = 'application/octet-stream';
|
||||||
|
});
|
||||||
|
|
||||||
const promises = element._paramsChanged(
|
const promises = element._paramsChanged(
|
||||||
Object.assign({}, mockParams, {view: Gerrit.Nav.View.EDIT}));
|
Object.assign({}, mockParams, {view: Gerrit.Nav.View.EDIT}));
|
||||||
@@ -84,6 +87,7 @@ suite('gr-editor-view tests', () => {
|
|||||||
return promises.then(() => {
|
return promises.then(() => {
|
||||||
assert.equal(element._content, 'text');
|
assert.equal(element._content, 'text');
|
||||||
assert.equal(element._newContent, 'text');
|
assert.equal(element._newContent, 'text');
|
||||||
|
assert.equal(element._type, 'application/octet-stream');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -179,5 +183,41 @@ suite('gr-editor-view tests', () => {
|
|||||||
assert.isTrue(navigateStub.called);
|
assert.isTrue(navigateStub.called);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
suite('_getFileData', () => {
|
||||||
|
setup(() => {
|
||||||
|
element._newContent = 'initial';
|
||||||
|
element._content = 'initial';
|
||||||
|
element._type = 'initial';
|
||||||
|
});
|
||||||
|
|
||||||
|
test('res.ok', () => {
|
||||||
|
sandbox.stub(element.$.restAPI, 'getFileInChangeEdit')
|
||||||
|
.returns(Promise.resolve({
|
||||||
|
ok: true,
|
||||||
|
type: 'text/javascript',
|
||||||
|
content: 'new content',
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Ensure no data is set with a bad response.
|
||||||
|
return element._getFileData('1', 'test/path').then(() => {
|
||||||
|
assert.equal(element._newContent, 'new content');
|
||||||
|
assert.equal(element._content, 'new content');
|
||||||
|
assert.equal(element._type, 'text/javascript');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('!res.ok', () => {
|
||||||
|
sandbox.stub(element.$.restAPI, 'getFileInChangeEdit')
|
||||||
|
.returns(Promise.resolve({}));
|
||||||
|
|
||||||
|
// Ensure no data is set with a bad response.
|
||||||
|
return element._getFileData('1', 'test/path').then(() => {
|
||||||
|
assert.equal(element._newContent, 'initial');
|
||||||
|
assert.equal(element._content, 'initial');
|
||||||
|
assert.equal(element._type, 'initial');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@@ -1339,7 +1339,13 @@
|
|||||||
return this.getChangeURLAndSend(changeNum, 'GET', null, e, null, null,
|
return this.getChangeURLAndSend(changeNum, 'GET', null, e, null, null,
|
||||||
null, null, headers).then(res => {
|
null, null, headers).then(res => {
|
||||||
if (!res.ok) { return res; }
|
if (!res.ok) { return res; }
|
||||||
return this.getResponseObject(res);
|
|
||||||
|
// The file type (used for syntax highlighting) is identified in the
|
||||||
|
// X-FYI-Content-Type header of the response.
|
||||||
|
const type = res.headers.get('X-FYI-Content-Type');
|
||||||
|
return this.getResponseObject(res).then(content => {
|
||||||
|
return {content, type};
|
||||||
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -1181,5 +1181,26 @@ limitations under the License.
|
|||||||
fetchStub.lastCall.args[0],
|
fetchStub.lastCall.args[0],
|
||||||
'/projects/gerrit%2Fproject/dashboards/default%3Amain');
|
'/projects/gerrit%2Fproject/dashboards/default%3Amain');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('getFileInChangeEdit', () => {
|
||||||
|
sandbox.stub(element, 'getChangeURLAndSend')
|
||||||
|
.returns(Promise.resolve({
|
||||||
|
ok: 'true',
|
||||||
|
headers: {
|
||||||
|
get(header) {
|
||||||
|
if (header === 'X-FYI-Content-Type') {
|
||||||
|
return 'text/java';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
sandbox.stub(element, 'getResponseObject')
|
||||||
|
.returns(Promise.resolve('new content'));
|
||||||
|
|
||||||
|
return element.getFileInChangeEdit('1', 'test/path').then(res => {
|
||||||
|
assert.deepEqual(res, {content: 'new content', type: 'text/java'});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user