foreman_rh_cloud 0.9.4 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/foreman_inventory_upload/accounts_controller.rb +1 -0
  3. data/app/controllers/foreman_inventory_upload/uploads_controller.rb +14 -7
  4. data/app/models/setting/rh_cloud.rb +13 -0
  5. data/config/routes.rb +1 -0
  6. data/lib/foreman_inventory_upload.rb +12 -0
  7. data/lib/foreman_inventory_upload/async/generate_all_reports_job.rb +8 -0
  8. data/lib/foreman_inventory_upload/async/queue_for_upload_job.rb +10 -5
  9. data/lib/foreman_inventory_upload/async/upload_report_job.rb +1 -5
  10. data/lib/foreman_inventory_upload/generators/archived_report.rb +6 -3
  11. data/lib/foreman_inventory_upload/generators/queries.rb +1 -0
  12. data/lib/foreman_inventory_upload/generators/slice.rb +20 -4
  13. data/lib/foreman_inventory_upload/scripts/uploader.sh.erb +1 -0
  14. data/lib/foreman_rh_cloud/engine.rb +5 -1
  15. data/lib/foreman_rh_cloud/version.rb +1 -1
  16. data/package.json +20 -100
  17. data/test/controllers/accounts_controller_test.rb +8 -3
  18. data/test/controllers/uploads_controller_test.rb +13 -0
  19. data/test/factories/inventory_upload_factories.rb +13 -13
  20. data/test/unit/slice_generator_test.rb +47 -4
  21. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.fixtures.js +2 -0
  22. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.stories.js +5 -14
  23. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListActions.js +2 -1
  24. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListReducer.js +8 -0
  25. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListSelectors.js +2 -0
  26. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/__tests__/EmptyState.test.js +1 -1
  27. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/__tests__/ErrorState.test.js +1 -1
  28. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/__tests__/ListItem.test.js +1 -1
  29. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/__tests__/ListItemStatus.test.js +1 -1
  30. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountList.test.js +1 -1
  31. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListActions.test.js +1 -1
  32. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListIntegration.test.js +1 -1
  33. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListReducer.test.js +12 -1
  34. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListSelectors.test.js +10 -2
  35. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListReducer.test.js.snap +10 -0
  36. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListSelectors.test.js.snap +5 -2
  37. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcher.fixtures.js +1 -0
  38. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcher.js +32 -0
  39. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcherActions.js +27 -0
  40. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcherConstants.js +2 -0
  41. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/AutoUploadSwitcher.test.js +14 -0
  42. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/AutoUploadSwitcherActions.test.js +14 -0
  43. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/__snapshots__/AutoUploadSwitcher.test.js.snap +38 -0
  44. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/__snapshots__/AutoUploadSwitcherActions.test.js.snap +14 -0
  45. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/autoUploadSwitcher.scss +3 -0
  46. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/index.js +17 -0
  47. data/webpack/ForemanInventoryUpload/Components/Dashboard/Dashboard.fixtures.js +13 -9
  48. data/webpack/ForemanInventoryUpload/Components/Dashboard/Dashboard.stories.js +5 -15
  49. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/Dashboard.test.js +1 -2
  50. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardActions.test.js +15 -2
  51. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardIntegration.test.js +3 -2
  52. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardReducer.test.js +1 -1
  53. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardSelectors.test.js +1 -1
  54. data/webpack/ForemanInventoryUpload/Components/FileDownload/__tests__/FileDownload.test.js +1 -1
  55. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/__tests__/FullScreenModal.test.js +1 -1
  56. data/webpack/ForemanInventoryUpload/Components/NavContainer/NavContainer.fixtures.js +5 -2
  57. data/webpack/ForemanInventoryUpload/Components/NavContainer/__tests__/NavContainer.test.js +1 -2
  58. data/webpack/ForemanInventoryUpload/Components/NavContainer/__tests__/__snapshots__/NavContainer.test.js.snap +1 -1
  59. data/webpack/ForemanInventoryUpload/Components/PageHeader/PageHeader.js +21 -0
  60. data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/PageHeader.test.js +13 -0
  61. data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageHeader.test.js.snap +33 -0
  62. data/webpack/ForemanInventoryUpload/Components/PageHeader/index.js +1 -0
  63. data/webpack/ForemanInventoryUpload/Components/ReportGenerate/__tests__/ReportGenerate.test.js +1 -1
  64. data/webpack/ForemanInventoryUpload/Components/ReportUpload/__tests__/ReportUpload.test.js +1 -1
  65. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/ScheduledRun.fixtures.js +1 -0
  66. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/ScheduledRun.js +4 -2
  67. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/__tests__/ScheduledRun.test.js +1 -2
  68. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/__tests__/__snapshots__/ScheduledRun.test.js.snap +0 -2
  69. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/index.js +12 -1
  70. data/webpack/ForemanInventoryUpload/Components/StatusChart/__tests__/StatusChart.test.js +1 -1
  71. data/webpack/ForemanInventoryUpload/Components/TabBody/__tests__/TabBody.test.js +1 -1
  72. data/webpack/ForemanInventoryUpload/Components/TabBody/__tests__/__snapshots__/TabBody.test.js.snap +1 -1
  73. data/webpack/ForemanInventoryUpload/Components/TabContainer/__tests__/TabContainer.test.js +1 -1
  74. data/webpack/ForemanInventoryUpload/Components/TabFooter/__tests__/TabFooter.test.js +1 -1
  75. data/webpack/ForemanInventoryUpload/Components/TabHeader/__tests__/TabHeader.test.js +1 -1
  76. data/webpack/ForemanInventoryUpload/Components/Terminal/Terminal.js +1 -1
  77. data/webpack/ForemanInventoryUpload/Components/Terminal/__tests__/Terminal.test.js +1 -2
  78. data/webpack/ForemanInventoryUpload/ForemanInventoryUpload.js +5 -4
  79. data/webpack/ForemanInventoryUpload/ForemanInventoryUpload.test.js +1 -1
  80. data/webpack/ForemanInventoryUpload/__snapshots__/ForemanInventoryUpload.test.js.snap +6 -5
  81. metadata +49 -13
  82. data/webpack/stories/ForemanInventoryUploadReducers.js +0 -3
  83. data/webpack/stories/configureStore.js +0 -15
  84. data/webpack/stories/decorators/index.js +0 -1
  85. data/webpack/stories/decorators/withCardsDecorator.js +0 -14
  86. data/webpack/stories/index.js +0 -10
  87. data/webpack/stories/index.scss +0 -7
  88. data/webpack/test_setup.js +0 -6
