-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: New modal component to stop a running build (#1092)
- Loading branch information
Showing
3 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import Component from '@glimmer/component'; | ||
import { action } from '@ember/object'; | ||
import { service } from '@ember/service'; | ||
import { tracked } from '@glimmer/tracking'; | ||
|
||
export default class PipelineModalStopBuildComponent extends Component { | ||
@service shuttle; | ||
|
||
@tracked isDisabled = false; | ||
|
||
@tracked errorMessage = null; | ||
|
||
@tracked successMessage = null; | ||
|
||
@action | ||
async stopBuild() { | ||
await this.shuttle | ||
.fetchFromApi('put', `/builds/${this.args.buildId}`, { | ||
status: 'ABORTED' | ||
}) | ||
.then(() => { | ||
this.successMessage = 'Build stopped successfully'; | ||
this.isDisabled = true; | ||
}) | ||
.catch(err => { | ||
this.errorMessage = err.message; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<BsModal | ||
id="stop-build-modal" | ||
@onHide={{fn @closeModal}} | ||
@onSubmit={{fn this.stopBuild}} | ||
as |modal| | ||
> | ||
<modal.header> | ||
<div class="modal-title"> | ||
Stop the build | ||
</div> | ||
</modal.header> | ||
<modal.body> | ||
{{#if this.errorMessage}} | ||
<InfoMessage | ||
@message={{this.errorMessage}} | ||
@type="warning" | ||
@icon="exclamation-triangle" | ||
/> | ||
{{/if}} | ||
{{#if this.successMessage}} | ||
<InfoMessage | ||
@message={{this.successMessage}} | ||
@type="success" | ||
@icon="check-circle" | ||
/> | ||
{{/if}} | ||
Are you sure you want to stop the build? | ||
</modal.body> | ||
<modal.footer> | ||
<BsButton | ||
id="stop-build" | ||
@type="primary" | ||
@onClick={{modal.submit}} | ||
disabled={{this.isDisabled}} | ||
> | ||
Yes | ||
</BsButton> | ||
</modal.footer> | ||
</BsModal> |
77 changes: 77 additions & 0 deletions
77
tests/integration/components/pipeline/modal/stop-build/component-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'screwdriver-ui/tests/helpers'; | ||
import { click, render } from '@ember/test-helpers'; | ||
import { hbs } from 'ember-cli-htmlbars'; | ||
import sinon from 'sinon'; | ||
|
||
module('Integration | Component | pipeline/modal/stop-build', function (hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
test('it renders', async function (assert) { | ||
this.setProperties({ | ||
buildId: 1, | ||
closeModal: () => {} | ||
}); | ||
|
||
await render( | ||
hbs`<Pipeline::Modal::StopBuild | ||
@buildId={{this.buildId}} | ||
@closeModal={{this.closeModal}} | ||
/>` | ||
); | ||
|
||
assert.dom('.alert').doesNotExist(); | ||
assert.dom('#stop-build').exists({ count: 1 }); | ||
assert.dom('#stop-build').isEnabled(); | ||
}); | ||
|
||
test('it displays error message when stop fails', async function (assert) { | ||
const shuttle = this.owner.lookup('service:shuttle'); | ||
const errorMessage = 'Failed to stop build'; | ||
const shuttleStub = sinon | ||
.stub(shuttle, 'fetchFromApi') | ||
.rejects({ message: errorMessage }); | ||
|
||
this.setProperties({ | ||
buildId: 1, | ||
closeModal: () => {} | ||
}); | ||
|
||
await render( | ||
hbs`<Pipeline::Modal::StopBuild | ||
@buildId={{this.buildId}} | ||
@closeModal={{this.closeModal}} | ||
/>` | ||
); | ||
|
||
await click('#stop-build'); | ||
|
||
assert.equal(shuttleStub.calledOnce, true); | ||
assert.dom('.alert').exists({ count: 1 }); | ||
assert.dom('.alert > span').hasText(errorMessage); | ||
}); | ||
|
||
test('it displays success message when stop succeeds', async function (assert) { | ||
const shuttle = this.owner.lookup('service:shuttle'); | ||
const shuttleStub = sinon.stub(shuttle, 'fetchFromApi').resolves(); | ||
|
||
this.setProperties({ | ||
buildId: 1, | ||
closeModal: () => {} | ||
}); | ||
|
||
await render( | ||
hbs`<Pipeline::Modal::StopBuild | ||
@buildId={{this.buildId}} | ||
@closeModal={{this.closeModal}} | ||
/>` | ||
); | ||
|
||
await click('#stop-build'); | ||
|
||
assert.equal(shuttleStub.calledOnce, true); | ||
assert.dom('.alert').exists({ count: 1 }); | ||
assert.dom('.alert > span').hasText('Build stopped successfully'); | ||
assert.dom('#stop-build').isDisabled(); | ||
}); | ||
}); |