Closed tomwayson closed 6 years ago
FYI - here's a component test we were using in hub that could be modified to run here:
import { moduleForComponent, done, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
moduleForComponent('chart-card', 'Integration | Component | chart card', {
integration: true,
beforeEach () {
let intl = this.container.lookup('service:intl');
intl.setLocale('en-us');
this.inject.service('intl', {as: 'intl'});
this.set('model', {
component: {
settings: {
}
}
});
}
});
test('It shows a placeholder', function (assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });
this.render(hbs`{{chart-card model=model}}`);
assert.equal(this.$('.panel-body > img').attr('alt'), 'Chart Placeholder', 'Image is present and has alt text');
});
test('It generates a chart properly', function (assert) {
let done = assert.done;
this.on('updateEnd', function (e) {
console.log(e);
assert.equal(true, true);
done();
});
// const settings = ;
this.set('model', {
component: {
settings: {
title: 'New Chart Title',
titleVisible: true,
height: 400,
chartType: 'custom',
definition: {
'type': 'bar',
'datasets': [
{
'url': 'https://services.arcgis.com/uDTUpUPbk8X8mXwl/arcgis/rest/services/Public_Schools_in_Onondaga_County/FeatureServer/0',
'name': 'Number_of_SUM',
'query': {
'orderByFields': 'Number_of_SUM DESC',
'groupByFieldsForStatistics': 'Type',
'outStatistics': [
{
'statisticType': 'sum',
'onStatisticField': 'Number_of',
'outStatisticFieldName': 'Number_of_SUM'
}
]
}
}
],
'series': [
{
'category': {'field': 'Type', 'label': 'Type'},
'value': {'field': 'Number_of_SUM', 'label': 'Number of Students'},
'source': 'Number_of_SUM'
}
]
}
}
}
});
this.render(hbs`{{chart-card model=model onUpdateEnd=(action 'updateEnd')}}`);
// NOTE: this won't work
// emebr-cli-cedar may need to wrap calls to cedar API in Ember.run()
// return wait().then(() => {
// assert.equal(true, true);
// });
});
I'm going to open a new issue for acceptance tests and make this one about updating the existing integration test.
TODO:
datasets
, series
etc) and validate onUpdateStart
, transform
)NOTE: don't test onError
here, we can do that w/ acceptance tests.
Also, in the Hub apps we've had trouble w/ ember-sinon-qunit sometimes mysteriously not stubbing random methods. We could try https://github.com/ember-cli/ember-cli-mocha and https://github.com/csantero/ember-sinon here instead?
Well this looks interesting: https://dockyard.com/blog/2018/01/11/modern-ember-testing
I wonder if that works w/ ember-sinon-qunit?
resolved in #74
Integration tests that stub out cedar are probably better than acceptance (b/c it would be very hard to verify the charts via the DOM. At a minimum, add tests to to verify the chart constructor is called properly.
One test that might work as an acceptance would be to verify error messages on https://esri.github.io/ember-cli-cedar/#/error-handling