platformPicker.spec.jsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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('cocoa-swift');
  29. expect(filteredPlatforms).toContain('react-native');
  30. expect(filteredPlatforms).toContain('cocoa-objc');
  31. expect(filteredPlatforms).toContain('java-android');
  32. expect(filteredPlatforms).toContain('cordova');
  33. });
  34. it('should render renderPlatformList with Python when filtered with py', function() {
  35. const props = {
  36. ...baseProps,
  37. };
  38. const wrapper = shallow(<PlatformPicker {...props} />);
  39. wrapper.setState({category: 'all', filter: 'py'});
  40. const filteredPlatforms = wrapper
  41. .find('PlatformCard')
  42. .map(node => node.prop('platform').id);
  43. expect(filteredPlatforms).not.toContain('java');
  44. expect(filteredPlatforms).toContain('python-flask');
  45. });
  46. it('should render renderPlatformList with community SDKs message if platform not found', function() {
  47. const props = {
  48. ...baseProps,
  49. };
  50. const wrapper = shallow(<PlatformPicker {...props} />);
  51. wrapper.setState({filter: 'aaaaaa'});
  52. expect(wrapper.find('EmptyMessage')).toHaveLength(1);
  53. });
  54. it('should update State.tab onClick when particular tab is clicked', function() {
  55. const props = {
  56. ...baseProps,
  57. };
  58. const wrapper = mountWithTheme(
  59. <PlatformPicker {...props} />,
  60. TestStubs.routerContext()
  61. );
  62. const testListLink = wrapper
  63. .find('ListLink')
  64. .last()
  65. .find('a');
  66. expect(wrapper.state().category).toBe('popular');
  67. testListLink.simulate('click');
  68. expect(wrapper.state().category).toBe('all');
  69. });
  70. it('should clear the platform when clear is clicked', function() {
  71. const props = {
  72. ...baseProps,
  73. platform: 'java',
  74. setPlatform: jest.fn(),
  75. };
  76. const wrapper = mountWithTheme(
  77. <PlatformPicker {...props} />,
  78. TestStubs.routerContext()
  79. );
  80. wrapper.find('ClearButton').simulate('click');
  81. expect(props.setPlatform).toHaveBeenCalledWith('');
  82. });
  83. });
  84. });