github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/ui/tests/unit/models/job-test.js (about) 1 import { run } from '@ember/runloop'; 2 import { module, test } from 'qunit'; 3 import { setupTest } from 'ember-qunit'; 4 5 module('Unit | Model | job', function(hooks) { 6 setupTest(hooks); 7 8 test('should expose aggregate allocations derived from task groups', function(assert) { 9 const store = this.owner.lookup('service:store'); 10 let summary; 11 run(() => { 12 summary = store.createRecord('job-summary', { 13 taskGroupSummaries: [ 14 { 15 name: 'one', 16 queuedAllocs: 1, 17 startingAllocs: 2, 18 runningAllocs: 3, 19 completeAllocs: 4, 20 failedAllocs: 5, 21 lostAllocs: 6, 22 }, 23 { 24 name: 'two', 25 queuedAllocs: 2, 26 startingAllocs: 4, 27 runningAllocs: 6, 28 completeAllocs: 8, 29 failedAllocs: 10, 30 lostAllocs: 12, 31 }, 32 { 33 name: 'three', 34 queuedAllocs: 3, 35 startingAllocs: 6, 36 runningAllocs: 9, 37 completeAllocs: 12, 38 failedAllocs: 15, 39 lostAllocs: 18, 40 }, 41 ], 42 }); 43 }); 44 45 const job = run(() => 46 this.owner.lookup('service:store').createRecord('job', { 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 69 assert.equal( 70 job.get('totalAllocs'), 71 job 72 .get('taskGroups') 73 .mapBy('summary.totalAllocs') 74 .reduce((sum, allocs) => sum + allocs, 0), 75 'totalAllocs is the sum of all group totalAllocs' 76 ); 77 78 assert.equal( 79 job.get('queuedAllocs'), 80 job 81 .get('taskGroups') 82 .mapBy('summary.queuedAllocs') 83 .reduce((sum, allocs) => sum + allocs, 0), 84 'queuedAllocs is the sum of all group queuedAllocs' 85 ); 86 87 assert.equal( 88 job.get('startingAllocs'), 89 job 90 .get('taskGroups') 91 .mapBy('summary.startingAllocs') 92 .reduce((sum, allocs) => sum + allocs, 0), 93 'startingAllocs is the sum of all group startingAllocs' 94 ); 95 96 assert.equal( 97 job.get('runningAllocs'), 98 job 99 .get('taskGroups') 100 .mapBy('summary.runningAllocs') 101 .reduce((sum, allocs) => sum + allocs, 0), 102 'runningAllocs is the sum of all group runningAllocs' 103 ); 104 105 assert.equal( 106 job.get('completeAllocs'), 107 job 108 .get('taskGroups') 109 .mapBy('summary.completeAllocs') 110 .reduce((sum, allocs) => sum + allocs, 0), 111 'completeAllocs is the sum of all group completeAllocs' 112 ); 113 114 assert.equal( 115 job.get('failedAllocs'), 116 job 117 .get('taskGroups') 118 .mapBy('summary.failedAllocs') 119 .reduce((sum, allocs) => sum + allocs, 0), 120 'failedAllocs is the sum of all group failedAllocs' 121 ); 122 123 assert.equal( 124 job.get('lostAllocs'), 125 job 126 .get('taskGroups') 127 .mapBy('summary.lostAllocs') 128 .reduce((sum, allocs) => sum + allocs, 0), 129 'lostAllocs is the sum of all group lostAllocs' 130 ); 131 }); 132 });