dateTime.spec.jsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import {render, screen} from 'sentry-test/reactTestingLibrary';
  2. import DateTime from 'sentry/components/dateTime';
  3. import ConfigStore from 'sentry/stores/configStore';
  4. describe('DateTime', () => {
  5. const user = {
  6. ...TestStubs.User(),
  7. options: {
  8. clock24Hours: false,
  9. timezone: 'America/Los_Angeles',
  10. },
  11. };
  12. beforeAll(() => {
  13. ConfigStore.loadInitialData({user});
  14. });
  15. it('renders a date', () => {
  16. render(<DateTime date={new Date()} />);
  17. expect(screen.getByText('Oct 16, 7:41 PM')).toBeInTheDocument();
  18. });
  19. it('renders a date and shows the year if it is outside the current year', () => {
  20. const date = new Date();
  21. date.setYear(2016);
  22. date.setMonth(11);
  23. date.setDate(31);
  24. render(<DateTime date={date} />);
  25. expect(screen.getByText('Dec 31, 2016 7:41 PM')).toBeInTheDocument();
  26. });
  27. it('renders only the time', () => {
  28. render(<DateTime date={new Date()} timeOnly />);
  29. expect(screen.getByText('7:41 PM')).toBeInTheDocument();
  30. });
  31. it('renders only the date', () => {
  32. render(<DateTime date={new Date()} dateOnly />);
  33. expect(screen.getByText('Oct 16')).toBeInTheDocument();
  34. });
  35. it('renders a date with year', () => {
  36. render(<DateTime date={new Date()} year />);
  37. expect(screen.getByText('Oct 16, 2017 7:41 PM')).toBeInTheDocument();
  38. });
  39. it('renders a date with seconds', () => {
  40. render(<DateTime date={new Date()} seconds />);
  41. expect(screen.getByText('Oct 16, 7:41:20 PM')).toBeInTheDocument();
  42. });
  43. it('renders a date with the time zone', () => {
  44. render(<DateTime date={new Date()} timeZone />);
  45. expect(screen.getByText('Oct 16, 7:41 PM PDT')).toBeInTheDocument();
  46. });
  47. it('renders date with forced utc', () => {
  48. render(<DateTime date={new Date()} utc />);
  49. expect(screen.getByText('Oct 17, 2:41 AM UTC')).toBeInTheDocument();
  50. });
  51. describe('24 Hours', () => {
  52. beforeAll(() => {
  53. user.options.clock24Hours = true;
  54. ConfigStore.set('user', user);
  55. });
  56. afterAll(() => {
  57. user.options.clock24Hours = false;
  58. ConfigStore.set('user', user);
  59. });
  60. it('renders a date', () => {
  61. render(<DateTime date={new Date()} />);
  62. expect(screen.getByText('Oct 16, 19:41')).toBeInTheDocument();
  63. });
  64. it('renders only the time', () => {
  65. render(<DateTime date={new Date()} timeOnly />);
  66. expect(screen.getByText('19:41')).toBeInTheDocument();
  67. });
  68. it('renders date with forced utc', () => {
  69. render(<DateTime date={new Date()} utc />);
  70. expect(screen.getByText('Oct 17, 02:41 UTC')).toBeInTheDocument();
  71. });
  72. });
  73. });