Skip to content

Commit

Permalink
Change shape of input data
Browse files Browse the repository at this point in the history
  • Loading branch information
jamie-suse committed May 21, 2024
1 parent 06e5b20 commit e54e0c3
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 107 deletions.
34 changes: 14 additions & 20 deletions assets/js/common/UpgradablePackagesList/UpgradablePackagesList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import React from 'react';
import classNames from 'classnames';
import Table from '@common/Table';

const upgradablePackagesDefault = [];

function UpgradablePackagesList({
hostname,
upgradablePackages,
relevantPatches,
upgradablePackages = upgradablePackagesDefault,
}) {
const config = {
pagination: true,
Expand All @@ -14,7 +15,7 @@ function UpgradablePackagesList({
{
title: 'Installed Packages',
key: 'installedPackage',
render: (content, _) => <div>{content}</div>,
render: (content, _) => <div className="font-bold">{content}</div>,
},
{
title: 'Latest Package',
Expand All @@ -23,33 +24,26 @@ function UpgradablePackagesList({
},
{
title: 'Related Patches',
key: 'advisory_name',
render: (content, _) => <div>{content}</div>,
key: 'patches',
render: (content, { to_package_id }) => (
<div>
{content.map(({ advisory }) => (
<div key={`${to_package_id}-${advisory}`}>{advisory}</div>
))}
</div>
),
},
],
};

const relevantPatchesMap = relevantPatches.reduce(
(m, p) => m.set(p.id, p),
new Map()
);

const data = upgradablePackages.map((up) => {
const {
name,
from_version,
from_release,
to_version,
to_release,
arch,
to_package_id,
} = up;
const { name, from_version, from_release, to_version, to_release, arch } =
up;

return {
...up,
installedPackage: `${name}-${from_version}-${from_release}.${arch}`,
latestPackage: `${name}-${to_version}-${to_release}.${arch}`,
...relevantPatchesMap.get(to_package_id),
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ export default {
title: 'Components/UpgradablePackagesList',
component: UpgradablePackagesList,
argTypes: {
upgradablePackages: {
control: {
type: 'array',
},
hostname: {
type: 'string',
control: { type: 'text' },
description: 'The name of the host',
},
relevantPatches: {
upgradablePackages: {
control: {
type: 'array',
},
description: 'List of upgradable packages',
},
},
};
Expand All @@ -33,6 +34,32 @@ export const Default = {
to_version: '3.1.2',
from_arch: 'x86_64',
to_arch: 'x86_64',
patches: [
{
issue_date: '2023-05-30',
last_modified_date: '2023-05-30',
advisory: 'SUSE-15-SP4-2023-2317',
type: 'bugfix',
synopsis: 'Recommended update for util-linux',
update_date: '2023-05-30',
},
{
issue_date: '2024-03-13',
last_modified_date: '2024-03-13',
advisory: 'SUSE-15-SP4-2024-877',
type: 'security_advisory',
synopsis: 'important: Security update for sudo',
update_date: '2024-03-13',
},
{
issue_date: '2024-03-13',
last_modified_date: '2024-03-13',
advisory: 'SUSE-15-SP4-2024-871',
type: 'security_advisory',
synopsis: 'important: Security update for vim',
update_date: '2024-03-13',
},
],
},
{
from_epoch: ' ',
Expand All @@ -46,6 +73,16 @@ export const Default = {
to_version: '8.4p1',
from_arch: 'x86_64',
to_arch: 'x86_64',
patches: [
{
issue_date: '2024-03-11',
last_modified_date: '2024-03-11',
advisory: 'SUSE-15-SP4-2024-833',
type: 'security_advisory',
synopsis: 'moderate: Security update for openssl-1_1',
update_date: '2024-03-11',
},
],
},
{
from_epoch: ' ',
Expand All @@ -59,6 +96,7 @@ export const Default = {
to_version: '5.15.2+kde294',
from_arch: 'x86_64',
to_arch: 'x86_64',
patches: [],
},
{
from_epoch: ' ',
Expand All @@ -72,6 +110,16 @@ export const Default = {
to_version: '3.6.15',
from_arch: 'x86_64',
to_arch: 'x86_64',
patches: [
{
issue_date: '2023-03-22',
last_modified_date: '2023-03-22',
advisory: 'SUSE-15-SP4-2023-868',
type: 'security_advisory',
synopsis: 'important: Security update for python3',
update_date: '2023-03-22',
},
],
},
{
from_epoch: ' ',
Expand All @@ -85,71 +133,24 @@ export const Default = {
to_version: '5.15.2+kde294',
from_arch: 'x86_64',
to_arch: 'x86_64',
},
],
relevantPatches: [
{
date: '2023-03-22',
advisory_name: 'SUSE-15-SP4-2023-868',
advisory_type: 'security_advisory',
advisory_status: 'stable',
id: 2136,
advisory_synopsis: 'important: Security update for python3',
update_date: '2023-03-22',
},
{
date: '2024-03-11',
advisory_name: 'SUSE-15-SP4-2024-833',
advisory_type: 'security_advisory',
advisory_status: 'stable',
id: 4244,
advisory_synopsis: 'moderate: Security update for openssl-1_1',
update_date: '2024-03-11',
},
{
date: '2023-05-30',
advisory_name: 'SUSE-15-SP4-2023-2317',
advisory_type: 'bugfix',
advisory_status: 'stable',
id: 39543,
advisory_synopsis: 'Recommended update for util-linux',
update_date: '2023-05-30',
},
{
date: '2024-03-13',
advisory_name: 'SUSE-15-SP4-2024-877',
advisory_type: 'security_advisory',
advisory_status: 'stable',
id: 4263,
advisory_synopsis: 'important: Security update for sudo',
update_date: '2024-03-13',
},
{
date: '2024-03-13',
advisory_name: 'SUSE-15-SP4-2024-871',
advisory_type: 'security_advisory',
advisory_status: 'stable',
id: 4261,
advisory_synopsis: 'important: Security update for vim',
update_date: '2024-03-13',
},
{
date: '2024-03-13',
advisory_name: 'SUSE-15-SP4-2024-870',
advisory_type: 'security_advisory',
advisory_status: 'stable',
id: 4260,
advisory_synopsis: 'moderate: Security update for glibc',
update_date: '2024-03-13',
},
{
date: '2024-02-28',
advisory_name: 'SUSE-15-SP4-2024-641',
advisory_type: 'bugfix',
advisory_status: 'stable',
id: 4189,
advisory_synopsis: 'Recommended update for gcc7',
update_date: '2024-02-28',
patches: [
{
issue_date: '2024-03-13',
last_modified_date: '2024-03-13',
advisory: 'SUSE-15-SP4-2024-870',
type: 'security_advisory',
synopsis: 'moderate: Security update for glibc',
update_date: '2024-03-13',
},
{
issue_date: '2024-02-28',
last_modified_date: '2024-02-28',
advisory: 'SUSE-15-SP4-2024-641',
type: 'bugfix',
synopsis: 'Recommended update for gcc7',
update_date: '2024-02-28',
},
],
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,37 @@ import UpgradablePackagesList from './UpgradablePackagesList';
describe('UpgradablePackagesList component', () => {
it('should render the upgradable packages list', () => {
const hostname = 'Example Host';
const patches = [
{
issue_date: '2024-03-13',
last_modified_date: '2024-03-13',
advisory: 'SUSE-15-SP4-2024-870',
type: 'security_advisory',
synopsis: 'moderate: Security update for glibc',
update_date: '2024-03-13',
},
{
issue_date: '2024-02-28',
last_modified_date: '2024-02-28',
advisory: 'SUSE-15-SP4-2024-641',
type: 'bugfix',
synopsis: 'Recommended update for gcc7',
update_date: '2024-02-28',
},
];
const upgradablePackage = {
from_epoch: ' ',
to_release: '150300.3.30.1',
name: 'openssh-server',
from_release: '150300.3.15.4',
to_release: '150400.6.10.1',
name: 'libQt5Gui5',
from_release: '150400.6.3.1',
to_epoch: ' ',
arch: 'x86_64',
to_package_id: 39543,
from_version: '8.4p1',
to_version: '8.4p1',
to_package_id: 38391,
from_version: '5.15.2+kde294',
to_version: '5.15.2+kde294',
from_arch: 'x86_64',
to_arch: 'x86_64',
};
const relevantPatch = {
date: '2023-05-30',
advisory_name: 'SUSE-15-SP4-2023-2317',
advisory_type: 'bugfix',
advisory_status: 'stable',
id: 39543,
advisory_synopsis: 'Recommended update for util-linux',
update_date: '2023-05-30',
patches,
};

const expectedInstalledPackage = `${upgradablePackage.name}-${upgradablePackage.from_version}-${upgradablePackage.from_release}.${upgradablePackage.arch}`;
Expand All @@ -36,13 +46,14 @@ describe('UpgradablePackagesList component', () => {
<UpgradablePackagesList
hostname={hostname}
upgradablePackages={[upgradablePackage]}
relevantPatches={[relevantPatch]}
/>
);

expect(screen.getByText(hostname)).toBeVisible();
expect(screen.getByText(expectedInstalledPackage)).toBeVisible();
expect(screen.getByText(expectedLatestPackage)).toBeVisible();
expect(screen.getByText(relevantPatch.advisory_name)).toBeVisible();
patches.forEach(({ advisory }) => {
expect(screen.getByText(advisory)).toBeVisible();
});
});
});

0 comments on commit e54e0c3

Please sign in to comment.