diff --git a/ui/app/templates/jobs/job/task-group.hbs b/ui/app/templates/jobs/job/task-group.hbs index 7910b1059..307cd2bbf 100644 --- a/ui/app/templates/jobs/job/task-group.hbs +++ b/ui/app/templates/jobs/job/task-group.hbs @@ -11,6 +11,7 @@ {{#if model.scaling}} total + n; @@ -61,6 +62,8 @@ module('Acceptance | task group detail', function(hooks) { previousAllocation: allocations[0].id, }); + managementToken = server.create('token'); + window.localStorage.clear(); }); @@ -297,6 +300,59 @@ module('Acceptance | task group detail', function(hooks) { }); }); + test('the count stepper sends the appropriate POST request', async function(assert) { + window.localStorage.nomadTokenSecret = managementToken.secretId; + + job = server.create('job', { + groupCount: 0, + createAllocations: false, + shallow: true, + noActiveDeployment: true, + }); + const scalingGroup = server.create('task-group', { + job, + name: 'scaling', + count: 1, + shallow: true, + withScaling: true, + }); + job.update({ taskGroupIds: [scalingGroup.id] }); + + await TaskGroup.visit({ id: job.id, name: scalingGroup.name }); + await TaskGroup.countStepper.increment.click(); + await settled(); + + const scaleRequest = server.pretender.handledRequests.find(req => req.url.endsWith('/scale')); + const requestBody = JSON.parse(scaleRequest.requestBody); + assert.equal(requestBody.Target.Group, scalingGroup.name); + assert.equal(requestBody.Count, scalingGroup.count + 1); + }); + + test('the count stepper is disabled when a deployment is running', async function(assert) { + window.localStorage.nomadTokenSecret = managementToken.secretId; + + job = server.create('job', { + groupCount: 0, + createAllocations: false, + shallow: true, + activeDeployment: true, + }); + const scalingGroup = server.create('task-group', { + job, + name: 'scaling', + count: 1, + shallow: true, + withScaling: true, + }); + job.update({ taskGroupIds: [scalingGroup.id] }); + + await TaskGroup.visit({ id: job.id, name: scalingGroup.name }); + + assert.ok(TaskGroup.countStepper.input.isDisabled); + assert.ok(TaskGroup.countStepper.increment.isDisabled); + assert.ok(TaskGroup.countStepper.decrement.isDisabled); + }); + test('when the job for the task group is not found, an error message is shown, but the URL persists', async function(assert) { await TaskGroup.visit({ id: 'not-a-real-job', name: 'not-a-real-task-group' }); diff --git a/ui/tests/pages/components/stepper-input.js b/ui/tests/pages/components/stepper-input.js index 807b6cf95..0fec7c85e 100644 --- a/ui/tests/pages/components/stepper-input.js +++ b/ui/tests/pages/components/stepper-input.js @@ -24,6 +24,7 @@ export default scope => ({ blur: blurrable(), value: value(), esc: triggerable('keydown', '', { eventProperties: { keyCode: 27 } }), + isDisabled: attribute('disabled'), }, decrement: { diff --git a/ui/tests/pages/jobs/job/task-group.js b/ui/tests/pages/jobs/job/task-group.js index 19f120f1f..d69b26750 100644 --- a/ui/tests/pages/jobs/job/task-group.js +++ b/ui/tests/pages/jobs/job/task-group.js @@ -12,6 +12,7 @@ import { import allocations from 'nomad-ui/tests/pages/components/allocations'; import error from 'nomad-ui/tests/pages/components/error'; import pageSizeSelect from 'nomad-ui/tests/pages/components/page-size-select'; +import stepperInput from 'nomad-ui/tests/pages/components/stepper-input'; import LifecycleChart from 'nomad-ui/tests/pages/components/lifecycle-chart'; export default create({ @@ -21,6 +22,8 @@ export default create({ search: fillable('.search-box input'), + countStepper: stepperInput('[data-test-task-group-count-stepper]'), + tasksCount: text('[data-test-task-group-tasks]'), cpu: text('[data-test-task-group-cpu]'), mem: text('[data-test-task-group-mem]'),