@@ -18,4 +18,17 @@ class UploadsControllerTest < ActionController::TestCase
18
18
  actual = JSON.parse(response.body)
19
19
  assert_equal 'test output', actual['output']
20
20
  end
21
+
22
+ test 'should update allow_auto_inventory_upload setting' do
23
+ FactoryBot.create(:setting, :name => 'allow_auto_inventory_upload', :settings_type => "boolean", :category => "Setting::RhCloud", :default => false, :value => false)
24
+
25
+ assert_equal false, Setting[:allow_auto_inventory_upload]
26
+
27
+ post :auto_upload, params: { value: true }, session: set_session_user
28
+
29
+ assert_response :success
30
+ actual = JSON.parse(response.body)
31
+ assert_equal true, actual['autoUploadEnabled']
32
+ assert_equal true, Setting[:allow_auto_inventory_upload]
33
+ end
21
34
  end
@@ -1,16 +1,16 @@
1
1
  # redefine katello factories, as long as katello is not compatible with dynamic properties
2
2
  FactoryBot.define do
3
3
  factory :katello_organization, :class => "Organization" do
4
- type {"Organization"}
4
+ type { "Organization" }
5
5
  sequence(:name) { |n| "Organization#{n}" }
6
6
  sequence(:label) { |n| "org#{n}" }
7
7
  sequence(:id) { |n| n }
8
8
 
9
9
  trait :acme_corporation do
10
- name {"ACME_Corporation"}
11
- type {"Organization"}
12
- description {"This is the first Organization."}
13
- label {"acme_corporation_label"}
10
+ name { "ACME_Corporation" }
11
+ type { "Organization" }
12
+ description { "This is the first Organization." }
13
+ label { "acme_corporation_label" }
14
14
  end
15
15
 
16
16
  trait :with_library do
@@ -24,11 +24,11 @@ end
24
24
  FactoryBot.define do
25
25
  factory :katello_content_view, :class => Katello::ContentView do
26
26
  sequence(:name) { |n| "Database#{n}" }
27
- description {"This content view is for database content"}
27
+ description { "This content view is for database content" }
28
28
  association :organization, :factory => :katello_organization
29
29
 
30
30
  trait :composite do
31
- composite {true}
31
+ composite { true }
32
32
  end
33
33
  end
34
34
  end
