foreman_kernel_care 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +619 -0
  3. data/README.md +37 -0
  4. data/Rakefile +47 -0
  5. data/app/helpers/concerns/foreman_kernel_care/hosts_helper_extensions.rb +13 -0
  6. data/app/models/concerns/foreman_kernel_care/host_extensions.rb +19 -0
  7. data/app/models/concerns/foreman_kernel_care/host_managed_extensions.rb +23 -0
  8. data/app/views/dashboard/_foreman_kernel_care_widget.html.erb +2 -0
  9. data/app/views/foreman_kernel_care/layouts/layouts/new_layout.html.erb +0 -0
  10. data/app/views/foreman_kernel_care/layouts/new_layout.html.erb +0 -0
  11. data/config/routes.rb +9 -0
  12. data/lib/foreman_kernel_care/engine.rb +57 -0
  13. data/lib/foreman_kernel_care/version.rb +3 -0
  14. data/lib/foreman_kernel_care.rb +4 -0
  15. data/lib/tasks/foreman_kernel_care_tasks.rake +48 -0
  16. data/locale/Makefile +60 -0
  17. data/locale/en/foreman_kernel_care.po +19 -0
  18. data/locale/foreman_kernel_care.pot +19 -0
  19. data/locale/gemspec.rb +2 -0
  20. data/package.json +44 -0
  21. data/test/factories/foreman_kernel_care_factories.rb +5 -0
  22. data/test/test_plugin_helper.rb +6 -0
  23. data/test/unit/foreman_kernel_care_test.rb +11 -0
  24. data/webpack/global_index.js +17 -0
  25. data/webpack/global_test_setup.js +11 -0
  26. data/webpack/index.js +8 -0
  27. data/webpack/src/Components/EmptyState/Constants.js +2 -0
  28. data/webpack/src/Components/EmptyState/EmptyStateReducer.js +19 -0
  29. data/webpack/src/Components/EmptyState/ExtendedEmptyState.js +43 -0
  30. data/webpack/src/Components/EmptyState/__tests__/ExtendedEmptyState.test.js +37 -0
  31. data/webpack/src/Extends/index.js +15 -0
  32. data/webpack/src/Router/WelcomePage/Welcome.js +9 -0
  33. data/webpack/src/Router/WelcomePage/index.js +1 -0
  34. data/webpack/src/Router/routes.js +12 -0
  35. data/webpack/src/reducers.js +10 -0
  36. data/webpack/test_setup.js +17 -0
  37. metadata +110 -0
