StatMigrations.test.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { PanelModel } from '@grafana/data';
  2. import { BigValueGraphMode, BigValueColorMode } from '@grafana/ui';
  3. import { BigValueTextMode } from '@grafana/ui/src/components/BigValue/BigValue';
  4. import { statPanelChangedHandler } from './StatMigrations';
  5. describe('Stat Panel Migrations', () => {
  6. it('change from angular singlestat sparkline disabled', () => {
  7. const old: any = {
  8. angular: {
  9. format: 'ms',
  10. decimals: 7,
  11. sparkline: {
  12. show: false,
  13. },
  14. },
  15. };
  16. const panel = {} as PanelModel;
  17. const options = statPanelChangedHandler(panel, 'singlestat', old);
  18. expect(options.graphMode).toBe(BigValueGraphMode.None);
  19. });
  20. it('change from angular singlestat sparkline enabled', () => {
  21. const old: any = {
  22. angular: {
  23. format: 'ms',
  24. decimals: 7,
  25. sparkline: {
  26. show: true,
  27. },
  28. },
  29. };
  30. const panel = {} as PanelModel;
  31. const options = statPanelChangedHandler(panel, 'singlestat', old);
  32. expect(options.graphMode).toBe(BigValueGraphMode.Area);
  33. });
  34. it('change from angular singlestat color background', () => {
  35. const old: any = {
  36. angular: {
  37. format: 'ms',
  38. decimals: 7,
  39. colorBackground: true,
  40. },
  41. };
  42. const panel = {} as PanelModel;
  43. const options = statPanelChangedHandler(panel, 'singlestat', old);
  44. expect(options.colorMode).toBe(BigValueColorMode.Background);
  45. });
  46. it('change from angular singlestat with name stat', () => {
  47. const old: any = {
  48. angular: {
  49. valueName: 'name',
  50. },
  51. };
  52. const panel = {} as PanelModel;
  53. const options = statPanelChangedHandler(panel, 'singlestat', old);
  54. expect(options.textMode).toBe(BigValueTextMode.Name);
  55. });
  56. it('use no color unless one was configured', () => {
  57. let old: any = {
  58. angular: {
  59. valueName: 'name',
  60. },
  61. };
  62. let panel = {} as PanelModel;
  63. let options = statPanelChangedHandler(panel, 'singlestat', old);
  64. expect(options.colorMode).toBe(BigValueColorMode.None);
  65. old = {
  66. angular: {
  67. valueName: 'name',
  68. colorBackground: true,
  69. },
  70. };
  71. panel = {} as PanelModel;
  72. options = statPanelChangedHandler(panel, 'singlestat', old);
  73. expect(options.colorMode).toBe(BigValueColorMode.Background);
  74. });
  75. });