diff --git a/ui/app/serializers/job-summary.js b/ui/app/serializers/job-summary.js index 87badef45..ed464e819 100644 --- a/ui/app/serializers/job-summary.js +++ b/ui/app/serializers/job-summary.js @@ -9,8 +9,9 @@ export default ApplicationSerializer.extend({ hash.ID = JSON.stringify([hash.JobID, hash.Namespace || 'default']); hash.JobID = hash.ID; - hash.TaskGroupSummaries = Object.keys(get(hash, 'Summary') || {}).map(key => { - const allocStats = get(hash, `Summary.${key}`) || {}; + const fullSummary = hash.Summary || {}; + hash.TaskGroupSummaries = Object.keys(fullSummary).map(key => { + const allocStats = fullSummary[key] || {}; const summary = { Name: key }; Object.keys(allocStats).forEach( diff --git a/ui/tests/unit/serializers/job-summary-test.js b/ui/tests/unit/serializers/job-summary-test.js new file mode 100644 index 000000000..8272cf2a5 --- /dev/null +++ b/ui/tests/unit/serializers/job-summary-test.js @@ -0,0 +1,103 @@ +import { test } from 'ember-qunit'; +import JobSummaryModel from 'nomad-ui/models/job-summary'; +import moduleForSerializer from '../../helpers/module-for-serializer'; + +moduleForSerializer('job-summary', 'Unit | Serializer | JobSummary', { + needs: [ + 'serializer:job-summary', + 'transform:fragment-array', + 'model:job', + 'model:task-group-summary', + ], +}); + +const normalizationTestCases = [ + { + name: 'Normal', + in: { + JobID: 'test-summary', + Namespace: 'test-namespace', + Summary: { + taskGroup: { + Complete: 0, + Running: 1, + }, + }, + }, + out: { + data: { + id: '["test-summary","test-namespace"]', + type: 'job-summary', + attributes: { + taskGroupSummaries: [ + { + name: 'taskGroup', + completeAllocs: 0, + runningAllocs: 1, + }, + ], + }, + relationships: { + job: { + data: { + id: '["test-summary","test-namespace"]', + type: 'job', + }, + }, + }, + }, + }, + }, + + { + name: 'Dots in task group names', + in: { + JobID: 'test-summary', + Namespace: 'test-namespace', + Summary: { + 'one.two': { + Complete: 0, + Running: 1, + }, + 'three.four': { + Failed: 2, + Lost: 3, + }, + }, + }, + out: { + data: { + id: '["test-summary","test-namespace"]', + type: 'job-summary', + attributes: { + taskGroupSummaries: [ + { + name: 'one.two', + completeAllocs: 0, + runningAllocs: 1, + }, + { + name: 'three.four', + failedAllocs: 2, + lostAllocs: 3, + }, + ], + }, + relationships: { + job: { + data: { + id: '["test-summary","test-namespace"]', + type: 'job', + }, + }, + }, + }, + }, + }, +]; + +normalizationTestCases.forEach(testCase => { + test(`normalization: ${testCase.name}`, function(assert) { + assert.deepEqual(this.subject().normalize(JobSummaryModel, testCase.in), testCase.out); + }); +});