
* Implementing Context to the Topic messages pages * Using TopicContext in the Topics Topic MessageTable component * Using TopicContext variable in the Filters component * Fixing the Ordering of the Live mode Topic messaging * Fixing isLive parameter bug during page refresh * Minor code modification in Topic Filter Message page * Implement the correct seekType during live mode in url as well as in api call * Add Test cases to Messages and refactor eventSource Mock * Add initial Testing file for messages table * improve the MessagesTable test File * improve the MessagesTable test File + Filter Test File * improve the MessagesTable test File * Change the function name toggleSeekDirection to changeSeekDirection * change the name of the test suites to be more declarative * Display the table progress bar in live mode only when no data is fetched
161 lines
3.9 KiB
TypeScript
161 lines
3.9 KiB
TypeScript
import { render, EventSourceMock } from 'lib/testHelpers';
|
|
import React from 'react';
|
|
import Query, {
|
|
getFormattedErrorFromTableData,
|
|
} from 'components/KsqlDb/Query/Query';
|
|
import { screen, waitFor, within } from '@testing-library/dom';
|
|
import fetchMock from 'fetch-mock';
|
|
import userEvent from '@testing-library/user-event';
|
|
import { Route } from 'react-router-dom';
|
|
import { clusterKsqlDbQueryPath } from 'lib/paths';
|
|
|
|
const clusterName = 'testLocal';
|
|
const renderComponent = () =>
|
|
render(
|
|
<Route path={clusterKsqlDbQueryPath(':clusterName')}>
|
|
<Query />
|
|
</Route>,
|
|
{
|
|
pathname: clusterKsqlDbQueryPath(clusterName),
|
|
}
|
|
);
|
|
|
|
describe('Query', () => {
|
|
it('renders', () => {
|
|
renderComponent();
|
|
|
|
expect(screen.getByLabelText('KSQL')).toBeInTheDocument();
|
|
expect(
|
|
screen.getByLabelText('Stream properties (JSON format)')
|
|
).toBeInTheDocument();
|
|
});
|
|
|
|
afterEach(() => fetchMock.reset());
|
|
it('fetch on execute', async () => {
|
|
renderComponent();
|
|
|
|
const mock = fetchMock.postOnce(`/api/clusters/${clusterName}/ksql/v2`, {
|
|
pipeId: 'testPipeID',
|
|
});
|
|
|
|
Object.defineProperty(window, 'EventSource', {
|
|
value: EventSourceMock,
|
|
});
|
|
|
|
await waitFor(() =>
|
|
userEvent.paste(
|
|
within(screen.getByLabelText('KSQL')).getByRole('textbox'),
|
|
'show tables;'
|
|
)
|
|
);
|
|
|
|
await waitFor(() =>
|
|
userEvent.click(screen.getByRole('button', { name: 'Execute' }))
|
|
);
|
|
expect(mock.calls().length).toBe(1);
|
|
});
|
|
|
|
it('fetch on execute with streamParams', async () => {
|
|
renderComponent();
|
|
|
|
const mock = fetchMock.postOnce(`/api/clusters/${clusterName}/ksql/v2`, {
|
|
pipeId: 'testPipeID',
|
|
});
|
|
|
|
Object.defineProperty(window, 'EventSource', {
|
|
value: EventSourceMock,
|
|
});
|
|
|
|
await waitFor(() =>
|
|
userEvent.paste(
|
|
within(screen.getByLabelText('KSQL')).getByRole('textbox'),
|
|
'show tables;'
|
|
)
|
|
);
|
|
|
|
await waitFor(() =>
|
|
userEvent.paste(
|
|
within(
|
|
screen.getByLabelText('Stream properties (JSON format)')
|
|
).getByRole('textbox'),
|
|
'{"some":"json"}'
|
|
)
|
|
);
|
|
|
|
await waitFor(() =>
|
|
userEvent.click(screen.getByRole('button', { name: 'Execute' }))
|
|
);
|
|
expect(mock.calls().length).toBe(1);
|
|
});
|
|
|
|
it('fetch on execute with streamParams', async () => {
|
|
renderComponent();
|
|
|
|
const mock = fetchMock.postOnce(`/api/clusters/${clusterName}/ksql/v2`, {
|
|
pipeId: 'testPipeID',
|
|
});
|
|
|
|
Object.defineProperty(window, 'EventSource', {
|
|
value: EventSourceMock,
|
|
});
|
|
|
|
await waitFor(() =>
|
|
userEvent.paste(
|
|
within(screen.getByLabelText('KSQL')).getByRole('textbox'),
|
|
'show tables;'
|
|
)
|
|
);
|
|
|
|
await waitFor(() =>
|
|
userEvent.paste(
|
|
within(
|
|
screen.getByLabelText('Stream properties (JSON format)')
|
|
).getByRole('textbox'),
|
|
'{"some":"json"}'
|
|
)
|
|
);
|
|
|
|
await waitFor(() =>
|
|
userEvent.click(screen.getByRole('button', { name: 'Execute' }))
|
|
);
|
|
expect(mock.calls().length).toBe(1);
|
|
});
|
|
});
|
|
|
|
describe('getFormattedErrorFromTableData', () => {
|
|
it('works', () => {
|
|
expect(getFormattedErrorFromTableData([['Test Error']])).toStrictEqual({
|
|
title: 'Test Error',
|
|
message: '',
|
|
});
|
|
|
|
expect(
|
|
getFormattedErrorFromTableData([
|
|
['some_type', 'errorCode', 'messageText'],
|
|
])
|
|
).toStrictEqual({
|
|
title: '[Error #errorCode] some_type',
|
|
message: 'messageText',
|
|
});
|
|
|
|
expect(
|
|
getFormattedErrorFromTableData([
|
|
[
|
|
'some_type',
|
|
'errorCode',
|
|
'messageText',
|
|
'statementText',
|
|
['test1', 'test2'],
|
|
],
|
|
])
|
|
).toStrictEqual({
|
|
title: '[Error #errorCode] some_type',
|
|
message: '[test1, test2] "statementText" messageText',
|
|
});
|
|
|
|
expect(getFormattedErrorFromTableData([])).toStrictEqual({
|
|
title: 'Unknown error',
|
|
message: 'Recieved empty response',
|
|
});
|
|
});
|
|
});
|