platformPicker.spec.jsx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import React from 'react';
  2. import {shallow, mount} from '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('swift');
  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 community SDKs message if platform not found', function() {
  43. const props = {
  44. ...baseProps,
  45. };
  46. const wrapper = shallow(<PlatformPicker {...props} />);
  47. wrapper.setState({filter: 'aaaaaa'});
  48. expect(wrapper.find('EmptyMessage')).toHaveLength(1);
  49. });
  50. it('should update State.tab onClick when particular tab is clicked', function() {
  51. const props = {
  52. ...baseProps,
  53. };
  54. const wrapper = mount(<PlatformPicker {...props} />, TestStubs.routerContext());
  55. const testListLink = wrapper
  56. .find('ListLink')
  57. .last()
  58. .find('a');
  59. expect(wrapper.state().category).toBe('popular');
  60. testListLink.simulate('click');
  61. expect(wrapper.state().category).toBe('all');
  62. });
  63. it('should clear the platform when clear is clicked', function() {
  64. const props = {
  65. ...baseProps,
  66. platform: 'java',
  67. setPlatform: jest.fn(),
  68. };
  69. const wrapper = mount(<PlatformPicker {...props} />, TestStubs.routerContext());
  70. wrapper.find('ClearButton').simulate('click');
  71. expect(props.setPlatform).toHaveBeenCalledWith('');
  72. });
  73. });
  74. });