github.com/hspak/nomad@v0.7.2-0.20180309000617-bc4ae22a39a5/ui/tests/unit/models/job-test.js (about) 1 import { getOwner } from '@ember/application'; 2 import { run } from '@ember/runloop'; 3 import { moduleForModel, test } from 'ember-qunit'; 4 5 moduleForModel('job', 'Unit | Model | job', { 6 needs: ['model:job-summary', 'model:task-group', 'model:task', 'model:task-group-summary'], 7 }); 8 9 test('should expose aggregate allocations derived from task groups', function(assert) { 10 const store = getOwner(this).lookup('service:store'); 11 let summary; 12 run(() => { 13 summary = store.createRecord('job-summary', { 14 taskGroupSummaries: [ 15 { 16 name: 'one', 17 queuedAllocs: 1, 18 startingAllocs: 2, 19 runningAllocs: 3, 20 completeAllocs: 4, 21 failedAllocs: 5, 22 lostAllocs: 6, 23 }, 24 { 25 name: 'two', 26 queuedAllocs: 2, 27 startingAllocs: 4, 28 runningAllocs: 6, 29 completeAllocs: 8, 30 failedAllocs: 10, 31 lostAllocs: 12, 32 }, 33 { 34 name: 'three', 35 queuedAllocs: 3, 36 startingAllocs: 6, 37 runningAllocs: 9, 38 completeAllocs: 12, 39 failedAllocs: 15, 40 lostAllocs: 18, 41 }, 42 ], 43 }); 44 }); 45 46 const job = this.subject({ 47 summary, 48 name: 'example', 49 taskGroups: [ 50 { 51 name: 'one', 52 count: 0, 53 tasks: [], 54 }, 55 { 56 name: 'two', 57 count: 0, 58 tasks: [], 59 }, 60 { 61 name: 'three', 62 count: 0, 63 tasks: [], 64 }, 65 ], 66 }); 67 68 assert.equal( 69 job.get('totalAllocs'), 70 job 71 .get('taskGroups') 72 .mapBy('summary.totalAllocs') 73 .reduce((sum, allocs) => sum + allocs, 0), 74 'totalAllocs is the sum of all group totalAllocs' 75 ); 76 77 assert.equal( 78 job.get('queuedAllocs'), 79 job 80 .get('taskGroups') 81 .mapBy('summary.queuedAllocs') 82 .reduce((sum, allocs) => sum + allocs, 0), 83 'queuedAllocs is the sum of all group queuedAllocs' 84 ); 85 86 assert.equal( 87 job.get('startingAllocs'), 88 job 89 .get('taskGroups') 90 .mapBy('summary.startingAllocs') 91 .reduce((sum, allocs) => sum + allocs, 0), 92 'startingAllocs is the sum of all group startingAllocs' 93 ); 94 95 assert.equal( 96 job.get('runningAllocs'), 97 job 98 .get('taskGroups') 99 .mapBy('summary.runningAllocs') 100 .reduce((sum, allocs) => sum + allocs, 0), 101 'runningAllocs is the sum of all group runningAllocs' 102 ); 103 104 assert.equal( 105 job.get('completeAllocs'), 106 job 107 .get('taskGroups') 108 .mapBy('summary.completeAllocs') 109 .reduce((sum, allocs) => sum + allocs, 0), 110 'completeAllocs is the sum of all group completeAllocs' 111 ); 112 113 assert.equal( 114 job.get('failedAllocs'), 115 job 116 .get('taskGroups') 117 .mapBy('summary.failedAllocs') 118 .reduce((sum, allocs) => sum + allocs, 0), 119 'failedAllocs is the sum of all group failedAllocs' 120 ); 121 122 assert.equal( 123 job.get('lostAllocs'), 124 job 125 .get('taskGroups') 126 .mapBy('summary.lostAllocs') 127 .reduce((sum, allocs) => sum + allocs, 0), 128 'lostAllocs is the sum of all group lostAllocs' 129 ); 130 });