add more to tests - need help though

This commit is contained in:
Timothy Sullivan 2020-07-02 16:05:57 -07:00
parent 6aacfbd25d
commit 6428455873
2 changed files with 40 additions and 2 deletions

View file

@ -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' });
});
});
});

View file

@ -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 () => {
@ -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?
}
});
});