2019-09-18 12:03:13 +00:00
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import MockDate from 'mockdate';
|
2021-09-25 08:51:32 +00:00
|
|
|
import dayjs from 'dayjs';
|
2019-09-18 12:03:13 +00:00
|
|
|
import Statistic from '..';
|
2020-03-07 11:45:13 +00:00
|
|
|
import { formatTimeStr } from '../utils';
|
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2019-09-18 12:03:13 +00:00
|
|
|
|
|
|
|
describe('Statistic', () => {
|
2020-03-07 11:45:13 +00:00
|
|
|
mountTest(Statistic);
|
|
|
|
mountTest(Statistic.Countdown);
|
|
|
|
|
2019-09-18 12:03:13 +00:00
|
|
|
beforeAll(() => {
|
2021-09-25 08:51:32 +00:00
|
|
|
MockDate.set(dayjs('2018-11-28 00:00:00'));
|
2019-09-18 12:03:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
MockDate.reset();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('customize formatter', () => {
|
|
|
|
const formatter = jest.fn(() => 93);
|
|
|
|
const props = {
|
2020-07-25 07:46:49 +00:00
|
|
|
props: {
|
2019-09-18 12:03:13 +00:00
|
|
|
value: 1128,
|
|
|
|
formatter,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const wrapper = mount(Statistic, props);
|
|
|
|
expect(formatter).toBeCalledWith(expect.objectContaining({ value: 1128 }));
|
|
|
|
expect(wrapper.find('.ant-statistic-content-value').text()).toEqual('93');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('groupSeparator', () => {
|
|
|
|
const props = {
|
2020-07-25 07:46:49 +00:00
|
|
|
props: {
|
2019-09-18 12:03:13 +00:00
|
|
|
value: 1128,
|
|
|
|
groupSeparator: '__TEST__',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const wrapper = mount(Statistic, props);
|
|
|
|
expect(wrapper.find('.ant-statistic-content-value').text()).toEqual('1__TEST__128');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('not a number', () => {
|
|
|
|
const props = {
|
2020-07-25 07:46:49 +00:00
|
|
|
props: {
|
2019-09-18 12:03:13 +00:00
|
|
|
value: 'bamboo',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const wrapper = mount(Statistic, props);
|
|
|
|
expect(wrapper.find('.ant-statistic-content-value').text()).toEqual('bamboo');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('support negetive number', () => {
|
|
|
|
const props = {
|
2020-07-25 07:46:49 +00:00
|
|
|
props: {
|
2019-09-18 12:03:13 +00:00
|
|
|
title: 'Account Balance (CNY)',
|
|
|
|
value: -112893.12345,
|
|
|
|
precision: 2,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const wrapper = mount(Statistic, props);
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Countdown', () => {
|
|
|
|
it('render correctly', () => {
|
2021-09-25 08:51:32 +00:00
|
|
|
const now = dayjs().add(2, 'd').add(11, 'h').add(28, 'm').add(9, 's').add(3, 'ms');
|
2019-09-18 12:03:13 +00:00
|
|
|
|
|
|
|
[
|
|
|
|
['H:m:s', '59:28:9'],
|
|
|
|
['HH:mm:ss', '59:28:09'],
|
|
|
|
['HH:mm:ss:SSS', '59:28:09:003'],
|
|
|
|
['DD-HH:mm:ss', '02-11:28:09'],
|
|
|
|
].forEach(([format, value]) => {
|
|
|
|
const props = {
|
2020-07-25 07:46:49 +00:00
|
|
|
props: {
|
2019-09-18 12:03:13 +00:00
|
|
|
format,
|
|
|
|
value: now,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const wrapper = mount(Statistic.Countdown, props);
|
|
|
|
expect(wrapper.find('.ant-statistic-content-value').text()).toEqual(value);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-03-07 11:45:13 +00:00
|
|
|
describe('utils', () => {
|
|
|
|
it('format should support escape', () => {
|
|
|
|
expect(formatTimeStr(1000 * 60 * 60 * 24, 'D [Day]')).toBe('1 Day');
|
|
|
|
});
|
|
|
|
});
|
2019-09-18 12:03:13 +00:00
|
|
|
});
|