From db8375a594fd1da6cabae829169fcbb177495432 Mon Sep 17 00:00:00 2001 From: stanislavh Date: Wed, 12 Apr 2023 17:33:33 +0200 Subject: [PATCH] SONAR-18443 RTL migration for System page --- .../main/js/api/mocks/SystemServiceMock.ts | 72 ++++ .../js/apps/system/__tests__/utils-test.ts | 20 +- .../js/apps/system/components/PageHeader.tsx | 21 +- .../js/apps/system/components/SystemApp.tsx | 3 +- .../system/components/__tests__/App-test.tsx | 86 ----- .../__tests__/ChangeLogLevelForm-test.tsx | 38 --- .../__tests__/ClusterSysInfos-test.tsx | 98 ------ .../components/__tests__/PageActions-test.tsx | 55 --- .../components/__tests__/PageHeader-test.tsx | 54 --- .../__tests__/StandaloneSysInfos-test.tsx | 38 --- .../components/__tests__/SystemApp-it.tsx | 141 ++++++++ .../__tests__/__snapshots__/App-test.tsx.snap | 323 ------------------ .../ChangeLogLevelForm-test.tsx.snap | 219 ------------ .../ClusterSysInfos-test.tsx.snap | 88 ----- .../__snapshots__/PageActions-test.tsx.snap | 220 ------------ .../__snapshots__/PageHeader-test.tsx.snap | 182 ---------- .../StandaloneSysInfos-test.tsx.snap | 105 ------ .../components/info-items/HealthCard.tsx | 8 +- .../components/info-items/HealthCauseItem.tsx | 6 +- .../components/info-items/HealthItem.tsx | 9 +- .../components/info-items/SysInfoItem.tsx | 4 +- .../info-items/__tests__/HealthCard-test.tsx | 59 ---- .../__tests__/HealthCauseItem-test.tsx | 27 -- .../info-items/__tests__/HealthItem-test.tsx | 37 -- .../info-items/__tests__/Section-test.tsx | 32 -- .../info-items/__tests__/SysInfoItem-test.tsx | 38 --- .../__snapshots__/HealthCard-test.tsx.snap | 58 ---- .../HealthCauseItem-test.tsx.snap | 21 -- .../__snapshots__/HealthItem-test.tsx.snap | 66 ---- .../__snapshots__/Section-test.tsx.snap | 133 -------- .../__snapshots__/SysInfoItem-test.tsx.snap | 78 ----- .../src/main/js/apps/system/utils.ts | 22 +- .../src/main/js/helpers/testMocks.ts | 35 +- server/sonar-web/src/main/js/types/types.ts | 10 +- 34 files changed, 287 insertions(+), 2119 deletions(-) create mode 100644 server/sonar-web/src/main/js/api/mocks/SystemServiceMock.ts delete mode 100644 server/sonar-web/src/main/js/apps/system/components/__tests__/App-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/system/components/__tests__/ChangeLogLevelForm-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/system/components/__tests__/ClusterSysInfos-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/system/components/__tests__/PageActions-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/system/components/__tests__/PageHeader-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/system/components/__tests__/StandaloneSysInfos-test.tsx create mode 100644 server/sonar-web/src/main/js/apps/system/components/__tests__/SystemApp-it.tsx delete mode 100644 server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/App-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/ChangeLogLevelForm-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/ClusterSysInfos-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/PageActions-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/PageHeader-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/StandaloneSysInfos-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/HealthCard-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/HealthCauseItem-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/HealthItem-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/Section-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/SysInfoItem-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/HealthCard-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/HealthCauseItem-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/HealthItem-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/Section-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/SysInfoItem-test.tsx.snap diff --git a/server/sonar-web/src/main/js/api/mocks/SystemServiceMock.ts b/server/sonar-web/src/main/js/api/mocks/SystemServiceMock.ts new file mode 100644 index 00000000000..c3dcb5192b5 --- /dev/null +++ b/server/sonar-web/src/main/js/api/mocks/SystemServiceMock.ts @@ -0,0 +1,72 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { cloneDeep } from 'lodash'; +import { SysInfoCluster, SysInfoLogging, SysInfoStandalone } from '../../types/types'; + +import { LogsLevels } from '../../apps/system/utils'; +import { mockClusterSysInfo, mockLogs, mockStandaloneSysInfo } from '../../helpers/testMocks'; +import { getSystemInfo, setLogLevel } from '../system'; + +export default class SystemServiceMock { + isCluster: boolean = false; + logging: SysInfoLogging = mockLogs(); + systemInfo: SysInfoCluster | SysInfoStandalone = mockStandaloneSysInfo(); + + constructor() { + this.updateSystemInfo(); + jest.mocked(getSystemInfo).mockImplementation(this.handleGetSystemInfo); + jest.mocked(setLogLevel).mockImplementation(this.handleSetLogLevel); + } + + handleGetSystemInfo = () => { + return this.reply(this.systemInfo); + }; + + handleSetLogLevel = (logsLevel: LogsLevels) => { + this.logging = mockLogs(logsLevel); + this.updateSystemInfo(); + + return this.reply(undefined); + }; + + updateSystemInfo = () => { + const logs = { + 'Web Logging': this.logging, + 'Compute Engine Logging': this.logging, + }; + + this.systemInfo = this.isCluster ? mockClusterSysInfo(logs) : mockStandaloneSysInfo(logs); + }; + + setIsCluster = (isCluster: boolean = false) => { + this.isCluster = isCluster; + this.updateSystemInfo(); + }; + + reset = () => { + this.logging = mockLogs(); + this.setIsCluster(false); + this.updateSystemInfo(); + }; + + reply(response: T): Promise { + return Promise.resolve(cloneDeep(response)); + } +} diff --git a/server/sonar-web/src/main/js/apps/system/__tests__/utils-test.ts b/server/sonar-web/src/main/js/apps/system/__tests__/utils-test.ts index d2a3d999c38..8322576286f 100644 --- a/server/sonar-web/src/main/js/apps/system/__tests__/utils-test.ts +++ b/server/sonar-web/src/main/js/apps/system/__tests__/utils-test.ts @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import { mockClusterSysInfo, mockStandaloneSysInfo } from '../../../helpers/testMocks'; +import { mockClusterSysInfo, mockLogs, mockStandaloneSysInfo } from '../../../helpers/testMocks'; import { SysInfoBase, SysInfoStandalone } from '../../../types/types'; import * as u from '../utils'; @@ -46,11 +46,11 @@ describe('groupSections', () => { describe('getSystemLogsLevel', () => { it('should correctly return the worst log level for standalone mode', () => { - expect(u.getSystemLogsLevel(mockStandaloneSysInfo())).toBe('DEBUG'); + expect(u.getSystemLogsLevel(mockStandaloneSysInfo())).toBe(u.LogsLevels.INFO); }); it('should return the worst log level for cluster mode', () => { - expect(u.getSystemLogsLevel(mockClusterSysInfo())).toBe('DEBUG'); + expect(u.getSystemLogsLevel(mockClusterSysInfo())).toBe(u.LogsLevels.DEBUG); }); it('should not fail if the log informations are not there yet', () => { @@ -60,15 +60,15 @@ describe('getSystemLogsLevel', () => { 'Application Nodes': [{ Name: 'App 1' }, { Name: 'App 2' }], }) ) - ).toBe('INFO'); + ).toBe(u.LogsLevels.INFO); expect( u.getSystemLogsLevel( mockClusterSysInfo({ 'Application Nodes': [{ 'Compute Engine Logging': {} }, { Name: 'App 2' }], }) ) - ).toBe('INFO'); - expect(u.getSystemLogsLevel({} as SysInfoStandalone)).toBe('INFO'); + ).toBe(u.LogsLevels.INFO); + expect(u.getSystemLogsLevel({} as SysInfoStandalone)).toBe(u.LogsLevels.INFO); }); }); @@ -189,14 +189,14 @@ describe('getLogsLevel', () => { it('should return the worst level', () => { expect( u.getLogsLevel({ - 'Web Logging': { 'Logs Level': 'DEBUG' }, - 'Compute Engine Logging': { 'Logs Level': 'TRACE' }, + 'Web Logging': mockLogs(u.LogsLevels.DEBUG), + 'Compute Engine Logging': mockLogs(u.LogsLevels.TRACE), }) - ).toEqual('TRACE'); + ).toEqual(u.LogsLevels.TRACE); }); it('should return the default level if no information is provided', () => { - expect(u.getLogsLevel()).toEqual('INFO'); + expect(u.getLogsLevel()).toEqual(u.LogsLevels.INFO); }); }); diff --git a/server/sonar-web/src/main/js/apps/system/components/PageHeader.tsx b/server/sonar-web/src/main/js/apps/system/components/PageHeader.tsx index ce68f7b2254..19d64ecdc80 100644 --- a/server/sonar-web/src/main/js/apps/system/components/PageHeader.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/PageHeader.tsx @@ -33,24 +33,21 @@ export interface Props { onLogLevelChange: () => void; appState: AppState; serverId?: string; - showActions: boolean; version?: string; } -export function PageHeader(props: Props) { - const { isCluster, loading, logLevel, serverId, showActions, version, appState } = props; +function PageHeader(props: Props) { + const { isCluster, loading, logLevel, serverId, version, appState } = props; return (

{translate('system_info.page')}

- {showActions && ( - - )} + {loading && (
diff --git a/server/sonar-web/src/main/js/apps/system/components/SystemApp.tsx b/server/sonar-web/src/main/js/apps/system/components/SystemApp.tsx index 7b32745252c..d9e135e7b9a 100644 --- a/server/sonar-web/src/main/js/apps/system/components/SystemApp.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/SystemApp.tsx @@ -50,7 +50,7 @@ interface State { sysInfoData?: SysInfoCluster | SysInfoStandalone; } -export class SystemApp extends React.PureComponent { +class SystemApp extends React.PureComponent { mounted = false; state: State = { loading: true }; @@ -136,7 +136,6 @@ export class SystemApp extends React.PureComponent { logLevel={getSystemLogsLevel(sysInfoData)} onLogLevelChange={this.fetchSysInfo} serverId={getServerId(sysInfoData)} - showActions={sysInfoData !== undefined} version={ isCluster(sysInfoData) ? getClusterVersion(sysInfoData) : getVersion(sysInfoData) } diff --git a/server/sonar-web/src/main/js/apps/system/components/__tests__/App-test.tsx b/server/sonar-web/src/main/js/apps/system/components/__tests__/App-test.tsx deleted file mode 100644 index b00ae1736aa..00000000000 --- a/server/sonar-web/src/main/js/apps/system/components/__tests__/App-test.tsx +++ /dev/null @@ -1,86 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { shallow } from 'enzyme'; -import * as React from 'react'; -import { getSystemInfo } from '../../../../api/system'; -import { - mockClusterSysInfo, - mockLocation, - mockRouter, - mockStandaloneSysInfo, -} from '../../../../helpers/testMocks'; -import { waitAndUpdate } from '../../../../helpers/testUtils'; -import { SystemApp } from '../SystemApp'; - -jest.mock('../../../../api/system', () => ({ - getSystemInfo: jest.fn().mockResolvedValue(null), -})); - -beforeEach(jest.clearAllMocks); - -it('should render correctly', () => { - const wrapper = shallowRender(); - expect(wrapper).toMatchSnapshot('loading'); - expect( - wrapper.setState({ loading: false, sysInfoData: mockStandaloneSysInfo() }) - ).toMatchSnapshot('stand-alone sysinfo'); - expect(wrapper.setState({ loading: false, sysInfoData: mockClusterSysInfo() })).toMatchSnapshot( - 'cluster sysinfo' - ); -}); - -it('should fetch system info', async () => { - const sysInfoData = mockStandaloneSysInfo(); - (getSystemInfo as jest.Mock).mockResolvedValue(sysInfoData); - - const wrapper = shallowRender(); - await waitAndUpdate(wrapper); - expect(getSystemInfo).toHaveBeenCalled(); - expect(wrapper.state().sysInfoData).toBe(sysInfoData); -}); - -it('should toggle cards and update the URL', () => { - const replace = jest.fn(); - const wrapper = shallowRender({ router: mockRouter({ replace }) }); - - // Open - wrapper.instance().toggleSysInfoCards('foo'); - expect(replace).toHaveBeenCalledWith( - expect.objectContaining({ - query: { expand: 'foo' }, - }) - ); - - // Close. - replace.mockClear(); - wrapper.setProps({ location: mockLocation({ query: { expand: 'foo,bar' } }) }); - wrapper.instance().toggleSysInfoCards('foo'); - expect(replace).toHaveBeenCalledWith( - expect.objectContaining({ - query: { expand: 'bar' }, - }) - ); -}); - -function shallowRender(props: Partial = {}) { - return shallow( - - ); -} diff --git a/server/sonar-web/src/main/js/apps/system/components/__tests__/ChangeLogLevelForm-test.tsx b/server/sonar-web/src/main/js/apps/system/components/__tests__/ChangeLogLevelForm-test.tsx deleted file mode 100644 index 6c92e08fef1..00000000000 --- a/server/sonar-web/src/main/js/apps/system/components/__tests__/ChangeLogLevelForm-test.tsx +++ /dev/null @@ -1,38 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { shallow } from 'enzyme'; -import * as React from 'react'; -import ChangeLogLevelForm from '../ChangeLogLevelForm'; - -it('should render correctly', () => { - expect( - shallow( - {}} onClose={() => {}} /> - ) - ).toMatchSnapshot(); -}); - -it('should display some warning messages for non INFO levels', () => { - expect( - shallow( - {}} onClose={() => {}} /> - ) - ).toMatchSnapshot(); -}); diff --git a/server/sonar-web/src/main/js/apps/system/components/__tests__/ClusterSysInfos-test.tsx b/server/sonar-web/src/main/js/apps/system/components/__tests__/ClusterSysInfos-test.tsx deleted file mode 100644 index f837933ff4b..00000000000 --- a/server/sonar-web/src/main/js/apps/system/components/__tests__/ClusterSysInfos-test.tsx +++ /dev/null @@ -1,98 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { shallow } from 'enzyme'; -import * as React from 'react'; -import { mockClusterSysInfo } from '../../../../helpers/testMocks'; -import ClusterSysInfos from '../ClusterSysInfos'; - -it('should render correctly', () => { - expect( - shallowRender( - mockClusterSysInfo({ - sysInfoData: { - Health: 'RED', - 'Health Causes': ['Database down'], - 'Application Nodes': [ - { - Name: 'Foo', - Health: 'GREEN', - 'Health Causes': [], - 'Compute Engine Logging': { 'Logs Level': 'INFO' }, - 'Web Logging': { 'Logs Level': 'INFO' }, - }, - { - Name: 'Bar', - Health: 'RED', - 'Health Causes': [], - 'Compute Engine Logging': { 'Logs Level': 'INFO' }, - 'Web Logging': { 'Logs Level': 'DEBUG' }, - }, - { - Name: 'Baz', - Health: 'YELLOW', - 'Health Causes': [], - 'Compute Engine Logging': { 'Logs Level': 'TRACE' }, - 'Web Logging': { 'Logs Level': 'DEBUG' }, - }, - ], - }, - }) - ).find('HealthCard') - ).toHaveLength(4); -}); - -it('should support more than two nodes', () => { - expect(shallowRender()).toMatchSnapshot(); -}); - -function shallowRender(props = {}) { - return shallow( - {}} - {...props} - /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/system/components/__tests__/PageActions-test.tsx b/server/sonar-web/src/main/js/apps/system/components/__tests__/PageActions-test.tsx deleted file mode 100644 index f7b5638a31b..00000000000 --- a/server/sonar-web/src/main/js/apps/system/components/__tests__/PageActions-test.tsx +++ /dev/null @@ -1,55 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { shallow } from 'enzyme'; -import * as React from 'react'; -import { click } from '../../../../helpers/testUtils'; -import PageActions from '../PageActions'; - -jest.mock('../../utils', () => ({ - getFileNameSuffix: (suffix?: string) => `filesuffix(${suffix || ''})`, -})); - -it('should render correctly', () => { - const wrapper = getWrapper({ serverId: 'MyServerId' }); - expect(wrapper).toMatchSnapshot(); - expect(wrapper.find('Dropdown')).toMatchSnapshot(); -}); - -it('should render without log download', () => { - expect(getWrapper({ canDownloadLogs: false, cluster: true })).toMatchSnapshot(); -}); - -it('should open change log level modal', () => { - const wrapper = getWrapper(); - click(wrapper.find('#edit-logs-level-button')); - expect(wrapper.find('ChangeLogLevelForm')).toHaveLength(1); -}); - -function getWrapper(props = {}) { - return shallow( - {}} - {...props} - /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/system/components/__tests__/PageHeader-test.tsx b/server/sonar-web/src/main/js/apps/system/components/__tests__/PageHeader-test.tsx deleted file mode 100644 index 1865ef065ad..00000000000 --- a/server/sonar-web/src/main/js/apps/system/components/__tests__/PageHeader-test.tsx +++ /dev/null @@ -1,54 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { shallow } from 'enzyme'; -import * as React from 'react'; -import { mockAppState } from '../../../../helpers/testMocks'; -import { PageHeader, Props } from '../PageHeader'; - -jest.mock('../../../../helpers/dates', () => ({ - toShortNotSoISOString: () => '2019-01-01', -})); - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot(); - expect( - shallowRender({ - appState: mockAppState({ productionDatabase: false }), - serverId: 'foo-bar', - version: '7.7.0.1234', - }) - ).toMatchSnapshot('on embedded database'); - expect(shallowRender({ loading: true, showActions: false })).toMatchSnapshot(); - expect(shallowRender({ serverId: 'foo-bar', version: '7.7.0.1234' })).toMatchSnapshot(); -}); - -function shallowRender(props: Partial = {}) { - return shallow( - - ); -} diff --git a/server/sonar-web/src/main/js/apps/system/components/__tests__/StandaloneSysInfos-test.tsx b/server/sonar-web/src/main/js/apps/system/components/__tests__/StandaloneSysInfos-test.tsx deleted file mode 100644 index 44e399c0f03..00000000000 --- a/server/sonar-web/src/main/js/apps/system/components/__tests__/StandaloneSysInfos-test.tsx +++ /dev/null @@ -1,38 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { shallow } from 'enzyme'; -import * as React from 'react'; -import { mockStandaloneSysInfo } from '../../../../helpers/testMocks'; -import StandaloneSysInfos from '../StandaloneSysInfos'; - -it('should render correctly', () => { - expect(getWrapper()).toMatchSnapshot(); -}); - -function getWrapper(props = {}) { - return shallow( - {}} - {...props} - /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/system/components/__tests__/SystemApp-it.tsx b/server/sonar-web/src/main/js/apps/system/components/__tests__/SystemApp-it.tsx new file mode 100644 index 00000000000..295c2a65f58 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/system/components/__tests__/SystemApp-it.tsx @@ -0,0 +1,141 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import { first } from 'lodash'; +import { byRole } from 'testing-library-selector'; +import SystemServiceMock from '../../../../api/mocks/SystemServiceMock'; +import { renderAppRoutes } from '../../../../helpers/testReactTestingUtils'; +import routes from '../../routes'; +import { LogsLevels } from '../../utils'; + +jest.mock('../../../../api/system'); + +const systemMock = new SystemServiceMock(); + +afterEach(() => { + systemMock.reset(); +}); + +describe('System Info Standalone', () => { + it('renders correctly', async () => { + const { user, ui } = getPageObjects(); + renderSystemApp(); + await ui.appIsLoaded(); + + expect(ui.copyIdInformation.get()).toHaveAttribute( + 'data-clipboard-text', + expect.stringContaining(`Server ID: asd564-asd54a-5dsfg45`) + ); + + expect(ui.sectionButton('System').get()).toBeInTheDocument(); + expect(screen.queryByRole('cell', { name: 'High Availability' })).not.toBeInTheDocument(); + await user.click(ui.sectionButton('System').get()); + expect(screen.getByRole('cell', { name: 'High Availability' })).toBeInTheDocument(); + }); + + it('can change logs level', async () => { + const { user, ui } = getPageObjects(); + renderSystemApp(); + expect(await ui.pageHeading.find()).toBeInTheDocument(); + + await user.click(ui.changeLogLevelButton.get()); + expect(ui.logLevelWarning.queryAll()).toHaveLength(0); + await user.click(ui.logLevelsRadioButton(LogsLevels.DEBUG).get()); + expect(ui.logLevelWarning.get()).toHaveTextContent( + 'alert.tooltip.warningsystem.log_level.warning' + ); + + await user.click(ui.saveButton.get()); + expect(ui.logLevelWarning.queryAll()).toHaveLength(2); + }); + + it('can download logs & system info', async () => { + const { user, ui } = getPageObjects(); + renderSystemApp(); + expect(await ui.pageHeading.find()).toBeInTheDocument(); + + await user.click(ui.downloadLogsButton.get()); + ['Main Process', 'Compute Engine', 'Search Engine', 'Web Server', 'Access Logs'].forEach( + (link) => { + expect(screen.getByRole('link', { name: link })).toBeInTheDocument(); + } + ); + expect(ui.downloadSystemInfoButton.get()).toBeInTheDocument(); + }); +}); + +describe('System Info Cluster', () => { + it('renders correctly', async () => { + systemMock.setIsCluster(true); + const { user, ui } = getPageObjects(); + renderSystemApp(); + await ui.appIsLoaded(); + + expect(await ui.pageHeading.find()).toBeInTheDocument(); + + expect(ui.downloadLogsButton.query()).not.toBeInTheDocument(); + expect(ui.downloadSystemInfoButton.get()).toBeInTheDocument(); + + expect(ui.copyIdInformation.get()).toHaveAttribute( + 'data-clipboard-text', + expect.stringContaining(`Server ID: asd564-asd54a-5dsfg45`) + ); + + // Renders health checks + expect(ui.healthCauseWarning.getAll()).toHaveLength(3); + + // Renders App node + expect(first(ui.sectionButton('server1.example.com').getAll())).toBeInTheDocument(); + expect(screen.queryByRole('heading', { name: 'Web Logging' })).not.toBeInTheDocument(); + await user.click(first(ui.sectionButton('server1.example.com').getAll()) as HTMLElement); + expect(screen.getByRole('heading', { name: 'Web Logging' })).toBeInTheDocument(); + }); +}); + +function renderSystemApp() { + return renderAppRoutes('system', routes); +} + +function getPageObjects() { + const user = userEvent.setup(); + + const ui = { + pageHeading: byRole('heading', { name: 'system_info.page' }), + downloadLogsButton: byRole('button', { name: 'system.download_logs' }), + downloadSystemInfoButton: byRole('link', { name: 'system.download_system_info' }), + copyIdInformation: byRole('button', { name: 'copy_to_clipboard' }), + sectionButton: (name: string) => byRole('button', { name }), + changeLogLevelButton: byRole('button', { name: 'system.logs_level.change' }), + logLevelsRadioButton: (name: LogsLevels) => byRole('radio', { name }), + logLevelWarning: byRole('alert'), + healthCauseWarning: byRole('alert'), + saveButton: byRole('button', { name: 'save' }), + }; + + async function appIsLoaded() { + expect(await ui.pageHeading.find()).toBeInTheDocument(); + } + + return { + ui: { ...ui, appIsLoaded }, + user, + }; +} diff --git a/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/App-test.tsx.snap b/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/App-test.tsx.snap deleted file mode 100644 index aeffef45a27..00000000000 --- a/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/App-test.tsx.snap +++ /dev/null @@ -1,323 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly: cluster sysinfo 1`] = ` -
- - -
- -
- - -
-`; - -exports[`should render correctly: loading 1`] = ` -
- - -
- -
-
-`; - -exports[`should render correctly: stand-alone sysinfo 1`] = ` -
- - -
- -
- - -
-`; diff --git a/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/ChangeLogLevelForm-test.tsx.snap b/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/ChangeLogLevelForm-test.tsx.snap deleted file mode 100644 index 35853191a1a..00000000000 --- a/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/ChangeLogLevelForm-test.tsx.snap +++ /dev/null @@ -1,219 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should display some warning messages for non INFO levels 1`] = ` - -
-
-

- system.set_log_level -

-
-
-

- - -

-

- - -

-

- - -

- - Foo - - - system.log_level.warning - -
-
- - save - - - cancel - -
-
-
-`; - -exports[`should render correctly 1`] = ` - -
-
-

- system.set_log_level -

-
-
-

- - -

-

- - -

-

- - -

- - Foo - -
-
- - save - - - cancel - -
-
-
-`; diff --git a/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/ClusterSysInfos-test.tsx.snap b/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/ClusterSysInfos-test.tsx.snap deleted file mode 100644 index 6f44479f0e0..00000000000 --- a/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/ClusterSysInfos-test.tsx.snap +++ /dev/null @@ -1,88 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should support more than two nodes 1`] = ` - - -
  • - system.application_nodes_title -
  • - -
  • - system.search_nodes_title -
  • - -
    -`; diff --git a/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/PageActions-test.tsx.snap b/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/PageActions-test.tsx.snap deleted file mode 100644 index 0df51df6a79..00000000000 --- a/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/PageActions-test.tsx.snap +++ /dev/null @@ -1,220 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` -
    - - - system.logs_level - : - - INFO - - - - - -
  • - - Main Process - -
  • -
  • - - Compute Engine - -
  • -
  • - - Search Engine - -
  • -
  • - - Web Server - -
  • -
  • - - Access Logs - -
  • - - } - > - -
    - - system.download_system_info - -
    -`; - -exports[`should render correctly 2`] = ` - -
  • - - Main Process - -
  • -
  • - - Compute Engine - -
  • -
  • - - Search Engine - -
  • -
  • - - Web Server - -
  • -
  • - - Access Logs - -
  • - - } -> - -
    -`; - -exports[`should render without log download 1`] = ` -
    - - - system.logs_level - : - - INFO - - - - - - system.download_system_info - -
    -`; diff --git a/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/PageHeader-test.tsx.snap b/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/PageHeader-test.tsx.snap deleted file mode 100644 index c8ef70f9e61..00000000000 --- a/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/PageHeader-test.tsx.snap +++ /dev/null @@ -1,182 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` -
    -

    - system_info.page -

    - -
    -`; - -exports[`should render correctly 2`] = ` -
    -

    - system_info.page -

    -
    - -
    -
    -`; - -exports[`should render correctly 3`] = ` -
    -

    - system_info.page -

    - -
    -
    -
    - - - - - - - - - - - -
    - - system.server_id - - - - foo-bar - -
    - - system.version - - - 7.7.0.1234 -
    -
    - - system.copy_id_info - -
    -
    -
    -`; - -exports[`should render correctly: on embedded database 1`] = ` -
    -

    - system_info.page -

    - -
    - - system.not_production_database_warning - -
    -
    - - - - - - - - - - - -
    - - system.server_id - - - - foo-bar - -
    - - system.version - - - 7.7.0.1234 -
    -
    - - system.copy_id_info - -
    -
    -
    -`; diff --git a/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/StandaloneSysInfos-test.tsx.snap b/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/StandaloneSysInfos-test.tsx.snap deleted file mode 100644 index a5e38efa9cf..00000000000 --- a/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/StandaloneSysInfos-test.tsx.snap +++ /dev/null @@ -1,105 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` - - - - - - -`; diff --git a/server/sonar-web/src/main/js/apps/system/components/info-items/HealthCard.tsx b/server/sonar-web/src/main/js/apps/system/components/info-items/HealthCard.tsx index d8c78cebf83..7578f442834 100644 --- a/server/sonar-web/src/main/js/apps/system/components/info-items/HealthCard.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/info-items/HealthCard.tsx @@ -22,14 +22,14 @@ import * as React from 'react'; import BoxedGroupAccordion from '../../../../components/controls/BoxedGroupAccordion'; import { Alert } from '../../../../components/ui/Alert'; import { translate } from '../../../../helpers/l10n'; -import { HealthType, SysInfoValueObject } from '../../../../types/types'; -import { getLogsLevel, groupSections, LOGS_LEVELS } from '../../utils'; +import { HealthTypes, SysInfoValueObject } from '../../../../types/types'; +import { getLogsLevel, groupSections, LogsLevels } from '../../utils'; import HealthItem from './HealthItem'; import Section from './Section'; interface Props { biggerHealth?: boolean; - health?: HealthType; + health?: HealthTypes; healthCauses?: string[]; onClick: (toggledCard: string) => void; open: boolean; @@ -50,7 +50,7 @@ export default function HealthCard({ const showFields = open && mainSection && Object.keys(mainSection).length > 0; const showSections = open && sections; const logLevel = getLogsLevel(sysInfoData); - const showLogLevelWarning = logLevel && logLevel !== LOGS_LEVELS[0]; + const showLogLevelWarning = logLevel && logLevel !== LogsLevels.INFO; return ( {healthCause} diff --git a/server/sonar-web/src/main/js/apps/system/components/info-items/HealthItem.tsx b/server/sonar-web/src/main/js/apps/system/components/info-items/HealthItem.tsx index 089f94cb469..733c28d218c 100644 --- a/server/sonar-web/src/main/js/apps/system/components/info-items/HealthItem.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/info-items/HealthItem.tsx @@ -22,26 +22,27 @@ import * as React from 'react'; import StatusIndicator from '../../../../components/common/StatusIndicator'; import Tooltip from '../../../../components/controls/Tooltip'; import { translateWithParameters } from '../../../../helpers/l10n'; -import { HealthType } from '../../../../types/types'; +import { HealthTypes } from '../../../../types/types'; import HealthCauseItem from './HealthCauseItem'; interface Props { biggerHealth?: boolean; name?: string; className?: string; - health: HealthType; + health: HealthTypes; healthCauses?: string[]; } export default function HealthItem({ biggerHealth, className, name, health, healthCauses }: Props) { - const hasHealthCauses = healthCauses && healthCauses.length > 0 && health !== 'GREEN'; + const hasHealthCauses = healthCauses && healthCauses.length > 0 && health !== HealthTypes.GREEN; + const statusIndicator = ( ); return (
    {hasHealthCauses && - healthCauses!.map((cause, idx) => ( + healthCauses.map((cause, idx) => ( ))} {name ? ( diff --git a/server/sonar-web/src/main/js/apps/system/components/info-items/SysInfoItem.tsx b/server/sonar-web/src/main/js/apps/system/components/info-items/SysInfoItem.tsx index 2af1e1ff403..103534b08d4 100644 --- a/server/sonar-web/src/main/js/apps/system/components/info-items/SysInfoItem.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/info-items/SysInfoItem.tsx @@ -20,7 +20,7 @@ import { map } from 'lodash'; import * as React from 'react'; import { translate } from '../../../../helpers/l10n'; -import { HealthType, SysInfoValue } from '../../../../types/types'; +import { HealthTypes, SysInfoValue } from '../../../../types/types'; import { HEALTH_FIELD, STATE_FIELD } from '../../utils'; import HealthItem from './HealthItem'; @@ -31,7 +31,7 @@ export interface Props { export default function SysInfoItem({ name, value }: Props) { if (name === HEALTH_FIELD || name === STATE_FIELD) { - return ; + return ; } if (value instanceof Array) { return {JSON.stringify(value)}; diff --git a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/HealthCard-test.tsx b/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/HealthCard-test.tsx deleted file mode 100644 index 718a7cba945..00000000000 --- a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/HealthCard-test.tsx +++ /dev/null @@ -1,59 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { shallow } from 'enzyme'; -import * as React from 'react'; -import HealthCard from '../HealthCard'; - -it('should render correctly', () => { - expect(getWrapper()).toMatchSnapshot(); -}); - -it('should show a main section and multiple sub sections', () => { - const sysInfoData = { - Name: 'foo', - bar: 'Bar', - Database: { db: 'test' }, - Elasticseach: { Elastic: 'search' }, - }; - expect(getWrapper({ open: true, sysInfoData })).toMatchSnapshot(); -}); - -it('should display the log level alert', () => { - expect( - getWrapper({ sysInfoData: { 'Logs Level': 'DEBUG' } }) - .dive() - .find('Alert') - ).toMatchSnapshot(); -}); - -function getWrapper(props = {}) { - return shallow( - {}} - open={false} - sysInfoData={{}} - {...props} - /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/HealthCauseItem-test.tsx b/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/HealthCauseItem-test.tsx deleted file mode 100644 index c46e2567ece..00000000000 --- a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/HealthCauseItem-test.tsx +++ /dev/null @@ -1,27 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { shallow } from 'enzyme'; -import * as React from 'react'; -import HealthCauseItem from '../HealthCauseItem'; - -it('should render correctly', () => { - expect(shallow()).toMatchSnapshot(); - expect(shallow()).toMatchSnapshot(); -}); diff --git a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/HealthItem-test.tsx b/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/HealthItem-test.tsx deleted file mode 100644 index dce1e1f8f24..00000000000 --- a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/HealthItem-test.tsx +++ /dev/null @@ -1,37 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { shallow } from 'enzyme'; -import * as React from 'react'; -import HealthItem from '../HealthItem'; - -it('should render correctly', () => { - expect( - shallow() - ).toMatchSnapshot(); -}); - -it('should not render health causes', () => { - expect(shallow()).toMatchSnapshot(); - expect(shallow()).toMatchSnapshot(); -}); - -it('should render multiple health causes', () => { - expect(shallow()).toMatchSnapshot(); -}); diff --git a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/Section-test.tsx b/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/Section-test.tsx deleted file mode 100644 index 8a109644cc5..00000000000 --- a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/Section-test.tsx +++ /dev/null @@ -1,32 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { shallow } from 'enzyme'; -import * as React from 'react'; -import Section from '../Section'; - -it('should render correctly', () => { - expect( - shallow(
    ) - ).toMatchSnapshot(); -}); - -it('should not render a title', () => { - expect(shallow(
    )).toMatchSnapshot(); -}); diff --git a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/SysInfoItem-test.tsx b/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/SysInfoItem-test.tsx deleted file mode 100644 index 4f8913f1fe3..00000000000 --- a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/SysInfoItem-test.tsx +++ /dev/null @@ -1,38 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { shallow } from 'enzyme'; -import * as React from 'react'; -import HealthItem from '../HealthItem'; -import SysInfoItem, { Props } from '../SysInfoItem'; - -it('should render correctly', () => { - expect(shallowRender('/some/path/as/an/example')).toMatchSnapshot('string'); - expect(shallowRender({ foo: 'Far', bar: { a: 1, b: 'b' }, baz: true })).toMatchSnapshot('object'); - expect(shallowRender(true)).toMatchSnapshot('true'); - expect(shallowRender(false)).toMatchSnapshot('false'); -}); - -it('should render health item', () => { - expect(shallowRender('GREEN', 'Health').find(HealthItem).prop('health')).toBe('GREEN'); -}); - -function shallowRender(value: Props['value'], name: Props['name'] = 'foo') { - return shallow(); -} diff --git a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/HealthCard-test.tsx.snap b/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/HealthCard-test.tsx.snap deleted file mode 100644 index c2312372cea..00000000000 --- a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/HealthCard-test.tsx.snap +++ /dev/null @@ -1,58 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should display the log level alert 1`] = ` - - system.log_level.warning.short - -`; - -exports[`should render correctly 1`] = ` - -`; - -exports[`should show a main section and multiple sub sections 1`] = ` - -
    -
    -
    - -`; diff --git a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/HealthCauseItem-test.tsx.snap b/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/HealthCauseItem-test.tsx.snap deleted file mode 100644 index 900bbd1a029..00000000000 --- a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/HealthCauseItem-test.tsx.snap +++ /dev/null @@ -1,21 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` - - foo - -`; - -exports[`should render correctly 2`] = ` - - foo - -`; diff --git a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/HealthItem-test.tsx.snap b/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/HealthItem-test.tsx.snap deleted file mode 100644 index 8f8a741f4b0..00000000000 --- a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/HealthItem-test.tsx.snap +++ /dev/null @@ -1,66 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should not render health causes 1`] = ` -
    - -
    -`; - -exports[`should not render health causes 2`] = ` -
    - -
    -`; - -exports[`should render correctly 1`] = ` -
    - - - - - - -
    -`; - -exports[`should render multiple health causes 1`] = ` -
    - - - -
    -`; diff --git a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/Section-test.tsx.snap b/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/Section-test.tsx.snap deleted file mode 100644 index b2a00b9c039..00000000000 --- a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/Section-test.tsx.snap +++ /dev/null @@ -1,133 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should not render a title 1`] = ` -
    - - - - - - - -
    -
    - foo -
    -
    - -
    -
    -`; - -exports[`should render correctly 1`] = ` -
    -

    - foo -

    - - - - - - - - - - - - - - - -
    -
    - foo -
    -
    - -
    -
    - bar -
    -
    - -
    -
    - baz -
    -
    - -
    -
    -`; diff --git a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/SysInfoItem-test.tsx.snap b/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/SysInfoItem-test.tsx.snap deleted file mode 100644 index 26fb233e4a4..00000000000 --- a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/SysInfoItem-test.tsx.snap +++ /dev/null @@ -1,78 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly: false 1`] = ` - - no - -`; - -exports[`should render correctly: object 1`] = ` - - - - - - - - - - - - - - - -
    - foo - - -
    - bar - - -
    - baz - - -
    -`; - -exports[`should render correctly: string 1`] = ` - - /some/path/as/an/example - -`; - -exports[`should render correctly: true 1`] = ` - - yes - -`; diff --git a/server/sonar-web/src/main/js/apps/system/utils.ts b/server/sonar-web/src/main/js/apps/system/utils.ts index bc41e843035..69fc7e55d4f 100644 --- a/server/sonar-web/src/main/js/apps/system/utils.ts +++ b/server/sonar-web/src/main/js/apps/system/utils.ts @@ -36,8 +36,14 @@ export interface Query { expandedCards: string[]; } -export const LOGS_LEVELS = ['INFO', 'DEBUG', 'TRACE']; -const DEFAULT_LOG_LEVEL = LOGS_LEVELS[0]; +export enum LogsLevels { + INFO = 'INFO', + DEBUG = 'DEBUG', + TRACE = 'TRACE', +} + +export const LOGS_LEVELS = Object.values(LogsLevels); +const DEFAULT_LOG_LEVEL = LogsLevels.INFO; export const APP_NODES_FIELD = 'Application Nodes'; export const ALMS_FIELD = 'ALMs'; @@ -84,17 +90,17 @@ export function getHealthCauses(sysInfoObject: SysInfoBase) { return sysInfoObject[HEALTH_CAUSES_FIELD]; } -export function getLogsLevel(sysInfoObject?: SysInfoValueObject): string { +export function getLogsLevel(sysInfoObject?: SysInfoValueObject): LogsLevels { if (sysInfoObject !== undefined) { if (isLogInfoBlock(sysInfoObject)) { - return sysInfoObject[LOGS_LEVEL_FIELD]; + return sysInfoObject[LOGS_LEVEL_FIELD] as LogsLevels; } else if (hasLoggingInfo(sysInfoObject)) { return sortBy( [ getLogsLevel(sysInfoObject[WEB_LOGGING_FIELD]), getLogsLevel(sysInfoObject[CE_LOGGING_FIELD]), ], - (logLevel) => LOGS_LEVELS.indexOf(logLevel) + (logLevel: LogsLevels) => LOGS_LEVELS.indexOf(logLevel) )[1]; } } @@ -140,13 +146,13 @@ export function getClusterVersion(sysInfoData: SysInfoCluster): string | undefin export function getSystemLogsLevel(sysInfoData: SysInfoCluster | SysInfoStandalone): string { if (isCluster(sysInfoData)) { - const logLevels = sortBy(getAppNodes(sysInfoData).map(getLogsLevel), (logLevel) => + const logLevels = sortBy(getAppNodes(sysInfoData).map(getLogsLevel), (logLevel: LogsLevels) => LOGS_LEVELS.indexOf(logLevel) ); return logLevels.length > 0 ? logLevels[logLevels.length - 1] : DEFAULT_LOG_LEVEL; - } else { - return getLogsLevel(sysInfoData); } + + return getLogsLevel(sysInfoData); } export function getNodeName(nodeInfo: SysInfoAppNode | SysInfoSearchNode): string { diff --git a/server/sonar-web/src/main/js/helpers/testMocks.ts b/server/sonar-web/src/main/js/helpers/testMocks.ts index 40521eaeac6..c5646eff516 100644 --- a/server/sonar-web/src/main/js/helpers/testMocks.ts +++ b/server/sonar-web/src/main/js/helpers/testMocks.ts @@ -21,6 +21,7 @@ import { To } from 'react-router-dom'; import { CompareResponse } from '../api/quality-profiles'; import { RuleDescriptionSections } from '../apps/coding-rules/rule'; import { Exporter, Profile } from '../apps/quality-profiles/types'; +import { LogsLevels } from '../apps/system/utils'; import { Location, Router } from '../components/hoc/withRouter'; import { AppState } from '../types/appstate'; import { RuleRepository } from '../types/coding-rules'; @@ -35,7 +36,7 @@ import { Condition, FlowLocation, Group, - HealthType, + HealthTypes, IdentityProvider, Issue, Measure, @@ -50,6 +51,7 @@ import { RuleParameter, SysInfoBase, SysInfoCluster, + SysInfoLogging, SysInfoStandalone, } from '../types/types'; import { CurrentUser, LoggedInUser, User } from '../types/users'; @@ -78,7 +80,7 @@ export function mockAppState(overrides: Partial = {}): AppState { export function mockBaseSysInfo(overrides: Partial = {}): SysInfoBase { return { - Health: 'GREEN' as HealthType, + Health: HealthTypes.GREEN, 'Health Causes': [], System: { Version: '7.8', @@ -119,10 +121,10 @@ export function mockClusterSysInfo(overrides: Partial = {}): SysInfoCluster }, 'Application Nodes': [ { - Name: 'server9.example.com', + Name: 'server1.example.com', Host: '10.0.0.0', - Health: 'GREEN' as HealthType, - 'Health Causes': [], + Health: HealthTypes.RED, + 'Health Causes': ['Something is wrong'], System: { Version: '7.8', }, @@ -162,10 +164,10 @@ export function mockClusterSysInfo(overrides: Partial = {}): SysInfoCluster }, }, { - Name: 'server9.example.com', + Name: 'server2.example.com', Host: '10.0.0.0', - Health: 'GREEN' as HealthType, - 'Health Causes': [], + Health: HealthTypes.YELLOW, + 'Health Causes': ['Friendly warning'], System: { Version: '7.8', }, @@ -208,7 +210,7 @@ export function mockClusterSysInfo(overrides: Partial = {}): SysInfoCluster ], 'Search Nodes': [ { - Name: 'server.example.com', + Name: 'server1.example.com', Host: '10.0.0.0', 'Search State': { 'CPU Usage (%)': 0, @@ -216,7 +218,7 @@ export function mockClusterSysInfo(overrides: Partial = {}): SysInfoCluster }, }, { - Name: 'server.example.com', + Name: 'server2.example.com', Host: '10.0.0.0', 'Search State': { 'CPU Usage (%)': 0, @@ -224,7 +226,7 @@ export function mockClusterSysInfo(overrides: Partial = {}): SysInfoCluster }, }, { - Name: 'server.example.com', + Name: 'server3.example.com', Host: '10.0.0.0', 'Search State': { 'CPU Usage (%)': 0, @@ -608,6 +610,10 @@ export function mockRuleDetailsParameter(overrides: Partial = {}) }; } +export function mockLogs(logsLevel: LogsLevels = LogsLevels.INFO): SysInfoLogging { + return { 'Logs Level': logsLevel, 'Logs Dir': '/logs' }; +} + export function mockStandaloneSysInfo(overrides: Partial = {}): SysInfoStandalone { const baseInfo = mockBaseSysInfo(overrides); return { @@ -629,7 +635,7 @@ export function mockStandaloneSysInfo(overrides: Partial = {}): SysInfoStan 'Pool Active Connections': 0, 'Pool Max Connections': 60, }, - 'Web Logging': { 'Logs Level': 'INFO', 'Logs Dir': '/logs' }, + 'Web Logging': mockLogs(), 'Web JVM Properties': { 'file.encoding': 'UTF-8', 'file.separator': '/', @@ -646,10 +652,7 @@ export function mockStandaloneSysInfo(overrides: Partial = {}): SysInfoStan 'Pool Initial Size': 0, 'Pool Active Connections': 0, }, - 'Compute Engine Logging': { - 'Logs Level': 'DEBUG', - 'Logs Dir': '/logs', - }, + 'Compute Engine Logging': mockLogs(), 'Compute Engine JVM Properties': { 'file.encoding': 'UTF-8', 'file.separator': '/', diff --git a/server/sonar-web/src/main/js/types/types.ts b/server/sonar-web/src/main/js/types/types.ts index 8ee9858b8f1..c7dea270668 100644 --- a/server/sonar-web/src/main/js/types/types.ts +++ b/server/sonar-web/src/main/js/types/types.ts @@ -222,7 +222,11 @@ export interface Group { managed: boolean; } -export type HealthType = 'RED' | 'YELLOW' | 'GREEN'; +export enum HealthTypes { + RED = 'RED', + YELLOW = 'YELLOW', + GREEN = 'GREEN', +} export interface IdentityProvider { backgroundColor: string; @@ -680,7 +684,7 @@ export interface SysInfoAppNode extends SysInfoBase { } export interface SysInfoBase extends SysInfoValueObject { - Health: HealthType; + Health: HealthTypes; 'Health Causes': string[]; Plugins?: Dict; System: { @@ -732,7 +736,7 @@ export type SysInfoValue = | string | number | undefined - | HealthType + | HealthTypes | SysInfoValueObject | SysInfoValueArray; -- 2.39.5