|
@@ -1,56 +1,45 @@
|
|
|
import React from 'react';
|
|
|
-import { mount, ReactWrapper } from 'enzyme';
|
|
|
-import { Route, Router } from 'react-router-dom';
|
|
|
-import { act } from 'react-dom/test-utils';
|
|
|
+import { render } from 'lib/testHelpers';
|
|
|
+import { screen, waitFor, within } from '@testing-library/react';
|
|
|
+import { Route, Router, StaticRouter } from 'react-router';
|
|
|
import ClusterContext, {
|
|
|
ContextProps,
|
|
|
} from 'components/contexts/ClusterContext';
|
|
|
import List, { TopicsListProps } from 'components/Topics/List/List';
|
|
|
import { createMemoryHistory } from 'history';
|
|
|
-import { StaticRouter } from 'react-router';
|
|
|
-import Search from 'components/common/Search/Search';
|
|
|
import { externalTopicPayload } from 'redux/reducers/topics/__test__/fixtures';
|
|
|
-import { ConfirmationModalProps } from 'components/common/ConfirmationModal/ConfirmationModal';
|
|
|
-import theme from 'theme/theme';
|
|
|
-import { ThemeProvider } from 'styled-components';
|
|
|
-import { SortOrder } from 'generated-sources';
|
|
|
-
|
|
|
-jest.mock(
|
|
|
- 'components/common/ConfirmationModal/ConfirmationModal',
|
|
|
- () => 'mock-ConfirmationModal'
|
|
|
-);
|
|
|
+import { CleanUpPolicy, SortOrder } from 'generated-sources';
|
|
|
+import userEvent from '@testing-library/user-event';
|
|
|
|
|
|
describe('List', () => {
|
|
|
const setupComponent = (props: Partial<TopicsListProps> = {}) => (
|
|
|
- <ThemeProvider theme={theme}>
|
|
|
- <List
|
|
|
- areTopicsFetching={false}
|
|
|
- topics={[]}
|
|
|
- totalPages={1}
|
|
|
- fetchTopicsList={jest.fn()}
|
|
|
- deleteTopic={jest.fn()}
|
|
|
- deleteTopics={jest.fn()}
|
|
|
- clearTopicsMessages={jest.fn()}
|
|
|
- clearTopicMessages={jest.fn()}
|
|
|
- recreateTopic={jest.fn()}
|
|
|
- search=""
|
|
|
- orderBy={null}
|
|
|
- sortOrder={SortOrder.ASC}
|
|
|
- setTopicsSearch={jest.fn()}
|
|
|
- setTopicsOrderBy={jest.fn()}
|
|
|
- {...props}
|
|
|
- />
|
|
|
- </ThemeProvider>
|
|
|
+ <List
|
|
|
+ areTopicsFetching={false}
|
|
|
+ topics={[]}
|
|
|
+ totalPages={1}
|
|
|
+ fetchTopicsList={jest.fn()}
|
|
|
+ deleteTopic={jest.fn()}
|
|
|
+ deleteTopics={jest.fn()}
|
|
|
+ clearTopicsMessages={jest.fn()}
|
|
|
+ clearTopicMessages={jest.fn()}
|
|
|
+ recreateTopic={jest.fn()}
|
|
|
+ search=""
|
|
|
+ orderBy={null}
|
|
|
+ sortOrder={SortOrder.ASC}
|
|
|
+ setTopicsSearch={jest.fn()}
|
|
|
+ setTopicsOrderBy={jest.fn()}
|
|
|
+ {...props}
|
|
|
+ />
|
|
|
);
|
|
|
|
|
|
const historyMock = createMemoryHistory();
|
|
|
|
|
|
- const mountComponentWithProviders = (
|
|
|
+ const renderComponentWithProviders = (
|
|
|
contextProps: Partial<ContextProps> = {},
|
|
|
props: Partial<TopicsListProps> = {},
|
|
|
history = historyMock
|
|
|
) =>
|
|
|
- mount(
|
|
|
+ render(
|
|
|
<Router history={history}>
|
|
|
<ClusterContext.Provider
|
|
|
value={{
|
|
@@ -68,84 +57,79 @@ describe('List', () => {
|
|
|
|
|
|
describe('when it has readonly flag', () => {
|
|
|
it('does not render the Add a Topic button', () => {
|
|
|
- const component = mountComponentWithProviders();
|
|
|
- expect(component.exists('Link')).toBeFalsy();
|
|
|
+ renderComponentWithProviders();
|
|
|
+ expect(screen.queryByText(/add a topic/)).not.toBeInTheDocument();
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('when it does not have readonly flag', () => {
|
|
|
- let fetchTopicsList = jest.fn();
|
|
|
- let component: ReactWrapper;
|
|
|
- const internalTopicsSwitchName = 'input[name="ShowInternalTopics"]';
|
|
|
+ const fetchTopicsList = jest.fn();
|
|
|
|
|
|
jest.useFakeTimers();
|
|
|
|
|
|
- beforeEach(() => {
|
|
|
- fetchTopicsList = jest.fn();
|
|
|
-
|
|
|
- component = mountComponentWithProviders(
|
|
|
- { isReadOnly: false },
|
|
|
- { fetchTopicsList }
|
|
|
- );
|
|
|
+ afterEach(() => {
|
|
|
+ fetchTopicsList.mockClear();
|
|
|
});
|
|
|
|
|
|
it('renders the Add a Topic button', () => {
|
|
|
- expect(component.exists('Link')).toBeTruthy();
|
|
|
+ renderComponentWithProviders({ isReadOnly: false }, { fetchTopicsList });
|
|
|
+ expect(screen.getByText(/add a topic/i)).toBeInTheDocument();
|
|
|
});
|
|
|
|
|
|
- it('calls setTopicsSearch on input', () => {
|
|
|
+ it('calls setTopicsSearch on input', async () => {
|
|
|
const setTopicsSearch = jest.fn();
|
|
|
- component = mountComponentWithProviders({}, { setTopicsSearch });
|
|
|
+ renderComponentWithProviders({}, { setTopicsSearch });
|
|
|
const query = 'topic';
|
|
|
- const input = component.find(Search);
|
|
|
- input.props().handleSearch(query);
|
|
|
- expect(setTopicsSearch).toHaveBeenCalledWith(query);
|
|
|
+ const searchElement = screen.getByPlaceholderText('Search by Topic Name');
|
|
|
+ userEvent.type(searchElement, query);
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(setTopicsSearch).toHaveBeenCalledWith(query);
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
it('show internal toggle state should be true if user has not used it yet', () => {
|
|
|
- const toggle = component.find(internalTopicsSwitchName);
|
|
|
- const { checked } = toggle.props();
|
|
|
+ renderComponentWithProviders({ isReadOnly: false }, { fetchTopicsList });
|
|
|
+ const internalCheckBox = screen.getByRole('checkbox');
|
|
|
|
|
|
- expect(checked).toEqual(true);
|
|
|
+ expect(internalCheckBox).toBeChecked();
|
|
|
});
|
|
|
|
|
|
it('show internal toggle state should match user preference', () => {
|
|
|
localStorage.setItem('hideInternalTopics', 'true');
|
|
|
- component = mountComponentWithProviders(
|
|
|
- { isReadOnly: false },
|
|
|
- { fetchTopicsList }
|
|
|
- );
|
|
|
+ renderComponentWithProviders({ isReadOnly: false }, { fetchTopicsList });
|
|
|
|
|
|
- const toggle = component.find(internalTopicsSwitchName);
|
|
|
- const { checked } = toggle.props();
|
|
|
+ const internalCheckBox = screen.getByRole('checkbox');
|
|
|
|
|
|
- expect(checked).toEqual(false);
|
|
|
+ expect(internalCheckBox).not.toBeChecked();
|
|
|
});
|
|
|
|
|
|
- it('should refetch topics on show internal toggle change', () => {
|
|
|
- jest.clearAllMocks();
|
|
|
- const toggle = component.find(internalTopicsSwitchName);
|
|
|
- const { checked } = toggle.props();
|
|
|
- toggle.simulate('change');
|
|
|
+ it('should re-fetch topics on show internal toggle change', async () => {
|
|
|
+ renderComponentWithProviders({ isReadOnly: false }, { fetchTopicsList });
|
|
|
+ const internalCheckBox: HTMLInputElement = screen.getByRole('checkbox');
|
|
|
|
|
|
- expect(fetchTopicsList).toHaveBeenLastCalledWith({
|
|
|
- search: '',
|
|
|
- showInternal: !checked,
|
|
|
- sortOrder: SortOrder.ASC,
|
|
|
+ userEvent.click(internalCheckBox);
|
|
|
+ const { value } = internalCheckBox;
|
|
|
+
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(fetchTopicsList).toHaveBeenLastCalledWith({
|
|
|
+ search: '',
|
|
|
+ showInternal: value === 'on',
|
|
|
+ sortOrder: SortOrder.ASC,
|
|
|
+ });
|
|
|
});
|
|
|
});
|
|
|
|
|
|
it('should reset page query param on show internal toggle change', () => {
|
|
|
const mockedHistory = createMemoryHistory();
|
|
|
jest.spyOn(mockedHistory, 'push');
|
|
|
- component = mountComponentWithProviders(
|
|
|
+ renderComponentWithProviders(
|
|
|
{ isReadOnly: false },
|
|
|
{ fetchTopicsList },
|
|
|
mockedHistory
|
|
|
);
|
|
|
|
|
|
- const toggle = component.find(internalTopicsSwitchName);
|
|
|
- toggle.simulate('change');
|
|
|
+ const internalCheckBox: HTMLInputElement = screen.getByRole('checkbox');
|
|
|
+ userEvent.click(internalCheckBox);
|
|
|
|
|
|
expect(mockedHistory.push).toHaveBeenCalledWith('/?page=1&perPage=25');
|
|
|
});
|
|
@@ -153,127 +137,158 @@ describe('List', () => {
|
|
|
it('should set cached page query param on show internal toggle change', async () => {
|
|
|
const mockedHistory = createMemoryHistory();
|
|
|
jest.spyOn(mockedHistory, 'push');
|
|
|
- component = mountComponentWithProviders(
|
|
|
+
|
|
|
+ const cachedPage = 5;
|
|
|
+ mockedHistory.push(`/?page=${cachedPage}&perPage=25`);
|
|
|
+
|
|
|
+ renderComponentWithProviders(
|
|
|
{ isReadOnly: false },
|
|
|
{ fetchTopicsList, totalPages: 10 },
|
|
|
mockedHistory
|
|
|
);
|
|
|
|
|
|
- const cachedPage = 5;
|
|
|
+ const searchInput = screen.getByPlaceholderText('Search by Topic Name');
|
|
|
+ userEvent.type(searchInput, 'nonEmptyString');
|
|
|
|
|
|
- mockedHistory.push(`/?page=${cachedPage}&perPage=25`);
|
|
|
-
|
|
|
- const input = component.find(Search);
|
|
|
- input.props().handleSearch('nonEmptyString');
|
|
|
-
|
|
|
- expect(mockedHistory.push).toHaveBeenCalledWith('/?page=1&perPage=25');
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(mockedHistory.push).toHaveBeenCalledWith('/?page=1&perPage=25');
|
|
|
+ });
|
|
|
|
|
|
- input.props().handleSearch('');
|
|
|
+ userEvent.clear(searchInput);
|
|
|
|
|
|
- expect(mockedHistory.push).toHaveBeenCalledWith(
|
|
|
- `/?page=${cachedPage}&perPage=25`
|
|
|
- );
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(mockedHistory.push).toHaveBeenCalledWith(
|
|
|
+ `/?page=${cachedPage}&perPage=25`
|
|
|
+ );
|
|
|
+ });
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('when some list items are selected', () => {
|
|
|
const mockDeleteTopics = jest.fn();
|
|
|
+ const mockDeleteTopic = jest.fn();
|
|
|
+ const mockClearTopic = jest.fn();
|
|
|
const mockClearTopicsMessages = jest.fn();
|
|
|
+ const mockRecreate = jest.fn();
|
|
|
+ const fetchTopicsList = jest.fn();
|
|
|
+
|
|
|
jest.useFakeTimers();
|
|
|
const pathname = '/ui/clusters/local/topics';
|
|
|
- const component = mount(
|
|
|
- <StaticRouter location={{ pathname }}>
|
|
|
- <Route path="/ui/clusters/:clusterName">
|
|
|
- <ClusterContext.Provider
|
|
|
- value={{
|
|
|
- isReadOnly: false,
|
|
|
- hasKafkaConnectConfigured: true,
|
|
|
- hasSchemaRegistryConfigured: true,
|
|
|
- isTopicDeletionAllowed: true,
|
|
|
- }}
|
|
|
- >
|
|
|
- {setupComponent({
|
|
|
- topics: [
|
|
|
- externalTopicPayload,
|
|
|
- { ...externalTopicPayload, name: 'external.topic2' },
|
|
|
- ],
|
|
|
- deleteTopics: mockDeleteTopics,
|
|
|
- clearTopicsMessages: mockClearTopicsMessages,
|
|
|
- })}
|
|
|
- </ClusterContext.Provider>
|
|
|
- </Route>
|
|
|
- </StaticRouter>
|
|
|
- );
|
|
|
- const getCheckboxInput = (at: number) =>
|
|
|
- component.find('TableRow').at(at).find('input[type="checkbox"]').at(0);
|
|
|
|
|
|
- const getConfirmationModal = () =>
|
|
|
- component.find('mock-ConfirmationModal').at(0);
|
|
|
+ beforeEach(() => {
|
|
|
+ render(
|
|
|
+ <StaticRouter location={{ pathname }}>
|
|
|
+ <Route path="/ui/clusters/:clusterName">
|
|
|
+ <ClusterContext.Provider
|
|
|
+ value={{
|
|
|
+ isReadOnly: false,
|
|
|
+ hasKafkaConnectConfigured: true,
|
|
|
+ hasSchemaRegistryConfigured: true,
|
|
|
+ isTopicDeletionAllowed: true,
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ {setupComponent({
|
|
|
+ topics: [
|
|
|
+ {
|
|
|
+ ...externalTopicPayload,
|
|
|
+ cleanUpPolicy: CleanUpPolicy.DELETE,
|
|
|
+ },
|
|
|
+ { ...externalTopicPayload, name: 'external.topic2' },
|
|
|
+ ],
|
|
|
+ deleteTopics: mockDeleteTopics,
|
|
|
+ clearTopicsMessages: mockClearTopicsMessages,
|
|
|
+ recreateTopic: mockRecreate,
|
|
|
+ deleteTopic: mockDeleteTopic,
|
|
|
+ clearTopicMessages: mockClearTopic,
|
|
|
+ fetchTopicsList,
|
|
|
+ })}
|
|
|
+ </ClusterContext.Provider>
|
|
|
+ </Route>
|
|
|
+ </StaticRouter>
|
|
|
+ );
|
|
|
+ });
|
|
|
+
|
|
|
+ afterEach(() => {
|
|
|
+ mockDeleteTopics.mockClear();
|
|
|
+ mockClearTopicsMessages.mockClear();
|
|
|
+ mockRecreate.mockClear();
|
|
|
+ mockDeleteTopic.mockClear();
|
|
|
+ });
|
|
|
+
|
|
|
+ const getCheckboxInput = (at: number) => {
|
|
|
+ const rows = screen.getAllByRole('row');
|
|
|
+ return within(rows[at + 1]).getByRole('checkbox');
|
|
|
+ };
|
|
|
|
|
|
it('renders delete/purge buttons', () => {
|
|
|
- expect(getCheckboxInput(0).props().checked).toBeFalsy();
|
|
|
- expect(getCheckboxInput(1).props().checked).toBeFalsy();
|
|
|
- expect(component.find('.buttons').length).toEqual(0);
|
|
|
+ const firstCheckbox = getCheckboxInput(0);
|
|
|
+ const secondCheckbox = getCheckboxInput(1);
|
|
|
+ expect(firstCheckbox).not.toBeChecked();
|
|
|
+ expect(secondCheckbox).not.toBeChecked();
|
|
|
+ // expect(component.find('.buttons').length).toEqual(0);
|
|
|
|
|
|
// check first item
|
|
|
- getCheckboxInput(0).simulate('change', { target: { checked: true } });
|
|
|
- expect(getCheckboxInput(0).props().checked).toBeTruthy();
|
|
|
- expect(getCheckboxInput(1).props().checked).toBeFalsy();
|
|
|
+ userEvent.click(firstCheckbox);
|
|
|
+ expect(firstCheckbox).toBeChecked();
|
|
|
+ expect(secondCheckbox).not.toBeChecked();
|
|
|
+
|
|
|
+ expect(screen.getByTestId('delete-buttons')).toBeInTheDocument();
|
|
|
|
|
|
// check second item
|
|
|
- getCheckboxInput(1).simulate('change', { target: { checked: true } });
|
|
|
- expect(getCheckboxInput(0).props().checked).toBeTruthy();
|
|
|
- expect(getCheckboxInput(1).props().checked).toBeTruthy();
|
|
|
- expect(
|
|
|
- component.find('div[data-testid="delete-buttons"]').length
|
|
|
- ).toEqual(1);
|
|
|
+ userEvent.click(secondCheckbox);
|
|
|
+ expect(firstCheckbox).toBeChecked();
|
|
|
+ expect(secondCheckbox).toBeChecked();
|
|
|
+
|
|
|
+ expect(screen.getByTestId('delete-buttons')).toBeInTheDocument();
|
|
|
|
|
|
// uncheck second item
|
|
|
- getCheckboxInput(1).simulate('change', { target: { checked: false } });
|
|
|
- expect(getCheckboxInput(0).props().checked).toBeTruthy();
|
|
|
- expect(getCheckboxInput(1).props().checked).toBeFalsy();
|
|
|
- expect(
|
|
|
- component.find('div[data-testid="delete-buttons"]').length
|
|
|
- ).toEqual(1);
|
|
|
+ userEvent.click(secondCheckbox);
|
|
|
+ expect(firstCheckbox).toBeChecked();
|
|
|
+ expect(secondCheckbox).not.toBeChecked();
|
|
|
+
|
|
|
+ expect(screen.getByTestId('delete-buttons')).toBeInTheDocument();
|
|
|
|
|
|
// uncheck first item
|
|
|
- getCheckboxInput(0).simulate('change', { target: { checked: false } });
|
|
|
- expect(getCheckboxInput(0).props().checked).toBeFalsy();
|
|
|
- expect(getCheckboxInput(1).props().checked).toBeFalsy();
|
|
|
- expect(
|
|
|
- component.find('div[data-testid="delete-buttons"]').length
|
|
|
- ).toEqual(0);
|
|
|
+ userEvent.click(firstCheckbox);
|
|
|
+ expect(firstCheckbox).not.toBeChecked();
|
|
|
+ expect(secondCheckbox).not.toBeChecked();
|
|
|
+
|
|
|
+ expect(screen.queryByTestId('delete-buttons')).not.toBeInTheDocument();
|
|
|
});
|
|
|
|
|
|
- const checkActionButtonClick = async (action: string) => {
|
|
|
+ const checkActionButtonClick = async (
|
|
|
+ action: 'deleteTopics' | 'clearTopicsMessages'
|
|
|
+ ) => {
|
|
|
const buttonIndex = action === 'deleteTopics' ? 0 : 1;
|
|
|
+
|
|
|
const confirmationText =
|
|
|
action === 'deleteTopics'
|
|
|
? 'Are you sure you want to remove selected topics?'
|
|
|
: 'Are you sure you want to purge messages of selected topics?';
|
|
|
const mockFn =
|
|
|
action === 'deleteTopics' ? mockDeleteTopics : mockClearTopicsMessages;
|
|
|
- getCheckboxInput(0).simulate('change', { target: { checked: true } });
|
|
|
- getCheckboxInput(1).simulate('change', { target: { checked: true } });
|
|
|
- let modal = getConfirmationModal();
|
|
|
- expect(modal.prop('isOpen')).toBeFalsy();
|
|
|
- component
|
|
|
- .find('div[data-testid="delete-buttons"]')
|
|
|
- .find('button')
|
|
|
- .at(buttonIndex)
|
|
|
- .simulate('click');
|
|
|
- expect(modal.text()).toEqual(confirmationText);
|
|
|
- modal = getConfirmationModal();
|
|
|
- expect(modal.prop('isOpen')).toBeTruthy();
|
|
|
- await act(async () => {
|
|
|
- (modal.props() as ConfirmationModalProps).onConfirm();
|
|
|
+
|
|
|
+ const firstCheckbox = getCheckboxInput(0);
|
|
|
+ const secondCheckbox = getCheckboxInput(1);
|
|
|
+ userEvent.click(firstCheckbox);
|
|
|
+ userEvent.click(secondCheckbox);
|
|
|
+
|
|
|
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
|
|
|
+
|
|
|
+ const deleteButtonContainer = screen.getByTestId('delete-buttons');
|
|
|
+ const buttonClickedElement = within(deleteButtonContainer).getAllByRole(
|
|
|
+ 'button'
|
|
|
+ )[buttonIndex];
|
|
|
+ userEvent.click(buttonClickedElement);
|
|
|
+
|
|
|
+ const modal = screen.getByRole('dialog');
|
|
|
+ expect(within(modal).getByText(confirmationText)).toBeInTheDocument();
|
|
|
+ userEvent.click(within(modal).getByRole('button', { name: 'Submit' }));
|
|
|
+
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(screen.queryByTestId('delete-buttons')).not.toBeInTheDocument();
|
|
|
});
|
|
|
- component.update();
|
|
|
- expect(getCheckboxInput(0).props().checked).toBeFalsy();
|
|
|
- expect(getCheckboxInput(1).props().checked).toBeFalsy();
|
|
|
- expect(
|
|
|
- component.find('div[data-testid="delete-buttons"]').length
|
|
|
- ).toEqual(0);
|
|
|
+
|
|
|
expect(mockFn).toBeCalledTimes(1);
|
|
|
expect(mockFn).toBeCalledWith('local', [
|
|
|
externalTopicPayload.name,
|
|
@@ -290,28 +305,84 @@ describe('List', () => {
|
|
|
});
|
|
|
|
|
|
it('closes ConfirmationModal when clicked on the cancel button', async () => {
|
|
|
- getCheckboxInput(0).simulate('change', { target: { checked: true } });
|
|
|
- getCheckboxInput(1).simulate('change', { target: { checked: true } });
|
|
|
- let modal = getConfirmationModal();
|
|
|
- expect(modal.prop('isOpen')).toBeFalsy();
|
|
|
- component
|
|
|
- .find('div[data-testid="delete-buttons"]')
|
|
|
- .find('button')
|
|
|
- .at(0)
|
|
|
- .simulate('click');
|
|
|
- modal = getConfirmationModal();
|
|
|
- expect(modal.prop('isOpen')).toBeTruthy();
|
|
|
- await act(async () => {
|
|
|
- (modal.props() as ConfirmationModalProps).onCancel();
|
|
|
+ const firstCheckbox = getCheckboxInput(0);
|
|
|
+ const secondCheckbox = getCheckboxInput(1);
|
|
|
+
|
|
|
+ userEvent.click(firstCheckbox);
|
|
|
+ userEvent.click(secondCheckbox);
|
|
|
+
|
|
|
+ const deleteButton = screen.getByText('Delete selected topics');
|
|
|
+
|
|
|
+ userEvent.click(deleteButton);
|
|
|
+
|
|
|
+ const modal = screen.getByRole('dialog');
|
|
|
+ userEvent.click(within(modal).getByText('Cancel'));
|
|
|
+
|
|
|
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
|
|
|
+ expect(firstCheckbox).toBeChecked();
|
|
|
+ expect(secondCheckbox).toBeChecked();
|
|
|
+
|
|
|
+ expect(screen.getByTestId('delete-buttons')).toBeInTheDocument();
|
|
|
+
|
|
|
+ expect(mockDeleteTopics).not.toHaveBeenCalled();
|
|
|
+ });
|
|
|
+
|
|
|
+ const tableRowActionClickAndCheck = async (
|
|
|
+ action: 'deleteTopics' | 'clearTopicsMessages' | 'recreate'
|
|
|
+ ) => {
|
|
|
+ const row = screen.getAllByRole('row')[1];
|
|
|
+ userEvent.hover(row);
|
|
|
+ const actionBtn = within(row).getByRole('menu', { hidden: true });
|
|
|
+
|
|
|
+ userEvent.click(actionBtn);
|
|
|
+
|
|
|
+ let textBtn;
|
|
|
+ let mock: jest.Mock;
|
|
|
+
|
|
|
+ if (action === 'clearTopicsMessages') {
|
|
|
+ textBtn = 'Clear Messages';
|
|
|
+ mock = mockClearTopic;
|
|
|
+ } else if (action === 'deleteTopics') {
|
|
|
+ textBtn = 'Remove Topic';
|
|
|
+ mock = mockDeleteTopic;
|
|
|
+ } else {
|
|
|
+ textBtn = 'Recreate Topic';
|
|
|
+ mock = mockRecreate;
|
|
|
+ }
|
|
|
+
|
|
|
+ const ourAction = screen.getByText(textBtn);
|
|
|
+
|
|
|
+ userEvent.click(ourAction);
|
|
|
+
|
|
|
+ let dialog = screen.getByRole('dialog');
|
|
|
+ expect(dialog).toBeInTheDocument();
|
|
|
+ userEvent.click(within(dialog).getByRole('button', { name: 'Submit' }));
|
|
|
+
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(mock).toHaveBeenCalled();
|
|
|
+ if (action === 'clearTopicsMessages') {
|
|
|
+ expect(fetchTopicsList).toHaveBeenCalled();
|
|
|
+ }
|
|
|
});
|
|
|
- component.update();
|
|
|
- expect(getConfirmationModal().prop('isOpen')).toBeFalsy();
|
|
|
- expect(getCheckboxInput(0).props().checked).toBeTruthy();
|
|
|
- expect(getCheckboxInput(1).props().checked).toBeTruthy();
|
|
|
- expect(
|
|
|
- component.find('div[data-testid="delete-buttons"]').length
|
|
|
- ).toEqual(1);
|
|
|
- expect(mockDeleteTopics).toBeCalledTimes(0);
|
|
|
+
|
|
|
+ userEvent.click(ourAction);
|
|
|
+ dialog = screen.getByRole('dialog');
|
|
|
+ expect(dialog).toBeInTheDocument();
|
|
|
+ userEvent.click(within(dialog).getByRole('button', { name: 'Cancel' }));
|
|
|
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
|
|
|
+ expect(mock).toHaveBeenCalledTimes(1);
|
|
|
+ };
|
|
|
+
|
|
|
+ it('should test the actions of the row and their modal and fetching for removing', async () => {
|
|
|
+ await tableRowActionClickAndCheck('deleteTopics');
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should test the actions of the row and their modal and fetching for clear', async () => {
|
|
|
+ await tableRowActionClickAndCheck('clearTopicsMessages');
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should test the actions of the row and their modal and fetching for recreate', async () => {
|
|
|
+ await tableRowActionClickAndCheck('recreate');
|
|
|
});
|
|
|
});
|
|
|
});
|