platformPicker.spec.jsx 3.2 KB

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