Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nilumilak committed Jun 20, 2024
1 parent 160a659 commit 90b0073
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<MessagesTableProps>) => {
(useAppParams as jest.Mock).mockImplementation(() => ({
topicName: 'testTopic',
}));
return render(
<MessagesTable messages={[]} isFetching={false} {...props} />
);
Expand Down Expand Up @@ -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' }],
},
})
);
});
});
});

0 comments on commit 90b0073

Please sign in to comment.