diff --git a/tests/integration/components/chart-contributions-by-type/component-test.js b/tests/integration/components/chart-contributions-by-type/component-test.js index 9d0375b..b59d58d 100644 --- a/tests/integration/components/chart-contributions-by-type/component-test.js +++ b/tests/integration/components/chart-contributions-by-type/component-test.js @@ -6,21 +6,24 @@ import hbs from 'htmlbars-inline-precompile'; module('Integration | Component | chart-contributions-by-type', function(hooks) { setupRenderingTest(hooks); - test('it renders', async function(assert) { - // Set any properties with this.set('myProperty', 'value'); - // Handle any actions with this.set('myAction', function(val) { ... }); + let proposals = [ + { kind: 'dev', amount: 500 }, + { kind: 'dev', amount: 1500 }, + { kind: 'ops', amount: 1500 }, + { kind: 'design', amount: 5000 }, + { kind: 'ops', amount: 1500 }, + { kind: 'dev', amount: 5000 }, + { kind: 'community', amount: 5000 }, + { kind: 'docs', amount: 500 }, + { kind: 'docs', amount: 500 }, + { kind: 'docs', amount: 500 }, + ]; - await render(hbs`{{chart-contributions-by-type}}`); + test('it renders', async function(assert) { + this.set('proposals', proposals); + + await render(hbs`{{chart-contributions-by-type contributions=proposals}}`); assert.equal(this.element.textContent.trim(), ''); - - // Template block usage: - await render(hbs` - {{#chart-contributions-by-type}} - template block text - {{/chart-contributions-by-type}} - `); - - assert.equal(this.element.textContent.trim(), 'template block text'); }); }); diff --git a/tests/unit/components/chart-contributions-by-type-test.js b/tests/unit/components/chart-contributions-by-type-test.js new file mode 100644 index 0000000..5d85a5c --- /dev/null +++ b/tests/unit/components/chart-contributions-by-type-test.js @@ -0,0 +1,37 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('Unit | Component | chart-contributions-by-type', function(hooks) { + setupTest(hooks); + + let proposals = [ + { kind: 'dev', amount: 500 }, + { kind: 'dev', amount: 1500 }, + { kind: 'ops', amount: 1500 }, + { kind: 'design', amount: 5000 }, + { kind: 'ops', amount: 1500 }, + { kind: 'dev', amount: 5000 }, + { kind: 'community', amount: 5000 }, + { kind: 'docs', amount: 500 }, + { kind: 'docs', amount: 500 }, + { kind: 'docs', amount: 500 }, + ]; + + test('#chartData', function(assert) { + let component = this.owner.factoryFor('component:chart-contributions-by-type').create(); + component.set('contributions', proposals); + + let data = component.get('chartData'); + + assert.deepEqual( + data.labels, + ['Community', 'Design', 'Development', 'Operations & Infrastructure', 'Documentation'], + 'returns the correct labels' + ); + assert.deepEqual( + data.datasets[0].data, + [5000, 5000, 7000, 3000, 1500], + 'returns the correct kredit sums' + ); + }); +});