Create unit test.

This commit is contained in:
Brian Cao 2023-09-25 13:31:25 -07:00
parent ce2a83a09f
commit e6eb9a487e
4 changed files with 21 additions and 19 deletions

View file

@ -30,6 +30,8 @@ export const FILTER_RANGE = 'filter-range';
export const FILTER_REFERRERS = 'filter-referrers';
export const FILTER_PAGES = 'filter-pages';
export const UNIT_TYPES = ['year', 'month', 'hour', 'day'];
export const USER_FILTER_TYPES = {
all: 'All',
username: 'Username',

View file

@ -1,5 +1,6 @@
import moment from 'moment';
import * as yup from 'yup';
import { UNIT_TYPES } from './constants';
export const DateRangeValidation = {
startAt: yup.number().integer().required(),
@ -20,5 +21,11 @@ export function getFilterValidation(matchRegex) {
export const TimezoneTest = yup.string().test(
'timezone',
() => `Invalid timezone`,
value => !moment.tz.zone(value),
value => !value || !moment.tz.zone(value),
);
export const UnitTypeTest = yup.string().test(
'unit',
() => `Invalid unit`,
value => !value || !UNIT_TYPES.includes(value),
);