Skip to content

Commit

Permalink
Merge branch 'master' into FET/add-crud-to-stores
Browse files Browse the repository at this point in the history
# Conflicts:
#	assets/dist/build-manifest.json
#	assets/dist/ee-components.622f86c8649619cbcbcb.dist.js
#	assets/dist/ee-components.7d6c99591998d2eae4c0.dist.js
#	assets/dist/ee-components.b72fa352434166ef52be.dist.js
#	assets/dist/ee-data-stores.67b185e1920ba24c7431.dist.js
#	assets/dist/ee-model.7f810d358d08f82e088b.dist.js
#	assets/dist/ee-model.93606ab921bb65bfe8e0.dist.js
#	assets/dist/ee-model.b08f7f3ee436d1dbb468.dist.js
  • Loading branch information
nerrad committed Jan 24, 2019
2 parents 3324fc5 + 1e0c1bb commit 9e4c752
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 72 deletions.
39 changes: 24 additions & 15 deletions assets/src/components/form/model/base/test/build-options.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
/**
* Internal imports
*/
import buildOptions from '../build-options';
import moment from 'moment-timezone';
import { prettyDateFromDateTime } from '../../../../../data/model/datetime/formatter';

/**
* External imports
*/
import {
DATE_TIME_FORMAT_SITE,
TIME_FORMAT_SITE,
} from '@eventespresso/helpers';
import { prettyDateFromDateTime } from '../../../../../data/model/datetime/formatter';
import { ServerDateTime as DateTime, Duration } from '@eventespresso/value-objects';
import { DateTimeFactory } from '@test/fixtures';

describe( 'buildOptions()', () => {
const testResponse = [
Expand Down Expand Up @@ -83,29 +91,30 @@ describe( 'buildOptions()', () => {
);
} );
it( 'returns expected values for options using default optionsEntityMap for DatetimeSelect', () => {
const testLocalMoment = moment( '2018-12-24 05:00:00' ).local();
const dateTimeResponse = [
const testDate = DateTime.fromISO( '2019-01-23T19:20:03.531Z' );
const testEndDate = testDate.plus( Duration.fromObject(
{ [ Duration.UNIT_HOURS ]: 1 } )
);
const testDateTime = DateTimeFactory.createNew(
{
DTT_ID: 30,
DTT_name: 'DateTime 1',
DTT_EVT_start: moment( testLocalMoment ).format(),
DTT_EVT_end: moment( testLocalMoment ).add( 1, 'h' ).format(),
},
];
DTT_EVT_start: testDate,
DTT_EVT_end: testEndDate,
}
);
const response = [ testDateTime ];
const expectedLabel = 'DateTime 1' + ' (' +
moment( testLocalMoment ).format( DATE_TIME_FORMAT_SITE ) +
testDate.toFormat( DATE_TIME_FORMAT_SITE ) +
' - ' +
moment( testLocalMoment ).add( 1, 'h' ).format( TIME_FORMAT_SITE ) +
testEndDate.toFormat( TIME_FORMAT_SITE ) +
')';
expect( buildOptions( dateTimeResponse, datetimeOptionsEntityMap ) ).toEqual(
expect( buildOptions( response, datetimeOptionsEntityMap ) ).toEqual(
[
{
value: 30,
value: testDateTime.DTT_ID,
label: expectedLabel,
},
]
);
} );
} );

// location: assets/src/components/form/select/test/build-options.js
2 changes: 0 additions & 2 deletions assets/src/components/form/model/base/test/model-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,3 @@ describe( 'ModelSelect props check', () => {
expect( wrapper.childAt( 0 ).text() ).toEqual( 'Label for Select' );
} );
} );

// location: assets/src/components/form/select/test/model-select.js
49 changes: 20 additions & 29 deletions assets/src/data/model/datetime/formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
* Internal imports
*/
import * as baseFormatter from '../base-date-formatter';

/**
* External imports
*/
import { forOwn, pullAt } from 'lodash';
import {
TIME_FORMAT_SITE,
DATE_TIME_FORMAT_SITE,
allDateTimesAsString,
SEPARATOR_SPACE_DASH_SPACE,
} from '@eventespresso/helpers';

