From 9f325fb142b0cba31af2e2b720c6e6d6f3a44593 Mon Sep 17 00:00:00 2001 From: Nelson Kopliku Date: Thu, 8 Jun 2023 07:59:02 +0200 Subject: [PATCH] Adjust tests --- .../ClusterDetails/ClusterDetailsPage.jsx | 2 +- .../ClusterDetails/HanaClusterDetails.jsx | 4 +- .../HanaClusterDetails.test.jsx | 65 +++++++------------ .../js/state/selectors/lastExecutions.test.js | 20 +++--- 4 files changed, 37 insertions(+), 54 deletions(-) diff --git a/assets/js/components/ClusterDetails/ClusterDetailsPage.jsx b/assets/js/components/ClusterDetails/ClusterDetailsPage.jsx index 6b1df749cf..db10f24ff9 100644 --- a/assets/js/components/ClusterDetails/ClusterDetailsPage.jsx +++ b/assets/js/components/ClusterDetails/ClusterDetailsPage.jsx @@ -20,7 +20,6 @@ export function ClusterDetailsPage() { const dispatch = useDispatch(); const lastExecution = useSelector(getLastExecution(clusterID)); - useEffect(() => { dispatch(updateLastExecution(clusterID)); }, [dispatch]); @@ -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': diff --git a/assets/js/components/ClusterDetails/HanaClusterDetails.jsx b/assets/js/components/ClusterDetails/HanaClusterDetails.jsx index 7a7f921895..583153dcc9 100644 --- a/assets/js/components/ClusterDetails/HanaClusterDetails.jsx +++ b/assets/js/components/ClusterDetails/HanaClusterDetails.jsx @@ -72,8 +72,8 @@ function HanaClusterDetails({ provider, details, lastExecution, - onStartExecution, - navigate, + onStartExecution = () => {}, + navigate = () => {}, }) { const enrichedNodes = enrichNodes(details?.nodes, hosts); diff --git a/assets/js/components/ClusterDetails/HanaClusterDetails.test.jsx b/assets/js/components/ClusterDetails/HanaClusterDetails.test.jsx index 9236c610b5..adbc1c8827 100644 --- a/assets/js/components/ClusterDetails/HanaClusterDetails.test.jsx +++ b/assets/js/components/ClusterDetails/HanaClusterDetails.test.jsx @@ -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( { provider={provider} details={details} lastExecution={lastExecution} - onStartExecution={jest.fn()} - navigate={jest.fn()} /> ); expect(screen.getByText(`Pacemaker Cluster Details:`)).toBeInTheDocument(); }); - - // Add more test cases here - - // ... }); diff --git a/assets/js/state/selectors/lastExecutions.test.js b/assets/js/state/selectors/lastExecutions.test.js index f9df047385..13d1fd948b 100644 --- a/assets/js/state/selectors/lastExecutions.test.js +++ b/assets/js/state/selectors/lastExecutions.test.js @@ -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: { @@ -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;