123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- import {mountWithTheme} from 'sentry-test/enzyme';
- import DateTime from 'app/components/dateTime';
- import ConfigStore from 'app/stores/configStore';
- describe('DateTime', () => {
- const user = {
- ...TestStubs.User(),
- options: {
- clock24Hours: false,
- timezone: 'America/Los_Angeles',
- },
- };
- beforeAll(() => {
- ConfigStore.loadInitialData({user});
- });
- it('renders a date', () => {
- const wrapper = mountWithTheme(<DateTime date={new Date()} />);
- expect(wrapper.text()).toBe('Oct 16, 2017 7:41:20 PM PDT');
- });
- it('renders a date without seconds', () => {
- const wrapper = mountWithTheme(<DateTime date={new Date()} seconds={false} />);
- expect(wrapper.text()).toBe('Oct 16, 2017 7:41 PM');
- });
- it('renders timeonly', () => {
- const wrapper = mountWithTheme(<DateTime date={new Date()} timeOnly />);
- expect(wrapper.text()).toBe('7:41 PM');
- });
- it('renders dateOnly', () => {
- const wrapper = mountWithTheme(<DateTime date={new Date()} dateOnly />);
- expect(wrapper.text()).toBe('October 16, 2017');
- });
- it('renders shortDate', () => {
- const wrapper = mountWithTheme(<DateTime date={new Date()} shortDate />);
- expect(wrapper.text()).toBe('10/16/2017');
- });
- it('renders timeAndDate', () => {
- const wrapper = mountWithTheme(<DateTime date={new Date()} timeAndDate />);
- expect(wrapper.text()).toBe('Oct 16, 7:41 PM');
- });
- it('renders date with forced utc', () => {
- const wrapper = mountWithTheme(<DateTime date={new Date()} utc />);
- expect(wrapper.text()).toBe('Oct 17, 2017 2:41:20 AM UTC');
- });
- describe('24 Hours', () => {
- beforeAll(() => {
- user.options.clock24Hours = true;
- ConfigStore.set('user', user);
- });
- afterAll(() => {
- user.options.clock24Hours = false;
- ConfigStore.set('user', user);
- });
- it('renders a date', () => {
- const wrapper = mountWithTheme(<DateTime date={new Date()} />);
- expect(wrapper.text()).toBe('Oct 16, 2017 19:41');
- });
- it('renders timeonly', () => {
- const wrapper = mountWithTheme(<DateTime date={new Date()} timeOnly />);
- expect(wrapper.text()).toBe('19:41');
- });
- it('renders timeAndDate', () => {
- const wrapper = mountWithTheme(<DateTime date={new Date()} timeAndDate />);
- expect(wrapper.text()).toBe('Oct 16, 19:41');
- });
- it('renders date with forced utc', () => {
- const wrapper = mountWithTheme(<DateTime date={new Date()} utc />);
- expect(wrapper.text()).toBe('Oct 17, 2017 02:41');
- });
- });
- });
|