Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(2728): gray out the Restart button for jobs that are disabled on the build details page #808

Merged
merged 2 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions app/components/build-banner/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ export default Component.extend({
}
}),

isButtonDisabledLoaded: false,
isButtonDisabled: computed('buildStatus', 'jobDisabled', {
get() {
if (this.buildAction === 'Restart') {
return this.jobDisabled.then(jobDisabled => {
this.set('isButtonDisabledLoaded', true);

return jobDisabled;
});
}

this.set('isButtonDisabledLoaded', true);

return false;
}
}),

overrideCoverageInfo() {
const { buildMeta } = this;

Expand Down
4 changes: 3 additions & 1 deletion app/components/build-banner/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@
</li>
<li class="call-to-action button-right">
{{#if isAuthenticated}}
{{#bs-button onClick=(action "buildButtonClick")}}{{buildAction}}{{/bs-button}}
{{#bs-button onClick=(action "buildButtonClick") disabled=(or (await isButtonDisabled) (not isButtonDisabledLoaded))}}
{{buildAction}}
{{/bs-button}}
{{/if}}
</li>
</ul>
17 changes: 17 additions & 0 deletions app/pipeline/build/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ export default Controller.extend({
stepList: mapBy('build.steps', 'name'),
isShowingModal: false,
errorMessage: '',
jobDisabled: computed('model.job', {
get() {
const job = this.get('model.job');
const jobsPromise = this.get('model.pipeline.jobs');

return jobsPromise.then(jobs => {
if (this.get('model.event.type') === 'pr') {
const originalJob = jobs.find(j => j.id === job.prParentJobId);

return originalJob ? originalJob.isDisabled : false;
}

return job.isDisabled;
});
}
}),

prEvents: computed('model.{event.pr.url,pipeline.id}', {
get() {
if (this.get('model.event.type') === 'pr') {
Expand Down
1 change: 1 addition & 0 deletions app/pipeline/build/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
buildMeta=build.meta
jobName=job.name
jobId=job.id
jobDisabled=jobDisabled
annotations=job.annotations
pipelineId=pipeline.id
pipelineName=pipeline.name
Expand Down
96 changes: 95 additions & 1 deletion tests/integration/components/build-banner/component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ module('Integration | Component | build banner', function (hooks) {
});

test('it renders a restart button for completed jobs when authenticated', async function (assert) {
assert.expect(3);
assert.expect(4);

const reloadBuildSpy = this.spy();

Expand All @@ -332,6 +332,8 @@ module('Integration | Component | build banner', function (hooks) {
});
this.set('eventMock', prEventMock);
this.set('prEvents', new EmberPromise(resolves => resolves([])));
this.set('isButtonDisabledLoaded', true);
this.set('jobDisabled', new EmberPromise(resolves => resolves(false)));

await render(hbs`{{build-banner
buildContainer="node:6"
Expand All @@ -340,6 +342,7 @@ module('Integration | Component | build banner', function (hooks) {
buildStart="2016-11-04T20:09:41.238Z"
buildSteps=buildStepsMock
jobName="PR-671"
jobDisabled=jobDisabled
isAuthenticated=true
event=eventMock
prEvents=prEvents
Expand All @@ -348,10 +351,46 @@ module('Integration | Component | build banner', function (hooks) {
}}`);

assert.dom('button').hasText('Restart');
assert.dom('.clicks-disabled').doesNotExist();
assert.notOk(reloadBuildSpy.called);
await click('button');
});

test('it renders a disabled restart button for completed disabled jobs when authenticated', async function (assert) {
assert.expect(3);

const reloadBuildSpy = this.spy();

this.set('buildStepsMock', buildStepsMock);
this.set('reloadCb', reloadBuildSpy);
this.set('externalStart', () => {
assert.ok(true);
});
this.set('eventMock', prEventMock);
this.set('prEvents', new EmberPromise(resolves => resolves([])));
this.set('isButtonDisabledLoaded', true);
this.set('jobDisabled', new EmberPromise(resolves => resolves(true)));

await render(hbs`{{build-banner
buildContainer="node:6"
duration="5 seconds"
buildStatus="ABORTED"
buildStart="2016-11-04T20:09:41.238Z"
buildSteps=buildStepsMock
jobName="PR-671"
jobDisabled=jobDisabled
isAuthenticated=true
event=eventMock
prEvents=prEvents
onStart=(action externalStart)
reloadBuild=(action reloadCb)
}}`);

assert.dom('button').hasText('Restart');
assert.dom('button').hasAttribute('disabled');
assert.notOk(reloadBuildSpy.called);
});

test('it renders a stop button for running job when authenticated', async function (assert) {
assert.expect(4);
this.set('willRender', () => {
Expand All @@ -364,6 +403,42 @@ module('Integration | Component | build banner', function (hooks) {
this.set('buildStepsMock', buildStepsMock);
this.set('eventMock', prEventMock);
this.set('prEvents', new EmberPromise(resolves => resolves([])));
this.set('isButtonDisabledLoaded', true);
this.set('jobDisabled', new EmberPromise(resolves => resolves(false)));

await render(hbs`{{build-banner
buildContainer="node:6"
duration="5 seconds"
buildStatus="RUNNING"
buildStart="2016-11-04T20:09:41.238Z"
buildSteps=buildStepsMock
jobName="main"
jobDisabled=jobDisabled
isAuthenticated=true
event=eventMock
prEvents=prEvents
onStop=(action externalStop)
reloadBuild=(action willRender)
}}`);

assert.dom('button').hasText('Stop');
await click('button');
});

test('it renders a stop button for running disabled job when authenticated', async function (assert) {
assert.expect(5);
this.set('willRender', () => {
assert.ok(true);
});

this.set('externalStop', () => {
assert.ok(true);
});
this.set('buildStepsMock', buildStepsMock);
this.set('eventMock', prEventMock);
this.set('prEvents', new EmberPromise(resolves => resolves([])));
this.set('isButtonDisabledLoaded', true);
this.set('jobDisabled', new EmberPromise(resolves => resolves(true)));

await render(hbs`{{build-banner
buildContainer="node:6"
Expand All @@ -372,6 +447,7 @@ module('Integration | Component | build banner', function (hooks) {
buildStart="2016-11-04T20:09:41.238Z"
buildSteps=buildStepsMock
jobName="main"
jobDisabled=jobDisabled
isAuthenticated=true
event=eventMock
prEvents=prEvents
Expand All @@ -380,6 +456,7 @@ module('Integration | Component | build banner', function (hooks) {
}}`);

assert.dom('button').hasText('Stop');
assert.dom('.clicks-disabled').doesNotExist();
await click('button');
});

Expand All @@ -395,6 +472,8 @@ module('Integration | Component | build banner', function (hooks) {
this.set('buildStepsMock', buildStepsMock);
this.set('eventMock', prEventMock);
this.set('prEvents', new EmberPromise(resolves => resolves([])));
this.set('isButtonDisabledLoaded', true);
this.set('jobDisabled', new EmberPromise(resolves => resolves(false)));

await render(hbs`{{build-banner
buildContainer="node:6"
Expand All @@ -403,6 +482,7 @@ module('Integration | Component | build banner', function (hooks) {
buildStart="2016-11-04T20:09:41.238Z"
buildSteps=buildStepsMock
jobName="main"
jobDisabled=jobDisabled
isAuthenticated=true
event=eventMock
prEvents=prEvents
Expand Down Expand Up @@ -433,6 +513,7 @@ module('Integration | Component | build banner', function (hooks) {
this.set('buildStepsMock', coverageStepsMock);
this.set('buildMetaMock', buildMetaMock);
this.set('prEvents', new EmberPromise(resolves => resolves([])));
this.set('jobDisabled', new EmberPromise(resolves => resolves(false)));

await render(hbs`{{build-banner
buildContainer="node:6"
Expand All @@ -443,6 +524,7 @@ module('Integration | Component | build banner', function (hooks) {
buildStart="2016-11-04T20:09:41.238Z"
buildSteps=buildStepsMock
jobId=1
jobDisabled=jobDisabled
jobName="main"
isAuthenticated=true
event=eventMock
Expand Down Expand Up @@ -479,6 +561,8 @@ module('Integration | Component | build banner', function (hooks) {
this.set('buildStepsMock', coverageStepsMock);
this.set('buildMetaMock', buildMetaMock);
this.set('prEvents', new EmberPromise(resolves => resolves([])));
this.set('isButtonDisabledLoaded', true);
this.set('jobDisabled', new EmberPromise(resolves => resolves(false)));

await render(hbs`{{build-banner
buildContainer="node:6"
Expand All @@ -489,6 +573,7 @@ module('Integration | Component | build banner', function (hooks) {
buildStart="2016-11-04T20:09:41.238Z"
buildSteps=buildStepsMock
jobId=1
jobDisabled=jobDisabled
jobName="main"
isAuthenticated=true
event=eventMock
Expand Down Expand Up @@ -533,6 +618,7 @@ module('Integration | Component | build banner', function (hooks) {
this.set('buildStepsMock', coverageStepsMock);
this.set('buildMetaMock', buildMetaMock);
this.set('prEvents', new EmberPromise(resolves => resolves([])));
this.set('jobDisabled', new EmberPromise(resolves => resolves(false)));

await render(hbs`{{build-banner
buildContainer="node:6"
Expand All @@ -543,6 +629,7 @@ module('Integration | Component | build banner', function (hooks) {
buildSteps=buildStepsMock
buildMeta=buildMetaMock
jobId=1
jobDisabled=jobDisabled
jobName="main"
isAuthenticated=true
event=eventMock
Expand Down Expand Up @@ -579,6 +666,7 @@ module('Integration | Component | build banner', function (hooks) {
this.set('buildStepsMock', coverageStepsMock);
this.set('buildMetaMock', buildMetaMock);
this.set('prEvents', new EmberPromise(resolves => resolves([])));
this.set('jobDisabled', new EmberPromise(resolves => resolves(false)));

await render(hbs`{{build-banner
buildContainer="node:6"
Expand All @@ -589,6 +677,7 @@ module('Integration | Component | build banner', function (hooks) {
buildSteps=buildStepsMock
buildMeta=buildMetaMock
jobId=1
jobDisabled=jobDisabled
jobName="main"
isAuthenticated=true
event=eventMock
Expand All @@ -613,6 +702,7 @@ module('Integration | Component | build banner', function (hooks) {
this.set('eventMock', prEventMock);
this.set('buildStepsMock', buildStepsMock);
this.set('prEvents', new EmberPromise(resolves => resolves([])));
this.set('jobDisabled', new EmberPromise(resolves => resolves(false)));

await render(hbs`{{build-banner
buildContainer="node:6"
Expand All @@ -622,6 +712,7 @@ module('Integration | Component | build banner', function (hooks) {
buildStart="2016-11-04T20:09:41.238Z"
buildSteps=buildStepsMock
jobId=1
jobDisabled=jobDisabled
jobName="main"
isAuthenticated=true
event=eventMock
Expand All @@ -647,6 +738,8 @@ module('Integration | Component | build banner', function (hooks) {
this.set('eventMock', prEventMock);
this.set('buildStepsMock', coverageStepsMock);
this.set('prEvents', new EmberPromise(resolves => resolves([])));
this.set('isButtonDisabledLoaded', true);
this.set('jobDisabled', new EmberPromise(resolves => resolves(false)));

await render(hbs`{{build-banner
buildContainer="node:6"
Expand All @@ -656,6 +749,7 @@ module('Integration | Component | build banner', function (hooks) {
buildStart="2016-11-04T20:09:41.238Z"
buildSteps=buildStepsMock
jobId=1
jobDisabled=jobDisabled
jobName="main"
isAuthenticated=true
event=eventMock
Expand Down