@@ -50,23 +50,23 @@ end
50
50
  FactoryBot.define do
51
51
  factory :katello_subscription_facets, :aliases => [:subscription_facet], :class => ::Katello::Host::SubscriptionFacet do
52
52
  sequence(:uuid) { |n| "uuid-#{n}-#{rand(500)}" }
53
- facts { {'memory.memtotal' => "12 GB"} }
53
+ facts { { 'memory.memtotal' => "12 GB" } }
54
54
  end
55
55
  end
56
56
 
57
57
  FactoryBot.define do
58
58
  factory :katello_pool, :class => Katello::Pool do
59
- active {true}
60
- end_date {Date.today + 1.year}
59
+ active { true }
60
+ end_date { Date.today + 1.year }
61
61
  end
62
62
  end
63
63
 
64
64
  FactoryBot.modify do
65
65
  factory :host do
66
66
  transient do
67
- content_view {nil}
68
- lifecycle_environment {nil}
69
- content_source {nil}
67
+ content_view { nil }
68
+ lifecycle_environment { nil }
69
+ content_source { nil }
70
70
  end
71
71
 
72
72
  trait :with_content do
@@ -17,6 +17,8 @@ class ReportGeneratorTest < ActiveSupport::TestCase
17
17
  )
18
18
 
19
19
  @host.subscription_facet.pools << FactoryBot.create(:katello_pool, account_number: '1234', cp_id: 1)
20
+
21
+ ForemanInventoryUpload::Generators::Queries.instance_variable_set(:@fact_names, nil)
20
22
  end
21
23
 
22
24
  def interesting_facts
@@ -30,9 +32,11 @@ class ReportGeneratorTest < ActiveSupport::TestCase
30
32
  'dmi::bios::vendor',
31
33
  'dmi::bios::version',
32
34
  'dmi::bios::relase_date',
33
- 'distribution::name',
34
35
  'uname::release',
35
36
  'lscpu::flags',
37
+ 'distribution::name',
38
+ 'distribution::version',
39
+ 'distribution::id',
36
40
  ]
37
41
  end
38
42
 
@@ -56,6 +60,7 @@ class ReportGeneratorTest < ActiveSupport::TestCase
56
60
  assert_equal @host.name, actual_host['display_name']
57
61
  assert_equal @host.fqdn, actual_host['fqdn']
58
62
  assert_equal '1234', actual_host['account']
63
+ assert_equal 1, generator.hosts_count
59
64
  end
60
65
 
61
66
  test 'generates a report with satellite facts' do
@@ -72,13 +77,13 @@ class ReportGeneratorTest < ActiveSupport::TestCase
72
77
  assert_equal 'satellite-id', satellite_facts['satellite_instance_id']
73
78
  assert_equal @host.organization_id, satellite_facts['organization_id']
74
79
 
75
- instance_id_tag = actual['hosts'].first['tags'].find { |tag| tag['namespace'] == 'satellite' && tag['key'] == 'satellite_instance_id'}
80
+ instance_id_tag = actual['hosts'].first['tags'].find { |tag| tag['namespace'] == 'satellite' && tag['key'] == 'satellite_instance_id' }
76
81
  assert_not_nil instance_id_tag
77
82
  assert_equal 'satellite-id', instance_id_tag['value']
78
83
 
79
- org_id_tag = actual['hosts'].first['tags'].find { |tag| tag['namespace'] == 'satellite' && tag['key'] == 'organization_id'}
84
+ org_id_tag = actual['hosts'].first['tags'].find { |tag| tag['namespace'] == 'satellite' && tag['key'] == 'organization_id' }
80
85
  assert_not_nil org_id_tag
81
- assert_equal @host.organization_id, org_id_tag['value']
86
+ assert_equal @host.organization_id.to_s, org_id_tag['value']
82
87
 
83
88
  version = satellite_facts['satellite_version']
84
89
  if defined?(ForemanThemeSatellite)
@@ -158,6 +163,7 @@ class ReportGeneratorTest < ActiveSupport::TestCase
158
163
  assert_equal @host.name, actual_host['display_name']
159
164
  assert_equal @host.fqdn, actual_host['fqdn']
160
165
  assert_equal '1234', actual_host['account']
166
+ assert_equal 1, generator.hosts_count
161
167
  end
162
168
 
163
169
  test 'shows system_memory_bytes in bytes' do
@@ -174,4 +180,41 @@ class ReportGeneratorTest < ActiveSupport::TestCase
174
180
  assert_not_nil(actual_profile = actual_host['system_profile'])
