Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved SearchForm test suite #688

Merged
merged 5 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
});
});
});