platformPicker.spec.jsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import React from 'react';
  2. import {shallow, mountWithTheme} from 'sentry-test/enzyme';
  3. import {Client} from 'app/api';
  4. import PlatformPicker from 'app/components/platformPicker';
  5. describe('PlatformPicker', function() {
  6. beforeEach(function() {
  7. this.stubbedApiRequest = jest.spyOn(Client.prototype, 'request');
  8. });
  9. afterEach(function() {
  10. Client.prototype.request.mockRestore();
  11. });
  12. describe('render()', function() {
  13. const baseProps = {
  14. platform: '',
  15. setPlatform: () => {},
  16. location: {query: {}},
  17. };
  18. it('should only render Mobile platforms under Mobile tab', function() {
  19. const props = {
  20. ...baseProps,
  21. };
  22. const wrapper = shallow(<PlatformPicker {...props} />);
  23. wrapper.setState({category: 'mobile'});
  24. const filteredPlatforms = wrapper
  25. .find('PlatformCard')
  26. .map(node => node.prop('platform').id);
  27. expect(filteredPlatforms).not.toContain('java');
  28. expect(filteredPlatforms).toContain('apple-ios');
  29. expect(filteredPlatforms).toContain('react-native');
  30. });
  31. it('should render renderPlatformList with Python when filtered with py', function() {
  32. const props = {
  33. ...baseProps,
  34. };
  35. const wrapper = shallow(<PlatformPicker {...props} />);
  36. wrapper.setState({category: 'all', filter: 'py'});
  37. const filteredPlatforms = wrapper
  38. .find('PlatformCard')
  39. .map(node => node.prop('platform').id);
  40. expect(filteredPlatforms).not.toContain('java');
  41. expect(filteredPlatforms).toContain('python-flask');
  42. });
  43. it('should render renderPlatformList with community SDKs message if platform not found', function() {
  44. const props = {
  45. ...baseProps,
  46. };
  47. const wrapper = shallow(<PlatformPicker {...props} />);
  48. wrapper.setState({filter: 'aaaaaa'});
  49. expect(wrapper.find('EmptyMessage')).toHaveLength(1);
  50. });
  51. it('should update State.tab onClick when particular tab is clicked', function() {
  52. const props = {
  53. ...baseProps,
  54. };
  55. const wrapper = mountWithTheme(
  56. <PlatformPicker {...props} />,
  57. TestStubs.routerContext()
  58. );
  59. const testListLink = wrapper
  60. .find('ListLink')
  61. .last()
  62. .find('a');
  63. expect(wrapper.state().category).toBe('popular');
  64. testListLink.simulate('click');
  65. expect(wrapper.state().category).toBe('all');
  66. });
  67. it('should clear the platform when clear is clicked', function() {
  68. const props = {
  69. ...baseProps,
  70. platform: 'java',
  71. setPlatform: jest.fn(),
  72. };
  73. const wrapper = mountWithTheme(
  74. <PlatformPicker {...props} />,
  75. TestStubs.routerContext()
  76. );
  77. wrapper.find('ClearButton').simulate('click');
  78. expect(props.setPlatform).toHaveBeenCalledWith('');
  79. });
  80. });
  81. });