selectors.test.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { getSearchQuery, getAlertRuleItems } from './selectors';
  2. describe('Get search query', () => {
  3. it('should get search query', () => {
  4. const state = { searchQuery: 'dashboard' };
  5. const result = getSearchQuery(state as any);
  6. expect(result).toEqual(state.searchQuery);
  7. });
  8. });
  9. describe('Get alert rule items', () => {
  10. it('should get alert rule items', () => {
  11. const state = {
  12. alertRules: {
  13. items: [
  14. {
  15. id: 1,
  16. dashboardId: 1,
  17. panelId: 1,
  18. name: '',
  19. state: '',
  20. stateText: '',
  21. stateIcon: '',
  22. stateClass: '',
  23. stateAge: '',
  24. url: '',
  25. },
  26. ],
  27. searchQuery: '',
  28. },
  29. };
  30. const result = getAlertRuleItems(state as any);
  31. expect(result.length).toEqual(1);
  32. });
  33. it('should filter rule items based on search query', () => {
  34. const state = {
  35. alertRules: {
  36. items: [
  37. {
  38. id: 1,
  39. dashboardId: 1,
  40. panelId: 1,
  41. name: 'dashboard',
  42. state: '',
  43. stateText: '',
  44. stateIcon: '',
  45. stateClass: '',
  46. stateAge: '',
  47. url: '',
  48. },
  49. {
  50. id: 2,
  51. dashboardId: 3,
  52. panelId: 1,
  53. name: 'dashboard2',
  54. state: '',
  55. stateText: '',
  56. stateIcon: '',
  57. stateClass: '',
  58. stateAge: '',
  59. url: '',
  60. },
  61. {
  62. id: 3,
  63. dashboardId: 5,
  64. panelId: 1,
  65. name: 'hello',
  66. state: '',
  67. stateText: '',
  68. stateIcon: '',
  69. stateClass: '',
  70. stateAge: '',
  71. url: '',
  72. },
  73. {
  74. id: 4,
  75. dashboardId: 7,
  76. panelId: 1,
  77. name: 'test',
  78. state: '',
  79. stateText: 'dashboard',
  80. stateIcon: '',
  81. stateClass: '',
  82. stateAge: '',
  83. url: '',
  84. },
  85. ],
  86. searchQuery: 'dashboard',
  87. },
  88. };
  89. const result = getAlertRuleItems(state as any);
  90. expect(result.length).toEqual(3);
  91. });
  92. });