PolyGerrit: Update create dialog

Keeps private as a checkbox as it's optional.

Bug: Issue 7250
Change-Id: I48db44dcf469c79d8fe3a8176014140477b3f21a
This commit is contained in:
Paladox 2017-12-29 00:13:05 +00:00 committed by Paladox none
parent 63489d858c
commit 985bfc48ef
3 changed files with 73 additions and 50 deletions

@ -24,7 +24,6 @@ limitations under the License.
<link rel="import" href="../../core/gr-navigation/gr-navigation.html">
<link rel="import" href="../../shared/gr-autocomplete/gr-autocomplete.html">
<link rel="import" href="../../shared/gr-button/gr-button.html">
<link rel="import" href="../../shared/gr-confirm-dialog/gr-confirm-dialog.html">
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">
<link rel="import" href="../../shared/gr-select/gr-select.html">
@ -102,17 +101,7 @@ limitations under the License.
<input
type="checkbox"
id="privateChangeCheckBox"
checked$="[[_repoConfig.private_by_default.inherited_value]]">
</span>
</section>
<section>
<label
class="title"
for="wipChangeCheckBox">WIP Change</label>
<span class="value">
<input
type="checkbox"
id="wipChangeCheckBox">
checked$="[[_formatBooleanString(_repoConfig.private_by_default)]]">
</span>
</section>
</div>

@ -61,13 +61,11 @@
handleCreateChange() {
const isPrivate = this.$.privateChangeCheckBox.checked;
const isWip = this.$.wipChangeCheckBox.checked;
const isWip = true;
return this.$.restAPI.createChange(this.repoName, this.branch,
this.subject, this.topic, isPrivate, isWip)
.then(changeCreated => {
if (!changeCreated) {
return;
}
if (!changeCreated) { return; }
Gerrit.Nav.navigateToChange(changeCreated);
});
},
@ -94,5 +92,21 @@
return branches;
});
},
_formatBooleanString(config) {
if (config && config.configured_value === 'TRUE') {
return true;
} else if (config && config.configured_value === 'FALSE') {
return false;
} else if (config && config.configured_value === 'INHERIT') {
if (config && config.inherited_value) {
return true;
} else {
return false;
}
} else {
return false;
}
},
});
})();

@ -55,9 +55,12 @@ limitations under the License.
},
});
element = fixture('basic');
element.repoName = 'test-repo';
element.repoName = 'test-repo',
element._repoConfig = {
private_by_default: {},
private_by_default: {
configured_value: 'FALSE',
inherited_value: false,
},
};
});
@ -65,18 +68,57 @@ limitations under the License.
sandbox.restore();
});
test('new change created with private', () => {
test('new change created with default', done => {
const configInputObj = {
branch: 'test-branch',
subject: 'first change created with polygerrit ui',
topic: 'test-topic',
is_private: false,
work_in_progress: true,
};
const saveStub = sandbox.stub(element.$.restAPI,
'createChange', () => {
return Promise.resolve({});
});
element.branch = 'test-branch';
element.topic = 'test-topic';
element.subject = 'first change created with polygerrit ui';
assert.isFalse(element.$.privateChangeCheckBox.checked);
element.$.branchInput.bindValue = configInputObj.branch;
element.$.tagNameInput.bindValue = configInputObj.topic;
element.$.messageInput.bindValue = configInputObj.subject;
element.handleCreateChange().then(() => {
// Private change
assert.isFalse(saveStub.lastCall.args[4]);
// WIP Change
assert.isTrue(saveStub.lastCall.args[5]);
assert.isTrue(saveStub.called);
done();
});
});
test('new change created with private', done => {
element._repoConfig = {
private_by_default: {
inherited_value: true,
configured_value: 'TRUE',
inherited_value: false,
},
};
sandbox.stub(element, '_formatBooleanString', () => {
return Promise.resolve(true);
});
flushAsynchronousOperations();
const configInputObj = {
branch: 'test-branch',
topic: 'test-topic',
subject: 'first change created with polygerrit ui',
work_in_progress: false,
topic: 'test-topic',
is_private: true,
work_in_progress: true,
};
const saveStub = sandbox.stub(element.$.restAPI,
@ -94,34 +136,12 @@ limitations under the License.
element.$.messageInput.bindValue = configInputObj.subject;
element.handleCreateChange().then(() => {
assert.isTrue(saveStub.lastCall.calledWithExactly(configInputObj));
});
});
test('new change created with wip', () => {
const configInputObj = {
branch: 'test-branch',
topic: 'test-topic',
subject: 'first change created with polygerrit ui',
};
const saveStub = sandbox.stub(element.$.restAPI,
'createChange', () => {
return Promise.resolve({});
});
element.branch = 'test-branch';
element.topic = 'test-topic';
element.subject = 'first change created with polygerrit ui';
element.$.wipChangeCheckBox.checked = true;
assert.isFalse(element.$.privateChangeCheckBox.checked);
element.$.branchInput.bindValue = configInputObj.branch;
element.$.tagNameInput.bindValue = configInputObj.topic;
element.$.messageInput.bindValue = configInputObj.subject;
element.handleCreateChange().then(() => {
assert.isTrue(saveStub.lastCall.calledWithExactly(configInputObj));
// Private change
assert.isTrue(saveStub.lastCall.args[4]);
// WIP Change
assert.isTrue(saveStub.lastCall.args[5]);
assert.isTrue(saveStub.called);
done();
});
});