qt-public-ui
Version:
新设计规范下业务组件库
146 lines • 5.46 kB
JavaScript
import React from 'react';
import { mount } from 'enzyme';
import moment from 'moment';
import MockDate from 'mockdate';
import CyclePicker from '../indexv3';
var option = ['today', 'yesterday', 'recent7Day', 'recent15Day', 'recent15DayFromToday', 'recent7DayFromToday', 'recent30Day', 'recent60Day', 'recent60DayFromToday', 'recent90Day', 'recent90DayFromToday', 'recent30DayFromToday', 'recent48Hour', 'recent24Hour', 'recent1Hour', 'thisWeek', 'lastWeek', 'thisMonth', 'lastMonth'];
export var radioOptions = [{
name: '本周',
value: 'thisWeek'
}, {
name: '上周',
value: 'lastWeek' // 不包含今天
}, {
name: '本月',
value: 'thisMonth'
}, {
name: '上月',
value: 'lastMonth' // 不包含今天
}, {
name: '过去1小时',
value: 'recent1Hour'
}, {
name: '过去24小时',
value: 'recent24Hour'
}, {
name: '过去48小时',
value: 'recent48Hour'
}, {
name: '实时',
value: 'today'
}, {
name: '昨天',
value: 'yesterday'
}, {
name: '过去7天',
value: 'recent7Day' // 不包含今天
}, {
name: '近7天',
value: 'recent7DayFromToday' // 包含今天
}, {
name: '过去15天',
value: 'recent15Day'
}, {
name: '近15天',
value: 'recent15DayFromToday' // 包含今天
}, {
name: '过去30天',
value: 'recent30Day'
}, {
name: '近30天',
value: 'recent30DayFromToday'
}, {
name: '过去60天',
value: 'recent60Day'
}, {
name: '近60天',
value: 'recent60DayFromToday'
}, {
name: '过去90天',
value: 'recent90Day'
}, {
name: '近90天',
value: 'recent90DayFromToday'
}];
var getDateRange = function getDateRange(key) {
switch (key) {
case 'recent24Hour':
return [moment().subtract(23, 'h'), moment()];
case 'recent48Hour':
return [moment().subtract(47, 'h'), moment()];
case 'recent1Hour':
return [moment().subtract(59, 'm'), moment()];
case 'today':
return [moment().startOf('d'), moment().endOf('d')];
case 'yesterday':
return [moment().subtract(1, 'd').startOf('d'), moment().subtract(1, 'd').endOf('d')];
case 'recent7Day':
return [moment().subtract(7, 'd').startOf('d'), moment().subtract(1, 'd').endOf('d')];
case 'recent7DayFromToday':
return [moment().subtract(6, 'd').startOf('d'), moment().endOf('d')];
case 'recent15Day':
return [moment().subtract(15, 'd').startOf('d'), moment().subtract(1, 'd').endOf('d')];
case 'recent15DayFromToday':
return [moment().subtract(14, 'd').startOf('d'), moment().endOf('d')];
case 'recent30Day':
return [moment().subtract(30, 'd').startOf('d'), moment().subtract(1, 'd').endOf('d')];
case 'recent30DayFromToday':
return [moment().subtract(29, 'd').startOf('d'), moment().endOf('d')];
case 'recent60Day':
return [moment().subtract(60, 'd').startOf('d'), moment().subtract(1, 'd').endOf('d')];
case 'recent60DayFromToday':
return [moment().subtract(59, 'd').startOf('d'), moment().endOf('d')];
case 'recent90Day':
return [moment().subtract(90, 'd').startOf('d'), moment().subtract(1, 'd').endOf('d')];
case 'recent90DayFromToday':
return [moment().subtract(89, 'd').startOf('d'), moment().endOf('d')];
case 'thisWeek':
return [moment().isoWeekday(1).startOf('d'), moment().subtract(1, 'd').endOf('d')];
case 'lastWeek':
return [moment().isoWeekday(-6).startOf('d'), moment().isoWeekday(0).endOf('d')];
case 'thisMonth':
return [moment().set('date', 1).startOf('d'), moment().subtract(1, 'd').endOf('d')];
case 'lastMonth':
return [moment().set('month', moment().get('month') - 1).set('date', 1).startOf('d'), moment().set('date', 1).subtract(1, 'd').endOf('d')];
default:
return null;
}
};
describe('CyclePicker', function () {
radioOptions.forEach(function (item, index) {
it("Set value by radio:" + item.value, function () {
MockDate.set('2021-12-15');
var wrapper = mount( /*#__PURE__*/React.createElement(CyclePicker, {
useShortcuts: option
}));
var radios = wrapper.find('input');
radios.at(index).simulate('change');
// console.log(wrapper.find('.ant-picker-input').map(i =>i.children().prop('value')),item.name,getDateRange(item.value).map(i => i.format('YYYY-MM-DD')))
expect(wrapper.find('.ant-calendar-range-picker-input').map(function (i) {
return i.prop('value');
})).toEqual(getDateRange(item.value).map(function (i) {
return i.format('YYYY-MM-DD');
}));
});
});
radioOptions.forEach(function (item, index) {
it("Map value to radio:" + item.value, function () {
MockDate.set('2021-12-15');
var wrapper = mount( /*#__PURE__*/React.createElement(CyclePicker, {
useShortcuts: option,
defaultValue: CyclePicker.getShortcutRange(item.value)
}));
expect(wrapper.find('.ant-radio-button-wrapper-checked').text()).toEqual(item.name);
});
});
it("Disabled on the first day of the week", function () {
MockDate.set('2022-1-17');
var wrapper = mount( /*#__PURE__*/React.createElement(CyclePicker, null));
expect(wrapper.find('.ant-radio-button-wrapper-disabled').text()).toEqual('本周');
});
it("Disabled on the first day of the month", function () {
MockDate.set('2022-1-1');
var wrapper = mount( /*#__PURE__*/React.createElement(CyclePicker, null));
expect(wrapper.find('.ant-radio-button-wrapper-disabled').text()).toEqual('本月');
});
});