選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

TaskActions-test.tsx 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2022 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 { shallow } from 'enzyme';
  21. import * as React from 'react';
  22. import { mockTask } from '../../../../helpers/mocks/tasks';
  23. import { click } from '../../../../helpers/testUtils';
  24. import { Task, TaskStatuses } from '../../../../types/tasks';
  25. import TaskActions from '../TaskActions';
  26. it('renders', () => {
  27. expect(shallowRender()).toMatchSnapshot();
  28. expect(shallowRender({ status: TaskStatuses.Success })).toMatchSnapshot();
  29. expect(shallowRender({ hasScannerContext: true })).toMatchSnapshot();
  30. expect(shallowRender({ errorMessage: 'error!' })).toMatchSnapshot();
  31. expect(shallowRender({}, { component: { key: 'foo' } })).toMatchSnapshot();
  32. });
  33. it('shows stack trace', () => {
  34. const wrapper = shallowRender({ errorMessage: 'error!' });
  35. click(wrapper.find('.js-task-show-stacktrace'));
  36. expect(wrapper.find('Stacktrace')).toMatchSnapshot();
  37. wrapper.find('Stacktrace').prop<Function>('onClose')();
  38. wrapper.update();
  39. expect(wrapper.find('Stacktrace').exists()).toBe(false);
  40. });
  41. it('shows scanner context', () => {
  42. const wrapper = shallowRender({ hasScannerContext: true });
  43. click(wrapper.find('.js-task-show-scanner-context'));
  44. expect(wrapper.find('ScannerContext')).toMatchSnapshot();
  45. wrapper.find('ScannerContext').prop<Function>('onClose')();
  46. wrapper.update();
  47. expect(wrapper.find('ScannerContext').exists()).toBe(false);
  48. });
  49. it('shows warnings', () => {
  50. const wrapper = shallowRender({ warningCount: 2 });
  51. click(wrapper.find('.js-task-show-warnings'));
  52. expect(wrapper.find('withCurrentUserContext(AnalysisWarningsModal)')).toMatchSnapshot();
  53. wrapper.find('withCurrentUserContext(AnalysisWarningsModal)').prop<Function>('onClose')();
  54. wrapper.update();
  55. expect(wrapper.find('withCurrentUserContext(AnalysisWarningsModal)').exists()).toBe(false);
  56. });
  57. function shallowRender(fields?: Partial<Task>, props?: Partial<TaskActions['props']>) {
  58. return shallow(
  59. <TaskActions
  60. onCancelTask={jest.fn()}
  61. onFilterTask={jest.fn()}
  62. task={mockTask({ ...fields })}
  63. {...props}
  64. />
  65. );
  66. }