timeSince.spec.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import {render, screen} from 'sentry-test/reactTestingLibrary';
  2. import TimeSince from 'sentry/components/timeSince';
  3. describe('TimeSince', function () {
  4. const now = new Date();
  5. const tenMinAgo = new Date(now.getTime() - 10 * 60 * 1000);
  6. it('renders a relative date', () => {
  7. const {rerender} = render(<TimeSince date={now} />);
  8. expect(screen.getByText('a few seconds ago')).toBeInTheDocument();
  9. rerender(<TimeSince date={tenMinAgo} />);
  10. expect(screen.getByText('10 minutes ago')).toBeInTheDocument();
  11. });
  12. it('renders a relative date without suffix', () => {
  13. render(<TimeSince date={tenMinAgo} suffix="" />);
  14. expect(screen.getByText('10 minutes')).toBeInTheDocument();
  15. });
  16. it('renders a shortened date', () => {
  17. render(<TimeSince shorten date={tenMinAgo} />);
  18. expect(screen.getByText('10min ago')).toBeInTheDocument();
  19. });
  20. it('renders a extrashort date', () => {
  21. render(<TimeSince shorten extraShort date={tenMinAgo} />);
  22. expect(screen.getByText('10m ago')).toBeInTheDocument();
  23. });
  24. it('renders a spanish suffix', () => {
  25. render(<TimeSince date={tenMinAgo} suffix="atrás" />);
  26. expect(screen.getByText('10 minutes atrás')).toBeInTheDocument();
  27. });
  28. it('renders a spanish suffix with shortened', () => {
  29. render(<TimeSince shorten extraShort date={tenMinAgo} suffix="atrás" />);
  30. expect(screen.getByText('10m atrás')).toBeInTheDocument();
  31. });
  32. });