transformers_specs.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import {describe, beforeEach, it, sinon, expect} from 'test/lib/common';
  2. import {TableModel} from '../table_model';
  3. describe('when transforming time series table', () => {
  4. var table;
  5. describe('given 2 time series', () => {
  6. var time = new Date().getTime();
  7. var timeSeries = [
  8. {
  9. target: 'series1',
  10. datapoints: [[12.12, time], [14.44, time+1]],
  11. },
  12. {
  13. target: 'series2',
  14. datapoints: [[16.12, time]],
  15. }
  16. ];
  17. describe('timeseries_to_rows', () => {
  18. var panel = {
  19. transform: 'timeseries_to_rows',
  20. sort: {col: 0, desc: true},
  21. };
  22. beforeEach(() => {
  23. table = TableModel.transform(timeSeries, panel);
  24. });
  25. it('should return 3 rows', () => {
  26. expect(table.rows.length).to.be(3);
  27. expect(table.rows[0][1]).to.be('series1');
  28. expect(table.rows[1][1]).to.be('series1');
  29. expect(table.rows[2][1]).to.be('series2');
  30. expect(table.rows[0][2]).to.be(12.12);
  31. });
  32. it('should return 3 rows', () => {
  33. expect(table.columns.length).to.be(3);
  34. expect(table.columns[0].text).to.be('Time');
  35. expect(table.columns[1].text).to.be('Series');
  36. expect(table.columns[2].text).to.be('Value');
  37. });
  38. });
  39. describe('timeseries_to_columns', () => {
  40. var panel = {
  41. transform: 'timeseries_to_columns'
  42. };
  43. beforeEach(() => {
  44. table = TableModel.transform(timeSeries, panel);
  45. });
  46. it ('should return 3 columns', () => {
  47. expect(table.columns.length).to.be(3);
  48. expect(table.columns[0].text).to.be('Time');
  49. expect(table.columns[1].text).to.be('series1');
  50. expect(table.columns[2].text).to.be('series2');
  51. });
  52. it ('should return 2 rows', () => {
  53. expect(table.rows.length).to.be(2);
  54. expect(table.rows[0][1]).to.be(12.12);
  55. expect(table.rows[0][2]).to.be(16.12);
  56. });
  57. it ('should be undefined when no value for timestamp', () => {
  58. expect(table.rows[1][2]).to.be(undefined);
  59. });
  60. });
  61. describe('JSON Data', () => {
  62. var panel = {
  63. transform: 'json',
  64. fields: [{name: 'timestamp'}, {name: 'message'}]
  65. };
  66. var rawData = [
  67. {
  68. type: 'docs',
  69. datapoints: [
  70. {
  71. timestamp: 'time',
  72. message: 'message'
  73. }
  74. ]
  75. }
  76. ];
  77. beforeEach(() => {
  78. table = TableModel.transform(rawData, panel);
  79. });
  80. it ('should return 2 columns', () => {
  81. expect(table.columns.length).to.be(2);
  82. expect(table.columns[0].text).to.be('timestamp');
  83. expect(table.columns[1].text).to.be('message');
  84. });
  85. it ('should return 2 rows', () => {
  86. expect(table.rows.length).to.be(1);
  87. expect(table.rows[0][0]).to.be('time');
  88. expect(table.rows[0][1]).to.be('message');
  89. });
  90. });
  91. describe('Annnotations', () => {
  92. var panel = {transform: 'annotations'};
  93. var rawData = [
  94. {
  95. min: 1000,
  96. text: 'hej',
  97. tags: ['tags', 'asd'],
  98. title: 'title',
  99. }
  100. ];
  101. beforeEach(() => {
  102. table = TableModel.transform(rawData, panel);
  103. });
  104. it ('should return 4 columns', () => {
  105. expect(table.columns.length).to.be(4);
  106. expect(table.columns[0].text).to.be('Time');
  107. expect(table.columns[1].text).to.be('Title');
  108. expect(table.columns[2].text).to.be('Text');
  109. expect(table.columns[3].text).to.be('Tags');
  110. });
  111. it ('should return 1 rows', () => {
  112. expect(table.rows.length).to.be(1);
  113. expect(table.rows[0][0]).to.be(1000);
  114. });
  115. });
  116. });
  117. });