platformPicker.spec.jsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import PlatformPicker from 'sentry/components/platformPicker';
  3. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  4. jest.mock('sentry/utils/analytics/trackAdvancedAnalyticsEvent');
  5. describe('PlatformPicker', function () {
  6. const baseProps = {
  7. platform: '',
  8. setPlatform: () => {},
  9. location: {query: {}},
  10. };
  11. it('should only render Mobile platforms under Mobile tab', function () {
  12. render(<PlatformPicker {...baseProps} defaultCategory="mobile" />);
  13. expect(screen.queryByTestId('platform-java')).not.toBeInTheDocument();
  14. expect(screen.getByTestId('platform-apple-ios')).toBeInTheDocument();
  15. expect(screen.getByTestId('platform-react-native')).toBeInTheDocument();
  16. });
  17. it('should render renderPlatformList with Python when filtered with py', function () {
  18. render(<PlatformPicker {...baseProps} defaultCategory="all" platform="py" />);
  19. expect(screen.queryByTestId('platform-java')).not.toBeInTheDocument();
  20. expect(screen.getByTestId('platform-python-flask')).toBeInTheDocument();
  21. });
  22. it('should render renderPlatformList with Native when filtered with c++ alias', function () {
  23. render(<PlatformPicker {...baseProps} defaultCategory="all" platform="c++" />);
  24. expect(screen.getByTestId('platform-native')).toBeInTheDocument();
  25. });
  26. it('should render renderPlatformList with community SDKs message if platform not found', function () {
  27. render(<PlatformPicker {...baseProps} />);
  28. userEvent.paste(screen.getByPlaceholderText('Filter Platforms'), 'aaaaaa');
  29. expect(screen.getByText("We don't have an SDK for that yet!")).toBeInTheDocument();
  30. });
  31. it('should update State.tab onClick when particular tab is clicked', function () {
  32. render(<PlatformPicker {...baseProps} />);
  33. expect(screen.getByText('Popular')).toBeInTheDocument();
  34. userEvent.click(screen.getByText('All'));
  35. expect(trackAdvancedAnalyticsEvent).toHaveBeenCalledWith(
  36. 'growth.platformpicker_category',
  37. expect.objectContaining({
  38. category: 'all',
  39. })
  40. );
  41. });
  42. it('should clear the platform when clear is clicked', function () {
  43. const props = {
  44. ...baseProps,
  45. platform: 'java',
  46. setPlatform: jest.fn(),
  47. };
  48. render(<PlatformPicker {...props} />);
  49. userEvent.click(screen.getByRole('button', {name: 'Clear'}));
  50. expect(props.setPlatform).toHaveBeenCalledWith(null);
  51. });
  52. });