175
181
  assert_equal 1024, actual_profile['system_memory_bytes']
176
182
  end
183
+
184
+ test 'reports an account for hosts with multiple pools' do
185
+ first_pool = @host.subscription_facet.pools.first
186
+ second_pool = FactoryBot.create(:katello_pool, account_number: nil, cp_id: 2)
187
+ @host.subscription_facet.pools = []
188
+ @host.subscription_facet.save!
189
+ @host.subscription_facet.pools << first_pool
190
+ @host.subscription_facet.pools << second_pool
191
+
192
+ batch = Host.where(id: @host.id).in_batches.first
193
+ generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice_123')
194
+
195
+ json_str = generator.render
196
+ actual = JSON.parse(json_str.join("\n"))
197
+
198
+ assert_equal 'slice_123', actual['report_slice_id']
199
+ assert_not_nil(actual_host = actual['hosts'].first)
200
+ assert_not_nil(actual_host['account'])
201
+ assert_not_empty(actual_host['account'])
202
+ end
203
+
204
+ test 'Generates os_release with version and id' do
205
+ FactoryBot.create(:fact_value, fact_name: fact_names['distribution::name'], value: 'Red Hat Test Linux', host: @host)
206
+ FactoryBot.create(:fact_value, fact_name: fact_names['distribution::version'], value: '7.1', host: @host)
207
+ FactoryBot.create(:fact_value, fact_name: fact_names['distribution::id'], value: 'TestId', host: @host)
208
+
209
+ batch = Host.where(id: @host.id).in_batches.first
210
+ generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice_123')
211
+
212
+ json_str = generator.render
213
+ actual = JSON.parse(json_str.join("\n"))
214
+
215
+ assert_equal 'slice_123', actual['report_slice_id']
216
+ assert_not_nil(actual_host = actual['hosts'].first)
217
+ assert_not_nil(actual_profile = actual_host['system_profile'])
218
+ assert_equal 'Red Hat Test Linux 7.1 (TestId)', actual_profile['os_release']
219
+ end
177
220
  end
@@ -28,6 +28,8 @@ export const accountID = 'user@redhat.com';
28
28
 
29
29
  export const processStatusName = 'upload_report_status';
30
30
 
