Skip to content

Commit

Permalink
Improved SearchForm test suite (jaegertracing#688)
Browse files Browse the repository at this point in the history
* improved searchform test suite

Signed-off-by: Amanda Chesin <Amanda.Chesin1@aexp.com>

* improved searchform test suite, removede snapshots

Signed-off-by: Amanda Chesin <Amanda.Chesin1@aexp.com>

* removed snapshot tests

Signed-off-by: Amanda Chesin <Amanda.Chesin1@aexp.com>
Signed-off-by: vvvprabhakar <vvvprabhakar@gmail.com>
  • Loading branch information
achesin authored and vvvprabhakar committed Jun 23, 2021
1 parent 591868b commit c089a13
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ export function mapStateToProps(state) {
};
}

function mapDispatchToProps(dispatch) {
export function mapDispatchToProps(dispatch) {
const { searchTraces } = bindActionCreators(jaegerApiActions, dispatch);
return {
onSubmit: fields => submitForm(fields, searchTraces),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
convTagsLogfmt,
getUnixTimeStampInMSFromForm,
lookbackToTimestamp,
mapDispatchToProps,
mapStateToProps,
optionsWithinMaxLookback,
submitForm,
Expand Down Expand Up @@ -264,6 +265,23 @@ describe('submitForm()', () => {
expect(operation).toBe(undefined);
});

it('expects operation to be value defined in beforeEach', () => {
submitForm(fields, searchTraces);
const { calls } = searchTraces.mock;
expect(calls.length).toBe(1);
const { operation } = calls[0][0];
expect(operation).toBe('op-a');
});

it('expects operation to be value assigned before call is made', () => {
fields.operation = 'test';
submitForm(fields, searchTraces);
const { calls } = searchTraces.mock;
expect(calls.length).toBe(1);
const { operation } = calls[0][0];
expect(operation).toBe('test');
});

describe('`fields.lookback`', () => {
function getCalledDuration(mock) {
const { start, end } = mock.calls[0][0];
Expand Down Expand Up @@ -370,6 +388,22 @@ describe('<SearchForm>', () => {
expect(ops.prop('props').disabled).toBe(false);
});

it('keeps operation disabled when no service selected', () => {
let ops = wrapper.find('[placeholder="Select An Operation"]');
expect(ops.prop('props').disabled).toBe(true);
wrapper = shallow(<SearchForm {...defaultProps} selectedService="" />);
ops = wrapper.find('[placeholder="Select An Operation"]');
expect(ops.prop('props').disabled).toBe(true);
});

it('enables operation when unknown service selected', () => {
let ops = wrapper.find('[placeholder="Select An Operation"]');
expect(ops.prop('props').disabled).toBe(true);
wrapper = shallow(<SearchForm {...defaultProps} selectedService="svcC" />);
ops = wrapper.find('[placeholder="Select An Operation"]');
expect(ops.prop('props').disabled).toBe(false);
});

it('shows custom date inputs when `props.selectedLookback` is "custom"', () => {
function getDateFieldLengths(compWrapper) {
return [
Expand Down Expand Up @@ -439,7 +473,7 @@ describe('mapStateToProps()', () => {
let state;

beforeEach(() => {
state = { router: { location: { serach: '' } } };
state = { router: { location: { search: '' } } };
});

it('does not explode when the query string is empty', () => {
Expand Down Expand Up @@ -542,3 +576,11 @@ describe('mapStateToProps()', () => {
expect(msDiff(dateParams.dateStr, dateParams.dateTimeStr, endDate, endDateTime)).toBeLessThan(60 * 1000);
});
});

describe('mapDispatchToProps()', () => {
it('creates the actions correctly', () => {
expect(mapDispatchToProps(() => {})).toEqual({
onSubmit: expect.any(Function),
});
});
});

0 comments on commit c089a13

Please sign in to comment.