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.

App-test.tsx 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 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. /* eslint-disable import/first, import/order */
  21. jest.mock('../../../../api/measures', () => ({
  22. getMeasures: jest.fn(() => Promise.resolve([]))
  23. }));
  24. jest.mock('../../../../api/components', () => ({
  25. getChildren: jest.fn(() => Promise.resolve({ components: [], paging: { total: 0 } }))
  26. }));
  27. import * as React from 'react';
  28. import { shallow, mount } from 'enzyme';
  29. import { App } from '../App';
  30. const getMeasures = require('../../../../api/measures').getMeasures as jest.Mock<any>;
  31. const getChildren = require('../../../../api/components').getChildren as jest.Mock<any>;
  32. const component = { key: 'foo', name: 'Foo', qualifier: 'TRK' } as T.Component;
  33. it('renders', () => {
  34. const wrapper = shallow(<App component={component} fetchMetrics={jest.fn()} metrics={{}} />);
  35. wrapper.setState({
  36. loading: false,
  37. measures: { ncloc: '173', reliability_rating: '1' },
  38. subComponents: [],
  39. totalSubComponents: 0
  40. });
  41. expect(wrapper).toMatchSnapshot();
  42. });
  43. it('renders when portfolio is empty', () => {
  44. const wrapper = shallow(<App component={component} fetchMetrics={jest.fn()} metrics={{}} />);
  45. wrapper.setState({ loading: false, measures: { reliability_rating: '1' } });
  46. expect(wrapper).toMatchSnapshot();
  47. });
  48. it('renders when portfolio is not computed', () => {
  49. const wrapper = shallow(<App component={component} fetchMetrics={jest.fn()} metrics={{}} />);
  50. wrapper.setState({ loading: false, measures: { ncloc: '173' } });
  51. expect(wrapper).toMatchSnapshot();
  52. });
  53. it('fetches measures and children components', () => {
  54. getMeasures.mockClear();
  55. getChildren.mockClear();
  56. mount(<App component={component} fetchMetrics={jest.fn()} metrics={{}} />);
  57. expect(getMeasures).toBeCalledWith({
  58. component: 'foo',
  59. metricKeys:
  60. 'projects,ncloc,ncloc_language_distribution,releasability_rating,releasability_effort,sqale_rating,maintainability_rating_effort,reliability_rating,reliability_rating_effort,security_rating,security_rating_effort,security_review_rating,security_review_rating_effort,last_change_on_releasability_rating,last_change_on_maintainability_rating,last_change_on_security_rating,last_change_on_security_review_rating,last_change_on_reliability_rating'
  61. });
  62. expect(getChildren).toBeCalledWith(
  63. 'foo',
  64. [
  65. 'ncloc',
  66. 'releasability_rating',
  67. 'security_rating',
  68. 'security_review_rating',
  69. 'reliability_rating',
  70. 'sqale_rating',
  71. 'alert_status'
  72. ],
  73. { ps: 20, s: 'qualifier' }
  74. );
  75. });