Remove hour from default clause in getAllowedIntervalsForQuery when period is empty (https://github.com/woocommerce/woocommerce-admin/pull/1279)

This commit is contained in:
Timmy Crawford 2019-01-11 07:51:24 -08:00 committed by GitHub
parent 764845a6c0
commit 7d89799194
3 changed files with 53 additions and 1 deletions

View File

@ -1,3 +1,7 @@
# 1.0.5 Not Released
- Fixed bug in getAllowedIntervalsForQuery() to not return `hour` for default intervals
# 1.0.4
- Remove deprecated @wordpress/date::getSettings() usage.

View File

@ -395,7 +395,7 @@ export function getAllowedIntervalsForQuery( query ) {
allowed = [ 'day', 'week', 'month', 'quarter' ];
break;
default:
allowed = [ 'hour', 'day' ];
allowed = [ 'day' ];
break;
}
}

View File

@ -21,6 +21,7 @@ import {
getDateDifferenceInDays,
getPreviousDate,
getChartTypeForQuery,
getAllowedIntervalsForQuery,
} from '../src';
describe( 'appendTimestamp', () => {
@ -82,6 +83,53 @@ describe( 'toMoment', () => {
} );
} );
describe( 'getAllowedIntervalsForQuery', () => {
it( 'should return days when query period is defined but empty', () => {
const allowedIntervals = getAllowedIntervalsForQuery( { period: '' } );
expect( allowedIntervals ).toEqual( [ 'day' ] );
} );
it( 'should return days and hours for today and yesterday periods', () => {
const allowedIntervalsToday = getAllowedIntervalsForQuery( { period: 'today' } );
expect( allowedIntervalsToday ).toEqual( [ 'hour', 'day' ] );
const allowedIntervalsYesterday = getAllowedIntervalsForQuery( { period: 'yesterday' } );
expect( allowedIntervalsYesterday ).toEqual( [ 'hour', 'day' ] );
} );
it( 'should return day for week and last_week periods', () => {
const allowedIntervalsWeek = getAllowedIntervalsForQuery( { period: 'week' } );
expect( allowedIntervalsWeek ).toEqual( [ 'day' ] );
const allowedIntervalsLastWeek = getAllowedIntervalsForQuery( { period: 'last_week' } );
expect( allowedIntervalsLastWeek ).toEqual( [ 'day' ] );
} );
it( 'should return day, week for month and last_month periods', () => {
const allowedIntervalsMonth = getAllowedIntervalsForQuery( { period: 'month' } );
expect( allowedIntervalsMonth ).toEqual( [ 'day', 'week' ] );
const allowedIntervalsLastMonth = getAllowedIntervalsForQuery( { period: 'last_month' } );
expect( allowedIntervalsLastMonth ).toEqual( [ 'day', 'week' ] );
} );
it( 'should return day, week, month for quarter and last_quarter periods', () => {
const allowedIntervalsQuarter = getAllowedIntervalsForQuery( { period: 'quarter' } );
expect( allowedIntervalsQuarter ).toEqual( [ 'day', 'week', 'month' ] );
const allowedIntervalsLastQuarter = getAllowedIntervalsForQuery( { period: 'last_quarter' } );
expect( allowedIntervalsLastQuarter ).toEqual( [ 'day', 'week', 'month' ] );
} );
it( 'should return day, week, month, quarter for year and last_year periods', () => {
const allowedIntervalsYear = getAllowedIntervalsForQuery( { period: 'year' } );
expect( allowedIntervalsYear ).toEqual( [ 'day', 'week', 'month', 'quarter' ] );
const allowedIntervalsLastYear = getAllowedIntervalsForQuery( { period: 'last_year' } );
expect( allowedIntervalsLastYear ).toEqual( [ 'day', 'week', 'month', 'quarter' ] );
} );
} );
describe( 'getCurrentPeriod', () => {
it( 'should return a DateValue object with correct properties', () => {
const dateValue = getCurrentPeriod( 'day', 'previous_period' );