Sha256: c34aa3d0a1bbfc977ab2fd638aab770634c2c7100625c2b9ff0d0e658858f49a

Contents?: true

Size: 1.78 KB

Versions: 10

Compression:

Stored size: 1.78 KB

Contents

import { testActionSnapshotWithFixtures } from 'react-redux-test-utils';
import API from 'foremanReact/API';
import {
  getInsightsSyncSettings,
  setInsightsSyncEnabled,
} from '../InsightsSettingsActions';
import { rhCloudStateWrapper } from '../../../../ForemanRhCloudTestHelpers';

const serverMock = {
  data: { insightsSyncEnabled: true },
};

jest.mock('foremanReact/API');
API.get.mockImplementation(() => serverMock);
API.patch.mockImplementation(() => serverMock);

const runWithGetState = (state, action, params) => dispatch => {
  const getState = () => rhCloudStateWrapper({ InsightsCloudSync: state });
  action(params)(dispatch, getState);
};

const fixtures = {
  'should generate INSIGHTS_SYNC_SETTINGS_GET_SUCCESS action': () =>
    runWithGetState({ settings: {} }, getInsightsSyncSettings, {}),
  'should handle getInsightsSyncSettings with error ': () => {
    API.get.mockImplementationOnce(() =>
      Promise.reject(new Error('Network error!'))
    );
    return runWithGetState({ settings: {} }, getInsightsSyncSettings, {});
  },
  'should generate INSIGHTS_SYNC_SETTING_SET action': () =>
    runWithGetState(
      { settings: { insightsSyncEnabled: false } },
      setInsightsSyncEnabled,
      true
    ),
  'should handle setInsightsSyncEnabled with error ': () => {
    API.patch.mockImplementationOnce(() =>
      Promise.reject(new Error('Network error!'))
    );
    return runWithGetState(
      { settings: { insightsSyncEnabled: false } },
      setInsightsSyncEnabled,
      true
    );
  },
};

describe('InsightsSettings actions', () => {
  const { location } = window;

  beforeAll(() => {
    delete window.location;
    window.location = { href: jest.fn() };
  });

  afterAll(() => {
    window.location = location;
  });

  return testActionSnapshotWithFixtures(fixtures);
});

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
foreman_rh_cloud-1.0.18 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js
foreman_rh_cloud-1.0.17 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js
foreman_rh_cloud-1.0.16 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js
foreman_rh_cloud-1.0.15 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js
foreman_rh_cloud-1.0.14 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js
foreman_rh_cloud-0.9.14 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js
foreman_rh_cloud-0.9.13.1 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js
foreman_rh_cloud-1.0.13.1 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js
foreman_rh_cloud-0.9.13 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js
foreman_rh_cloud-1.0.13 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js