Remove hour from default clause in getAllowedIntervalsForQuery when period is empty (https://github.com/woocommerce/woocommerce-admin/pull/1279)
This commit is contained in:
parent
764845a6c0
commit
7d89799194
|
@ -1,3 +1,7 @@
|
||||||
|
# 1.0.5 Not Released
|
||||||
|
|
||||||
|
- Fixed bug in getAllowedIntervalsForQuery() to not return `hour` for default intervals
|
||||||
|
|
||||||
# 1.0.4
|
# 1.0.4
|
||||||
|
|
||||||
- Remove deprecated @wordpress/date::getSettings() usage.
|
- Remove deprecated @wordpress/date::getSettings() usage.
|
||||||
|
|
|
@ -395,7 +395,7 @@ export function getAllowedIntervalsForQuery( query ) {
|
||||||
allowed = [ 'day', 'week', 'month', 'quarter' ];
|
allowed = [ 'day', 'week', 'month', 'quarter' ];
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
allowed = [ 'hour', 'day' ];
|
allowed = [ 'day' ];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import {
|
||||||
getDateDifferenceInDays,
|
getDateDifferenceInDays,
|
||||||
getPreviousDate,
|
getPreviousDate,
|
||||||
getChartTypeForQuery,
|
getChartTypeForQuery,
|
||||||
|
getAllowedIntervalsForQuery,
|
||||||
} from '../src';
|
} from '../src';
|
||||||
|
|
||||||
describe( 'appendTimestamp', () => {
|
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', () => {
|
describe( 'getCurrentPeriod', () => {
|
||||||
it( 'should return a DateValue object with correct properties', () => {
|
it( 'should return a DateValue object with correct properties', () => {
|
||||||
const dateValue = getCurrentPeriod( 'day', 'previous_period' );
|
const dateValue = getCurrentPeriod( 'day', 'previous_period' );
|
||||||
|
|
Loading…
Reference in New Issue