From f0363675ef49818d09dae236453ce6b64ebd4f7e Mon Sep 17 00:00:00 2001 From: John Cowen Date: Mon, 15 Jan 2018 12:49:08 +0000 Subject: [PATCH] Move placement failures to a component, begin separate integration tests 1. Simple move of placement-failures template code to a component 2. Start adding integration tests - hit `inc` surprise --- ui/app/components/placement-failure.js | 5 ++ .../components/placement-failure.hbs | 40 ++++++++++ ui/app/templates/jobs/job/index.hbs | 40 +--------- ui/tests/integration/cleanWhitespace.js | 6 ++ ui/tests/integration/job-diff-test.js | 8 +- .../integration/placement-failure-test.js | 75 +++++++++++++++++++ 6 files changed, 128 insertions(+), 46 deletions(-) create mode 100644 ui/app/components/placement-failure.js create mode 100644 ui/app/templates/components/placement-failure.hbs create mode 100644 ui/tests/integration/cleanWhitespace.js create mode 100644 ui/tests/integration/placement-failure-test.js diff --git a/ui/app/components/placement-failure.js b/ui/app/components/placement-failure.js new file mode 100644 index 000000000..00d6fa37e --- /dev/null +++ b/ui/app/components/placement-failure.js @@ -0,0 +1,5 @@ +import Ember from 'ember'; + +const { Component } = Ember; + +export default Component.extend({}); diff --git a/ui/app/templates/components/placement-failure.hbs b/ui/app/templates/components/placement-failure.hbs new file mode 100644 index 000000000..5066f2d32 --- /dev/null +++ b/ui/app/templates/components/placement-failure.hbs @@ -0,0 +1,40 @@ +{{#if taskGroup.placementFailures}} + {{#with taskGroup.placementFailures as |failures|}} +

+ {{taskGroup.name}} + {{inc failures.coalescedFailures}} unplaced +

+ + {{/with}} +{{/if}} + diff --git a/ui/app/templates/jobs/job/index.hbs b/ui/app/templates/jobs/job/index.hbs index 8a0ac1c0d..347b7081a 100644 --- a/ui/app/templates/jobs/job/index.hbs +++ b/ui/app/templates/jobs/job/index.hbs @@ -56,45 +56,7 @@
{{#each model.taskGroups as |taskGroup|}} - {{#if taskGroup.placementFailures}} - {{#with taskGroup.placementFailures as |failures|}} -

- {{taskGroup.name}} - {{inc failures.coalescedFailures}} unplaced -

- - {{/with}} - {{/if}} + {{#placement-failure taskGroup=taskGroup}}{{/placement-failure}} {{/each}}
diff --git a/ui/tests/integration/cleanWhitespace.js b/ui/tests/integration/cleanWhitespace.js new file mode 100644 index 000000000..c589984b6 --- /dev/null +++ b/ui/tests/integration/cleanWhitespace.js @@ -0,0 +1,6 @@ +export default function cleanWhitespace(string) { + return string + .replace(/\n/g, '') + .replace(/ +/g, ' ') + .trim(); +} diff --git a/ui/tests/integration/job-diff-test.js b/ui/tests/integration/job-diff-test.js index d1821e452..f9fac114c 100644 --- a/ui/tests/integration/job-diff-test.js +++ b/ui/tests/integration/job-diff-test.js @@ -1,6 +1,7 @@ import { findAll, find } from 'ember-native-dom-helpers'; import { test, moduleForComponent } from 'ember-qunit'; import hbs from 'htmlbars-inline-precompile'; +import cleanWhitespace from './cleanWhitespace'; moduleForComponent('job-diff', 'Integration | Component | job diff', { integration: true, @@ -192,10 +193,3 @@ function field(name, type, newVal, oldVal) { Name: name, }; } - -function cleanWhitespace(string) { - return string - .replace(/\n/g, '') - .replace(/ +/g, ' ') - .trim(); -} diff --git a/ui/tests/integration/placement-failure-test.js b/ui/tests/integration/placement-failure-test.js new file mode 100644 index 000000000..712c60696 --- /dev/null +++ b/ui/tests/integration/placement-failure-test.js @@ -0,0 +1,75 @@ +import { find } from 'ember-native-dom-helpers'; +import { test, moduleForComponent } from 'ember-qunit'; +import hbs from 'htmlbars-inline-precompile'; +import cleanWhitespace from './cleanWhitespace'; + +moduleForComponent('placement-failure', 'Integration | Component | placement failure', { + integration: true, +}); + +const commonTemplate = hbs` +
+
+ {{#placement-failure taskGroup=taskGroup}}{{/placement-failure}} +
+
+`; + +const name = 'My Name'; +const failures = 10; + +test('placement failure report', function(assert) { + this.set('taskGroup', { + name: name, + placementFailures: createFailures(failures), + }); + this.render(commonTemplate); + assert.equal( + cleanWhitespace(find('.title').textContent), + `${name} ${failures} unplaced`, + 'Title is rendered correctly with a count of unplaced' + ); +}); + +function createFailures(count) { + return { + coalescedFailures: count, + nodesEvaluated: 0, + nodesAvailable: [ + { + datacenter: 0, + }, + ], + classFiltered: [ + { + filtered: 1, + }, + ], + constraintFiltered: [ + { + 'prop = val': 1, + }, + ], + nodesExhausted: 3, + classExhausted: [ + { + class: 3, + }, + ], + dimensionExhausted: [ + { + iops: 3, + }, + ], + quotaExhausted: [ + { + quota: 'dimension', + }, + ], + scores: [ + { + name: 3, + }, + ], + }; +}