You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SystemApp-it.tsx 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2024 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import { screen } from '@testing-library/react';
  21. import userEvent from '@testing-library/user-event';
  22. import { first } from 'lodash';
  23. import SystemServiceMock from '../../../../api/mocks/SystemServiceMock';
  24. import { renderAppRoutes } from '../../../../helpers/testReactTestingUtils';
  25. import { byRole, byText } from '../../../../helpers/testSelector';
  26. import { AppState } from '../../../../types/appstate';
  27. import routes from '../../routes';
  28. import { LogsLevels } from '../../utils';
  29. const systemMock = new SystemServiceMock();
  30. afterEach(() => {
  31. systemMock.reset();
  32. });
  33. describe('System Info Standalone', () => {
  34. it('renders correctly', async () => {
  35. const { user, ui } = getPageObjects();
  36. renderSystemApp();
  37. await ui.appIsLoaded();
  38. expect(ui.copyIdInformation.get()).toHaveAttribute(
  39. 'data-clipboard-text',
  40. expect.stringContaining(`Server ID: asd564-asd54a-5dsfg45`),
  41. );
  42. expect(ui.sectionButton('System').get()).toBeInTheDocument();
  43. expect(screen.queryByRole('cell', { name: 'High Availability' })).not.toBeInTheDocument();
  44. await user.click(ui.sectionButton('System').get());
  45. expect(screen.getByRole('cell', { name: 'High Availability' })).toBeInTheDocument();
  46. });
  47. it('can change logs level', async () => {
  48. const { user, ui } = getPageObjects();
  49. renderSystemApp();
  50. await ui.appIsLoaded();
  51. await user.click(ui.changeLogLevelButton.get());
  52. expect(ui.logLevelWarning.queryAll()).toHaveLength(0);
  53. await user.click(ui.logLevelsRadioButton(LogsLevels.DEBUG).get());
  54. expect(ui.logLevelWarning.get()).toBeInTheDocument();
  55. await user.click(ui.saveButton.get());
  56. expect(ui.logLevelWarningShort.queryAll()).toHaveLength(2);
  57. });
  58. it('can download logs & system info', async () => {
  59. const { user, ui } = getPageObjects();
  60. renderSystemApp();
  61. expect(await ui.pageHeading.find()).toBeInTheDocument();
  62. await user.click(ui.downloadLogsButton.get());
  63. [
  64. 'Main Process',
  65. 'Compute Engine',
  66. 'Search Engine',
  67. 'Web Server',
  68. 'Access Logs',
  69. 'Deprecation Logs',
  70. ].forEach((name) => {
  71. expect(screen.getByRole('menuitem', { name })).toBeInTheDocument();
  72. });
  73. expect(ui.downloadSystemInfoButton.get()).toBeInTheDocument();
  74. });
  75. it('should render current version and status', async () => {
  76. const { ui } = getPageObjects();
  77. renderSystemApp();
  78. await ui.appIsLoaded();
  79. expect(ui.versionLabel('7.8').get()).toBeInTheDocument();
  80. expect(ui.ltaDocumentationLinkActive.get()).toBeInTheDocument();
  81. });
  82. });
  83. describe('System Info Cluster', () => {
  84. it('renders correctly', async () => {
  85. systemMock.setIsCluster(true);
  86. const { user, ui } = getPageObjects();
  87. renderSystemApp();
  88. await ui.appIsLoaded();
  89. expect(ui.downloadLogsButton.query()).not.toBeInTheDocument();
  90. expect(ui.downloadSystemInfoButton.get()).toBeInTheDocument();
  91. expect(ui.copyIdInformation.get()).toHaveAttribute(
  92. 'data-clipboard-text',
  93. expect.stringContaining(`Server ID: asd564-asd54a-5dsfg45`),
  94. );
  95. // Renders health checks
  96. expect(ui.healthCauseWarning.get()).toBeInTheDocument();
  97. // Renders App node
  98. expect(first(ui.sectionButton('server1.example.com').getAll())).toBeInTheDocument();
  99. expect(screen.queryByRole('heading', { name: 'Web Logging' })).not.toBeInTheDocument();
  100. await user.click(first(ui.sectionButton('server1.example.com').getAll()) as HTMLElement);
  101. expect(screen.getByRole('heading', { name: 'Web Logging' })).toBeInTheDocument();
  102. });
  103. it('should render current version and status', async () => {
  104. systemMock.setIsCluster(true);
  105. const { ui } = getPageObjects();
  106. renderSystemApp();
  107. await ui.appIsLoaded();
  108. expect(ui.versionLabel('7.8').get()).toBeInTheDocument();
  109. expect(ui.ltaDocumentationLinkActive.get()).toBeInTheDocument();
  110. });
  111. });
  112. function renderSystemApp(appState?: AppState) {
  113. return renderAppRoutes('system', routes, { appState });
  114. }
  115. function getPageObjects() {
  116. const user = userEvent.setup();
  117. const ui = {
  118. pageHeading: byRole('heading', { name: 'system_info.page' }),
  119. downloadLogsButton: byRole('button', { name: 'system.download_logs' }),
  120. downloadSystemInfoButton: byRole('link', { name: 'system.download_system_info' }),
  121. copyIdInformation: byRole('button', { name: 'system.copy_id_info' }),
  122. sectionButton: (name: string) => byRole('button', { name }),
  123. changeLogLevelButton: byRole('button', { name: 'system.logs_level.change' }),
  124. logLevelsRadioButton: (name: LogsLevels) => byRole('radio', { name }),
  125. logLevelWarning: byText('system.log_level.warning'),
  126. logLevelWarningShort: byText('system.log_level.warning.short'),
  127. healthCauseWarning: byText('Friendly warning'),
  128. saveButton: byRole('button', { name: 'save' }),
  129. versionLabel: (version?: string) =>
  130. version ? byText(/footer\.version\s*(\d.\d)/) : byText(/footer\.version/),
  131. ltaDocumentationLinkActive: byRole('link', {
  132. name: `footer.version.status.active open_in_new_window`,
  133. }),
  134. };
  135. async function appIsLoaded() {
  136. expect(await ui.pageHeading.find()).toBeInTheDocument();
  137. }
  138. return {
  139. ui: { ...ui, appIsLoaded },
  140. user,
  141. };
  142. }