Skip to content

Commit

Permalink
Acceptance testing for allocation lifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
DingoEatingFuzz committed May 21, 2019
1 parent 769aae7 commit 9714d7a
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 14 deletions.
4 changes: 2 additions & 2 deletions ui/app/controllers/allocations/allocation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default Controller.extend(Sortable, {
} catch (err) {
this.set('error', {
title: 'Could Not Stop Allocation',
description: 'Your ACL token does not grant allocation lifecyle permissions.',
description: 'Your ACL token does not grant allocation lifecycle permissions.',
});
}
}),
Expand All @@ -63,7 +63,7 @@ export default Controller.extend(Sortable, {
} catch (err) {
this.set('error', {
title: 'Could Not Restart Allocation',
description: 'Your ACL token does not grant allocation lifecyle permissions.',
description: 'Your ACL token does not grant allocation lifecycle permissions.',
});
}
}),
Expand Down
3 changes: 1 addition & 2 deletions ui/app/controllers/allocations/allocation/task/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ export default Controller.extend({
try {
yield this.model.restart();
} catch (err) {
console.log('OOPs', err);
this.set('error', {
title: 'Could Not Restart Task',
description: 'Your ACL token does not grant allocation lifecyle permissions.',
description: 'Your ACL token does not grant allocation lifecycle permissions.',
});
}
}),
Expand Down
2 changes: 1 addition & 1 deletion ui/app/mixins/with-watchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default Mixin.create(WithVisibilityDetection, {
actions: {
willTransition(transition) {
// Don't cancel watchers if transitioning into a sub-route
if (!transition.intent.name.startsWith(this.routeName)) {
if (!transition.intent.name || !transition.intent.name.startsWith(this.routeName)) {
this.cancelAllWatchers();
}

Expand Down
8 changes: 4 additions & 4 deletions ui/app/templates/allocations/allocation/index.hbs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<section class="section">
{{#if error}}
<div class="notification is-danger">
<div data-test-inline-error class="notification is-danger">
<div class="columns">
<div class="column">
<h3 data-test-error-title class="title is-4">{{error.title}}</h3>
<p data-test-error-body>{{error.description}}</p>
<h3 data-test-inline-error-title class="title is-4">{{error.title}}</h3>
<p data-test-inline-error-body>{{error.description}}</p>
</div>
<div class="column is-centered is-minimum">
<button data-test-error-close class="button is-danger" onclick={{action onDismiss}}>Okay</button>
<button data-test-inline-error-close class="button is-danger" onclick={{action onDismiss}}>Okay</button>
</div>
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions ui/app/templates/allocations/allocation/task/index.hbs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{{partial "allocations/allocation/task/subnav"}}
<section class="section">
{{#if error}}
<div class="notification is-danger">
<div data-test-inline-error class="notification is-danger">
<div class="columns">
<div class="column">
<h3 data-test-error-title class="title is-4">{{error.title}}</h3>
<p data-test-error-body>{{error.description}}</p>
<h3 data-test-inline-error-title class="title is-4">{{error.title}}</h3>
<p data-test-inline-error-body>{{error.description}}</p>
</div>
<div class="column is-centered is-minimum">
<button data-test-error-close class="button is-danger" onclick={{action onDismiss}}>Okay</button>
<button data-test-inline-error-close class="button is-danger" onclick={{action onDismiss}}>Okay</button>
</div>
</div>
</div>
Expand Down
58 changes: 58 additions & 0 deletions ui/tests/acceptance/allocation-detail-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { run } from '@ember/runloop';
import { currentURL } from '@ember/test-helpers';
import { assign } from '@ember/polyfills';
import { module, test } from 'qunit';
Expand Down Expand Up @@ -155,6 +156,63 @@ module('Acceptance | allocation detail', function(hooks) {
assert.ok(Allocation.error.isShown, 'Error message is shown');
assert.equal(Allocation.error.title, 'Not Found', 'Error message is for 404');
});

test('allocation can be stopped', async function(assert) {
await Allocation.stop.idle();
await Allocation.stop.confirm();

assert.equal(
server.pretender.handledRequests.findBy('method', 'POST').url,
`/v1/allocation/${allocation.id}/stop`,
'Stop request is made for the allocation'
);
});

test('allocation can be restarted', async function(assert) {
await Allocation.restart.idle();
await Allocation.restart.confirm();

assert.equal(
server.pretender.handledRequests.findBy('method', 'PUT').url,
`/v1/client/allocation/${allocation.id}/restart`,
'Restart request is made for the allocation'
);
});

test('while an allocation is being restarted, the stop button is disabled', async function(assert) {
server.pretender.post('/v1/allocation/:id/stop', () => [204, {}, ''], true);

await Allocation.stop.idle();

run.later(() => {
assert.ok(Allocation.stop.isRunning, 'Stop is loading');
assert.ok(Allocation.restart.isDisabled, 'Restart is disabled');
server.pretender.resolve(server.pretender.requestReferences[0].request);
}, 500);

await Allocation.stop.confirm();
});

test('if stopping or restarting fails, an error message is shown', async function(assert) {
server.pretender.post('/v1/allocation/:id/stop', () => [403, {}, '']);

await Allocation.stop.idle();
await Allocation.stop.confirm();

assert.ok(Allocation.inlineError.isShown, 'Inline error is shown');
assert.ok(
Allocation.inlineError.title.includes('Could Not Stop Allocation'),
'Title is descriptive'
);
assert.ok(
/ACL token.+?allocation lifecycle/.test(Allocation.inlineError.message),
'Message mentions ACLs and the appropriate permission'
);

await Allocation.inlineError.dismiss();

assert.notOk(Allocation.inlineError.isShown, 'Inline error is no longer shown');
});
});

module('Acceptance | allocation detail (rescheduled)', function(hooks) {
Expand Down
36 changes: 36 additions & 0 deletions ui/tests/acceptance/task-detail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,42 @@ module('Acceptance | task detail', function(hooks) {
assert.ok(Task.error.isPresent, 'Error message is shown');
assert.equal(Task.error.title, 'Not Found', 'Error message is for 404');
});

test('task can be restarted', async function(assert) {
await Task.restart.idle();
await Task.restart.confirm();

const request = server.pretender.handledRequests.findBy('method', 'PUT');
assert.equal(
request.url,
`/v1/client/allocation/${allocation.id}/restart`,
'Restart request is made for the allocation'
);

assert.deepEqual(
JSON.parse(request.requestBody),
{ TaskName: task.name },
'Restart request is made for the correct task'
);
});

test('when task restart fails, an error message is shown', async function(assert) {
server.pretender.put('/v1/client/allocation/:id/restart', () => [403, {}, '']);

await Task.restart.idle();
await Task.restart.confirm();

assert.ok(Task.inlineError.isShown, 'Inline error is shown');
assert.ok(Task.inlineError.title.includes('Could Not Restart Task'), 'Title is descriptive');
assert.ok(
/ACL token.+?allocation lifecycle/.test(Task.inlineError.message),
'Message mentions ACLs and the appropriate permission'
);

await Task.inlineError.dismiss();

assert.notOk(Task.inlineError.isShown, 'Inline error is no longer shown');
});
});

module('Acceptance | task detail (no addresses)', function(hooks) {
Expand Down
11 changes: 11 additions & 0 deletions ui/tests/pages/allocations/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ import {
} from 'ember-cli-page-object';

import allocations from 'nomad-ui/tests/pages/components/allocations';
import twoStepButton from 'nomad-ui/tests/pages/components/two-step-button';

export default create({
visit: visitable('/allocations/:id'),

title: text('[data-test-title]'),

stop: twoStepButton('[data-test-stop]'),
restart: twoStepButton('[data-test-restart]'),

details: {
scope: '[data-test-allocation-details]',

Expand Down Expand Up @@ -77,4 +81,11 @@ export default create({
message: text('[data-test-error-message]'),
seekHelp: clickable('[data-test-error-message] a'),
},

inlineError: {
isShown: isPresent('[data-test-inline-error]'),
title: text('[data-test-inline-error-title]'),
message: text('[data-test-inline-error-body]'),
dismiss: clickable('[data-test-inline-error-close]'),
},
});
11 changes: 11 additions & 0 deletions ui/tests/pages/allocations/task/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ import {
visitable,
} from 'ember-cli-page-object';

import twoStepButton from 'nomad-ui/tests/pages/components/two-step-button';

export default create({
visit: visitable('/allocations/:id/:name'),

title: text('[data-test-title]'),
state: text('[data-test-state]'),
startedAt: text('[data-test-started-at]'),

restart: twoStepButton('[data-test-restart]'),

breadcrumbs: collection('[data-test-breadcrumb]', {
id: attribute('data-test-breadcrumb'),
text: text(),
Expand Down Expand Up @@ -51,4 +55,11 @@ export default create({
message: text('[data-test-error-message]'),
seekHelp: clickable('[data-test-error-message] a'),
},

inlineError: {
isShown: isPresent('[data-test-inline-error]'),
title: text('[data-test-inline-error-title]'),
message: text('[data-test-inline-error-body]'),
dismiss: clickable('[data-test-inline-error-close]'),
},
});
14 changes: 14 additions & 0 deletions ui/tests/pages/components/two-step-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { attribute, clickable, hasClass, isPresent } from 'ember-cli-page-object';

export default scope => ({
scope,

isPresent: isPresent(),

idle: clickable('[data-test-idle-button]'),
confirm: clickable('[data-test-confirm-button]'),
cancel: clickable('[data-test-cancel-button]'),

isRunning: hasClass('is-loading', '[data-test-confirm-button]'),
isDisabled: attribute('disabled', '[data-test-idle-button]'),
});
1 change: 0 additions & 1 deletion ui/tests/unit/adapters/allocation-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { settled } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage';
Expand Down

0 comments on commit 9714d7a

Please sign in to comment.