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

feat: New modal component to stop a running build #1092

Merged
merged 3 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
29 changes: 29 additions & 0 deletions app/components/pipeline/modal/stop-build/component.js
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;
});
}
}
39 changes: 39 additions & 0 deletions app/components/pipeline/modal/stop-build/template.hbs
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>
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();
});
});