Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Item-test.tsx 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 { click } from 'sonar-ui-common/helpers/testUtils';
  23. import Item from '../Item';
  24. const metric = { id: '3', key: 'foo', name: 'Foo', type: 'INT' };
  25. it('should render', () => {
  26. expect(
  27. shallow(<Item metric={metric} onDelete={jest.fn()} onEdit={jest.fn()} />)
  28. ).toMatchSnapshot();
  29. });
  30. it('should edit metric', () => {
  31. const onEdit = jest.fn();
  32. const wrapper = shallow(
  33. <Item
  34. domains={['Coverage', 'Issues']}
  35. metric={metric}
  36. onDelete={jest.fn()}
  37. onEdit={onEdit}
  38. types={['INT', 'STRING']}
  39. />
  40. );
  41. click(wrapper.find('.js-metric-update'));
  42. wrapper.update();
  43. wrapper.find('Form').prop<Function>('onSubmit')({
  44. ...metric,
  45. description: 'bla bla',
  46. domain: 'Coverage'
  47. });
  48. expect(onEdit).toBeCalledWith({ ...metric, description: 'bla bla', domain: 'Coverage' });
  49. });
  50. it('should delete metric', () => {
  51. const onDelete = jest.fn();
  52. const wrapper = shallow(<Item metric={metric} onDelete={onDelete} onEdit={jest.fn()} />);
  53. click(wrapper.find('.js-metric-delete'));
  54. wrapper.update();
  55. wrapper.find('DeleteForm').prop<Function>('onSubmit')();
  56. expect(onDelete).toBeCalledWith('foo');
  57. });