Skip to content

Commit

Permalink
Read SUSE Manager Enabled flag from config in HostDetailsPage (#2477
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jamie-suse authored Mar 26, 2024
1 parent f23ce55 commit 8469773
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 6 deletions.
4 changes: 2 additions & 2 deletions assets/js/pages/HostDetailsPage/HostDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import classNames from 'classnames';
import { EOS_CLEAR_ALL, EOS_PLAY_CIRCLE, EOS_SETTINGS } from 'eos-icons-react';

import { agentVersionWarning } from '@lib/agent';
import { getFromConfig } from '@lib/config';

import BackButton from '@common/BackButton';
import Button from '@common/Button';
Expand Down Expand Up @@ -64,6 +63,7 @@ function HostDetails({
slesSubscriptions,
catalog,
lastExecution,
suseManagerEnabled,
relevantPatches,
upgradablePackages,
softwareUpdatesLoading,
Expand Down Expand Up @@ -223,7 +223,7 @@ function HostDetails({
</div>
</div>

{getFromConfig('suseManagerEnabled') && (
{suseManagerEnabled && (
<AvailableSoftwareUpdates
className="mx-0 my-4"
relevantPatches={relevantPatches}
Expand Down
32 changes: 32 additions & 0 deletions assets/js/pages/HostDetailsPage/HostDetails.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ export const Default = {
completed_at: faker.date.past().toISOString(),
},
},
suseManagerEnabled: false,
relevantPatches: 0,
upgradablePackages: 0,
softwareUpdatesLoading: false,
softwareUpdatesTooltip: undefined,
selectedChecks: [],
slesSubscriptions: host.sles_subscriptions,
},
Expand Down Expand Up @@ -249,3 +254,30 @@ export const HostSummaryWithTooltip = {
ipAddresses: Array.from({ length: 10 }, () => faker.internet.ipv4()),
},
};

export const WithSuseManager = {
args: {
...Default.args,
suseManagerEnabled: true,
relevantPatches: 123,
upgradablePackages: 456,
},
};

export const SuseManagerLoading = {
args: {
...Default.args,
suseManagerEnabled: true,
softwareUpdatesLoading: true,
},
};

export const SuseManagerUnknown = {
args: {
...Default.args,
suseManagerEnabled: true,
relevantPatches: undefined,
upgradablePackages: undefined,
softwareUpdatesTooltip: 'SUSE Manager is not available',
},
};
29 changes: 28 additions & 1 deletion assets/js/pages/HostDetailsPage/HostDetails.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,15 @@ describe('HostDetails component', () => {
});
});

describe('SUMA', () => {
describe('SUSE Manager', () => {
it('should show the summary of SUMA software updates', () => {
const relevantPatches = faker.number.int(100);
const upgradablePackages = faker.number.int(100);

renderWithRouter(
<HostDetails
agentVersion="2.0.0"
suseManagerEnabled
relevantPatches={relevantPatches}
upgradablePackages={upgradablePackages}
/>
Expand Down Expand Up @@ -211,6 +212,7 @@ describe('HostDetails component', () => {
renderWithRouter(
<HostDetails
agentVersion="2.0.0"
suseManagerEnabled
relevantPatches={relevantPatches}
upgradablePackages={upgradablePackages}
/>
Expand All @@ -226,6 +228,31 @@ describe('HostDetails component', () => {
expect(relevantPatchesElement).toHaveTextContent('Unknown');
expect(upgradablePackagesElement).toHaveTextContent('Unknown');
});

it('should show the summary of SUMA software updates in a loading state', () => {
const relevantPatches = faker.number.int(100);
const upgradablePackages = faker.number.int(100);

renderWithRouter(
<HostDetails
agentVersion="2.0.0"
suseManagerEnabled
softwareUpdatesLoading
relevantPatches={relevantPatches}
upgradablePackages={upgradablePackages}
/>
);

const relevantPatchesElement = screen
.getByText(/Relevant Patches/)
.closest('div');
const upgradablePackagesElement = screen
.getByText(/Upgradable Packages/)
.closest('div');

expect(relevantPatchesElement).toHaveTextContent('Loading');
expect(upgradablePackagesElement).toHaveTextContent('Loading');
});
});

describe('last execution overview', () => {
Expand Down
8 changes: 5 additions & 3 deletions assets/js/pages/HostDetailsPage/HostDetailsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useParams, useNavigate } from 'react-router-dom';
import { useSelector, useDispatch } from 'react-redux';
import { get } from 'lodash';

import { getFromConfig } from '@lib/config';
import { networkClient } from '@lib/network';

import { TARGET_HOST } from '@lib/model';
Expand All @@ -28,8 +29,8 @@ import { deregisterHost } from '@state/hosts';
import { fetchSoftwareUpdates } from '@state/softwareUpdates';
import HostDetails from './HostDetails';

// eslint-disable-next-line no-undef
const { chartsEnabled } = config;
const chartsEnabled = getFromConfig('chartsEnabled');
const suseManagerEnabled = getFromConfig('suseManagerEnabled');

function HostDetailsPage() {
const { hostID } = useParams();
Expand Down Expand Up @@ -105,6 +106,8 @@ function HostDetailsPage() {
selectedChecks={hostSelectedChecks}
slesSubscriptions={host.sles_subscriptions}
catalog={catalog}
lastExecution={lastExecution}
suseManagerEnabled={suseManagerEnabled}
relevantPatches={numRelevantPatches}
upgradablePackages={numUpgradablePackages}
softwareUpdatesLoading={softwareUpdatesLoading}
Expand All @@ -113,7 +116,6 @@ function HostDetailsPage() {
? 'SUSE Manager is not available'
: undefined
}
lastExecution={lastExecution}
cleanUpHost={() => {
dispatch(
deregisterHost({ id: hostID, hostname: host.hostname, navigate })
Expand Down

0 comments on commit 8469773

Please sign in to comment.