/**
* External imports
*/
import { forOwn, pullAt } from 'lodash';
import { isModelEntityOfModel } from '@eventespresso/validators';

/**
* Array of fields that have date information
Expand Down Expand Up @@ -62,51 +63,41 @@ forOwn( baseFormatter, ( implementation, functionName ) => {
* This will account for if both start and end are in the same day and simply
* use time for the end part.
*
* @param { Object } DateTimeEntity
* @param { BaseEntity } DateTimeEntity
* @return { string } A formatted string representing the provided
* DateTimeEntity.
*/
export const prettyDateFromDateTime = ( DateTimeEntity = {} ) => {
export const prettyDateFromDateTime = ( DateTimeEntity ) => {
let content = '';
DateTimeEntity = formatters.convertEntityDatesToMoment( DateTimeEntity );
if ( DateTimeEntity.DTT_EVT_start && DateTimeEntity.DTT_EVT_end ) {
if ( DateTimeEntity.DTT_EVT_start.local().format( 'md' ) ===
DateTimeEntity.DTT_EVT_end.local().format( 'md' ) ) {
if ( isModelEntityOfModel( DateTimeEntity, 'datetime' ) ) {
if ( DateTimeEntity.DTT_EVT_start.hasSame(
DateTimeEntity.DTT_EVT_end,
'day'
) ) {
content += allDateTimesAsString(
SEPARATOR_SPACE_DASH_SPACE,
DateTimeEntity.DTT_EVT_start.format(
DateTimeEntity.DTT_EVT_start.toFormat(
DATE_TIME_FORMAT_SITE
),
DateTimeEntity.DTT_EVT_end.format(
DateTimeEntity.DTT_EVT_end.toFormat(
TIME_FORMAT_SITE
),
);
} else {
content += allDateTimesAsString(
SEPARATOR_SPACE_DASH_SPACE,
DateTimeEntity.DTT_EVT_start.format(
DateTimeEntity.DTT_EVT_start.toFormat(
DATE_TIME_FORMAT_SITE
),
DateTimeEntity.DTT_EVT_end.format(
DateTimeEntity.DTT_EVT_end.toFormat(
DATE_TIME_FORMAT_SITE
),
);
}
} else {
if ( DateTimeEntity.DTT_EVT_start ) {
content += DateTimeEntity.DTT_EVT_start.format(
DATE_TIME_FORMAT_SITE
);
}
if ( DateTimeEntity.DTT_EVT_end ) {
content += DateTimeEntity.DTT_EVT_end.format(
DATE_TIME_FORMAT_SITE
);
}
content = DateTimeEntity.DTT_name ?
`${ DateTimeEntity.DTT_name } (${ content })` :
content;
}
content = DateTimeEntity.DTT_name ?
`${ DateTimeEntity.DTT_name } (${ content })` :
content;
return content;
};

Expand Down
70 changes: 46 additions & 24 deletions assets/src/data/model/datetime/test/formatter.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
/**
* Internal imports
*/
import formatters, { prettyDateFromDateTime } from '../formatter';

/**
* External imports
*/
import moment from 'moment-timezone';
import {
DATE_TIME_FORMAT_MYSQL,
DATE_TIME_FORMAT_ISO8601,
DATE_TIME_FORMAT_SITE,
TIME_FORMAT_SITE,
} from '@eventespresso/helpers';
import {
ServerDateTime as DateTime,
Duration,
} from '@eventespresso/value-objects';
import { DateTimeFactory } from '@test/fixtures';

const {
formatDatesOnEntities,
Expand Down Expand Up @@ -391,43 +403,53 @@ describe( 'convertEntitiesDatesToMoment()', () => {
} );

describe( 'prettyDateFromDateTime', () => {
const testDate = DateTime.fromISO( '2019-01-23T19:20:03.531Z' );
const getDateTimeEntity = (
name,
start,
end
) => name ? DateTimeFactory.createNew(
{
DTT_name: name,
DTT_EVT_start: start,
DTT_EVT_end: end,
}
) :
DateTimeFactory.createNew( { DTT_EVT_start: start, DTT_EVT_end: end } );
it( 'returns expected value for no arguments passed in', () => {
expect( prettyDateFromDateTime() ).toEqual( '' );
} );
it( 'returns expected value when DTT_name is present and start date and' +
' end date are on different days',
() => {
expect( prettyDateFromDateTime( testEntities[ 3 ] ) ).toEqual(
'Test Date D' + ' (' + moment( testLocalMoment )
.format( DATE_TIME_FORMAT_SITE ) +
' - ' + moment( testLocalMoment )
.add( 1, 'd' )
.format( DATE_TIME_FORMAT_SITE ) + ')',
const endDate = testDate.plus(
Duration.fromObject( { [ Duration.UNIT_DAYS ]: 2 } )
);
expect( prettyDateFromDateTime(
getDateTimeEntity(
'Test Date D',
testDate,
endDate,
)
) ).toEqual(
'Test Date D' + ' (' + testDate.toFormat( DATE_TIME_FORMAT_SITE ) +
' - ' + endDate.toFormat( DATE_TIME_FORMAT_SITE ) + ')',
);
},
);
it( 'returns expected value when DTT_name is not present and start date' +
' and end date are on the same day',
() => {
expect( prettyDateFromDateTime( testEntities[ 2 ] ) ).toEqual(
moment( testLocalMoment ).format( DATE_TIME_FORMAT_SITE ) +
' - ' + moment( testLocalMoment ).add( 1, 'h' )
.format( TIME_FORMAT_SITE ),
const endDate = testDate.plus(
Duration.fromObject( { [ Duration.UNIT_HOURS ]: 1 } )
);
},
);
it( 'returns expected value when DTT_name is not present and start date' +
' is not present', () => {
expect( prettyDateFromDateTime( testEntities[ 5 ] ) ).toEqual(
'Test Date F' + ' (' + moment( testLocalMoment )
.format( DATE_TIME_FORMAT_SITE ) + ')'
);
} );
it( 'returns expected value when DTT_name is present and end date' +
' is not present', () => {
expect( prettyDateFromDateTime( testEntities[ 4 ] ) ).toEqual(
'Test Date E' + ' (' + moment( testLocalMoment )
.format( DATE_TIME_FORMAT_SITE ) + ')'
expect( prettyDateFromDateTime( getDateTimeEntity(
'',
testDate,
endDate,
) ) ).toEqual(
testDate.toFormat( DATE_TIME_FORMAT_SITE ) +
' - ' + endDate.toFormat( TIME_FORMAT_SITE ),
);
} );
} );
Expand Down
4 changes: 2 additions & 2 deletions espresso.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name:Event Espresso
Plugin URI: http://eventespresso.com/pricing/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=wordpress_plugins_page&utm_content=support_link
Description: Manage events, sell tickets, and receive payments from your WordPress website. Reduce event administration time, cut-out ticketing fees, and own your customer data. | <a href="https://eventespresso.com/add-ons/?utm_source=plugin_activation_screen&utm_medium=link&utm_campaign=plugin_description">Extensions</a> | <a href="https://eventespresso.com/pricing/?utm_source=plugin_activation_screen&utm_medium=link&utm_campaign=plugin_description">Sales</a> | <a href="admin.php?page=espresso_support">Support</a>
Version: 4.9.78.rc.000
Version: 4.9.78.rc.001
Author: Event Espresso
Author URI: http://eventespresso.com/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=wordpress_plugins_page&utm_content=support_link
License: GPLv2
Expand Down Expand Up @@ -102,7 +102,7 @@ function espresso_minimum_php_version_error()
*/
function espresso_version()
{
return apply_filters('FHEE__espresso__espresso_version', '4.9.78.rc.000');
return apply_filters('FHEE__espresso__espresso_version', '4.9.78.rc.001');
}

/**
Expand Down

0 comments on commit 9e4c752

Please sign in to comment.