31
+ export const autoUploadEnabled = true;
32
+
31
33
  export const props = {
32
34
  accounts,
33
35
  fetchAccountsStatus: noop,
@@ -1,18 +1,9 @@
1
1
  import React from 'react';
2
- import { storiesOf } from '@storybook/react';
3
- import { withKnobs } from '@storybook/addon-knobs';
4
- import { Provider } from 'react-redux';
5
- import configureStore from '../../../stories/configureStore';
6
2
  import AccountList from './AccountList';
7
3
 
8
- const store = configureStore();
4
+ export default {
5
+ title: 'AccountList',
6
+ component: AccountList,
7
+ };
9
8
 
10
- storiesOf('Account list', module)
11
- .addDecorator(withKnobs)
12
- .add('Account list', () => (
13
- <div style={{ margin: '20px' }}>
14
- <Provider store={store}>
15
- <AccountList />
16
- </Provider>
17
- </div>
18
- ));
9
+ export const Basic = () => <AccountList />;
@@ -10,12 +10,13 @@ import {
10
10
  export const fetchAccountsStatus = () => async dispatch => {
11
11
  try {
12
12
  const {
13
- data: { accounts },
13
+ data: { accounts, autoUploadEnabled },
14
14
  } = await API.get('accounts');
15
15
  dispatch({
16
16
  type: INVENTORY_ACCOUNT_STATUS_POLLING,
17
17
  payload: {
18
18
  accounts,
19
+ autoUploadEnabled,
19
20
  },
20
21
  });
21
22
  } catch (error) {
@@ -5,6 +5,7 @@ import {
5
5
  INVENTORY_ACCOUNT_STATUS_POLLING_START,
6
6
  INVENTORY_PROCESS_RESTART,
7
7
  } from './AccountListConstants';
8
+ import { AUTO_UPLOAD_TOGGLE } from '../AutoUploadSwitcher/AutoUploadSwitcherConstants';
8
9
 
9
10
  const initialState = Immutable({
10
11
  accounts: {},
@@ -20,6 +21,7 @@ export default (state = initialState, action) => {
20
21
  accounts,
21
22
  accountID,
22
23
  processStatusName,
24
+ autoUploadEnabled,
23
25
  } = {},
24
26
  } = action;
25
27
 
@@ -28,6 +30,7 @@ export default (state = initialState, action) => {
28
30
  return state.merge({
29
31
  ...state,
30
32
  accounts,
33
+ autoUploadEnabled,
31
34
  error: null,
32
35
  });
33
36
  case INVENTORY_ACCOUNT_STATUS_POLLING_ERROR:
@@ -49,6 +52,11 @@ export default (state = initialState, action) => {
49
52
  [processStatusName]: 'Restarting...',
50
53
  },
51
54
  });
55
+ case AUTO_UPLOAD_TOGGLE:
56
+ return state.merge({
57
+ ...state,
58
+ autoUploadEnabled,
59
+ });
52
60
  default:
53
61
  return state;
54
62
  }
@@ -6,3 +6,5 @@ export const selectAccounts = state => selectAccountsList(state).accounts;
6
6
  export const selectPollingProcessID = state =>
7
7
  selectAccountsList(state).pollingProcessID;
8
8
  export const selectError = state => selectAccountsList(state).error;
9
+ export const selectAutoUploadEnabled = state =>
10
+ selectAccountsList(state).autoUploadEnabled;
@@ -1,4 +1,4 @@
1
- import { testComponentSnapshotsWithFixtures } from 'react-redux-test-utils';
1
+ import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
2
 
3
3
  import EmptyState from '../EmptyState';
4
4
 
@@ -1,4 +1,4 @@
1
- import { testComponentSnapshotsWithFixtures } from 'react-redux-test-utils';
1
+ import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
2
 
3
3
  import ErrorState from '../ErrorState';
4
4
 
@@ -1,4 +1,4 @@
1
- import { testComponentSnapshotsWithFixtures } from 'react-redux-test-utils';
1
+ import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
2
 
3
3
  import ListItem from '../ListItem';
4
4
  import { props } from '../ListItem.fixtures';
@@ -1,4 +1,4 @@
1
- import { testComponentSnapshotsWithFixtures } from 'react-redux-test-utils';
1
+ import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
2
 
3
3
  import ListItemStatus from '../ListItemStatus';
4
4
  import { props } from '../ListItemStatus.fixtures';
@@ -1,4 +1,4 @@
1
- import { testComponentSnapshotsWithFixtures } from 'react-redux-test-utils';
1
+ import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
2
 
3
3
  import AccountList from '../AccountList';
4
4
  import { props } from '../AccountList.fixtures';
@@ -1,4 +1,4 @@
1
- import { testActionSnapshotWithFixtures } from 'react-redux-test-utils';
1
+ import { testActionSnapshotWithFixtures } from '@theforeman/test';
2
2
  import {
3
3
  fetchAccountsStatus,
4
4
  startAccountStatusPolling,
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { IntegrationTestHelper } from 'react-redux-test-utils';
2
+ import { IntegrationTestHelper } from '@theforeman/test';
3
3
 
4
4
  import AccountList from '../index';
5
5
  import reducers from '../../../ForemanInventoryUploadReducers';
@@ -1,4 +1,4 @@
1
- import { testReducerSnapshotWithFixtures } from 'react-redux-test-utils';
1
+ import { testReducerSnapshotWithFixtures } from '@theforeman/test';
2
2
 
3
3
  import {
4
4
  INVENTORY_ACCOUNT_STATUS_POLLING,
@@ -14,7 +14,9 @@ import {
14
14
  pollingProcessID,
15
15
  accountID,
16
16
  processStatusName,
17
+ autoUploadEnabled,
17
18
  } from '../AccountList.fixtures';
19
+ import { AUTO_UPLOAD_TOGGLE } from '../../AutoUploadSwitcher/AutoUploadSwitcherConstants';
18
20
 
19
21
  const fixtures = {
20
22
  'should return the initial state': {},
@@ -23,6 +25,7 @@ const fixtures = {
23
25
  type: INVENTORY_ACCOUNT_STATUS_POLLING,
24
26
  payload: {
25
27
  accounts,
28
+ autoUploadEnabled,
26
29
  },
27
30
  },
28
31
  },
@@ -54,6 +57,14 @@ const fixtures = {
54
57
  },
55
58
  },
56
59
  },
60
+ 'should handle AUTO_UPLOAD_TOGGLE': {
61
+ action: {
62
+ type: AUTO_UPLOAD_TOGGLE,
63
+ payload: {
64
+ autoUploadEnabled,
65
+ },
66
+ },
67
+ },
57
68
  };
58
69
 
59
70
  describe('AccountList reducer', () =>
@@ -1,16 +1,22 @@
1
- import { testSelectorsSnapshotWithFixtures } from 'react-redux-test-utils';
1
+ import { testSelectorsSnapshotWithFixtures } from '@theforeman/test';
2
2
  import {
3
3
  selectAccountsList,
4
4
  selectAccounts,
5
5
  selectPollingProcessID,
6
+ selectAutoUploadEnabled,
6
7
  } from '../AccountListSelectors';
7
- import { pollingProcessID, accounts } from '../AccountList.fixtures';
8
+ import {
9
+ pollingProcessID,
10
+ accounts,
11
+ autoUploadEnabled,
12
+ } from '../AccountList.fixtures';
8
13
 
9
14
  const state = {
10
15
  ForemanInventoryUpload: {
11
16
  accountsList: {
12
17
  accounts,
13
18
  pollingProcessID,
19
+ autoUploadEnabled,
14
20
  },
15
21
  },
16
22
  };
@@ -20,6 +26,8 @@ const fixtures = {
20
26
  'should return AccountList accounts': () => selectAccounts(state),
21
27
  'should return AccountList pollingProcessID': () =>
22
28
  selectPollingProcessID(state),
29
+ 'should return AccountList autoUploadEnabled': () =>
30
+ selectAutoUploadEnabled(state),
23
31
  };
24
32
 
25
33
  describe('AccountList selectors', () =>
@@ -1,5 +1,14 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
+ exports[`AccountList reducer should handle AUTO_UPLOAD_TOGGLE 1`] = `
4
+ Object {
5
+ "accounts": Object {},
6
+ "autoUploadEnabled": true,
7
+ "error": null,
8
+ "pollingProcessID": 0,
9
+ }
10
+ `;
11
+
3
12
  exports[`AccountList reducer should handle INVENTORY_ACCOUNT_STATUS_POLLING 1`] = `
4
13
  Object {
5
14
  "accounts": Object {
@@ -19,6 +28,7 @@ Object {
19
28
  "upload_report_status": "success",
20
29
  },
21
30
  },
31
+ "autoUploadEnabled": true,
22
32
  "error": null,
23
33
  "pollingProcessID": 0,
24
34
  }
@@ -1,7 +1,5 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`AccountList selectors should return AccountList pollingProcessID 1`] = `0`;
4
-
5
3
  exports[`AccountList selectors should return AccountList accounts 1`] = `
6
4
  Object {
7
5
  "Account1": Object {
@@ -22,6 +20,10 @@ Object {
22
20
  }
23
21
  `;
24
22
 
23
+ exports[`AccountList selectors should return AccountList autoUploadEnabled 1`] = `true`;
24
+
25
+ exports[`AccountList selectors should return AccountList pollingProcessID 1`] = `0`;
26
+
25
27
  exports[`AccountList selectors should return AccountsList 1`] = `
26
28
  Object {
27
29
  "accounts": Object {
@@ -41,6 +43,7 @@ Object {
41
43
  "upload_report_status": "success",
42
44
  },
43
45
  },
46
+ "autoUploadEnabled": true,
44
47
  "pollingProcessID": 0,
45
48
  }
46
49
  `;
@@ -0,0 +1 @@
1
+ export const handleToggleResponse = { data: { autoUploadEnabled: true } };
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { Switch, FieldLevelHelp } from 'patternfly-react';
4
+ import { translate as __ } from 'foremanReact/common/I18n';
5
+ import './autoUploadSwitcher.scss';
6
+
7
+ const AutoUploadSwitcher = ({ autoUploadEnabled, handleToggle }) => (
8
+ <div className="auto_upload_switcher">
9
+ <Switch
10
+ size="mini"
11
+ value={autoUploadEnabled}
12
+ onChange={() => handleToggle(autoUploadEnabled)}
13
+ />
14
+ <FieldLevelHelp
15
+ content={__(
16
+ 'Enable automatic upload of your host inventory to the Red Hat cloud'
17
+ )}
18
+ />
19
+ <span>Allow Auto Upload</span>
20
+ </div>
21
+ );
22
+
23
+ AutoUploadSwitcher.propTypes = {
24
+ autoUploadEnabled: PropTypes.bool,
25
+ handleToggle: PropTypes.func.isRequired,
26
+ };
27
+
28
+ AutoUploadSwitcher.defaultProps = {
29
+ autoUploadEnabled: true,
30
+ };
31
+
32
+ export default AutoUploadSwitcher;