From c1147355ecefe802a171c9fcc15e95976f6c874c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20St=C3=BCrmer?= Date: Tue, 11 Aug 2020 17:38:17 +0200 Subject: [PATCH] Add more tests --- .../pages/link_to/link_to_logs.test.tsx | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/x-pack/plugins/infra/public/pages/link_to/link_to_logs.test.tsx b/x-pack/plugins/infra/public/pages/link_to/link_to_logs.test.tsx index 0971ddaf89bf3..945b299674aaa 100644 --- a/x-pack/plugins/infra/public/pages/link_to/link_to_logs.test.tsx +++ b/x-pack/plugins/infra/public/pages/link_to/link_to_logs.test.tsx @@ -53,6 +53,86 @@ describe('LinkToLogsPage component', () => { useLogSourceMock.mockRestore(); }); + describe('default route', () => { + it('redirects to the stream at a given time filtered for a user-defined criterion', () => { + const { history } = renderRoutes( + + + + ); + + history.push('/link-to?time=1550671089404&filter=FILTER_FIELD:FILTER_VALUE'); + + expect(history.location.pathname).toEqual('/stream'); + + const searchParams = new URLSearchParams(history.location.search); + expect(searchParams.get('sourceId')).toEqual('default'); + expect(searchParams.get('logFilter')).toMatchInlineSnapshot( + `"(expression:'FILTER_FIELD:FILTER_VALUE',kind:kuery)"` + ); + expect(searchParams.get('logPosition')).toMatchInlineSnapshot( + `"(end:'2019-02-20T14:58:09.404Z',position:(tiebreaker:0,time:1550671089404),start:'2019-02-20T12:58:09.404Z',streamLive:!f)"` + ); + }); + + it('redirects to the stream using a specific source id', () => { + const { history } = renderRoutes( + + + + ); + + history.push('/link-to/OTHER_SOURCE'); + + expect(history.location.pathname).toEqual('/stream'); + + const searchParams = new URLSearchParams(history.location.search); + expect(searchParams.get('sourceId')).toEqual('OTHER_SOURCE'); + expect(searchParams.get('logFilter')).toMatchInlineSnapshot(`"(expression:'',kind:kuery)"`); + expect(searchParams.get('logPosition')).toEqual(null); + }); + }); + + describe('logs route', () => { + it('redirects to the stream at a given time filtered for a user-defined criterion', () => { + const { history } = renderRoutes( + + + + ); + + history.push('/link-to/logs?time=1550671089404&filter=FILTER_FIELD:FILTER_VALUE'); + + expect(history.location.pathname).toEqual('/stream'); + + const searchParams = new URLSearchParams(history.location.search); + expect(searchParams.get('sourceId')).toEqual('default'); + expect(searchParams.get('logFilter')).toMatchInlineSnapshot( + `"(expression:'FILTER_FIELD:FILTER_VALUE',kind:kuery)"` + ); + expect(searchParams.get('logPosition')).toMatchInlineSnapshot( + `"(end:'2019-02-20T14:58:09.404Z',position:(tiebreaker:0,time:1550671089404),start:'2019-02-20T12:58:09.404Z',streamLive:!f)"` + ); + }); + + it('redirects to the stream using a specific source id', () => { + const { history } = renderRoutes( + + + + ); + + history.push('/link-to/OTHER_SOURCE/logs'); + + expect(history.location.pathname).toEqual('/stream'); + + const searchParams = new URLSearchParams(history.location.search); + expect(searchParams.get('sourceId')).toEqual('OTHER_SOURCE'); + expect(searchParams.get('logFilter')).toMatchInlineSnapshot(`"(expression:'',kind:kuery)"`); + expect(searchParams.get('logPosition')).toEqual(null); + }); + }); + describe('host-logs route', () => { it('redirects to the stream filtered for a host', () => { const { history } = renderRoutes(