Skip to content

Commit

Permalink
fixes jaegertracing#167: 2 digit lookback (12h, 24h) parsing (jaegert…
Browse files Browse the repository at this point in the history
…racing#168)

* fix 2 digit lookback (12h, 24h) parsing

Signed-off-by: golonzovsky <alex.golonzovsky@gmail.com>

* add double digit lookback options parsing test

Signed-off-by: golonzovsky <alex.golonzovsky@gmail.com>

Signed-off-by: vvvprabhakar <vvvprabhakar@gmail.com>
  • Loading branch information
golonzovsky authored and tiffon committed Jan 15, 2018
1 parent a6e437a commit a08bb44
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/components/SearchTracePage/TraceSearchForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function submitForm(fields, searchTraces) {
let start;
let end;
if (lookback !== 'custom') {
const unit = lookback[1];
const unit = lookback.substr(-1);
const now = new Date();
start =
moment(now)
Expand Down
22 changes: 16 additions & 6 deletions src/components/SearchTracePage/TraceSearchForm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,24 @@ describe('submitForm()', () => {
});

describe('`fields.lookback`', () => {
function getCalledDuration(mock) {
const { start, end } = mock.calls[0][0];
const diffMs = (Number(end) - Number(start)) / 1000;
return moment.duration(diffMs);
}

it('subtracts `lookback` from `fields.end`', () => {
submitForm(fields, searchTraces);
const { calls } = searchTraces.mock;
expect(calls.length).toBe(1);
const { start, end } = calls[0][0];
const diffMs = (Number(end) - Number(start)) / 1000;
const duration = moment.duration(diffMs);
expect(duration.asSeconds()).toBe(LOOKBACK_VALUE);
expect(searchTraces).toHaveBeenCalledTimes(1);
expect(getCalledDuration(searchTraces.mock).asSeconds()).toBe(LOOKBACK_VALUE);
});

it('parses `lookback` double digit options', () => {
const lookbackDoubleDigitValue = 12;
fields.lookback = `${lookbackDoubleDigitValue}h`;
submitForm(fields, searchTraces);
expect(searchTraces).toHaveBeenCalledTimes(1);
expect(getCalledDuration(searchTraces.mock).asHours()).toBe(lookbackDoubleDigitValue);
});

it('processes form dates when `lookback` is "custom"', () => {
Expand Down

0 comments on commit a08bb44

Please sign in to comment.