mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-02 17:50:39 +00:00
Fixed appendTime function and its tests.
This commit is contained in:
@@ -5,7 +5,8 @@ import { appendTime } from '../node-details-health-link-item';
|
||||
|
||||
describe('NodeDetailsHealthLinkItem', () => {
|
||||
describe('appendTime', () => {
|
||||
const time = moment.unix(1496275200);
|
||||
const time = '2017-06-01T00:00:00Z';
|
||||
const timeUnix = moment(time).unix();
|
||||
|
||||
it('returns url for empty url or time', () => {
|
||||
expect(appendTime('', time)).toEqual('');
|
||||
@@ -15,10 +16,10 @@ describe('NodeDetailsHealthLinkItem', () => {
|
||||
|
||||
it('appends as json for cloud link', () => {
|
||||
const url = appendTime('/prom/:orgid/notebook/new/%7B%22cells%22%3A%5B%7B%22queries%22%3A%5B%22go_goroutines%22%5D%7D%5D%7D', time);
|
||||
expect(url).toContain(time.unix());
|
||||
expect(url).toContain(timeUnix);
|
||||
|
||||
const payload = JSON.parse(decodeURIComponent(url.substr(url.indexOf('new/') + 4)));
|
||||
expect(payload.time.queryEnd).toEqual(time.unix());
|
||||
expect(payload.time.queryEnd).toEqual(timeUnix);
|
||||
});
|
||||
|
||||
it('appends as GET parameter', () => {
|
||||
|
||||
@@ -10,7 +10,7 @@ import { trackAnalyticsEvent } from '../../utils/tracking-utils';
|
||||
|
||||
/**
|
||||
* @param {string} url
|
||||
* @param {Moment} time
|
||||
* @param {string} time
|
||||
* @returns {string}
|
||||
*/
|
||||
export function appendTime(url, time) {
|
||||
@@ -19,12 +19,13 @@ export function appendTime(url, time) {
|
||||
// rudimentary check whether we have a cloud link
|
||||
const cloudLinkPathEnd = 'notebook/new/';
|
||||
const pos = url.indexOf(cloudLinkPathEnd);
|
||||
const timeUnix = moment(time).unix();
|
||||
if (pos !== -1) {
|
||||
let payload;
|
||||
const json = decodeURIComponent(url.substr(pos + cloudLinkPathEnd.length));
|
||||
try {
|
||||
payload = JSON.parse(json);
|
||||
payload.time = { queryEnd: moment(time).unix() };
|
||||
payload.time = { queryEnd: timeUnix };
|
||||
} catch (e) {
|
||||
return url;
|
||||
}
|
||||
@@ -33,9 +34,9 @@ export function appendTime(url, time) {
|
||||
}
|
||||
|
||||
if (url.indexOf('?') !== -1) {
|
||||
return `${url}&time=${time.unix()}`;
|
||||
return `${url}&time=${timeUnix}`;
|
||||
}
|
||||
return `${url}?time=${time.unix()}`;
|
||||
return `${url}?time=${timeUnix}`;
|
||||
}
|
||||
|
||||
class NodeDetailsHealthLinkItem extends React.Component {
|
||||
|
||||
Reference in New Issue
Block a user