Skip to content

Commit

Permalink
Fix current date and time always showing in date selector (Event Atte…
Browse files Browse the repository at this point in the history
…ndees block) (#911)

The Event Attendees block is always showing the current datetime.  I think this happened as a result of the model-entity work being merged in.  The fix involved correctly accounting for the new DateTime model-entities which include usage of `DateTime` value objects for the date values.

Tests are updated as well.
  • Loading branch information
nerrad authored Jan 24, 2019
1 parent 2aec75f commit dd43836
Show file tree
Hide file tree
Showing 16 changed files with 875 additions and 873 deletions.
8 changes: 4 additions & 4 deletions assets/dist/build-manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"components.css": "ee-components.997177945b17ee98a639.dist.css",
"components.js": "ee-components.622f86c8649619cbcbcb.dist.js",
"data-stores.js": "ee-data-stores.dc634000795c4ba9a507.dist.js",
"components.js": "ee-components.b72fa352434166ef52be.dist.js",
"data-stores.js": "ee-data-stores.67b185e1920ba24c7431.dist.js",
"editor-hocs.js": "ee-editor-hocs.15a813aac7a51b5473cb.dist.js",
"eejs.js": "ee-eejs.42c92b6e2c9ea03b7fcb.dist.js",
"eventespresso-core-blocks-frontend.css": "ee-eventespresso-core-blocks-frontend.f0ea9ad96d720bc8dc9b.dist.css",
Expand All @@ -11,10 +11,10 @@
"helpers.js": "ee-helpers.aa14a7d4abec4efb1036.dist.js",
"hocs.js": "ee-hocs.97a8ee6842846da19735.dist.js",
"manifest.js": "ee-manifest.45b8faa573682047153a.dist.js",
"model.js": "ee-model.7f810d358d08f82e088b.dist.js",
"model.js": "ee-model.93606ab921bb65bfe8e0.dist.js",
"validators.js": "ee-validators.400994f2dc2c8922b864.dist.js",
"valueObjects.js": "ee-valueObjects.33103ace62bfb5a26030.dist.js",
"vendor.js": "ee-vendor.bd38b3513999b11ec414.dist.js",
"wp-plugins-page.css": "ee-wp-plugins-page.0aa86e25ceb666993965.dist.css",
"wp-plugins-page.js": "ee-wp-plugins-page.6711248a012a5dfbff0b.dist.js"
"wp-plugins-page.js": "ee-wp-plugins-page.affe522f72bae3a5e5df.dist.js"
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

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
2 changes: 1 addition & 1 deletion assets/src/data/model/entity-factory/test/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External imports
*/
import { InvalidDateTime, InvalidSchema } from '@eventespresso/eejs';
import { DateTime, Money, SiteCurrency } from '@eventespresso/vo';
import { DateTime, Money, SiteCurrency } from '@eventespresso/value-objects';
import {
EventSchema,
RegistrationSchemaProperties,
Expand Down
2 changes: 1 addition & 1 deletion assets/src/data/model/entity-factory/test/base-entity.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External imports
*/
import { DateTime } from '@eventespresso/vo';
import { DateTime } from '@eventespresso/value-objects';
import { PRIVATE_PROPERTIES, SAVE_STATE } from '../constants';
import { isCuid } from 'cuid';
import { isArray } from 'lodash';
Expand Down
2 changes: 1 addition & 1 deletion assets/src/data/model/entity-factory/test/extractors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External imports
*/
import { InvalidDateTime } from '@eventespresso/eejs';
import { DateTime, Money, SiteCurrency } from '@eventespresso/vo';
import { DateTime, Money, SiteCurrency } from '@eventespresso/value-objects';
import {
EventSchemaProperties,
RegistrationSchemaProperties,
Expand Down
2 changes: 1 addition & 1 deletion assets/src/data/model/entity-factory/test/validators.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External imports
*/
import { DateTime, Money, SiteCurrency } from '@eventespresso/vo';
import { DateTime, Money, SiteCurrency } from '@eventespresso/value-objects';
import { InvalidDateTime } from '@eventespresso/eejs';
import {
EventSchemaProperties,
Expand Down
2 changes: 1 addition & 1 deletion assets/src/higher-order-components/money.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Component } from 'react';
import { isFunction, isArray } from 'lodash';
import isShallowEqualArrays from '@wordpress/is-shallow-equal';
import warning from 'warning';
import { Money, SiteCurrency } from '@eventespresso/vo';
import { Money, SiteCurrency } from '@eventespresso/value-objects';

/**
* This validates whether the nextStateResponse is in the expected shape.
Expand Down
2 changes: 1 addition & 1 deletion assets/src/higher-order-components/test/money.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Internal Imports
*/
import withMoney from '../money';
import { Money, SiteCurrency } from '@eventespresso/vo';
import { Money, SiteCurrency } from '@eventespresso/value-objects';

/**
* External Imports
Expand Down
2 changes: 1 addition & 1 deletion tests/javascript-config/unit/jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@eventespresso\/helpers": "assets/src/data/helpers",
"@eventespresso\/validators": "assets/src/eejs/validators",
"@eventespresso\/model": "assets/src/data/model",
"@eventespresso\/vo": "assets/src/vo",
"@eventespresso\/value-objects": "assets/src/vo",
"@eventespresso\/components": "assets/src/components",
"@eventespresso\/editor-hocs": "assets/src/editor/hocs",
"tinymce": "<rootDir>/tests/javascript-config/unit/mocks/tinymce",
Expand Down

0 comments on commit dd43836

Please sign in to comment.