Skip to content

Commit

Permalink
Unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
e40pud committed Nov 5, 2024
1 parent 21dc82f commit 0fc3889
Showing 1 changed file with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,63 @@ describe('KnowledgeBaseSettingsManagement', () => {
expect(mockCreateEntry).toHaveBeenCalledWith({ ...mockData[3], users: undefined });
});

it('does not show duplicate entry modal on new document entry creation', async () => {
// Covers the BUG: https://github.com/elastic/kibana/issues/198892
const closeFlyoutMock = jest.fn();
(useFlyoutModalVisibility as jest.Mock).mockReturnValue({
isFlyoutOpen: true,
openFlyout: jest.fn(),
closeFlyout: closeFlyoutMock,
});
render(<KnowledgeBaseSettingsManagement dataViews={mockDataViews} />, {
wrapper,
});

await waitFor(() => {
fireEvent.click(screen.getAllByTestId('edit-button')[3]);
});
expect(screen.getByTestId('flyout')).toBeVisible();

await waitFor(() => {
expect(screen.getByText('Edit document entry')).toBeInTheDocument();
});

await waitFor(() => {
fireEvent.click(screen.getByTestId('sharing-select'));
fireEvent.click(screen.getByTestId('sharing-private-option'));
fireEvent.click(screen.getByTestId('save-button'));
});

expect(screen.getByTestId('create-duplicate-entry-modal')).toBeInTheDocument();
await waitFor(() => {
fireEvent.click(screen.getByTestId('confirmModalConfirmButton'));
});
expect(screen.queryByTestId('create-duplicate-entry-modal')).not.toBeInTheDocument();
await waitFor(() => {
expect(mockCreateEntry).toHaveBeenCalledTimes(1);
});

// Create a new document entry
await waitFor(() => {
fireEvent.click(screen.getByTestId('addEntry'));
});
await waitFor(() => {
fireEvent.click(screen.getByTestId('addDocument'));
});

expect(screen.getByTestId('flyout')).toBeVisible();

await userEvent.type(screen.getByTestId('entryNameInput'), 'hi');
await userEvent.type(screen.getByTestId('entryMarkdownInput'), 'hi');

await waitFor(() => {
fireEvent.click(screen.getByTestId('save-button'));
});

expect(screen.queryByTestId('create-duplicate-entry-modal')).not.toBeInTheDocument();
expect(closeFlyoutMock).toHaveBeenCalled();
});

it('shows warning icon for index entries with missing indices', async () => {
render(<KnowledgeBaseSettingsManagement dataViews={mockDataViews} />, {
wrapper,
Expand Down

0 comments on commit 0fc3889

Please sign in to comment.