dateTime.spec.jsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import DateTime from 'app/components/dateTime';
  3. import ConfigStore from 'app/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. const wrapper = mountWithTheme(<DateTime date={new Date()} />);
  17. expect(wrapper.text()).toBe('Oct 16, 2017 7:41:20 PM PDT');
  18. });
  19. it('renders a date without seconds', () => {
  20. const wrapper = mountWithTheme(<DateTime date={new Date()} seconds={false} />);
  21. expect(wrapper.text()).toBe('Oct 16, 2017 7:41 PM');
  22. });
  23. it('renders timeonly', () => {
  24. const wrapper = mountWithTheme(<DateTime date={new Date()} timeOnly />);
  25. expect(wrapper.text()).toBe('7:41 PM');
  26. });
  27. it('renders dateOnly', () => {
  28. const wrapper = mountWithTheme(<DateTime date={new Date()} dateOnly />);
  29. expect(wrapper.text()).toBe('October 16, 2017');
  30. });
  31. it('renders shortDate', () => {
  32. const wrapper = mountWithTheme(<DateTime date={new Date()} shortDate />);
  33. expect(wrapper.text()).toBe('10/16/2017');
  34. });
  35. it('renders timeAndDate', () => {
  36. const wrapper = mountWithTheme(<DateTime date={new Date()} timeAndDate />);
  37. expect(wrapper.text()).toBe('Oct 16, 7:41 PM');
  38. });
  39. it('renders date with forced utc', () => {
  40. const wrapper = mountWithTheme(<DateTime date={new Date()} utc />);
  41. expect(wrapper.text()).toBe('Oct 17, 2017 2:41:20 AM UTC');
  42. });
  43. describe('24 Hours', () => {
  44. beforeAll(() => {
  45. user.options.clock24Hours = true;
  46. ConfigStore.set('user', user);
  47. });
  48. afterAll(() => {
  49. user.options.clock24Hours = false;
  50. ConfigStore.set('user', user);
  51. });
  52. it('renders a date', () => {
  53. const wrapper = mountWithTheme(<DateTime date={new Date()} />);
  54. expect(wrapper.text()).toBe('Oct 16, 2017 19:41');
  55. });
  56. it('renders timeonly', () => {
  57. const wrapper = mountWithTheme(<DateTime date={new Date()} timeOnly />);
  58. expect(wrapper.text()).toBe('19:41');
  59. });
  60. it('renders timeAndDate', () => {
  61. const wrapper = mountWithTheme(<DateTime date={new Date()} timeAndDate />);
  62. expect(wrapper.text()).toBe('Oct 16, 19:41');
  63. });
  64. it('renders date with forced utc', () => {
  65. const wrapper = mountWithTheme(<DateTime date={new Date()} utc />);
  66. expect(wrapper.text()).toBe('Oct 17, 2017 02:41');
  67. });
  68. });
  69. });