Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

App-test.tsx 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 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 { waitAndUpdate } from 'sonar-ui-common/helpers/testUtils';
  23. import App from '../App';
  24. jest.mock('../../../../api/metrics', () => ({
  25. getMetricDomains: () => Promise.resolve(['Coverage', 'Issues']),
  26. getMetricTypes: () => Promise.resolve(['INT', 'STRING']),
  27. getMetrics: () =>
  28. Promise.resolve({
  29. metrics: [{ id: '3', key: 'foo', name: 'Foo', type: 'INT' }],
  30. p: 1,
  31. ps: 1,
  32. total: 1
  33. }),
  34. deleteMetric: () => Promise.resolve(),
  35. updateMetric: () => Promise.resolve(),
  36. createMetric: () =>
  37. Promise.resolve({ id: '4', domain: 'Coverage', key: 'bar', name: 'Bar', type: 'INT' })
  38. }));
  39. it('should work', async () => {
  40. const wrapper = shallow<App>(<App />);
  41. wrapper.instance().mounted = true;
  42. expect(wrapper).toMatchSnapshot();
  43. await waitAndUpdate(wrapper);
  44. expect(wrapper).toMatchSnapshot();
  45. // create
  46. wrapper.find('Header').prop<Function>('onCreate')({
  47. domain: 'Coverage',
  48. key: 'bar',
  49. name: 'Bar',
  50. type: 'INT'
  51. });
  52. await waitAndUpdate(wrapper);
  53. expect(wrapper.state().metrics).toMatchSnapshot();
  54. expect(wrapper.state().paging!.total).toBe(2);
  55. // edit
  56. wrapper.find('List').prop<Function>('onEdit')({
  57. domain: undefined,
  58. id: '4',
  59. key: 'bar',
  60. name: 'Bar',
  61. type: 'STRING'
  62. });
  63. await waitAndUpdate(wrapper);
  64. expect(wrapper.state().metrics).toMatchSnapshot();
  65. expect(wrapper.state().paging!.total).toBe(2);
  66. // delete
  67. wrapper.find('List').prop<Function>('onDelete')('bar');
  68. await waitAndUpdate(wrapper);
  69. expect(wrapper.state().metrics).toMatchSnapshot();
  70. expect(wrapper.state().paging!.total).toBe(1);
  71. });