Skip to content

Commit

Permalink
Refs #34527 - Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylenz committed Mar 2, 2022
1 parent 30a3f62 commit e671c3c
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 7 deletions.
Expand Up @@ -124,7 +124,7 @@ const HostCollectionsDetails = ({
);
};

const HostCollectionsDetailsCard = ({ hostDetails }) => {
const HostCollectionsCard = ({ hostDetails }) => {
if (hostDetails) {
return <HostCollectionsDetails {...propsToCamelCase(hostDetails)} />;
}
Expand All @@ -139,12 +139,12 @@ HostCollectionsDetails.defaultProps = {
hostCollections: [],
};

HostCollectionsDetailsCard.propTypes = {
HostCollectionsCard.propTypes = {
hostDetails: PropTypes.shape({}),
};

HostCollectionsDetailsCard.defaultProps = {
HostCollectionsCard.defaultProps = {
hostDetails: null,
};

export default HostCollectionsDetailsCard;
export default HostCollectionsCard;
Expand Up @@ -24,7 +24,7 @@ test('shows host details when content facet is set', () => {
});


test('doesnot show host details when content facet is not set', () => {
test('does not show host details when content facet is not set', () => {
const { queryByText } = render(<ContentViewDetailsCard />);
expect(queryByText('Version 1.0')).toBeNull();
});
Expand Down
@@ -0,0 +1,70 @@
import React from 'react';
import { render, fireEvent } from 'react-testing-lib-wrapper';
import HostCollectionsCard from '../HostCollectionsCard';

const hostDetails = {
host_collections: [
{
id: 1,
name: 'Jer Hosts',
description: null,
max_hosts: null,
unlimited_hosts: true,
total_hosts: 2,
},
{
id: 3,
name: 'Partha hosts',
description: null,
max_hosts: 1,
unlimited_hosts: false,
total_hosts: 1,
},
{
id: 2,
name: 'Jturel hosts',
description: 'This is my awesome description',
max_hosts: 43,
unlimited_hosts: false,
total_hosts: 1,
},
],
};

const emptyHostDetails = {
host_collections: [],
};

test('shows host collections and host limits when present', () => {
const { getByText } = render(<HostCollectionsCard hostDetails={hostDetails} />);
expect(getByText('Host collections')).toBeInTheDocument();
expect(getByText('Jturel hosts')).toBeInTheDocument();
expect(getByText('1/43')).toBeInTheDocument();
expect(getByText('1/1')).toBeInTheDocument();
expect(getByText('2/unlimited')).toBeInTheDocument();
});

test('shows empty card when no host collections present', () => {
const { queryByText } = render(<HostCollectionsCard hostDetails={emptyHostDetails} />);
expect(queryByText('Host collections')).toBeInTheDocument();
expect(queryByText('Jturel hosts')).not.toBeInTheDocument();
});

test('expands to show description', () => {
const { getByText, queryByText } = render(<HostCollectionsCard hostDetails={hostDetails} />);
expect(getByText('Jturel hosts')).toBeInTheDocument();
expect(queryByText('This is my awesome description')).not.toBeVisible();
fireEvent.click(getByText('Jturel hosts'));
expect(getByText('This is my awesome description')).toBeVisible();
});

test('expands to show when no description provided', () => {
const { getAllByText, queryAllByText } = render(<HostCollectionsCard
hostDetails={hostDetails}
/>);
const indescribableHostCollection = getAllByText('Jer Hosts')[0];
expect(indescribableHostCollection).toBeInTheDocument();
queryAllByText('No description provided').forEach(element => expect(element).not.toBeVisible());
fireEvent.click(indescribableHostCollection);
expect(getAllByText('No description provided')[0]).toBeVisible();
});
4 changes: 2 additions & 2 deletions webpack/global_index.js
Expand Up @@ -14,7 +14,7 @@ import RepositorySetsTab from './components/extensions/HostDetails/Tabs/Reposito
import TracesTab from './components/extensions/HostDetails/Tabs/TracesTab/TracesTab.js';
import extendReducer from './components/extensions/reducers';
import rootReducer from './redux/reducers';
import HostCollectionsDetailsCard from './components/extensions/HostDetails/Cards/HostCollectionsCard';
import HostCollectionsCard from './components/extensions/HostDetails/Cards/HostCollectionsCard';

registerReducer('katelloExtends', extendReducer);
registerReducer('katello', rootReducer);
Expand All @@ -36,7 +36,7 @@ addGlobalFill(
addGlobalFill(
'details-cards',
'Host collections',
<HostCollectionsDetailsCard key="host-collections-details" />,
<HostCollectionsCard key="host-collections-details" />,
700,
);
addGlobalFill('details-cards', 'Installable errata', <ErrataOverviewCard key="errata-overview" />, 1900);

0 comments on commit e671c3c

Please sign in to comment.