mirror of
https://github.com/strapi/strapi.git
synced 2025-11-03 03:17:11 +00:00
override dateFormats and getFilterType tests
Signed-off-by: Virginie Ky <virginie.ky@gmail.com>
This commit is contained in:
parent
1bc1ea2563
commit
4c6e50439d
@ -0,0 +1,160 @@
|
|||||||
|
import getFilterType from '../getFilterType';
|
||||||
|
|
||||||
|
describe('HELPER PLUGIN | utils | getFilterType', () => {
|
||||||
|
describe('Text types', () => {
|
||||||
|
const expected = [
|
||||||
|
{
|
||||||
|
id: 'components.FilterOptions.FILTER_TYPES.=',
|
||||||
|
value: '=',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'components.FilterOptions.FILTER_TYPES._ne',
|
||||||
|
value: '_ne',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'components.FilterOptions.FILTER_TYPES._lt',
|
||||||
|
value: '_lt',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'components.FilterOptions.FILTER_TYPES._lte',
|
||||||
|
value: '_lte',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'components.FilterOptions.FILTER_TYPES._gt',
|
||||||
|
value: '_gt',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'components.FilterOptions.FILTER_TYPES._gte',
|
||||||
|
value: '_gte',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'components.FilterOptions.FILTER_TYPES._contains',
|
||||||
|
value: '_contains',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'components.FilterOptions.FILTER_TYPES._containss',
|
||||||
|
value: '_containss',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'components.FilterOptions.FILTER_TYPES._in',
|
||||||
|
value: '_in',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'components.FilterOptions.FILTER_TYPES._nin',
|
||||||
|
value: '_nin',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
it('should generate the expected array if type is text', () => {
|
||||||
|
const type = 'text';
|
||||||
|
expect(getFilterType(type)).toEqual(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should generate the expected array if type is string', () => {
|
||||||
|
const type = 'string';
|
||||||
|
expect(getFilterType(type)).toEqual(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should generate the expected array if type is password', () => {
|
||||||
|
const type = 'password';
|
||||||
|
expect(getFilterType(type)).toEqual(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should generate the expected array if type is email', () => {
|
||||||
|
const type = 'email';
|
||||||
|
expect(getFilterType(type)).toEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Number and timestamp types', () => {
|
||||||
|
const expected = [
|
||||||
|
{
|
||||||
|
id: 'components.FilterOptions.FILTER_TYPES.=',
|
||||||
|
value: '=',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'components.FilterOptions.FILTER_TYPES._ne',
|
||||||
|
value: '_ne',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'components.FilterOptions.FILTER_TYPES._lt',
|
||||||
|
value: '_lt',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'components.FilterOptions.FILTER_TYPES._lte',
|
||||||
|
value: '_lte',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'components.FilterOptions.FILTER_TYPES._gt',
|
||||||
|
value: '_gt',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'components.FilterOptions.FILTER_TYPES._gte',
|
||||||
|
value: '_gte',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
it('should generate the expected array if type is integer', () => {
|
||||||
|
const type = 'integer';
|
||||||
|
expect(getFilterType(type)).toEqual(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should generate the expected array if type is biginteger', () => {
|
||||||
|
const type = 'biginteger';
|
||||||
|
expect(getFilterType(type)).toEqual(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should generate the expected array if type is float', () => {
|
||||||
|
const type = 'float';
|
||||||
|
expect(getFilterType(type)).toEqual(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should generate the expected array if type is decimal', () => {
|
||||||
|
const type = 'decimal';
|
||||||
|
expect(getFilterType(type)).toEqual(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should generate the expected array if type is date', () => {
|
||||||
|
const type = 'date';
|
||||||
|
expect(getFilterType(type)).toEqual(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should generate the expected array if type is datetime', () => {
|
||||||
|
const type = 'datetime';
|
||||||
|
expect(getFilterType(type)).toEqual(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should generate the expected array if type is time', () => {
|
||||||
|
const type = 'time';
|
||||||
|
expect(getFilterType(type)).toEqual(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should generate the expected array if type is timestamp', () => {
|
||||||
|
const type = 'timestamp';
|
||||||
|
expect(getFilterType(type)).toEqual(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should generate the expected array if type is timestampUpdate', () => {
|
||||||
|
const type = 'timestampUpdate';
|
||||||
|
expect(getFilterType(type)).toEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Other types', () => {
|
||||||
|
const expected = [
|
||||||
|
{
|
||||||
|
id: 'components.FilterOptions.FILTER_TYPES.=',
|
||||||
|
value: '=',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'components.FilterOptions.FILTER_TYPES._ne',
|
||||||
|
value: '_ne',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
it('should generate the expected array if type is size', () => {
|
||||||
|
const type = 'size';
|
||||||
|
expect(getFilterType(type)).toEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -3,12 +3,9 @@ import { withRouter } from 'react-router';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { get, isEmpty, isNull, isObject, toLower, toString } from 'lodash';
|
import { get, isEmpty, isNull, isObject, toLower, toString } from 'lodash';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import {
|
import { IcoContainer, useGlobalContext } from 'strapi-helper-plugin';
|
||||||
IcoContainer,
|
|
||||||
useGlobalContext,
|
|
||||||
dateFormats,
|
|
||||||
} from 'strapi-helper-plugin';
|
|
||||||
import useListView from '../../hooks/useListView';
|
import useListView from '../../hooks/useListView';
|
||||||
|
import formats from '../../utils/formats';
|
||||||
import CustomInputCheckbox from '../CustomInputCheckbox';
|
import CustomInputCheckbox from '../CustomInputCheckbox';
|
||||||
import MediaPreviewList from '../MediaPreviewList';
|
import MediaPreviewList from '../MediaPreviewList';
|
||||||
import { ActionContainer, Truncate, Truncated } from './styledComponents';
|
import { ActionContainer, Truncate, Truncated } from './styledComponents';
|
||||||
@ -45,7 +42,7 @@ const getDisplayedValue = (type, value, name) => {
|
|||||||
? JSON.stringify(value)
|
? JSON.stringify(value)
|
||||||
: value;
|
: value;
|
||||||
|
|
||||||
return dateToUtcTime(date).format(dateFormats[type]);
|
return dateToUtcTime(date).format(formats[type]);
|
||||||
}
|
}
|
||||||
case 'password':
|
case 'password':
|
||||||
return '••••••••';
|
return '••••••••';
|
||||||
@ -66,7 +63,7 @@ const getDisplayedValue = (type, value, name) => {
|
|||||||
};
|
};
|
||||||
const date = moment().set(timeObj);
|
const date = moment().set(timeObj);
|
||||||
|
|
||||||
return date.format(dateFormats.time);
|
return date.format(formats.time);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return '-';
|
return '-';
|
||||||
|
|||||||
@ -2,7 +2,8 @@ import React from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { get, toString } from 'lodash';
|
import { get, toString } from 'lodash';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { dateFormats, FilterButton } from 'strapi-helper-plugin';
|
import { FilterButton } from 'strapi-helper-plugin';
|
||||||
|
import formats from '../../utils/formats';
|
||||||
|
|
||||||
function Filter({
|
function Filter({
|
||||||
changeParams,
|
changeParams,
|
||||||
@ -24,9 +25,9 @@ function Filter({
|
|||||||
let format;
|
let format;
|
||||||
|
|
||||||
if (type === 'date' || type === 'timestamp') {
|
if (type === 'date' || type === 'timestamp') {
|
||||||
format = dateFormats.date;
|
format = formats.date;
|
||||||
} else {
|
} else {
|
||||||
format = dateFormats.datetime;
|
format = formats.datetime;
|
||||||
}
|
}
|
||||||
|
|
||||||
displayedValue = moment
|
displayedValue = moment
|
||||||
|
|||||||
@ -0,0 +1,12 @@
|
|||||||
|
import { dateFormats } from 'strapi-helper-plugin';
|
||||||
|
|
||||||
|
const formats = {
|
||||||
|
...dateFormats,
|
||||||
|
// Customise the format by uncommenting the one you wan to override it corresponds to the type of your field
|
||||||
|
// date: 'dddd, MMMM Do YYYY',
|
||||||
|
// datetime: 'dddd, MMMM Do YYYY HH:mm',
|
||||||
|
// time: 'HH:mm A',
|
||||||
|
// timestamp: 'dddd, MMMM Do YYYY HH:mm',
|
||||||
|
};
|
||||||
|
|
||||||
|
export default formats;
|
||||||
Loading…
x
Reference in New Issue
Block a user