multiPlatformPicker.spec.jsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. };
  47. render(<MultiPlatformPicker {...props} />);
  48. userEvent.click(screen.getByTestId('icon-close'));
  49. expect(props.removePlatform).toHaveBeenCalledWith('java');
  50. });
  51. it('clicking on icon calls addPlatform', function () {
  52. const props = {
  53. ...baseProps,
  54. addPlatform: jest.fn(),
  55. };
  56. render(<MultiPlatformPicker {...props} />);
  57. userEvent.click(screen.getByText('Java'));
  58. expect(props.addPlatform).toHaveBeenCalledWith('java');
  59. });
  60. it('clicking on icon calls does not call addPlatform if already in list', function () {
  61. const props = {
  62. ...baseProps,
  63. platforms: ['java'],
  64. addPlatform: jest.fn(),
  65. };
  66. render(<MultiPlatformPicker {...props} />);
  67. userEvent.click(screen.getByText('Java'));
  68. expect(props.addPlatform).not.toHaveBeenCalled();
  69. });
  70. });