Skip to content

Commit

Permalink
Adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonkopliku committed Jun 8, 2023
1 parent 065c072 commit 9f325fb
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 54 deletions.
2 changes: 1 addition & 1 deletion assets/js/components/ClusterDetails/ClusterDetailsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export function ClusterDetailsPage() {

const dispatch = useDispatch();
const lastExecution = useSelector(getLastExecution(clusterID));

useEffect(() => {
dispatch(updateLastExecution(clusterID));
}, [dispatch]);
Expand All @@ -32,6 +31,7 @@ export function ClusterDetailsPage() {
}

const hasSelectedChecks = cluster.selected_checks.length > 0;

switch (cluster.type) {
case 'hana_scale_up':
case 'hana_scale_out':
Expand Down
4 changes: 2 additions & 2 deletions assets/js/components/ClusterDetails/HanaClusterDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ function HanaClusterDetails({
provider,
details,
lastExecution,
onStartExecution,
navigate,
onStartExecution = () => {},
navigate = () => {},
}) {
const enrichedNodes = enrichNodes(details?.nodes, hosts);

Expand Down
65 changes: 25 additions & 40 deletions assets/js/components/ClusterDetails/HanaClusterDetails.test.jsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,40 @@
import React from 'react';
import { renderWithRouter } from '@lib/test-utils';
import HanaClusterDetails from './HanaClusterDetails';
import { screen } from '@testing-library/react';
import '@testing-library/jest-dom';

describe('HanaClusterDetails', () => {
it.only('should render cluster details', () => {
const clusterID = '123';
const clusterName = 'Test Cluster';
const selectedChecks = [];
import { renderWithRouter } from '@lib/test-utils';
import { clusterFactory, hostFactory } from '@lib/test-utils/factories';
import HanaClusterDetails from './HanaClusterDetails';

describe('HanaClusterDetails component', () => {
it('should render cluster details', () => {
const hanaCluster = clusterFactory.build({
type: 'hana_scale_out',
});

const {
clusterID,
clusterName,
cib_last_written: cibLastWritten,
type: clusterType,
sid,
provider,
details,
} = hanaCluster;

const hosts = hostFactory.buildList(2, { cluster_id: clusterID });

const hasSelectedChecks = false;
const hosts = [];
const clusterType = 'hana_scale_up';
const cibLastWritten = '17:11:00';
const sid = 'SID123';
const provider = 'AWS';
const details = {
nodes: [
{
id: '1',
name: 'Host1',
hana_status: 'Primary',
ip_addresses: ['192.168.1.1'],
virtual_ip: '192.168.1.100',
attributes: { attribute1: 'value1' },
resources: ['resource1', 'resource2'],
},
],
fencing_type: 'fencing_type1',
sr_health_state: 'healthy',
system_replication_mode: 'sync',
secondary_sync_state: 'completed',
system_replication_operation_mode: 'log',
stopped_resources: [],
sbd_devices: ['sbd_device1', 'sbd_device2'],
};

const lastExecution = {
['werkojg']: { data: null, loading: false, error: null },
werkojg: { data: null, loading: false, error: null },
};

renderWithRouter(
<HanaClusterDetails
clusterID={clusterID}
clusterName={clusterName}
selectedChecks={selectedChecks}
selectedChecks={hanaCluster.selected_checks}
hasSelectedChecks={hasSelectedChecks}
hosts={hosts}
clusterType={clusterType}
Expand All @@ -52,15 +43,9 @@ describe('HanaClusterDetails', () => {
provider={provider}
details={details}
lastExecution={lastExecution}
onStartExecution={jest.fn()}
navigate={jest.fn()}
/>
);

expect(screen.getByText(`Pacemaker Cluster Details:`)).toBeInTheDocument();
});

// Add more test cases here

// ...
});
20 changes: 9 additions & 11 deletions assets/js/state/selectors/lastExecutions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@ import {
import { getLastExecution, getLastExecutionData } from './lastExecutions';

describe('lastExecutions selector', () => {
it('should return loading state when lastExecution is not found', () => {
const { id: clusterID } = clusterFactory.build();
const state = {
lastExecutions: {},
};

const expectedState = { loading: true };

expect(getLastExecution(clusterID)(state)).toEqual(expectedState);
});

it('should return the expected last execution by group ID', () => {
const state = {
lastExecutions: {
Expand All @@ -39,6 +28,15 @@ describe('lastExecutions selector', () => {
expect(getLastExecution('someID')(state)).toEqual(expectedState);
});

it('should return a default loading lastExecution when none was found in the state', () => {
const { id: clusterID } = clusterFactory.build();
const state = {
lastExecutions: {},
};

expect(getLastExecution(clusterID)(state)).toEqual({ loading: true });
});

it('should return the expected last execution context by group ID', () => {
const aCluster = clusterFactory.build();
const { id: clusterID, name: clusterName } = aCluster;
Expand Down

0 comments on commit 9f325fb

Please sign in to comment.