From a53e7350305480803b474ed9fe015b128648451f Mon Sep 17 00:00:00 2001 From: Amanda Chesin Date: Tue, 16 Feb 2021 16:45:12 -0500 Subject: [PATCH 1/3] improved searchform test suite Signed-off-by: Amanda Chesin --- .../components/SearchTracePage/SearchForm.js | 2 +- .../SearchTracePage/SearchForm.test.js | 46 ++++++++++- .../__snapshots__/SearchForm.test.js.snap | 77 +++++++++++++++++++ 3 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 packages/jaeger-ui/src/components/SearchTracePage/__snapshots__/SearchForm.test.js.snap diff --git a/packages/jaeger-ui/src/components/SearchTracePage/SearchForm.js b/packages/jaeger-ui/src/components/SearchTracePage/SearchForm.js index 0dabd74345..e2cff1a185 100644 --- a/packages/jaeger-ui/src/components/SearchTracePage/SearchForm.js +++ b/packages/jaeger-ui/src/components/SearchTracePage/SearchForm.js @@ -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), diff --git a/packages/jaeger-ui/src/components/SearchTracePage/SearchForm.test.js b/packages/jaeger-ui/src/components/SearchTracePage/SearchForm.test.js index 8969dc6de7..103439d76c 100644 --- a/packages/jaeger-ui/src/components/SearchTracePage/SearchForm.test.js +++ b/packages/jaeger-ui/src/components/SearchTracePage/SearchForm.test.js @@ -26,6 +26,7 @@ import { convTagsLogfmt, getUnixTimeStampInMSFromForm, lookbackToTimestamp, + mapDispatchToProps, mapStateToProps, optionsWithinMaxLookback, submitForm, @@ -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]; @@ -414,6 +432,24 @@ describe('', () => { const field = wrapper.find(`Field[name="resultsLimit"]`); expect(field.prop('props').max).toEqual(maxLimit); }); + + it('disables operation when no service selected', () => { + wrapper = shallow(); + const field = wrapper.find(`Field[name="operation"]`); + expect(field).toMatchSnapshot(); + }); + + it('enables operation when unknown service selected', () => { + wrapper = shallow(); + const field = wrapper.find(`Field[name="operation"]`); + expect(field).toMatchSnapshot(); + }); + + it('enables operation when known service selected', () => { + wrapper = shallow(); + const field = wrapper.find(`Field[name="operation"]`); + expect(field).toMatchSnapshot(); + }); }); describe('validation', () => { @@ -439,7 +475,7 @@ describe('mapStateToProps()', () => { let state; beforeEach(() => { - state = { router: { location: { serach: '' } } }; + state = { router: { location: { search: '' } } }; }); it('does not explode when the query string is empty', () => { @@ -542,3 +578,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), + }); + }); +}); diff --git a/packages/jaeger-ui/src/components/SearchTracePage/__snapshots__/SearchForm.test.js.snap b/packages/jaeger-ui/src/components/SearchTracePage/__snapshots__/SearchForm.test.js.snap new file mode 100644 index 0000000000..e29080da90 --- /dev/null +++ b/packages/jaeger-ui/src/components/SearchTracePage/__snapshots__/SearchForm.test.js.snap @@ -0,0 +1,77 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` disables operation when no service selected 1`] = ` + +`; + +exports[` enables operation when known service selected 1`] = ` + +`; + +exports[` enables operation when unknown service selected 1`] = ` + +`; From 4dcd5bb66131cc579296b2828a4ae72888679f16 Mon Sep 17 00:00:00 2001 From: Amanda Chesin Date: Fri, 19 Feb 2021 16:33:28 -0500 Subject: [PATCH 2/3] improved searchform test suite, removede snapshots Signed-off-by: Amanda Chesin --- .../components/SearchTracePage/SearchForm.js | 2 +- .../SearchTracePage/SearchForm.test.js | 44 ++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/packages/jaeger-ui/src/components/SearchTracePage/SearchForm.js b/packages/jaeger-ui/src/components/SearchTracePage/SearchForm.js index 0dabd74345..e2cff1a185 100644 --- a/packages/jaeger-ui/src/components/SearchTracePage/SearchForm.js +++ b/packages/jaeger-ui/src/components/SearchTracePage/SearchForm.js @@ -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), diff --git a/packages/jaeger-ui/src/components/SearchTracePage/SearchForm.test.js b/packages/jaeger-ui/src/components/SearchTracePage/SearchForm.test.js index 8969dc6de7..fd109de365 100644 --- a/packages/jaeger-ui/src/components/SearchTracePage/SearchForm.test.js +++ b/packages/jaeger-ui/src/components/SearchTracePage/SearchForm.test.js @@ -26,6 +26,7 @@ import { convTagsLogfmt, getUnixTimeStampInMSFromForm, lookbackToTimestamp, + mapDispatchToProps, mapStateToProps, optionsWithinMaxLookback, submitForm, @@ -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]; @@ -370,6 +388,22 @@ describe('', () => { 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(); + 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(); + 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 [ @@ -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', () => { @@ -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), + }); + }); +}); From 117468c30ea8da41263733690fb6008b80e15030 Mon Sep 17 00:00:00 2001 From: Amanda Chesin Date: Fri, 19 Feb 2021 17:22:33 -0500 Subject: [PATCH 3/3] removed snapshot tests Signed-off-by: Amanda Chesin --- .../SearchTracePage/SearchForm.test.js | 18 ----- .../__snapshots__/SearchForm.test.js.snap | 77 ------------------- 2 files changed, 95 deletions(-) delete mode 100644 packages/jaeger-ui/src/components/SearchTracePage/__snapshots__/SearchForm.test.js.snap diff --git a/packages/jaeger-ui/src/components/SearchTracePage/SearchForm.test.js b/packages/jaeger-ui/src/components/SearchTracePage/SearchForm.test.js index 68b013d842..fd109de365 100644 --- a/packages/jaeger-ui/src/components/SearchTracePage/SearchForm.test.js +++ b/packages/jaeger-ui/src/components/SearchTracePage/SearchForm.test.js @@ -448,24 +448,6 @@ describe('', () => { const field = wrapper.find(`Field[name="resultsLimit"]`); expect(field.prop('props').max).toEqual(maxLimit); }); - - it('disables operation when no service selected', () => { - wrapper = shallow(); - const field = wrapper.find(`Field[name="operation"]`); - expect(field).toMatchSnapshot(); - }); - - it('enables operation when unknown service selected', () => { - wrapper = shallow(); - const field = wrapper.find(`Field[name="operation"]`); - expect(field).toMatchSnapshot(); - }); - - it('enables operation when known service selected', () => { - wrapper = shallow(); - const field = wrapper.find(`Field[name="operation"]`); - expect(field).toMatchSnapshot(); - }); }); describe('validation', () => { diff --git a/packages/jaeger-ui/src/components/SearchTracePage/__snapshots__/SearchForm.test.js.snap b/packages/jaeger-ui/src/components/SearchTracePage/__snapshots__/SearchForm.test.js.snap deleted file mode 100644 index e29080da90..0000000000 --- a/packages/jaeger-ui/src/components/SearchTracePage/__snapshots__/SearchForm.test.js.snap +++ /dev/null @@ -1,77 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[` disables operation when no service selected 1`] = ` - -`; - -exports[` enables operation when known service selected 1`] = ` - -`; - -exports[` enables operation when unknown service selected 1`] = ` - -`;