forked from hashicorp/nomad
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move job-page helpers and repeat stop tests on the service type
- Loading branch information
1 parent
91c9e09
commit 1d19d82
Showing
3 changed files
with
138 additions
and
53 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,51 @@ | ||
import { click, find } from 'ember-native-dom-helpers'; | ||
import wait from 'ember-test-helpers/wait'; | ||
|
||
export function jobURL(job, path = '') { | ||
const id = job.get('plainId'); | ||
const namespace = job.get('namespace.name') || 'default'; | ||
let expectedURL = `/v1/job/${id}${path}`; | ||
if (namespace !== 'default') { | ||
expectedURL += `?namespace=${namespace}`; | ||
} | ||
return expectedURL; | ||
} | ||
|
||
export function stopJob() { | ||
click('[data-test-stop] [data-test-idle-button]'); | ||
return wait().then(() => { | ||
click('[data-test-stop] [data-test-confirm-button]'); | ||
return wait(); | ||
}); | ||
} | ||
|
||
export function expectStopError(assert) { | ||
return () => { | ||
assert.equal( | ||
find('[data-test-job-error-title]').textContent, | ||
'Could Not Stop Job', | ||
'Appropriate error is shown' | ||
); | ||
assert.ok( | ||
find('[data-test-job-error-body]').textContent.includes('ACL'), | ||
'The error message mentions ACLs' | ||
); | ||
|
||
click('[data-test-job-error-close]'); | ||
assert.notOk(find('[data-test-job-error-title]'), 'Error message is dismissable'); | ||
return wait(); | ||
}; | ||
} | ||
|
||
export function expectDeleteRequest(assert, server, job) { | ||
const expectedURL = jobURL(job); | ||
|
||
assert.ok( | ||
server.pretender.handledRequests | ||
.filterBy('method', 'DELETE') | ||
.find(req => req.url === expectedURL), | ||
'DELETE URL was made correctly' | ||
); | ||
|
||
return wait(); | ||
} |
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
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,82 @@ | ||
import { getOwner } from '@ember/application'; | ||
import { test, moduleForComponent } from 'ember-qunit'; | ||
import wait from 'ember-test-helpers/wait'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage'; | ||
import { stopJob, expectStopError, expectDeleteRequest } from './helpers'; | ||
|
||
moduleForComponent('job-page/service', 'Integration | Component | job-page/service', { | ||
integration: true, | ||
beforeEach() { | ||
window.localStorage.clear(); | ||
this.store = getOwner(this).lookup('service:store'); | ||
this.server = startMirage(); | ||
this.server.create('namespace'); | ||
}, | ||
afterEach() { | ||
this.server.shutdown(); | ||
window.localStorage.clear(); | ||
}, | ||
}); | ||
|
||
const commonTemplate = hbs` | ||
{{job-page/service | ||
job=job | ||
sortProperty=sortProperty | ||
sortDescending=sortDescending | ||
currentPage=currentPage | ||
gotoJob=gotoJob}} | ||
`; | ||
|
||
const commonProperties = job => ({ | ||
job, | ||
sortProperty: 'name', | ||
sortDescending: true, | ||
currentPage: 1, | ||
gotoJob() {}, | ||
}); | ||
|
||
const makeMirageJob = server => | ||
server.create('job', { | ||
type: 'service', | ||
createAllocations: false, | ||
status: 'running', | ||
}); | ||
|
||
test('Stopping a job sends a delete request for the job', function(assert) { | ||
let job; | ||
|
||
const mirageJob = makeMirageJob(this.server); | ||
this.store.findAll('job'); | ||
|
||
return wait() | ||
.then(() => { | ||
job = this.store.peekAll('job').findBy('plainId', mirageJob.id); | ||
|
||
this.setProperties(commonProperties(job)); | ||
this.render(commonTemplate); | ||
|
||
return wait(); | ||
}) | ||
.then(stopJob) | ||
.then(() => expectDeleteRequest(assert, this.server, job)); | ||
}); | ||
|
||
test('Stopping a job without proper permissions shows an error message', function(assert) { | ||
this.server.pretender.delete('/v1/job/:id', () => [403, {}, null]); | ||
|
||
const mirageJob = makeMirageJob(this.server); | ||
this.store.findAll('job'); | ||
|
||
return wait() | ||
.then(() => { | ||
const job = this.store.peekAll('job').findBy('plainId', mirageJob.id); | ||
|
||
this.setProperties(commonProperties(job)); | ||
this.render(commonTemplate); | ||
|
||
return wait(); | ||
}) | ||
.then(stopJob) | ||
.then(expectStopError(assert)); | ||
}); |