Skip to content

Commit

Permalink
Add upgradable packages list component (#2636)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamie-suse authored and dottorblaster committed Jun 28, 2024
1 parent 70692ba commit 8ced934
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 0 deletions.
57 changes: 57 additions & 0 deletions assets/js/common/UpgradablePackagesList/UpgradablePackagesList.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from 'react';
import Table from '@common/Table';

const upgradablePackagesDefault = [];

function UpgradablePackagesList({
upgradablePackages = upgradablePackagesDefault,
}) {
const config = {
pagination: true,
usePadding: false,
columns: [
{
title: 'Installed Packages',
key: 'installedPackage',
render: (content, _) => <div className="font-bold">{content}</div>,
},
{
title: 'Latest Package',
key: 'latestPackage',
render: (content, _) => <div>{content}</div>,
},
{
title: 'Related Patches',
key: 'patches',
render: (content, { to_package_id }) => (
<div>
{content.map(({ advisory_name }) => (
<div key={`${to_package_id}-${advisory_name}`}>
{advisory_name}
</div>
))}
</div>
),
},
],
};

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

return {
...packageDetails,
installedPackage: `${name}-${from_version}-${from_release}.${arch}`,
latestPackage: `${name}-${to_version}-${to_release}.${arch}`,
};
});

return (
<div className="bg-white rounded-lg shadow">
<Table config={config} data={data} />
</div>
);
}

export default UpgradablePackagesList;
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { upgradablePackageFactory } from '@lib/test-utils/factories/upgradablePackage';
import UpgradablePackagesList from './UpgradablePackagesList';

export default {
title: 'Components/UpgradablePackagesList',
component: UpgradablePackagesList,
argTypes: {
hostname: {
type: 'string',
control: { type: 'text' },
description: 'The name of the host',
},
upgradablePackages: {
control: {
type: 'array',
},
description: 'List of upgradable packages',
},
},
};

export const Default = {
args: {
hostname: 'Example Host',
upgradablePackages: upgradablePackageFactory.buildList(4),
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { upgradablePackageFactory } from '@lib/test-utils/factories/upgradablePackage';
import UpgradablePackagesList from './UpgradablePackagesList';

describe('UpgradablePackagesList component', () => {
it('should render the upgradable packages list', () => {
const upgradablePackage = upgradablePackageFactory.build();
const { patches } = upgradablePackage;

const expectedInstalledPackage = `${upgradablePackage.name}-${upgradablePackage.from_version}-${upgradablePackage.from_release}.${upgradablePackage.arch}`;
const expectedLatestPackage = `${upgradablePackage.name}-${upgradablePackage.to_version}-${upgradablePackage.to_release}.${upgradablePackage.arch}`;

render(<UpgradablePackagesList upgradablePackages={[upgradablePackage]} />);

expect(screen.getByText(expectedInstalledPackage)).toBeVisible();
expect(screen.getByText(expectedLatestPackage)).toBeVisible();
patches.forEach(({ advisory_name }) => {
expect(screen.getByText(advisory_name)).toBeVisible();
});
});
});
21 changes: 21 additions & 0 deletions assets/js/lib/test-utils/factories/upgradablePackage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { faker } from '@faker-js/faker';
import { Factory } from 'fishery';
import { relevantPatchFactory } from './relevantPatches';

const releaseVersionFactory = () =>
`${faker.number.int({ min: 100000, max: 160000 })}.${faker.system.semver()}`;

export const upgradablePackageFactory = Factory.define(() => ({
from_epoch: faker.date.anytime(),
to_release: releaseVersionFactory(),
name: faker.company.buzzNoun(),
from_release: releaseVersionFactory(),
to_epoch: faker.date.anytime(),
arch: faker.airline.flightNumber(),
to_package_id: faker.number.int({ min: 2000, max: 5000 }),
from_version: faker.system.semver(),
to_version: faker.system.semver(),
from_arch: faker.airline.flightNumber(),
to_arch: faker.airline.flightNumber(),
patches: relevantPatchFactory.buildList(2),
}));

0 comments on commit 8ced934

Please sign in to comment.