diff --git a/src/legacy/ui/public/timefilter/setup_router.test.js b/src/legacy/ui/public/timefilter/setup_router.test.js new file mode 100644 index 000000000000..4bc797e5eff0 --- /dev/null +++ b/src/legacy/ui/public/timefilter/setup_router.test.js @@ -0,0 +1,53 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { registerTimefilterWithGlobalState } from './setup_router'; + +jest.mock('ui/utils/subscribe_with_scope', () => ({ + subscribeWithScope: jest.fn() +})); + +describe('registerTimefilterWithGlobalState()', () => { + it('should always use iso8601 strings', async () => { + const setTime = jest.fn(); + const timefilter = { + setTime, + setRefreshInterval: jest.fn(), + getRefreshIntervalUpdate$: jest.fn(), + getTimeUpdate$: jest.fn() + }; + + const globalState = { + time: { + from: '2017-09-07T20:12:04.011Z', + to: '2017-09-07T20:18:55.733Z', + }, + on: (eventName, callback) => { + callback(); + } + }; + + registerTimefilterWithGlobalState( + timefilter, + globalState + ); + + expect(setTime.mock.calls.length).toBe(2); + expect(setTime.mock.calls[1][0]).toEqual(globalState.time); + }); +}); diff --git a/src/legacy/ui/public/timefilter/setup_router.ts b/src/legacy/ui/public/timefilter/setup_router.ts index 3c81fde89149..ffc8a1fca6c6 100644 --- a/src/legacy/ui/public/timefilter/setup_router.ts +++ b/src/legacy/ui/public/timefilter/setup_router.ts @@ -30,7 +30,7 @@ import { TimefilterContract } from '../../../core_plugins/data/public/timefilter // and listener can be registered without angular. function convertISO8601(stringTime: string): string { const obj = moment(stringTime, 'YYYY-MM-DDTHH:mm:ss.SSSZ', true); - return obj.isValid() ? obj.toString() : stringTime; + return obj.isValid() ? obj.toISOString() : stringTime; } export function getTimefilterConfig() {