options.spec.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. describe('options (scriptable)', function() {
  2. [
  3. 'align',
  4. 'anchor',
  5. 'opacity'
  6. ].forEach(function(key) {
  7. it(key + ' should be called with a valid context', function() {
  8. var options = {};
  9. options[key] = function() {};
  10. spyOn(options, key);
  11. var chart = jasmine.chart.acquire({
  12. type: 'line',
  13. data: {
  14. datasets: [{
  15. data: [42, 51]
  16. }, {
  17. data: [2]
  18. }]
  19. },
  20. options: {
  21. plugins: {
  22. datalabels: options
  23. }
  24. }
  25. });
  26. expect(options[key].calls.count()).toBe(3);
  27. [
  28. {dataIndex: 0, datasetIndex: 0},
  29. {dataIndex: 1, datasetIndex: 0},
  30. {dataIndex: 0, datasetIndex: 1}
  31. ].forEach(function(e, i) {
  32. expect(options[key].calls.argsFor(i)[0]).toEqual({
  33. active: false,
  34. chart: chart,
  35. dataIndex: e.dataIndex,
  36. dataset: chart.data.datasets[e.datasetIndex],
  37. datasetIndex: e.datasetIndex
  38. });
  39. });
  40. });
  41. });
  42. });
  43. describe('option.align', function() {
  44. describe('auto', jasmine.fixture.specs('options.align'));
  45. });
  46. describe('option.anchor', function() {
  47. describe('auto', jasmine.fixture.specs('options.anchor'));
  48. });
  49. describe('option.opacity', function() {
  50. describe('auto', jasmine.fixture.specs('options.opacity'));
  51. });