dateTime.spec.jsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import React from 'react';
  2. import {mount} from 'sentry-test/enzyme';
  3. import DateTime from 'app/components/dateTime';
  4. import ConfigStore from 'app/stores/configStore';
  5. describe('DateTime', () => {
  6. const user = {
  7. ...TestStubs.User(),
  8. options: {
  9. clock24Hours: false,
  10. timezone: 'America/Los_Angeles',
  11. },
  12. };
  13. beforeAll(() => {
  14. ConfigStore.loadInitialData({user});
  15. });
  16. it('renders a date', () => {
  17. const wrapper = mount(<DateTime date={new Date()} />);
  18. expect(wrapper.text()).toBe('Oct 16, 2017 7:41:20 PM PDT');
  19. });
  20. it('renders a date without seconds', () => {
  21. const wrapper = mount(<DateTime date={new Date()} seconds={false} />);
  22. expect(wrapper.text()).toBe('Oct 16, 2017 7:41 PM');
  23. });
  24. it('renders timeonly', () => {
  25. const wrapper = mount(<DateTime date={new Date()} timeOnly />);
  26. expect(wrapper.text()).toBe('7:41 PM');
  27. });
  28. it('renders dateOnly', () => {
  29. const wrapper = mount(<DateTime date={new Date()} dateOnly />);
  30. expect(wrapper.text()).toBe('October 16, 2017');
  31. });
  32. it('renders shortDate', () => {
  33. const wrapper = mount(<DateTime date={new Date()} shortDate />);
  34. expect(wrapper.text()).toBe('10/16/2017');
  35. });
  36. it('renders timeAndDate', () => {
  37. const wrapper = mount(<DateTime date={new Date()} timeAndDate />);
  38. expect(wrapper.text()).toBe('Oct 16, 7:41 PM');
  39. });
  40. it('renders date with forced utc', () => {
  41. const wrapper = mount(<DateTime date={new Date()} utc />);
  42. expect(wrapper.text()).toBe('Oct 17, 2017 2:41:20 AM UTC');
  43. });
  44. describe('24 Hours', () => {
  45. beforeAll(() => {
  46. user.options.clock24Hours = true;
  47. ConfigStore.set('user', user);
  48. });
  49. afterAll(() => {
  50. user.options.clock24Hours = false;
  51. ConfigStore.set('user', user);
  52. });
  53. it('renders a date', () => {
  54. const wrapper = mount(<DateTime date={new Date()} />);
  55. expect(wrapper.text()).toBe('Oct 16, 2017 19:41');
  56. });
  57. it('renders timeonly', () => {
  58. const wrapper = mount(<DateTime date={new Date()} timeOnly />);
  59. expect(wrapper.text()).toBe('19:41');
  60. });
  61. it('renders date with forced utc', () => {
  62. const wrapper = mount(<DateTime date={new Date()} utc />);
  63. expect(wrapper.text()).toBe('Oct 17, 2017 02:41');
  64. });
  65. });
  66. });