data/Rakefile ADDED
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'ForemanKernelCare'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+ task default: :test
37
+
38
+ begin
39
+ require 'rubocop/rake_task'
40
+ RuboCop::RakeTask.new
41
+ rescue => _
42
+ puts 'Rubocop not loaded.'
43
+ end
44
+
45
+ task :default do
46
+ Rake::Task['rubocop'].execute
47
+ end
@@ -0,0 +1,13 @@
1
+ module ForemanKernelCare
2
+ module HostsHelperExtensions
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ # execute callbacks
7
+ end
8
+
9
+ # create or overwrite instance methods...
10
+ def instance_method_name
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ module ForemanKernelCare
2
+ module HostExtensions
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ # execute callbacks
7
+ end
8
+
9
+ # create or overwrite instance methods...
10
+ def instance_method_name
11
+ end
12
+
13
+ module ClassMethods
14
+ # create or overwrite class methods...
15
+ def class_method_name
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ module ForemanKernelCare
2
+ module HostManagedExtensions
3
+ def import_tracer_profile(tracer_profile)
4
+ traces = []
5
+ tracer_profile.each do |trace, attributes|
6
+ next if attributes[:helper].blank?
7
+
8
+ next if trace == 'kernel' && kernelcare?
9
+
10
+ traces << { host_id: self.id, application: trace, helper: attributes[:helper], app_type: attributes[:type] }
11
+ end
12
+ host_traces.delete_all
13
+ Katello::HostTracer.import(traces, validate: false)
14
+ update_trace_status
15
+ end
16
+
17
+ protected
18
+
19
+ def kernelcare?
20
+ !installed_packages.select { |package| package.name == 'kernelcare' }.empty?
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,2 @@
1
+ <h4 class="header ca"><%= _('ForemanKernelCare') %></h4>
2
+ <%= _('Widget content') %>
data/config/routes.rb ADDED
@@ -0,0 +1,9 @@
1
+ ForemanKernelCare::Engine.routes.draw do
2
+ get 'new_action', to: 'example#new_action', as: 'new_action'
3
+ get 'plugin_template_description', to: 'example#react_template_page_description'
4
+ get 'welcome', to: '/react#index', as: 'welcome'
5
+ end
6
+
7
+ Foreman::Application.routes.draw do
8
+ mount ForemanKernelCare::Engine, at: '/foreman_kernel_care'
9
+ end
@@ -0,0 +1,57 @@
1
+ module ForemanKernelCare
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace ForemanKernelCare
4
+ engine_name 'foreman_kernel_care'
5
+
6
+ config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
7
+ config.autoload_paths += Dir["#{config.root}/app/helpers/concerns"]
8
+ config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
9
+ config.autoload_paths += Dir["#{config.root}/app/overrides"]
10
+
11
+ # Add any db migrations
12
+ initializer 'foreman_kernel_care.load_app_instance_data' do |app|
13
+ ForemanKernelCare::Engine.paths['db/migrate'].existent.each do |path|
14
+ app.config.paths['db/migrate'] << path
15
+ end
16
+ end
17
+
18
+ initializer 'foreman_kernel_care.register_plugin', :before => :finisher_hook do |_app|
19
+ Foreman::Plugin.register :foreman_kernel_care do
20
+ requires_foreman '>= 2.4.0'
21
+
22
+ # Add Global files for extending foreman-core components and routes
23
+ register_global_js_file 'global'
24
+
25
+ # Add a new role called 'Discovery' if it doesn't exist
26
+ role 'ForemanKernelCare', [:view_foreman_kernel_care]
27
+
28
+ # add dashboard widget
29
+ widget 'foreman_kernel_care_widget', name: N_('KernelCare widget'), sizex: 4, sizey: 1
30
+ end
31
+ end
32
+
33
+ # Include concerns in this config.to_prepare block
34
+ config.to_prepare do
35
+
36
+ begin
37
+ Host::Managed.send(:include, ForemanKernelCare::HostExtensions)
38
+ HostsHelper.send(:include, ForemanKernelCare::HostsHelperExtensions)
39
+ Katello::Concerns::HostManagedExtensions.send(:prepend, ForemanKernelCare::HostManagedExtensions)
40
+ rescue => e
41
+ Rails.logger.warn "ForemanKernelCare: skipping engine hook (#{e})"
42
+ end
43
+ end
44
+
45
+ rake_tasks do
46
+ Rake::Task['db:seed'].enhance do
47
+ ForemanKernelCare::Engine.load_seed
48
+ end
49
+ end
50
+
51
+ initializer 'foreman_kernel_care.register_gettext', after: :load_config_initializers do |_app|
52
+ locale_dir = File.join(File.expand_path('../../..', __FILE__), 'locale')
53
+ locale_domain = 'foreman_kernel_care'
54
+ Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ module ForemanKernelCare
2
+ VERSION = '0.0.1'.freeze
3
+ end
@@ -0,0 +1,4 @@
1
+ require 'foreman_kernel_care/engine'
2
+
3
+ module ForemanKernelCare
4
+ end
@@ -0,0 +1,48 @@
1
+ require 'rake/testtask'
2
+
3
+ # Tasks
4
+ namespace :foreman_kernel_care do
5
+ namespace :example do
6
+ desc 'Example Task'
7
+ task task: :environment do
8
+ # Task goes here
9
+ end
10
+ end
11
+ end
12
+
13
+ # Tests
14
+ namespace :test do
15
+ desc 'Test ForemanKernelCare'
16
+ Rake::TestTask.new(:foreman_kernel_care) do |t|
17
+ test_dir = File.expand_path('../../test', __dir__)
18
+ t.libs << 'test'
19
+ t.libs << test_dir
20
+ t.pattern = "#{test_dir}/**/*_test.rb"
21
+ t.verbose = true
22
+ t.warning = false
23
+ end
24
+ end
25
+
26
+ namespace :foreman_kernel_care do
27
+ task :rubocop do
28
+ begin
29
+ require 'rubocop/rake_task'
30
+ RuboCop::RakeTask.new(:rubocop_foreman_kernel_care) do |task|
31
+ task.patterns = ["#{ForemanKernelCare::Engine.root}/app/**/*.rb",
32
+ "#{ForemanKernelCare::Engine.root}/lib/**/*.rb",
33
+ "#{ForemanKernelCare::Engine.root}/test/**/*.rb"]
34
+ end
35
+ rescue
36
+ puts 'Rubocop not loaded.'
37
+ end
38
+
39
+ Rake::Task['rubocop_foreman_kernel_care'].invoke
40
+ end
41
+ end
42
+
43
+ Rake::Task[:test].enhance ['test:foreman_kernel_care']
44
+
45
+ load 'tasks/jenkins.rake'
46
+ if Rake::Task.task_defined?(:'jenkins:unit')
47
+ Rake::Task['jenkins:unit'].enhance ['test:foreman_kernel_care', 'foreman_kernel_care:rubocop']
48
+ end
data/locale/Makefile ADDED
@@ -0,0 +1,60 @@
1
+ #
2
+ # Makefile for PO merging and MO generation. More info in the README.
3
+ #
4
+ # make all-mo (default) - generate MO files
5
+ # make check - check translations using translate-tool
6
+ # make tx-update - download and merge translations from Transifex
7
+ # make clean - clean everything
8
+ #
9
+ DOMAIN = foreman_kernel_care
10
+ VERSION = $(shell ruby -e 'require "rubygems";spec = Gem::Specification::load(Dir.glob("../*.gemspec")[0]);puts spec.version')
11
+ POTFILE = $(DOMAIN).pot
12
+ MOFILE = $(DOMAIN).mo
13
+ POFILES = $(shell find . -name '$(DOMAIN).po')
14
+ MOFILES = $(patsubst %.po,%.mo,$(POFILES))
15
+ POXFILES = $(patsubst %.po,%.pox,$(POFILES))
16
+ EDITFILES = $(patsubst %.po,%.edit.po,$(POFILES))
17
+
18
+ %.mo: %.po
19
+ mkdir -p $(shell dirname $@)/LC_MESSAGES
20
+ msgfmt -o $(shell dirname $@)/LC_MESSAGES/$(MOFILE) $<
21
+
22
+ # Generate MO files from PO files
23
+ all-mo: $(MOFILES)
24
+
25
+ # Check for malformed strings
26
+ %.pox: %.po
27
+ msgfmt -c $<
28
+ pofilter --nofuzzy -t variables -t blank -t urls -t emails -t long -t newlines \
29
+ -t endwhitespace -t endpunc -t puncspacing -t options -t printf -t validchars --gnome $< > $@
30
+ cat $@
31
+ ! grep -q msgid $@
32
+
33
+ %.edit.po:
34
+ touch $@
35
+
36
+ check: $(POXFILES)
37
+
38
+ # Unify duplicate translations
39
+ uniq-po:
40
+ for f in $(shell find ./ -name "*.po") ; do \
41
+ msguniq $$f -o $$f ; \
42
+ done
43
+
44
+ tx-pull: $(EDITFILES)
45
+ tx pull -f
46
+ for f in $(EDITFILES) ; do \
47
+ sed -i 's/^\("Project-Id-Version: \).*$$/\1$(DOMAIN) $(VERSION)\\n"/' $$f; \
48
+ done
49
+
50
+ tx-update: tx-pull
51
+ @echo
52
+ @echo Run rake plugin:gettext[$(DOMAIN)] from the Foreman installation, then make -C locale mo-files to finish
53
+ @echo
54
+
55
+ mo-files: $(MOFILES)
56
+ git add $(POFILES) $(POTFILE) ../locale/*/LC_MESSAGES
57
+ git commit -m "i18n - pulling from tx"
58
+ @echo
59
+ @echo Changes commited!
60
+ @echo
@@ -0,0 +1,19 @@
1
+ # foreman_kernel_care
2
+ #
3
+ # This file is distributed under the same license as foreman_kernel_care.
4
+ #
5
+ #, fuzzy
6
+ msgid ""
7
+ msgstr ""
8
+ "Project-Id-Version: version 0.0.1\n"
9
+ "Report-Msgid-Bugs-To: \n"
10
+ "POT-Creation-Date: 2014-08-20 08:46+0100\n"
11
+ "PO-Revision-Date: 2014-08-20 08:54+0100\n"
12
+ "Last-Translator: Foreman Team <foreman-dev@googlegroups.com>\n"
13
+ "Language-Team: Foreman Team <foreman-dev@googlegroups.com>\n"
14
+ "Language: \n"
15
+ "MIME-Version: 1.0\n"
16
+ "Content-Type: text/plain; charset=UTF-8\n"
17
+ "Content-Transfer-Encoding: 8bit\n"
18
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
19
+
@@ -0,0 +1,19 @@
1
+ # foreman_kernel_care
2
+ #
3
+ # This file is distributed under the same license as foreman_kernel_care.
4
+ #
5
+ #, fuzzy
6
+ msgid ""
7
+ msgstr ""
8
+ "Project-Id-Version: version 0.0.1\n"
9
+ "Report-Msgid-Bugs-To: \n"
10
+ "POT-Creation-Date: 2014-08-20 08:46+0100\n"
11
+ "PO-Revision-Date: 2014-08-20 08:46+0100\n"
12
+ "Last-Translator: Foreman Team <foreman-dev@googlegroups.com>\n"
13
+ "Language-Team: Foreman Team <foreman-dev@googlegroups.com>\n"
14
+ "Language: \n"
15
+ "MIME-Version: 1.0\n"
16
+ "Content-Type: text/plain; charset=UTF-8\n"
17
+ "Content-Transfer-Encoding: 8bit\n"
18
+ "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
19
+
data/locale/gemspec.rb ADDED
@@ -0,0 +1,2 @@
1
+ # Matches foreman_kernel_care.gemspec
2
+ _('TODO: Description of ForemanKernelCare.')
data/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "foreman_kernel_care",
3
+ "version": "1.0.0",
4
+ "description": "DESCRIPTION",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "lint": "tfm-lint --plugin -d /webpack",
8
+ "test": "tfm-test --config jest.config.js",
9
+ "test:watch": "tfm-test --plugin --watchAll",
10
+ "test:current": "tfm-test --plugin --watch",
11
+ "publish-coverage": "tfm-publish-coverage",
12
+ "stories": "tfm-stories --plugin",
13
+ "stories:build": "tfm-build-stories --plugin",
14
+ "create-react-component": "yo react-domain"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/theforeman/foreman_kernel_care.git"
19
+ },
20
+ "bugs": {
21
+ "url": "http://projects.theforeman.org/projects/foreman_kernel_care/issues"
22
+ },
23
+ "peerDependencies": {
24
+ "@theforeman/vendor": ">= 6.0.0"
25
+ },
26
+ "dependencies": {
27
+ "react-intl": "^2.8.0"
28
+ },
29
+ "devDependencies": {
30
+ "@babel/core": "^7.7.0",
31
+ "@sheerun/mutationobserver-shim": "^0.3.3",
32
+ "@theforeman/builder": "^6.0.0",
33
+ "@theforeman/eslint-plugin-foreman": "6.0.0",
34
+ "@theforeman/find-foreman": "^4.8.0",
35
+ "@theforeman/stories": "^7.0.0",
36
+ "@theforeman/test": "^8.0.0",
37
+ "@theforeman/vendor-dev": "^6.0.0",
38
+ "babel-eslint": "^10.0.3",
39
+ "eslint": "^6.7.2",
40
+ "prettier": "^1.19.1",
41
+ "stylelint-config-standard": "^18.0.0",
42
+ "stylelint": "^9.3.0"
43
+ }
44
+ }
@@ -0,0 +1,5 @@
1
+ FactoryBot.define do
2
+ factory :host do
3
+ name 'foreman_kernel_care'
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ # This calls the main test_helper in Foreman-core
2
+ require 'test_helper'
3
+
4
+ # Add plugin to FactoryBot's paths
5
+ FactoryBot.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
6
+ FactoryBot.reload
@@ -0,0 +1,11 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class ForemanPluginTemplateTest < ActiveSupport::TestCase
4
+ setup do
5
+ User.current = User.find_by_login 'admin'
6
+ end
7
+
8
+ test 'the truth' do
9
+ assert true
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ import { registerReducer } from 'foremanReact/common/MountingService';
2
+ import { addGlobalFill } from 'foremanReact/components/common/Fill/GlobalFill';
3
+ import { registerRoutes } from 'foremanReact/routes/RoutingService';
4
+ import Routes from './src/Router/routes'
5
+ import reducers from './src/reducers';
6
+
7
+ // register reducers
8
+ Object.entries(reducers).forEach(([key, reducer]) =>
9
+ registerReducer(key, reducer)
10
+ );
11
+
12
+ // register client routes
13
+ registerRoutes('PluginTemplate', Routes);
14
+
15
+ // register fills for extending foreman core
16
+ // http://foreman.surge.sh/?path=/docs/introduction-slot-and-fill--page
17
+ addGlobalFill('<slotId>', '<fillId>', <div key='plugin-template-example' />, 300);
@@ -0,0 +1,11 @@
1
+ // runs before each test to make sure console.error output will
2
+ // fail a test (i.e. default PropType missing). Check the error
3
+ // output and traceback for actual error.
4
+ global.console.error = (error, stack) => {
5
+ /* eslint-disable-next-line no-console */
6
+ if (stack) console.log(stack); // Prints out original stack trace
7
+ throw new Error(error);
8
+ };
9
+
10
+ // Increase jest timeout as some tests using multiple http mocks can time out on CI systems.
11
+ jest.setTimeout(10000);
data/webpack/index.js ADDED
@@ -0,0 +1,8 @@
1
+ import componentRegistry from 'foremanReact/components/componentRegistry';
2
+ import ExtendedEmptyState from './src/Components/EmptyState/ExtendedEmptyState';
3
+
4
+ // register components for erb mounting
5
+ componentRegistry.register({
6
+ name: 'ExtendedEmptyState',
7
+ type: ExtendedEmptyState,
8
+ });
@@ -0,0 +1,2 @@
1
+ export const GENERAL_ACTION_TYPE = '[PLUGIN_TEMPLATE] GENERAL ACTION';
2
+ export const FOREMAN_STORYBOOK = 'https://foreman.surge.sh';
@@ -0,0 +1,19 @@
1
+ // This is an example for a generic redux's reducer
2
+ // Reducers should be registered to foreman-core
3
+ // For a further registration demonstration, have a look in `webpack/global_index.js`
4
+
5
+ import Immutable from 'seamless-immutable';
6
+ import { GENERAL_ACTION_TYPE } from './Constants';
7
+
8
+ const initialState = Immutable({});
9
+
10
+ export default (state = initialState, action) => {
11
+ const { payload } = action;
12
+
13
+ switch (action.type) {
14
+ case GENERAL_ACTION_TYPE:
15
+ return state.set('generalProprty', payload);
16
+ default:
17
+ return state;
18
+ }
19
+ };
@@ -0,0 +1,43 @@
1
+ import React from 'react';
2
+ import { Button, Alert } from '@patternfly/react-core';
3
+ import EmptyState from 'foremanReact/components/common/EmptyState/EmptyStatePattern';
4
+ import SkeletonLoader from 'foremanReact/components/common/SkeletonLoader';
5
+ import PropTypes from 'prop-types';
6
+
7
+ import { STATUS } from 'foremanReact/constants'
8
+ import { useAPI } from 'foremanReact/common/hooks/API/APIHooks'
9
+ import { translate as __ } from 'foremanReact/common/I18n';
10
+ import { FOREMAN_STORYBOOK } from './Constants';
11
+
12
+ const ExtendedEmptyState = ({ header }) => {
13
+ // AJAX request using useAPI hook
14
+ const { response: { description }, status } = useAPI('get', '/foreman_kernel_care/plugin_template_description')
15
+
16
+
17
+ const storybookBtn = (
18
+ <Button onClick={() => window.open(FOREMAN_STORYBOOK, '_blank')}>
19
+ Storybook
20
+ </Button>
21
+ );
22
+
23
+ switch (status) {
24
+ case STATUS.ERROR:
25
+ return (<Alert variant="danger" title={__("Loading description has failed")} />);
26
+ case STATUS.RESOLVED: return (
27
+ <EmptyState
28
+ icon="add-circle-o"
29
+ action={storybookBtn}
30
+ header={header}
31
+ description={description}
32
+ documentation={false}
33
+ />
34
+ )
35
+ default:
36
+ return (<SkeletonLoader isLoading={status === STATUS.PENDING} count={5} />);
37
+ }
38
+ };
39
+ ExtendedEmptyState.PropTypes = {
40
+ header: PropTypes.string.isRequired
41
+ };
42
+
43
+ export default ExtendedEmptyState;
@@ -0,0 +1,37 @@
1
+ // Tests work with react-testing-library or enzyme
2
+ // This test uses react testing library
3
+ // https://testing-library.com/docs/react-testing-library/api
4
+
5
+ // For more information, test utils, and snapshots testing examples:
6
+ // https://github.com/theforeman/foreman-js/tree/master/packages/test
7
+
8
+
9
+ import React from 'react';
10
+ import { createStore, applyMiddleware, combineReducers } from 'redux';
11
+ import { render, waitFor, screen } from '@testing-library/react'
12
+ import { Provider } from 'react-redux';
13
+
14
+ import { reducers as APIReducer } from 'foremanReact/redux/API';
15
+ import { middlewares } from 'foremanReact/redux/middlewares';
16
+ import APIHelper from 'foremanReact/redux/API/API';
17
+ import ExtendedEmptyState from '../ExtendedEmptyState';
18
+
19
+ jest.mock('foremanReact/redux/API/API');
20
+
21
+ const reducers = combineReducers(APIReducer);
22
+ const store = createStore(reducers, applyMiddleware(...middlewares));
23
+ const wrapper = ({ children }) => (
24
+ <Provider store={store}>{children}</Provider>
25
+ );
26
+ describe('foreman plugin template', () => {
27
+ it('should render an error alert', async () => {
28
+ APIHelper.get.mockRejectedValue({ error: new Error() });
29
+ render(<ExtendedEmptyState />, { wrapper });
30
+ await waitFor(() => expect(screen.getByText('Loading description has failed')).toBeInTheDocument());
31
+ });
32
+ it('should render an empty state with custom description', async () => {
33
+ APIHelper.get.mockResolvedValue({ data: { description: 'some description' } });
34
+ render(<ExtendedEmptyState />, { wrapper });
35
+ await waitFor(() => expect(screen.getByText('some description')).toBeInTheDocument());
36
+ });
37
+ });
@@ -0,0 +1,15 @@
1
+ // This is an example of extending foreman-core's component via slot&fill
2
+ // http://foreman.surge.sh/?path=/docs/introduction-slot-and-fill--page
3
+ /*
4
+ import React from 'react';
5
+ import { addGlobalFill } from 'foremanReact/components/common/Fill/GlobalFill';
6
+
7
+ addGlobalFill('slotId', 'fillId', <SomeComponent key="some-key" />, 300);
8
+
9
+ addGlobalFill(
10
+ 'slotId',
11
+ 'fillId',
12
+ { someProp: 'this is an override prop' },
13
+ 300
14
+ );
15
+ */
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ import ExtendedEmptyState from '../../Components/EmptyState/ExtendedEmptyState';
3
+ import { translate as __ } from 'foremanReact/common/I18n';
4
+
5
+ const WelcomePage = () => (
6
+ <ExtendedEmptyState header={__("Welcome to the plugin template")} />
7
+ );
8
+
9
+ export default WelcomePage;
@@ -0,0 +1 @@
1
+ export { default } from './Welcome';
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import WelcomePage from './WelcomePage';
3
+
4
+ const routes = [
5
+ {
6
+ path: '/foreman_kernel_care/welcome',
7
+ exact: true,
8
+ render: (props) => <WelcomePage {...props} />,
9
+ },
10
+ ];
11
+
12
+ export default routes;
@@ -0,0 +1,10 @@
1
+ import { combineReducers } from 'redux';
2
+ import EmptyStateReducer from './Components/EmptyState/EmptyStateReducer';
3
+
4
+ const reducers = {
5
+ foremanKernelCare: combineReducers({
6
+ emptyState: EmptyStateReducer,
7
+ }),
8
+ };
9
+
10
+ export default reducers;
@@ -0,0 +1,17 @@
1
+ import 'core-js/shim';
2
+ import 'regenerator-runtime/runtime';
3
+ import MutationObserver from '@sheerun/mutationobserver-shim';
4
+
5
+ import { configure } from 'enzyme';
6
+ import Adapter from 'enzyme-adapter-react-16';
7
+
8
+ configure({ adapter: new Adapter() });
9
+
10
+ // Mocking translation function
11
+ global.__ = text => text; // eslint-disable-line
12
+
13
+ // Mocking locales to prevent unnecessary fallback messages
14
+ window.locales = { en: { domain: 'app', locale_data: { app: { '': {} } } } };
15
+
16
+ // see https://github.com/testing-library/dom-testing-library/releases/tag/v7.0.0
17
+ window.MutationObserver = MutationObserver;