Skip to content

Commit

Permalink
Add test for SaptuneDetailsPage
Browse files Browse the repository at this point in the history
  • Loading branch information
EMaksy committed Sep 29, 2023
1 parent 1fb5928 commit 4375dfa
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import SaptuneDetails from './SaptuneDetails';

describe('SaptuneDetails', () => {
it('should render the details correctly', () => {
it('should render saptune details correctly', () => {
const customSaptuneService = {
active: 'active',
enabled: 'enabled',
Expand Down
80 changes: 80 additions & 0 deletions assets/js/components/SaptuneDetails/SaptuneDetailsPage.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import React from 'react';
import { screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import {
renderWithRouterMatch,
withState,
defaultInitialState,
} from '@lib/test-utils';
import { hostFactory } from '@lib/test-utils/factories';

import SaptuneDetailsPage from './SaptuneDetailsPage';

describe('SaptuneDetailsPage', () => {
it('should render not found as the host is miissing', () => {
const hosts = hostFactory.buildList(2);
const hostID = 'NonExistingUUID';
const initialState = {
...defaultInitialState,
hostsList: {
hosts: [hosts],
},
};

const [StatefulSaptuneDetailsPage] = withState(
<SaptuneDetailsPage />,
initialState
);

renderWithRouterMatch(StatefulSaptuneDetailsPage, {
path: 'hosts/:hostID/saptune',
route: `/hosts/${hostID}/saptune`,
});

expect(screen.getByText('Not Found')).toBeTruthy();
});

it('should render saptune details not found', () => {
const host = hostFactory.build({ saptune_status: null });
const { id: hostID } = host;
const initialState = {
...defaultInitialState,
hostsList: {
hosts: [host],
},
};

const [StatefulSaptuneDetailsPage] = withState(
<SaptuneDetailsPage />,
initialState
);

renderWithRouterMatch(StatefulSaptuneDetailsPage, {
path: 'hosts/:hostID/saptune',
route: `/hosts/${hostID}/saptune`,
});

expect(screen.getByText('Saptune Details Not Found')).toBeTruthy();
});

it('should render the SaptuneDetailsPage', () => {
const host = hostFactory.build({ package_version: 3.1 });
const { id: hostID } = host;
const initialState = {
...defaultInitialState,
hostsList: {
hosts: [host],
},
};

const [StatefulSaptuneDetailsPage] = withState(
<SaptuneDetailsPage />,
initialState
);
renderWithRouterMatch(StatefulSaptuneDetailsPage, {
path: 'hosts/:hostID/saptune',
route: `/hosts/${hostID}/saptune`,
});
expect(screen.getByText('Saptune Details:')).toBeTruthy();
});
});

0 comments on commit 4375dfa

Please sign in to comment.