mockStore.js 3.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
19 20 21
import { createStore, applyMiddleware, compose } from 'redux';
import thunk from 'redux-thunk';

22
import rootReducer from 'src/dashboard/reducers/index';
23 24

import mockState from './mockState';
25 26 27 28
import {
  dashboardLayoutWithTabs,
  dashboardLayoutWithChartsInTabsAndRoot,
} from './mockDashboardLayout';
29 30
import { sliceId } from './mockChartQueries';
import { dashboardFilters } from './mockDashboardFilters';
31
import { nativeFilters } from './mockNativeFilters';
32

33 34 35 36 37 38
export const getMockStore = overrideState =>
  createStore(
    rootReducer,
    { ...mockState, ...overrideState },
    compose(applyMiddleware(thunk)),
  );
39

40 41 42 43 44 45 46 47 48 49 50 51 52
export const mockStore = getMockStore();

export const getMockStoreWithTabs = () =>
  createStore(
    rootReducer,
    {
      ...mockState,
      dashboardLayout: dashboardLayoutWithTabs,
      dashboardFilters: {},
    },
    compose(applyMiddleware(thunk)),
  );

53 54 55 56 57 58 59 60 61 62 63
export const getMockStoreWithChartsInTabsAndRoot = () =>
  createStore(
    rootReducer,
    {
      ...mockState,
      dashboardLayout: dashboardLayoutWithChartsInTabsAndRoot,
      dashboardFilters: {},
    },
    compose(applyMiddleware(thunk)),
  );

64
export const mockStoreWithTabs = getMockStoreWithTabs();
65
export const mockStoreWithChartsInTabsAndRoot = getMockStoreWithChartsInTabsAndRoot();
66 67 68 69 70 71 72 73 74

export const sliceIdWithAppliedFilter = sliceId + 1;
export const sliceIdWithRejectedFilter = sliceId + 2;

// has one chart with a filter that has been applied,
// one chart with a filter that has been rejected,
// and one chart with no filters set.
export const getMockStoreWithFilters = () =>
  createStore(rootReducer, {
75
    ...mockState,
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
    dashboardFilters,
    charts: {
      ...mockState.charts,
      [sliceIdWithAppliedFilter]: {
        ...mockState.charts[sliceId],
        queryResponse: {
          status: 'success',
          applied_filters: [{ column: 'region' }],
          rejected_filters: [],
        },
      },
      [sliceIdWithRejectedFilter]: {
        ...mockState.charts[sliceId],
        queryResponse: {
          status: 'success',
          applied_filters: [],
          rejected_filters: [{ column: 'region', reason: 'not_in_datasource' }],
        },
      },
    },
  });
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121

export const getMockStoreWithNativeFilters = () =>
  createStore(rootReducer, {
    ...mockState,
    nativeFilters,
    charts: {
      ...mockState.charts,
      [sliceIdWithAppliedFilter]: {
        ...mockState.charts[sliceId],
        queryResponse: {
          status: 'success',
          applied_filters: [{ column: 'region' }],
          rejected_filters: [],
        },
      },
      [sliceIdWithRejectedFilter]: {
        ...mockState.charts[sliceId],
        queryResponse: {
          status: 'success',
          applied_filters: [],
          rejected_filters: [{ column: 'region', reason: 'not_in_datasource' }],
        },
      },
    },
  });