multiPlatformPicker.spec.jsx 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import MultiPlatformPicker from 'sentry/components/multiPlatformPicker';
  3. describe('MultiPlatformPicker', function () {
  4. const baseProps = {
  5. platforms: [],
  6. };
  7. it('should only render Mobile platforms under Mobile tab', function () {
  8. const props = {...baseProps};
  9. render(<MultiPlatformPicker {...props} />);
  10. userEvent.click(screen.getByText('Mobile'));
  11. expect(screen.getByText('Android')).toBeInTheDocument();
  12. expect(screen.queryByText('Electron')).not.toBeInTheDocument();
  13. });
  14. it('should render renderPlatformList with Python when filtered with py', function () {
  15. const props = {
  16. ...baseProps,
  17. };
  18. render(<MultiPlatformPicker {...props} />);
  19. userEvent.type(screen.getByPlaceholderText('Filter Platforms'), 'py');
  20. expect(screen.getByText('Python')).toBeInTheDocument();
  21. expect(screen.queryByText('Electron')).not.toBeInTheDocument();
  22. });
  23. it('should render renderPlatformList with Native when filtered with c++ alias', function () {
  24. const props = {
  25. ...baseProps,
  26. };
  27. render(<MultiPlatformPicker {...props} />);
  28. userEvent.type(screen.getByPlaceholderText('Filter Platforms'), 'c++');
  29. expect(screen.getByText('Native (C/C++)')).toBeInTheDocument();
  30. expect(screen.queryByText('Electron')).not.toBeInTheDocument();
  31. });
  32. it('should render renderPlatformList with community SDKs message if platform not found', function () {
  33. const props = {
  34. ...baseProps,
  35. };
  36. render(<MultiPlatformPicker {...props} />);
  37. userEvent.type(screen.getByPlaceholderText('Filter Platforms'), 'aaaaa');
  38. expect(screen.getByText("We don't have an SDK for that yet!")).toBeInTheDocument();
  39. expect(screen.queryByText('Python')).not.toBeInTheDocument();
  40. });
  41. it('should clear the platform when clear is clicked', function () {
  42. const props = {
  43. ...baseProps,
  44. platforms: ['java'],
  45. removePlatform: jest.fn(),
  46. noAutoFilter: true,
  47. };
  48. render(<MultiPlatformPicker {...props} />);
  49. userEvent.click(screen.getByRole('button', {name: 'Clear'}));
  50. expect(props.removePlatform).toHaveBeenCalledWith('java');
  51. });
  52. it('clicking on icon calls addPlatform', function () {
  53. const props = {
  54. ...baseProps,
  55. addPlatform: jest.fn(),
  56. };
  57. render(<MultiPlatformPicker {...props} />);
  58. userEvent.click(screen.getByText('Java'));
  59. expect(props.addPlatform).toHaveBeenCalledWith('java');
  60. });
  61. it('clicking on icon calls does not call addPlatform if already in list', function () {
  62. const props = {
  63. ...baseProps,
  64. platforms: ['java'],
  65. addPlatform: jest.fn(),
  66. };
  67. render(<MultiPlatformPicker {...props} />);
  68. userEvent.click(screen.getByText('Java'));
  69. expect(props.addPlatform).not.toHaveBeenCalled();
  70. });
  71. });