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.

SystemUpgrade-test.tsx 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 userEvent from '@testing-library/user-event';
  21. import React from 'react';
  22. import { mockAppState } from '../../../helpers/testMocks';
  23. import { renderComponent } from '../../../helpers/testReactTestingUtils';
  24. import { byRole, byText } from '../../../helpers/testSelector';
  25. import SystemUpgradeButton from '../SystemUpgradeButton';
  26. import { UpdateUseCase } from '../utils';
  27. const ui = {
  28. learnMoreButton: byRole('button', { name: 'learn_more' }),
  29. header: byRole('heading', { name: 'system.system_upgrade' }),
  30. downloadLink: byRole('link', { name: /system.see_sonarqube_downloads/ }),
  31. ltaVersionHeader: byRole('heading', { name: /system.lta_version/ }),
  32. newPatchWarning: byText(/admin_notification.update/),
  33. };
  34. it('should render properly', async () => {
  35. const user = userEvent.setup();
  36. renderSystemUpgradeButton();
  37. await user.click(ui.learnMoreButton.get());
  38. expect(ui.header.get()).toBeInTheDocument();
  39. expect(ui.ltaVersionHeader.get()).toBeInTheDocument();
  40. expect(ui.downloadLink.get()).toBeInTheDocument();
  41. });
  42. it('should render properly for new patch', async () => {
  43. const user = userEvent.setup();
  44. renderSystemUpgradeButton(
  45. {
  46. updateUseCase: UpdateUseCase.NewPatch,
  47. latestLTA: '9.9',
  48. systemUpgrades: [{ downloadUrl: '', version: '9.9.1' }],
  49. },
  50. '9.9',
  51. );
  52. await user.click(ui.learnMoreButton.get());
  53. expect(ui.header.get()).toBeInTheDocument();
  54. expect(ui.newPatchWarning.get()).toBeInTheDocument();
  55. expect(ui.ltaVersionHeader.get()).toBeInTheDocument();
  56. expect(ui.downloadLink.get()).toBeInTheDocument();
  57. });
  58. function renderSystemUpgradeButton(
  59. props: Partial<React.ComponentPropsWithoutRef<typeof SystemUpgradeButton>> = {},
  60. version = '9.7',
  61. ) {
  62. renderComponent(
  63. <SystemUpgradeButton
  64. updateUseCase={UpdateUseCase.NewVersion}
  65. latestLTA="9.9"
  66. systemUpgrades={[
  67. { downloadUrl: 'eight', version: '9.8' },
  68. { downloadUrl: 'lts', version: '9.9' },
  69. { downloadUrl: 'patch', version: '9.9.1' },
  70. ]}
  71. {...props}
  72. />,
  73. '',
  74. { appState: mockAppState({ version }) },
  75. );
  76. }