Skip to content

Commit

Permalink
Refactor SaptuneDetails test
Browse files Browse the repository at this point in the history
  • Loading branch information
EMaksy committed Sep 28, 2023
1 parent 1f3cdd0 commit 5bd0f0b
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 27 deletions.
83 changes: 68 additions & 15 deletions assets/js/components/SaptuneDetails/SaptuneDetails.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,61 @@ import { screen } from '@testing-library/react';
import '@testing-library/jest-dom';

import { renderWithRouter } from '@lib/test-utils';
import { hostFactory, saptuneStatusFactory } from '@lib/test-utils/factories';
import {
hostFactory,
saptuneNoteFactory,
saptuneSolutionFactory,
saptuneStagingFactory,
saptuneStatusFactory,
} from '@lib/test-utils/factories';

import SaptuneDetails from './SaptuneDetails';

describe('SaptuneDetails', () => {
it('should render the details correctly', () => {
const customSaptuneService = {
active: 'active',
enabled: 'enabled',
name: 'saptune',
};

const customSapconfService = {
active: 'inactive',
enabled: 'disabled',
name: 'sapconf',
};

const customTunedService = {
active: null,
enabled: null,
name: 'tuned',
};

const services = [
customSaptuneService,
customSapconfService,
customTunedService,
];
const solution = saptuneSolutionFactory.build({ partial: false });
const { notes } = solution;
const allNotes = notes.map((id) => saptuneNoteFactory.build({ id }));

const staging = saptuneStagingFactory.build({ enabled: true });

const {
applied_notes: appliedNotes,
applied_solution: appliedSolution,
configured_version: configuredVersion,
enabled_solution: enabledSolution,
enabled_notes: enabledNotes,
package_version: packageVersion,
services,
staging,
tuning_state: tuningState,
} = saptuneStatusFactory.build();

const { hostname, id: hostID } = hostFactory.build();

renderWithRouter(
<SaptuneDetails
appliedNotes={appliedNotes}
appliedSolution={appliedSolution}
appliedNotes={allNotes}
appliedSolution={solution}
enabledNotes={allNotes}
enabledSolution={solution}
configuredVersion={configuredVersion}
enabledNotes={enabledNotes}
enabledSolution={enabledSolution}
hostname={hostname}
hostID={hostID}
packageVersion={packageVersion}
Expand All @@ -40,17 +68,42 @@ describe('SaptuneDetails', () => {
);

expect(screen.getByText(hostname)).toBeTruthy();

expect(screen.getByText('Package').nextSibling).toHaveTextContent(
packageVersion
);

expect(
screen.getByText('Configured Version').nextSibling
).toHaveTextContent(configuredVersion);

expect(screen.getByText('Tuning').nextSibling).toHaveTextContent(
new RegExp(tuningState, 'i')
);

expect(screen.getByText('Saptune Services Status')).toBeInTheDocument();
expect(screen.getByText('saptune.service').nextSibling).toHaveTextContent(
`${customSaptuneService.enabled}/${customSaptuneService.active}`
);
expect(screen.getByText('sapconf.service').nextSibling).toHaveTextContent(
`${customSapconfService.enabled}/${customSapconfService.active}`
);
expect(screen.getByText('tuned.service').nextSibling).toHaveTextContent(
`-`
);
expect(screen.getByText('Saptune Tuning Solutions')).toBeInTheDocument();
expect(screen.getByText('Enabled Solution').nextSibling).toHaveTextContent(
`${solution.id} (${solution.notes.join(', ')})`
);
expect(screen.getByText('Applied Solution').nextSibling).toHaveTextContent(
`${solution.id} (${solution.notes.join(', ')})`
);
expect(screen.getByText('Saptune Staging Status')).toBeInTheDocument();
expect(screen.getByText('Staging').nextSibling).toHaveTextContent(
`Enabled`
);
expect(screen.getByText('Staged Notes').nextSibling).toHaveTextContent(
`${staging.notes.join(', ')}`
);
expect(screen.getByText('Staged Solutions').nextSibling).toHaveTextContent(
staging.solutions_ids
);
});
});
23 changes: 11 additions & 12 deletions assets/js/lib/test-utils/factories/hosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { faker } from '@faker-js/faker';
import { Factory } from 'fishery';
import day from 'dayjs';
import { times } from 'lodash';

const slesSubscriptionDateFormat = 'YYYY-MM-DD HH:mm:ss UTC';

Expand Down Expand Up @@ -37,17 +38,15 @@ export const slesSubscriptionFactory = Factory.define(() => ({
version: '15.3',
}));

const sapNoteID = () => faker.number.int({ min: 100000, max: 999999 });
const sapNoteID = () =>
faker.number.int({ min: 100000, max: 999999 }).toString();

const sapNotesList = (count = 6) =>
Array(count)
.fill(null)
.map(() => sapNoteID());
const sapNotesList = (count = 6) => times(count, sapNoteID);

const saptuneServiceActiveEnum = () =>
const saptuneServiceEnabledEnum = () =>
faker.helpers.arrayElement(['enabled', 'disabled', null]);

const saptuneServiceEnabledEnum = () =>
const saptuneServiceActiveEnum = () =>
faker.helpers.arrayElement(['active', 'inactive', null]);

const saptuneServiceNameEnum = () =>
Expand All @@ -62,18 +61,18 @@ const saptuneServiceFactory = Factory.define(() => ({
name: saptuneServiceNameEnum(),
}));

const saptuneStagingFactory = Factory.define(() => ({
enabled: true,
export const saptuneStagingFactory = Factory.define(() => ({
enabled: faker.datatype.boolean(),
notes: sapNotesList(3),
solutions_ids: [saptuneSolutionNameEnum()],
}));

const saptuneNoteFactory = Factory.define(() => ({
export const saptuneNoteFactory = Factory.define(() => ({
additionally_enabled: faker.datatype.boolean(),
id: faker.number.int(),
id: sapNoteID(),
}));

const saptuneSolutionFactory = Factory.define(() => ({
export const saptuneSolutionFactory = Factory.define(() => ({
id: saptuneSolutionNameEnum(),
notes: sapNotesList(),
partial: faker.datatype.boolean(),
Expand Down

0 comments on commit 5bd0f0b

Please sign in to comment.