mockStore.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. import { setupStore } from 'src/views/store';
  20. import { FilterBarOrientation } from 'src/dashboard/types';
  21. import mockState from './mockState';
  22. import {
  23. dashboardLayoutWithTabs,
  24. dashboardLayoutWithChartsInTabsAndRoot,
  25. } from './mockDashboardLayout';
  26. import { sliceId } from './mockChartQueries';
  27. import { dashboardFilters } from './mockDashboardFilters';
  28. import { nativeFilters, dataMaskWith2Filters } from './mockNativeFilters';
  29. export const storeWithState = state =>
  30. setupStore({
  31. disableDebugger: true,
  32. initialState: state,
  33. });
  34. export const getMockStore = overrideState =>
  35. setupStore({
  36. disableDebugger: true,
  37. initialState: { ...mockState, ...overrideState },
  38. });
  39. export const mockStore = getMockStore();
  40. export const getMockStoreWithTabs = () =>
  41. setupStore({
  42. disableDebugger: true,
  43. initialState: {
  44. ...mockState,
  45. dashboardLayout: dashboardLayoutWithTabs,
  46. dashboardFilters: {},
  47. },
  48. });
  49. export const getMockStoreWithChartsInTabsAndRoot = () =>
  50. setupStore({
  51. disableDebugger: true,
  52. initialState: {
  53. ...mockState,
  54. dashboardLayout: dashboardLayoutWithChartsInTabsAndRoot,
  55. dashboardFilters: {},
  56. },
  57. });
  58. export const mockStoreWithTabs = getMockStoreWithTabs();
  59. export const mockStoreWithChartsInTabsAndRoot =
  60. getMockStoreWithChartsInTabsAndRoot();
  61. export const sliceIdWithAppliedFilter = sliceId + 1;
  62. export const sliceIdWithRejectedFilter = sliceId + 2;
  63. export const stateWithFilters = {
  64. ...mockState,
  65. dashboardFilters,
  66. dataMask: dataMaskWith2Filters,
  67. charts: {
  68. ...mockState.charts,
  69. [sliceIdWithAppliedFilter]: {
  70. ...mockState.charts[sliceId],
  71. queryResponse: {
  72. status: 'success',
  73. applied_filters: [{ column: 'region' }],
  74. rejected_filters: [],
  75. },
  76. },
  77. [sliceIdWithRejectedFilter]: {
  78. ...mockState.charts[sliceId],
  79. queryResponse: {
  80. status: 'success',
  81. applied_filters: [],
  82. rejected_filters: [{ column: 'region', reason: 'not_in_datasource' }],
  83. },
  84. },
  85. },
  86. };
  87. // has one chart with a filter that has been applied,
  88. // one chart with a filter that has been rejected,
  89. // and one chart with no filters set.
  90. export const getMockStoreWithFilters = () =>
  91. setupStore({
  92. disableDebugger: true,
  93. initialState: stateWithFilters,
  94. });
  95. export const stateWithNativeFilters = {
  96. ...mockState,
  97. nativeFilters,
  98. dataMask: dataMaskWith2Filters,
  99. charts: {
  100. ...mockState.charts,
  101. [sliceIdWithAppliedFilter]: {
  102. ...mockState.charts[sliceId],
  103. queryResponse: {
  104. status: 'success',
  105. applied_filters: [{ column: 'region' }],
  106. rejected_filters: [],
  107. },
  108. },
  109. [sliceIdWithRejectedFilter]: {
  110. ...mockState.charts[sliceId],
  111. queryResponse: {
  112. status: 'success',
  113. applied_filters: [],
  114. rejected_filters: [{ column: 'region', reason: 'not_in_datasource' }],
  115. },
  116. },
  117. },
  118. dashboardInfo: {
  119. filterBarOrientation: FilterBarOrientation.Vertical,
  120. },
  121. };
  122. export const getMockStoreWithNativeFilters = () =>
  123. setupStore({
  124. disableDebugger: true,
  125. initialState: stateWithNativeFilters,
  126. });
  127. export const stateWithoutNativeFilters = {
  128. ...mockState,
  129. charts: {
  130. ...mockState.charts,
  131. [sliceIdWithAppliedFilter]: {
  132. ...mockState.charts[sliceId],
  133. queryResponse: {
  134. status: 'success',
  135. applied_filters: [{ column: 'region' }],
  136. rejected_filters: [],
  137. },
  138. },
  139. [sliceIdWithRejectedFilter]: {
  140. ...mockState.charts[sliceId],
  141. queryResponse: {
  142. status: 'success',
  143. applied_filters: [],
  144. rejected_filters: [{ column: 'region', reason: 'not_in_datasource' }],
  145. },
  146. },
  147. },
  148. dashboardInfo: {
  149. dash_edit_perm: true,
  150. filterBarOrientation: FilterBarOrientation.Vertical,
  151. metadata: {
  152. native_filter_configuration: [],
  153. },
  154. },
  155. dataMask: {},
  156. nativeFilters: { filters: {} },
  157. };