From 90b0073a47f9b09021f79f0d06cbb7dcfde63137 Mon Sep 17 00:00:00 2001 From: Renat Kalimulin Date: Thu, 20 Jun 2024 13:57:53 +0300 Subject: [PATCH] added tests --- .../Messages/__test__/MessagesTable.spec.tsx | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/frontend/src/components/Topics/Topic/Messages/__test__/MessagesTable.spec.tsx b/frontend/src/components/Topics/Topic/Messages/__test__/MessagesTable.spec.tsx index 808dde9e4..77f31cebc 100644 --- a/frontend/src/components/Topics/Topic/Messages/__test__/MessagesTable.spec.tsx +++ b/frontend/src/components/Topics/Topic/Messages/__test__/MessagesTable.spec.tsx @@ -7,6 +7,8 @@ import MessagesTable, { } from 'components/Topics/Topic/Messages/MessagesTable'; import { TopicMessage, TopicMessageTimestampTypeEnum } from 'generated-sources'; import { useIsLiveMode } from 'lib/hooks/useMessagesFilters'; +import useAppParams from 'lib/hooks/useAppParams'; +import { LOCAL_STORAGE_KEY_PREFIX } from 'lib/constants'; export const topicMessagePayload: TopicMessage = { partition: 29, @@ -33,8 +35,16 @@ jest.mock('lib/hooks/useMessagesFilters', () => ({ usePaginateTopics: jest.fn(), })); +jest.mock('lib/hooks/useAppParams', () => ({ + __esModule: true, + default: jest.fn(), +})); + describe('MessagesTable', () => { const renderComponent = (props?: Partial) => { + (useAppParams as jest.Mock).mockImplementation(() => ({ + topicName: 'testTopic', + })); return render( ); @@ -99,4 +109,34 @@ describe('MessagesTable', () => { } }); }); + + describe('should save messages preview into localstorage', () => { + beforeEach(() => { + renderComponent({ messages: mockTopicsMessages, isFetching: false }); + }); + + it('should save messages preview into localstorage', async () => { + const previewButtons = screen.getAllByText('Preview'); + await userEvent.click(previewButtons[0]); + await userEvent.type(screen.getByPlaceholderText('Field'), 'test1'); + await userEvent.type(screen.getByPlaceholderText('Json Path'), 'test2'); + await userEvent.click(screen.getByText('Save')); + await userEvent.click(previewButtons[1]); + await userEvent.type(screen.getByPlaceholderText('Field'), 'test3'); + await userEvent.type(screen.getByPlaceholderText('Json Path'), 'test4'); + await userEvent.click(screen.getByText('Save')); + expect( + global.localStorage.getItem( + `${LOCAL_STORAGE_KEY_PREFIX}-message-preview` + ) + ).toEqual( + JSON.stringify({ + testTopic: { + keyFilters: [{ field: 'test1', path: 'test2' }], + contentFilters: [{ field: 'test3', path: 'test4' }], + }, + }) + ); + }); + }); });