version.spec.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import Version from 'sentry/components/version';
  3. const VERSION = 'foo.bar.Baz@1.0.0+20200101';
  4. describe('Version', () => {
  5. const context = TestStubs.routerContext();
  6. afterEach(() => {
  7. jest.resetAllMocks();
  8. });
  9. it('renders', () => {
  10. const {container} = render(<Version version={VERSION} />);
  11. expect(container).toSnapshot();
  12. });
  13. it('shows correct parsed version', () => {
  14. // component uses @sentry/release-parser package for parsing versions
  15. render(<Version version={VERSION} />);
  16. expect(screen.getByText('1.0.0 (20200101)')).toBeInTheDocument();
  17. });
  18. it('links to release page', () => {
  19. render(<Version version={VERSION} projectId="1" />, {
  20. context,
  21. });
  22. userEvent.click(screen.getByText('1.0.0 (20200101)'));
  23. expect(context.context.router.push).toHaveBeenCalledWith({
  24. pathname: '/organizations/org-slug/releases/foo.bar.Baz%401.0.0%2B20200101/',
  25. query: {project: '1'},
  26. });
  27. });
  28. it('shows raw version in tooltip', () => {
  29. jest.useFakeTimers();
  30. render(<Version version={VERSION} tooltipRawVersion />, {
  31. context,
  32. });
  33. expect(screen.queryByText(VERSION)).not.toBeInTheDocument();
  34. // Activate tooltip
  35. userEvent.hover(screen.getByText('1.0.0 (20200101)'));
  36. jest.advanceTimersByTime(50);
  37. expect(screen.getByText(VERSION)).toBeInTheDocument();
  38. });
  39. });