Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for operating_system's display issues #1451

Merged
merged 4 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/Utilities/OperatingSystemFormatter.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
import React from 'react';
import PropTypes from 'prop-types';

const OperatingSystemFormatter = ({ systemProfile }) => {
if (systemProfile?.operating_system?.name === 'RHEL') {
const version = (systemProfile.operating_system.major && systemProfile.operating_system.minor)
&& `${systemProfile.operating_system.major}.${systemProfile.operating_system?.minor}` || null;
const OperatingSystemFormatter = ({ operatingSystem }) => {
if (operatingSystem?.name === 'RHEL') {
const version = (operatingSystem.major && operatingSystem.minor !== null)
&& `${operatingSystem.major}.${operatingSystem?.minor}` || null;

return <span>
RHEL {version}
</span>;
}

return <span>
{systemProfile?.operating_system?.name || 'Not available'}
{operatingSystem?.name || 'Not available'}
</span>;
};

OperatingSystemFormatter.propTypes = {
systemProfile: PropTypes.shape({
operatingSystem: PropTypes.shape({
name: PropTypes.string,
major: PropTypes.number,
minor: PropTypes.number,
// eslint-disable-next-line camelcase
operating_system: PropTypes.shape({ name: PropTypes.string, major: PropTypes.number, minor: PropTypes.number })
minor: PropTypes.number
})
};

Expand Down
58 changes: 31 additions & 27 deletions src/Utilities/OperatingSystemFormatter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,64 +5,68 @@ import { mount } from 'enzyme';
import OperatingSystemFormatter from './OperatingSystemFormatter';

describe('OperatingSystemFormatter', () => {
let systemProfile;
let operatingSystem;

it('should render correctly with RHEL and version', () => {
systemProfile = {
operating_system: {
name: 'RHEL',
major: 7,
minor: 4
}
operatingSystem = {
name: 'RHEL',
major: 7,
minor: 4
};

const wrapper = mount(<OperatingSystemFormatter systemProfile={systemProfile}/>);
const wrapper = mount(<OperatingSystemFormatter operatingSystem={operatingSystem}/>);

expect(wrapper.text()).toEqual('RHEL 7.4');
});

it('should render correctly with RHEL and no version', () => {
systemProfile = {
operating_system: {
name: 'RHEL',
major: 7,
minor: null
}
operatingSystem = {
name: 'RHEL',
major: 7,
minor: null
};

const wrapper = mount(<OperatingSystemFormatter systemProfile={systemProfile}/>);
const wrapper = mount(<OperatingSystemFormatter operatingSystem={operatingSystem}/>);

expect(wrapper.text()).toEqual('RHEL ');
});

it('should render correctly with RHEL and minor version set to 0', () => {
operatingSystem = {
name: 'RHEL',
major: 7,
minor: 0
};

const wrapper = mount(<OperatingSystemFormatter operatingSystem={operatingSystem}/>);

expect(wrapper.text()).toEqual('RHEL 7.0');
});

it('should render with different system', () => {
systemProfile = {
operating_system: {
name: 'Windows'
}
operatingSystem = {
name: 'Windows'
};

const wrapper = mount(<OperatingSystemFormatter systemProfile={systemProfile}/>);
const wrapper = mount(<OperatingSystemFormatter operatingSystem={operatingSystem}/>);

expect(wrapper.text()).toEqual('Windows');
});

it('missing name', () => {
systemProfile = {
operating_system: {
name: null
}
operatingSystem = {
name: null
};

const wrapper = mount(<OperatingSystemFormatter systemProfile={systemProfile}/>);
const wrapper = mount(<OperatingSystemFormatter operatingSystem={operatingSystem}/>);

expect(wrapper.text()).toEqual('Not available');
});

it('missing operating system', () => {
systemProfile = {};
operatingSystem = {};

const wrapper = mount(<OperatingSystemFormatter systemProfile={systemProfile}/>);
const wrapper = mount(<OperatingSystemFormatter operatingSystem={operatingSystem}/>);

expect(wrapper.text()).toEqual('Not available');
});
Expand Down
6 changes: 5 additions & 1 deletion src/__mocks__/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ export const testProperties = {

export const osTest = {
arch: 'test-arch',
os_release: 'test-release',
operating_system: {
name: 'test-release',
major: 1,
minor: 0
},
os_kernel_version: 'test-kernel',
last_boot_time: 'test-boot',
kernel_modules: []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ exports[`GeneralInformation custom components should not render BiosCardWrapper
class=""
data-pf-content="true"
>
test-release
<span>
test-release
</span>
</dd>
<dt
class=""
Expand Down Expand Up @@ -995,7 +997,9 @@ exports[`GeneralInformation custom components should not render CollectionCardWr
class=""
data-pf-content="true"
>
test-release
<span>
test-release
</span>
</dd>
<dt
class=""
Expand Down Expand Up @@ -1646,7 +1650,9 @@ exports[`GeneralInformation custom components should not render ConfigurationCar
class=""
data-pf-content="true"
>
test-release
<span>
test-release
</span>
</dd>
<dt
class=""
Expand Down Expand Up @@ -2307,7 +2313,9 @@ exports[`GeneralInformation custom components should not render InfrastructureCa
class=""
data-pf-content="true"
>
test-release
<span>
test-release
</span>
</dd>
<dt
class=""
Expand Down Expand Up @@ -3369,7 +3377,9 @@ exports[`GeneralInformation custom components should not render SystemCardWrappe
class=""
data-pf-content="true"
>
test-release
<span>
test-release
</span>
</dd>
<dt
class=""
Expand Down Expand Up @@ -4132,7 +4142,9 @@ exports[`GeneralInformation custom components should render custom BiosCardWrapp
class=""
data-pf-content="true"
>
test-release
<span>
test-release
</span>
</dd>
<dt
class=""
Expand Down Expand Up @@ -4828,7 +4840,9 @@ exports[`GeneralInformation custom components should render custom CollectionCar
class=""
data-pf-content="true"
>
test-release
<span>
test-release
</span>
</dd>
<dt
class=""
Expand Down Expand Up @@ -5486,7 +5500,9 @@ exports[`GeneralInformation custom components should render custom Configuration
class=""
data-pf-content="true"
>
test-release
<span>
test-release
</span>
</dd>
<dt
class=""
Expand Down Expand Up @@ -6154,7 +6170,9 @@ exports[`GeneralInformation custom components should render custom Infrastructur
class=""
data-pf-content="true"
>
test-release
<span>
test-release
</span>
</dd>
<dt
class=""
Expand Down Expand Up @@ -7237,7 +7255,9 @@ exports[`GeneralInformation custom components should render custom SystemCardWra
class=""
data-pf-content="true"
>
test-release
<span>
test-release
</span>
</dd>
<dt
class=""
Expand Down Expand Up @@ -8826,7 +8846,9 @@ exports[`GeneralInformation should render correctly 1`] = `
class=""
data-pf-content="true"
>
test-release
<span>
test-release
</span>
</dd>
<dt
class=""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { generalMapper } from '../dataMapper';
import { operatingSystem } from '../selectors';
import DateFormat from '@redhat-cloud-services/frontend-components/DateFormat';
import { extraShape, isDate } from '../../../constants';
import OperatingSystemFormatter from '../../../Utilities/OperatingSystemFormatter';

const OperatingSystemCard = ({
systemInfo,
Expand All @@ -22,7 +23,7 @@ const OperatingSystemCard = ({
title="Operating system"
isLoading={ !detailLoaded }
items={ [
...hasRelease ? [{ title: 'Release', value: systemInfo.release }] : [],
...hasRelease ? [{ title: 'Release', value: <OperatingSystemFormatter operatingSystem={systemInfo.release} /> }] : [],
...hasKernelRelease ? [{ title: 'Kernel release', value: systemInfo.kernelRelease }] : [],
...hasArchitecture ? [{ title: 'Architecture', value: systemInfo.architecture }] : [],
...hasLastBoot ? [{ title: 'Last boot time', value: (isDate(systemInfo.bootTime) ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ exports[`OperatingSystemCard should not render hasArchitecture 1`] = `
class=""
data-pf-content="true"
>
test-release
<span>
test-release
</span>
</dd>
<dt
class=""
Expand Down Expand Up @@ -126,7 +128,9 @@ exports[`OperatingSystemCard should not render hasKernelModules 1`] = `
class=""
data-pf-content="true"
>
test-release
<span>
test-release
</span>
</dd>
<dt
class=""
Expand Down Expand Up @@ -211,7 +215,9 @@ exports[`OperatingSystemCard should not render hasKernelRelease 1`] = `
class=""
data-pf-content="true"
>
test-release
<span>
test-release
</span>
</dd>
<dt
class=""
Expand Down Expand Up @@ -296,7 +302,9 @@ exports[`OperatingSystemCard should not render hasLastBoot 1`] = `
class=""
data-pf-content="true"
>
test-release
<span>
test-release
</span>
</dd>
<dt
class=""
Expand Down Expand Up @@ -583,7 +591,9 @@ exports[`OperatingSystemCard should render correctly with data 1`] = `
class=""
data-pf-content="true"
>
test-release
<span>
test-release
</span>
</dd>
<dt
class=""
Expand Down Expand Up @@ -680,7 +690,9 @@ exports[`OperatingSystemCard should render correctly with rhsm facts 1`] = `
class=""
data-pf-content="true"
>
Not available
<span>
Not available
</span>
</dd>
<dt
class=""
Expand Down Expand Up @@ -777,7 +789,9 @@ exports[`OperatingSystemCard should render enabled/disabled 1`] = `
class=""
data-pf-content="true"
>
test-release
<span>
test-release
</span>
</dd>
<dt
class=""
Expand Down Expand Up @@ -874,7 +888,9 @@ exports[`OperatingSystemCard should render extra 1`] = `
class=""
data-pf-content="true"
>
test-release
<span>
test-release
</span>
</dd>
<dt
class=""
Expand Down
4 changes: 2 additions & 2 deletions src/components/GeneralInfo/selectors/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ export const propertiesSelector = ({

export const operatingSystem = ({
arch,
os_release,
operating_system,
os_kernel_version,
last_boot_time,
kernel_modules
} = {}, { facts } = {}) => ({
release: os_release,
release: operating_system,
kernelRelease: os_kernel_version,
architecture: arch || facts?.rhsm?.ARCHITECTURE,
bootTime: last_boot_time,
Expand Down
6 changes: 5 additions & 1 deletion src/components/GeneralInfo/selectors/selectors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ it('propertiesSelector - no data', () => {

it('operatingSystem should return correct data', () => {
expect(operatingSystem(osTest)).toEqual({
release: 'test-release',
release: {
name: 'test-release',
major: 1,
minor: 0
},
kernelRelease: 'test-kernel',
architecture: 'test-arch',
bootTime: 'test-boot',
Expand Down
Loading