Sha256: eaa1cebc08bb6d755e3d1fe36391cf65cc8ac36b83692cdd75f3f1d47201f3f4

Contents?: true

Size: 1.79 KB

Versions: 89

Compression:

Stored size: 1.79 KB

Contents

import { testActionSnapshotWithFixtures } from '@theforeman/test';
import { API } from 'foremanReact/redux/API';
import {
  getInsightsSyncSettings,
  setInsightsSyncEnabled,
} from '../InsightsSettingsActions';
import { rhCloudStateWrapper } from '../../../../ForemanRhCloudTestHelpers';

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

jest.mock('foremanReact/redux/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

89 entries across 89 versions & 1 rubygems

Version Path
foreman_rh_cloud-11.2.0 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js
foreman_rh_cloud-9.0.60 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js
foreman_rh_cloud-10.0.4 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js
foreman_rh_cloud-11.1.0 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js
foreman_rh_cloud-10.0.3 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js
foreman_rh_cloud-11.0.3 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js
foreman_rh_cloud-9.0.59 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js
foreman_rh_cloud-11.0.2 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js
foreman_rh_cloud-11.0.1 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js
foreman_rh_cloud-11.0.0 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js
foreman_rh_cloud-9.0.58 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js
foreman_rh_cloud-10.0.2 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js
foreman_rh_cloud-9.0.57 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js
foreman_rh_cloud-10.0.1 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js
foreman_rh_cloud-9.0.56 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js
foreman_rh_cloud-9.0.55 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js
foreman_rh_cloud-9.0.54 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js
foreman_rh_cloud-9.0.53 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js
foreman_rh_cloud-9.0.52 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js
foreman_rh_cloud-8.0.52 webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js