deviceName.spec.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import * as Sentry from '@sentry/react';
  2. import {generationByIdentifier} from 'ios-device-list';
  3. import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
  4. import * as Device from 'sentry/components/deviceName';
  5. jest.mock('ios-device-list');
  6. describe('DeviceName', () => {
  7. it('renders device name if module is loaded', async () => {
  8. generationByIdentifier.mockImplementation(() => 'iPhone 6s Plus');
  9. render(<Device.DeviceName value="iPhone8,2" />);
  10. expect(await screen.findByText('iPhone 6s Plus')).toBeInTheDocument();
  11. expect(generationByIdentifier).toHaveBeenCalledWith('iPhone8,2');
  12. });
  13. it('renders device name if name helper returns undefined', async () => {
  14. generationByIdentifier.mockImplementation(() => undefined);
  15. render(<Device.DeviceName value="iPhone8,2" />);
  16. expect(await screen.findByText('iPhone8,2')).toBeInTheDocument();
  17. expect(generationByIdentifier).toHaveBeenCalledWith('iPhone8,2');
  18. });
  19. it('renders device name if module fails to load', async () => {
  20. jest.spyOn(Device, 'loadDeviceListModule').mockImplementation(() => {
  21. return Promise.reject('Cannot load module');
  22. });
  23. const spy = jest.spyOn(Sentry, 'captureException');
  24. render(<Device.DeviceName value="iPhone8,2" />);
  25. await waitFor(() =>
  26. expect(spy).toHaveBeenCalledWith('Failed to load ios-device-list module')
  27. );
  28. expect(await screen.findByText('iPhone8,2')).toBeInTheDocument();
  29. });
  30. });