Skip to content

Commit

Permalink
add more to tests - need help though
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Jul 6, 2020
1 parent 6aacfbd commit 6428455
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,22 @@ describe('FieldFormatsRegistry', () => {
expect(params).toHaveProperty('parsedUrl');
});
});

describe('setCustomParams', () => {
test('should provide custom setting to formatters: timezone', () => {
fieldFormatsRegistry = new FieldFormatsRegistry();
fieldFormatsRegistry.init(
getConfig,
{
parsedUrl: {
origin: '',
pathname: '',
basePath: '',
},
},
[]
);
fieldFormatsRegistry.setCustomParams({ timezone: 'America/New_York' });
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
* under the License.
*/

import { FieldFormatsService } from './field_formats_service';
import { DateFormat } from './converters/date_server';
import { coreMock } from '../../../../core/server/mocks';
import { FIELD_FORMAT_IDS } from '../../common';
import { DateFormat } from './converters/date_server';
import { FieldFormatsService } from './field_formats_service';

describe('FieldFormatService', () => {
test('DateFormat is server version', async () => {
Expand All @@ -32,3 +33,22 @@ describe('FieldFormatService', () => {
expect(DateFormatFromRegsitry).toEqual(DateFormat);
});
});

describe('DateFormat with custom timezone', () => {
test('should provide custom setting to formatters: timezone', async () => {
const service = new FieldFormatsService();
const fieldFormatsService = await service.start();
const uiSettings = coreMock.createStart().uiSettings.asScopedToClient({} as any);
const fieldFormatsRegistry = await fieldFormatsService.fieldFormatServiceFactory(uiSettings);

fieldFormatsRegistry.setCustomParams({ timezone: 'America/Phoenix' }); // set the timezone into the registry

const fieldFormats = fieldFormatsRegistry.getByFieldType(FIELD_FORMAT_IDS.DATE as any);
const DateFormatInstance = fieldFormats.find((F) => F.id === 'date');
expect(DateFormatInstance).toBeDefined();
if (DateFormatInstance) {
const formatter = new DateFormatInstance();
// how to call the formatter?
}
});
});

0 comments on commit 6428455

Please sign in to comment.