@patternfly/chatbot 2.2.0-prerelease.16 → 2.2.0-prerelease.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/AttachmentEdit/AttachmentEdit.test.d.ts +1 -0
- package/dist/cjs/AttachmentEdit/AttachmentEdit.test.js +52 -0
- package/dist/cjs/Chatbot/Chatbot.test.d.ts +1 -0
- package/dist/cjs/Chatbot/Chatbot.test.js +28 -0
- package/dist/cjs/ChatbotAlert/ChatbotAlert.test.d.ts +1 -0
- package/dist/cjs/ChatbotAlert/ChatbotAlert.test.js +27 -0
- package/dist/cjs/ChatbotContent/ChatbotContent.test.d.ts +1 -0
- package/dist/cjs/ChatbotContent/ChatbotContent.test.js +18 -0
- package/dist/cjs/ChatbotFooter/ChatbotFooter.test.d.ts +1 -0
- package/dist/cjs/ChatbotFooter/ChatbotFooter.test.js +18 -0
- package/dist/cjs/ChatbotFooter/ChatbotFooternote.test.d.ts +1 -0
- package/dist/cjs/ChatbotFooter/ChatbotFooternote.test.js +87 -0
- package/dist/cjs/ChatbotHeader/ChatbotHeader.test.d.ts +1 -0
- package/dist/cjs/ChatbotHeader/ChatbotHeader.test.js +18 -0
- package/dist/cjs/ChatbotHeader/ChatbotHeaderActions.test.d.ts +1 -0
- package/dist/cjs/ChatbotHeader/ChatbotHeaderActions.test.js +18 -0
- package/dist/cjs/ChatbotHeader/ChatbotHeaderCloseButton.test.d.ts +1 -0
- package/dist/cjs/ChatbotHeader/ChatbotHeaderCloseButton.test.js +20 -0
- package/dist/cjs/ChatbotHeader/ChatbotHeaderMain.test.d.ts +1 -0
- package/dist/cjs/ChatbotHeader/ChatbotHeaderMain.test.js +18 -0
- package/dist/cjs/ChatbotHeader/ChatbotHeaderMenu.test.d.ts +1 -0
- package/dist/cjs/ChatbotHeader/ChatbotHeaderMenu.test.js +20 -0
- package/dist/cjs/ChatbotHeader/ChatbotHeaderOptionsDropdown.test.d.ts +1 -0
- package/dist/cjs/ChatbotHeader/ChatbotHeaderOptionsDropdown.test.js +43 -0
- package/dist/cjs/ChatbotHeader/ChatbotHeaderSelectorDropdown.test.d.ts +1 -0
- package/dist/cjs/ChatbotHeader/ChatbotHeaderSelectorDropdown.test.js +41 -0
- package/dist/cjs/ChatbotHeader/ChatbotHeaderTitle.test.d.ts +1 -0
- package/dist/cjs/ChatbotHeader/ChatbotHeaderTitle.test.js +47 -0
- package/dist/cjs/MessageBar/MessageBar.test.js +4 -4
- package/dist/cjs/MessageBox/MessageBox.test.d.ts +1 -0
- package/dist/cjs/MessageBox/MessageBox.test.js +22 -0
- package/dist/cjs/PreviewAttachment/PreviewAttachment.test.d.ts +1 -0
- package/dist/cjs/PreviewAttachment/PreviewAttachment.test.js +28 -0
- package/dist/cjs/Settings/SettingsForm.test.d.ts +1 -0
- package/dist/cjs/Settings/SettingsForm.test.js +26 -0
- package/dist/esm/AttachmentEdit/AttachmentEdit.test.d.ts +1 -0
- package/dist/esm/AttachmentEdit/AttachmentEdit.test.js +47 -0
- package/dist/esm/Chatbot/Chatbot.test.d.ts +1 -0
- package/dist/esm/Chatbot/Chatbot.test.js +23 -0
- package/dist/esm/ChatbotAlert/ChatbotAlert.test.d.ts +1 -0
- package/dist/esm/ChatbotAlert/ChatbotAlert.test.js +22 -0
- package/dist/esm/ChatbotContent/ChatbotContent.test.d.ts +1 -0
- package/dist/esm/ChatbotContent/ChatbotContent.test.js +13 -0
- package/dist/esm/ChatbotFooter/ChatbotFooter.test.d.ts +1 -0
- package/dist/esm/ChatbotFooter/ChatbotFooter.test.js +13 -0
- package/dist/esm/ChatbotFooter/ChatbotFooternote.test.d.ts +1 -0
- package/dist/esm/ChatbotFooter/ChatbotFooternote.test.js +82 -0
- package/dist/esm/ChatbotHeader/ChatbotHeader.test.d.ts +1 -0
- package/dist/esm/ChatbotHeader/ChatbotHeader.test.js +13 -0
- package/dist/esm/ChatbotHeader/ChatbotHeaderActions.test.d.ts +1 -0
- package/dist/esm/ChatbotHeader/ChatbotHeaderActions.test.js +13 -0
- package/dist/esm/ChatbotHeader/ChatbotHeaderCloseButton.test.d.ts +1 -0
- package/dist/esm/ChatbotHeader/ChatbotHeaderCloseButton.test.js +15 -0
- package/dist/esm/ChatbotHeader/ChatbotHeaderMain.test.d.ts +1 -0
- package/dist/esm/ChatbotHeader/ChatbotHeaderMain.test.js +13 -0
- package/dist/esm/ChatbotHeader/ChatbotHeaderMenu.test.d.ts +1 -0
- package/dist/esm/ChatbotHeader/ChatbotHeaderMenu.test.js +15 -0
- package/dist/esm/ChatbotHeader/ChatbotHeaderOptionsDropdown.test.d.ts +1 -0
- package/dist/esm/ChatbotHeader/ChatbotHeaderOptionsDropdown.test.js +38 -0
- package/dist/esm/ChatbotHeader/ChatbotHeaderSelectorDropdown.test.d.ts +1 -0
- package/dist/esm/ChatbotHeader/ChatbotHeaderSelectorDropdown.test.js +36 -0
- package/dist/esm/ChatbotHeader/ChatbotHeaderTitle.test.d.ts +1 -0
- package/dist/esm/ChatbotHeader/ChatbotHeaderTitle.test.js +42 -0
- package/dist/esm/MessageBar/MessageBar.test.js +4 -4
- package/dist/esm/MessageBox/MessageBox.test.d.ts +1 -0
- package/dist/esm/MessageBox/MessageBox.test.js +17 -0
- package/dist/esm/PreviewAttachment/PreviewAttachment.test.d.ts +1 -0
- package/dist/esm/PreviewAttachment/PreviewAttachment.test.js +23 -0
- package/dist/esm/Settings/SettingsForm.test.d.ts +1 -0
- package/dist/esm/Settings/SettingsForm.test.js +21 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/AttachmentEdit/AttachmentEdit.test.tsx +55 -0
- package/src/Chatbot/Chatbot.test.tsx +31 -0
- package/src/ChatbotAlert/ChatbotAlert.test.tsx +31 -0
- package/src/ChatbotContent/ChatbotContent.test.tsx +15 -0
- package/src/ChatbotFooter/ChatbotFooter.test.tsx +15 -0
- package/src/ChatbotFooter/ChatbotFooternote.test.tsx +84 -0
- package/src/ChatbotHeader/ChatbotHeader.test.tsx +15 -0
- package/src/ChatbotHeader/ChatbotHeaderActions.test.tsx +17 -0
- package/src/ChatbotHeader/ChatbotHeaderCloseButton.test.tsx +20 -0
- package/src/ChatbotHeader/ChatbotHeaderMain.test.tsx +17 -0
- package/src/ChatbotHeader/ChatbotHeaderMenu.test.tsx +19 -0
- package/src/ChatbotHeader/ChatbotHeaderOptionsDropdown.test.tsx +45 -0
- package/src/ChatbotHeader/ChatbotHeaderSelectorDropdown.test.tsx +43 -0
- package/src/ChatbotHeader/ChatbotHeaderTitle.test.tsx +59 -0
- package/src/MessageBar/MessageBar.test.tsx +4 -4
- package/src/MessageBox/MessageBox.test.tsx +26 -0
- package/src/PreviewAttachment/PreviewAttachment.test.tsx +51 -0
- package/src/Settings/SettingsForm.test.tsx +28 -0
@@ -0,0 +1,55 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
3
|
+
import AttachmentEdit, { AttachmentEditProps } from './AttachmentEdit';
|
4
|
+
|
5
|
+
describe('AttachmentEdit', () => {
|
6
|
+
it('should open AttachmentEdit modal', () => {
|
7
|
+
const props: AttachmentEditProps = {
|
8
|
+
code: 'code',
|
9
|
+
fileName: 'fileName',
|
10
|
+
onCancel: jest.fn(),
|
11
|
+
onSave: jest.fn(),
|
12
|
+
isModalOpen: true,
|
13
|
+
handleModalToggle: jest.fn()
|
14
|
+
};
|
15
|
+
|
16
|
+
render(<AttachmentEdit {...props} />);
|
17
|
+
expect(screen.getByText('Edit attachment')).toBeTruthy();
|
18
|
+
});
|
19
|
+
|
20
|
+
it('should call onSave handler when the save button is clicked', () => {
|
21
|
+
const onSaveHandler = jest.fn();
|
22
|
+
const props: AttachmentEditProps = {
|
23
|
+
code: 'code',
|
24
|
+
fileName: 'fileName',
|
25
|
+
onCancel: jest.fn(),
|
26
|
+
onSave: onSaveHandler,
|
27
|
+
isModalOpen: true,
|
28
|
+
handleModalToggle: jest.fn()
|
29
|
+
};
|
30
|
+
|
31
|
+
render(<AttachmentEdit {...props} />);
|
32
|
+
|
33
|
+
// Click on save button
|
34
|
+
fireEvent.click(screen.getByText('Save'));
|
35
|
+
expect(onSaveHandler).toHaveBeenCalledWith(expect.any(Object), 'code');
|
36
|
+
});
|
37
|
+
|
38
|
+
it('should call cancel handler when the cancel button is clicked', () => {
|
39
|
+
const onCancelHandler = jest.fn();
|
40
|
+
const props: AttachmentEditProps = {
|
41
|
+
code: 'code',
|
42
|
+
fileName: 'fileName',
|
43
|
+
onCancel: onCancelHandler,
|
44
|
+
onSave: jest.fn(),
|
45
|
+
isModalOpen: true,
|
46
|
+
handleModalToggle: jest.fn()
|
47
|
+
};
|
48
|
+
|
49
|
+
render(<AttachmentEdit {...props} />);
|
50
|
+
|
51
|
+
// Click on cancel button
|
52
|
+
fireEvent.click(screen.getByText('Cancel'));
|
53
|
+
expect(onCancelHandler).toHaveBeenCalled();
|
54
|
+
});
|
55
|
+
});
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import '@testing-library/jest-dom';
|
2
|
+
import React from 'react';
|
3
|
+
import { render, screen } from '@testing-library/react';
|
4
|
+
import Chatbot from './Chatbot';
|
5
|
+
|
6
|
+
describe('Chatbot', () => {
|
7
|
+
it('should render Chatbot with default display mode', () => {
|
8
|
+
render(<Chatbot>Chatbot Content</Chatbot>);
|
9
|
+
expect(screen.getByText('Chatbot Content')).toBeTruthy();
|
10
|
+
});
|
11
|
+
|
12
|
+
it('should render Chatbot with custom ariaLabel', () => {
|
13
|
+
render(<Chatbot ariaLabel="Chatbot">Chatbot Content</Chatbot>);
|
14
|
+
expect(screen.getByLabelText('Chatbot')).toBeTruthy();
|
15
|
+
});
|
16
|
+
|
17
|
+
it('should render Chatbot with custom className', () => {
|
18
|
+
const { container } = render(
|
19
|
+
<Chatbot ariaLabel="Chatbot" className="custom-class">
|
20
|
+
Chatbot Content
|
21
|
+
</Chatbot>
|
22
|
+
);
|
23
|
+
const chatbotElement = container.querySelector('.custom-class');
|
24
|
+
expect(chatbotElement).toBeInTheDocument();
|
25
|
+
});
|
26
|
+
|
27
|
+
it('should not render Chatbot', () => {
|
28
|
+
render(<Chatbot isVisible={false}>Chatbot Content</Chatbot>);
|
29
|
+
expect(screen.queryByLabelText('Chatbot')).toBeFalsy();
|
30
|
+
});
|
31
|
+
});
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
3
|
+
import ChatbotAlert from './ChatbotAlert';
|
4
|
+
|
5
|
+
describe('ChatbotAlert', () => {
|
6
|
+
it('should render ChatbotAlert with default variant', () => {
|
7
|
+
render(<ChatbotAlert title="Chatbot Alert" />);
|
8
|
+
expect(screen.getByText('Chatbot Alert')).toBeTruthy();
|
9
|
+
});
|
10
|
+
|
11
|
+
it('should render ChatbotAlert with children', () => {
|
12
|
+
render(<ChatbotAlert title="Chatbot Alert">Chatbot Alert Content</ChatbotAlert>);
|
13
|
+
expect(screen.getByText('Chatbot Alert Content')).toBeTruthy();
|
14
|
+
});
|
15
|
+
|
16
|
+
it('should call onClose handler when onClose button is clicked', () => {
|
17
|
+
const onCloseHandler = jest.fn();
|
18
|
+
render(
|
19
|
+
<ChatbotAlert title="Chatbot Alert" onClose={onCloseHandler}>
|
20
|
+
Chatbot Alert Content
|
21
|
+
</ChatbotAlert>
|
22
|
+
);
|
23
|
+
|
24
|
+
expect(screen.getByText('Chatbot Alert')).toBeTruthy();
|
25
|
+
expect(screen.getByText('Chatbot Alert Content')).toBeTruthy();
|
26
|
+
|
27
|
+
// click on the close button
|
28
|
+
fireEvent.click(screen.getByRole('button'));
|
29
|
+
expect(onCloseHandler).toHaveBeenCalled();
|
30
|
+
});
|
31
|
+
});
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { render, screen } from '@testing-library/react';
|
3
|
+
import ChatbotContent from './ChatbotContent';
|
4
|
+
|
5
|
+
describe('ChatbotContent', () => {
|
6
|
+
it('should render ChatbotContent with children', () => {
|
7
|
+
render(<ChatbotContent>Chatbot Content</ChatbotContent>);
|
8
|
+
expect(screen.getByText('Chatbot Content')).toBeTruthy();
|
9
|
+
});
|
10
|
+
|
11
|
+
it('should render ChatbotContent with custom classname', () => {
|
12
|
+
const { container } = render(<ChatbotContent className="custom-class">Chatbot Content</ChatbotContent>);
|
13
|
+
expect(container.querySelector('.custom-class')).toBeTruthy();
|
14
|
+
});
|
15
|
+
});
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { render, screen } from '@testing-library/react';
|
3
|
+
import ChatbotFooter from './ChatbotFooter';
|
4
|
+
|
5
|
+
describe('ChatbotFooter', () => {
|
6
|
+
it('should render ChatbotFooter with children', () => {
|
7
|
+
render(<ChatbotFooter>Chatbot Content</ChatbotFooter>);
|
8
|
+
expect(screen.getByText('Chatbot Content')).toBeTruthy();
|
9
|
+
});
|
10
|
+
|
11
|
+
it('should render ChatbotFooter with custom classname', () => {
|
12
|
+
const { container } = render(<ChatbotFooter className="custom-class">Chatbot Content</ChatbotFooter>);
|
13
|
+
expect(container.querySelector('.custom-class')).toBeTruthy();
|
14
|
+
});
|
15
|
+
});
|
@@ -0,0 +1,84 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';
|
3
|
+
import ChatbotFootnote from './ChatbotFootnote';
|
4
|
+
|
5
|
+
describe('ChatbotFooternote', () => {
|
6
|
+
const onClick = jest.fn();
|
7
|
+
const popoverProps = {
|
8
|
+
title: 'Verify accuracy',
|
9
|
+
description: 'description',
|
10
|
+
bannerImage: {
|
11
|
+
src: 'src',
|
12
|
+
alt: 'alt'
|
13
|
+
},
|
14
|
+
cta: {
|
15
|
+
label: 'Got it',
|
16
|
+
onClick
|
17
|
+
},
|
18
|
+
link: {
|
19
|
+
label: 'label',
|
20
|
+
url: 'url'
|
21
|
+
}
|
22
|
+
};
|
23
|
+
|
24
|
+
it('should render ChatbotFooternote', () => {
|
25
|
+
render(<ChatbotFootnote label="Chatbot footer" />);
|
26
|
+
expect(screen.getByText('Chatbot footer')).toBeTruthy();
|
27
|
+
});
|
28
|
+
|
29
|
+
it('should render ChatbotFooternote with popover', async () => {
|
30
|
+
render(<ChatbotFootnote label="Chatbot footer" popover={popoverProps} />);
|
31
|
+
|
32
|
+
// click on the footer button
|
33
|
+
act(() => {
|
34
|
+
fireEvent.click(screen.getByRole('button'));
|
35
|
+
});
|
36
|
+
|
37
|
+
await waitFor(() => {
|
38
|
+
// Check if the popover is visible and click on the cta button
|
39
|
+
screen.getByLabelText('More information');
|
40
|
+
screen.getByText('Verify accuracy');
|
41
|
+
fireEvent.click(screen.getByRole('button', { name: 'Got it' }));
|
42
|
+
expect(onClick).toHaveBeenCalled();
|
43
|
+
});
|
44
|
+
});
|
45
|
+
it('should call onClick handler when popover cta button is clicked', async () => {
|
46
|
+
render(<ChatbotFootnote label="Chatbot footer" popover={popoverProps} />);
|
47
|
+
|
48
|
+
// click on the footer button
|
49
|
+
act(() => {
|
50
|
+
fireEvent.click(screen.getByRole('button'));
|
51
|
+
});
|
52
|
+
|
53
|
+
await waitFor(() => {
|
54
|
+
// Check if the popover is visible and click on the cta button
|
55
|
+
screen.getByLabelText('More information');
|
56
|
+
screen.getByText('Verify accuracy');
|
57
|
+
fireEvent.click(screen.getByRole('button', { name: 'Got it' }));
|
58
|
+
expect(onClick).toHaveBeenCalled();
|
59
|
+
});
|
60
|
+
});
|
61
|
+
it('should close the popover when escape is pressed', async () => {
|
62
|
+
render(<ChatbotFootnote label="Chatbot footer" popover={popoverProps} />);
|
63
|
+
|
64
|
+
// click on the footer button
|
65
|
+
act(() => {
|
66
|
+
fireEvent.click(screen.getByRole('button'));
|
67
|
+
});
|
68
|
+
|
69
|
+
await waitFor(() => {
|
70
|
+
// Check if the popover is visible and click on the cta button
|
71
|
+
screen.getByLabelText('More information');
|
72
|
+
screen.getByText('Verify accuracy');
|
73
|
+
});
|
74
|
+
|
75
|
+
act(() => {
|
76
|
+
// trigger escape to close the popover
|
77
|
+
fireEvent.keyDown(document, { key: 'Escape', code: 'Escape' });
|
78
|
+
});
|
79
|
+
|
80
|
+
await waitFor(() => {
|
81
|
+
expect(screen.queryByText('Verify accuracy')).toBeFalsy();
|
82
|
+
});
|
83
|
+
});
|
84
|
+
});
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { render, screen } from '@testing-library/react';
|
3
|
+
import ChatbotHeader from './ChatbotHeader';
|
4
|
+
|
5
|
+
describe('ChatbotHeader', () => {
|
6
|
+
it('should render ChatbotHeader with children', () => {
|
7
|
+
render(<ChatbotHeader>Chatbot Header</ChatbotHeader>);
|
8
|
+
expect(screen.getByText('Chatbot Header')).toBeTruthy();
|
9
|
+
});
|
10
|
+
|
11
|
+
it('should render ChatbotHeader with custom classname', () => {
|
12
|
+
const { container } = render(<ChatbotHeader className="custom-header-class">Chatbot Content</ChatbotHeader>);
|
13
|
+
expect(container.querySelector('.custom-header-class')).toBeTruthy();
|
14
|
+
});
|
15
|
+
});
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { render, screen } from '@testing-library/react';
|
3
|
+
import ChatbotHeaderActions from './ChatbotHeaderActions';
|
4
|
+
|
5
|
+
describe('ChatbotHeaderActions', () => {
|
6
|
+
it('should render ChatbotHeaderActions with children', () => {
|
7
|
+
render(<ChatbotHeaderActions>Chatbot Header</ChatbotHeaderActions>);
|
8
|
+
expect(screen.getByText('Chatbot Header')).toBeTruthy();
|
9
|
+
});
|
10
|
+
|
11
|
+
it('should render ChatbotHeaderActions with custom classname', () => {
|
12
|
+
const { container } = render(
|
13
|
+
<ChatbotHeaderActions className="custom-header-action-class">Chatbot Content</ChatbotHeaderActions>
|
14
|
+
);
|
15
|
+
expect(container.querySelector('.custom-header-action-class')).toBeTruthy();
|
16
|
+
});
|
17
|
+
});
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
3
|
+
import { ChatbotHeaderCloseButton } from './ChatbotHeaderCloseButton';
|
4
|
+
|
5
|
+
describe('ChatbotHeaderCloseButton', () => {
|
6
|
+
it('should render ChatbotHeaderCloseButton', () => {
|
7
|
+
const { container } = render(
|
8
|
+
<ChatbotHeaderCloseButton className="custom-header-close-button" onClick={jest.fn()} />
|
9
|
+
);
|
10
|
+
|
11
|
+
expect(container.querySelector('.custom-header-close-button')).toBeTruthy();
|
12
|
+
});
|
13
|
+
|
14
|
+
it('should call onClick handler when close button is pressed', () => {
|
15
|
+
const onClick = jest.fn();
|
16
|
+
render(<ChatbotHeaderCloseButton className="custom-header-close-button" onClick={onClick} />);
|
17
|
+
fireEvent.click(screen.getByRole('button', { name: 'Close' }));
|
18
|
+
expect(onClick).toHaveBeenCalled();
|
19
|
+
});
|
20
|
+
});
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { render, screen } from '@testing-library/react';
|
3
|
+
import ChatbotHeaderMain from './ChatbotHeaderMain';
|
4
|
+
|
5
|
+
describe('ChatbotHeaderMain', () => {
|
6
|
+
it('should render ChatbotHeaderMain with children', () => {
|
7
|
+
render(<ChatbotHeaderMain>Chatbot Header Main</ChatbotHeaderMain>);
|
8
|
+
expect(screen.getByText('Chatbot Header Main')).toBeTruthy();
|
9
|
+
});
|
10
|
+
|
11
|
+
it('should render ChatbotHeaderMain with custom classname', () => {
|
12
|
+
const { container } = render(
|
13
|
+
<ChatbotHeaderMain className="custom-header-class">Chatbot Content</ChatbotHeaderMain>
|
14
|
+
);
|
15
|
+
expect(container.querySelector('.custom-header-class')).toBeTruthy();
|
16
|
+
});
|
17
|
+
});
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
3
|
+
import { ChatbotHeaderMenu } from './ChatbotHeaderMenu';
|
4
|
+
|
5
|
+
describe('ChatbotHeaderMenu', () => {
|
6
|
+
it('should render ChatbotHeaderMenu with custom class', () => {
|
7
|
+
const { container } = render(<ChatbotHeaderMenu className="custom-header-menu" onMenuToggle={jest.fn()} />);
|
8
|
+
|
9
|
+
expect(container.querySelector('.custom-header-menu')).toBeTruthy();
|
10
|
+
});
|
11
|
+
|
12
|
+
it('should call onMenuToggle when ChatbotHeaderMenu button is clicked', () => {
|
13
|
+
const onMenuToggle = jest.fn();
|
14
|
+
render(<ChatbotHeaderMenu className="custom-header-menu" onMenuToggle={onMenuToggle} />);
|
15
|
+
fireEvent.click(screen.getByRole('button', { name: 'Toggle menu' }));
|
16
|
+
|
17
|
+
expect(onMenuToggle).toHaveBeenCalled();
|
18
|
+
});
|
19
|
+
});
|
@@ -0,0 +1,45 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { DropdownItem } from '@patternfly/react-core';
|
3
|
+
import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';
|
4
|
+
import { ChatbotHeaderOptionsDropdown } from './ChatbotHeaderOptionsDropdown';
|
5
|
+
|
6
|
+
describe('ChatbotHeaderOptionsDropdown', () => {
|
7
|
+
const dropdownItems = (
|
8
|
+
<>
|
9
|
+
<DropdownItem>Option 1</DropdownItem>
|
10
|
+
<DropdownItem>Option 2</DropdownItem>
|
11
|
+
<DropdownItem>Option 3</DropdownItem>
|
12
|
+
</>
|
13
|
+
);
|
14
|
+
|
15
|
+
it('should render ChatbotHeaderOptionsDropdown', () => {
|
16
|
+
render(<ChatbotHeaderOptionsDropdown>{dropdownItems}</ChatbotHeaderOptionsDropdown>);
|
17
|
+
|
18
|
+
expect(screen.getByRole('button', { name: 'Chatbot options' })).toBeTruthy();
|
19
|
+
});
|
20
|
+
|
21
|
+
it('should call onselect handler when a dropdown item is clicked', async () => {
|
22
|
+
const onSelect = jest.fn();
|
23
|
+
const { container } = render(
|
24
|
+
<ChatbotHeaderOptionsDropdown className="custom-header-options-dropdown" onSelect={onSelect}>
|
25
|
+
{dropdownItems}
|
26
|
+
</ChatbotHeaderOptionsDropdown>
|
27
|
+
);
|
28
|
+
|
29
|
+
act(() => {
|
30
|
+
fireEvent.click(screen.getByRole('button', { name: 'Chatbot options' }));
|
31
|
+
});
|
32
|
+
|
33
|
+
await waitFor(() => {
|
34
|
+
expect(container.querySelector('.custom-header-options-dropdown')).toBeTruthy();
|
35
|
+
|
36
|
+
expect(screen.getByText('Option 1'));
|
37
|
+
expect(screen.getByText('Option 2'));
|
38
|
+
expect(screen.getByText('Option 3'));
|
39
|
+
|
40
|
+
fireEvent.click(screen.getByText('Option 3'));
|
41
|
+
|
42
|
+
expect(onSelect).toHaveBeenCalled();
|
43
|
+
});
|
44
|
+
});
|
45
|
+
});
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { DropdownItem } from '@patternfly/react-core';
|
3
|
+
import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';
|
4
|
+
import { ChatbotHeaderSelectorDropdown } from './ChatbotHeaderSelectorDropdown';
|
5
|
+
|
6
|
+
describe('ChatbotHeaderSelectorDropdown', () => {
|
7
|
+
const dropdownItems = (
|
8
|
+
<>
|
9
|
+
<DropdownItem>Option 1</DropdownItem>
|
10
|
+
<DropdownItem>Option 2</DropdownItem>
|
11
|
+
<DropdownItem>Option 3</DropdownItem>
|
12
|
+
</>
|
13
|
+
);
|
14
|
+
|
15
|
+
it('should render ChatbotHeaderSelectorDropdown', () => {
|
16
|
+
render(<ChatbotHeaderSelectorDropdown value="Option 1">{dropdownItems}</ChatbotHeaderSelectorDropdown>);
|
17
|
+
|
18
|
+
expect(screen.getByRole('button', { name: 'Chatbot selector' })).toBeTruthy();
|
19
|
+
});
|
20
|
+
|
21
|
+
it('should call onselect handler when a dropdown item is clicked', async () => {
|
22
|
+
const onSelect = jest.fn();
|
23
|
+
const { container } = render(
|
24
|
+
<ChatbotHeaderSelectorDropdown value="Option 1" className="custom-header-selector-dropdown" onSelect={onSelect}>
|
25
|
+
{dropdownItems}
|
26
|
+
</ChatbotHeaderSelectorDropdown>
|
27
|
+
);
|
28
|
+
|
29
|
+
act(() => {
|
30
|
+
fireEvent.click(screen.getByRole('button', { name: 'Chatbot selector' }));
|
31
|
+
});
|
32
|
+
|
33
|
+
await waitFor(() => {
|
34
|
+
expect(container.querySelector('.custom-header-selector-dropdown')).toBeTruthy();
|
35
|
+
|
36
|
+
expect(screen.getByText('Option 3'));
|
37
|
+
|
38
|
+
fireEvent.click(screen.getByText('Option 3'));
|
39
|
+
|
40
|
+
expect(onSelect).toHaveBeenCalled();
|
41
|
+
});
|
42
|
+
});
|
43
|
+
});
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { render, screen } from '@testing-library/react';
|
3
|
+
import { ChatbotDisplayMode } from '../Chatbot/Chatbot';
|
4
|
+
import ChatbotHeaderTitle from './ChatbotHeaderTitle';
|
5
|
+
|
6
|
+
describe('ChatbotHeaderTitle', () => {
|
7
|
+
it('should render ChatbotHeaderTitle with children', () => {
|
8
|
+
render(<ChatbotHeaderTitle>Chatbot Header Title</ChatbotHeaderTitle>);
|
9
|
+
expect(screen.getByText('Chatbot Header Title')).toBeTruthy();
|
10
|
+
});
|
11
|
+
|
12
|
+
it('should render ChatbotHeaderTitle with custom classname', () => {
|
13
|
+
const { container } = render(
|
14
|
+
<ChatbotHeaderTitle className="custom-header-class">Chatbot Header Title</ChatbotHeaderTitle>
|
15
|
+
);
|
16
|
+
expect(container.querySelector('.custom-header-class')).toBeTruthy();
|
17
|
+
});
|
18
|
+
|
19
|
+
it('should render title for default display mode', () => {
|
20
|
+
render(<ChatbotHeaderTitle displayMode={ChatbotDisplayMode.default} showOnDefault={'Default header title'} />);
|
21
|
+
expect(screen.getByText('Default header title')).toBeTruthy();
|
22
|
+
});
|
23
|
+
|
24
|
+
it('should render title for docked display mode', () => {
|
25
|
+
render(<ChatbotHeaderTitle displayMode={ChatbotDisplayMode.docked} showOnDocked={'Docked header title'} />);
|
26
|
+
expect(screen.getByText('Docked header title')).toBeTruthy();
|
27
|
+
});
|
28
|
+
|
29
|
+
it('should fallback to default title when docked display mode title is not configured', () => {
|
30
|
+
render(<ChatbotHeaderTitle displayMode={ChatbotDisplayMode.docked} showOnDefault={'Default header title'} />);
|
31
|
+
expect(screen.getByText('Default header title')).toBeTruthy();
|
32
|
+
});
|
33
|
+
|
34
|
+
it('should render title for embedded display mode', () => {
|
35
|
+
render(<ChatbotHeaderTitle displayMode={ChatbotDisplayMode.embedded} showOnEmbedded={'Embedded header title'} />);
|
36
|
+
expect(screen.getByText('Embedded header title')).toBeTruthy();
|
37
|
+
});
|
38
|
+
|
39
|
+
it('should fallback to default title when embedded display mode title is not configured', () => {
|
40
|
+
render(<ChatbotHeaderTitle displayMode={ChatbotDisplayMode.embedded} showOnDefault={'Default header title'} />);
|
41
|
+
expect(screen.getByText('Default header title')).toBeTruthy();
|
42
|
+
});
|
43
|
+
|
44
|
+
it('should render title for fullscreen display mode', () => {
|
45
|
+
render(
|
46
|
+
<ChatbotHeaderTitle
|
47
|
+
displayMode={ChatbotDisplayMode.fullscreen}
|
48
|
+
showOnFullScreen={'Fullscreen header title'}
|
49
|
+
className="custom-header-class"
|
50
|
+
/>
|
51
|
+
);
|
52
|
+
expect(screen.getByText('Fullscreen header title')).toBeTruthy();
|
53
|
+
});
|
54
|
+
|
55
|
+
it('should fallback to default title when fullscreen display mode title is not configured', () => {
|
56
|
+
render(<ChatbotHeaderTitle displayMode={ChatbotDisplayMode.fullscreen} showOnDefault={'Default header title'} />);
|
57
|
+
expect(screen.getByText('Default header title')).toBeTruthy();
|
58
|
+
});
|
59
|
+
});
|
@@ -1,11 +1,11 @@
|
|
1
|
+
import '@testing-library/jest-dom';
|
1
2
|
import React from 'react';
|
3
|
+
import { DropdownGroup, DropdownItem, DropdownList } from '@patternfly/react-core';
|
4
|
+
import { BellIcon, CalendarAltIcon, ClipboardIcon, CodeIcon } from '@patternfly/react-icons';
|
2
5
|
import { render, screen } from '@testing-library/react';
|
3
|
-
import '@testing-library/jest-dom';
|
4
6
|
import userEvent from '@testing-library/user-event';
|
5
|
-
import { MessageBar } from './MessageBar';
|
6
|
-
import { DropdownGroup, DropdownItem, DropdownList } from '@patternfly/react-core';
|
7
7
|
import SourceDetailsMenuItem from '../SourceDetailsMenuItem';
|
8
|
-
import {
|
8
|
+
import { MessageBar } from './MessageBar';
|
9
9
|
|
10
10
|
const ATTACH_MENU_ITEMS = [
|
11
11
|
<DropdownList key="list-1">
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { render, screen } from '@testing-library/react';
|
3
|
+
import { MessageBox } from './MessageBox';
|
4
|
+
|
5
|
+
describe('MessageBox', () => {
|
6
|
+
it('should render Message box', () => {
|
7
|
+
render(
|
8
|
+
<MessageBox>
|
9
|
+
<>Chatbot Messages</>
|
10
|
+
</MessageBox>
|
11
|
+
);
|
12
|
+
expect(screen.getByText('Chatbot Messages')).toBeTruthy();
|
13
|
+
});
|
14
|
+
|
15
|
+
it('should assign ref to Message box', () => {
|
16
|
+
const ref = React.createRef<HTMLDivElement>();
|
17
|
+
render(
|
18
|
+
<MessageBox ref={ref}>
|
19
|
+
<div>Test message content</div>
|
20
|
+
</MessageBox>
|
21
|
+
);
|
22
|
+
|
23
|
+
expect(ref.current).not.toBeNull();
|
24
|
+
expect(ref.current).toBeInstanceOf(HTMLDivElement);
|
25
|
+
});
|
26
|
+
});
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
3
|
+
import { PreviewAttachment } from './PreviewAttachment';
|
4
|
+
|
5
|
+
describe('PreviewAttachment', () => {
|
6
|
+
it('should render PreviewAttachment', () => {
|
7
|
+
render(
|
8
|
+
<PreviewAttachment
|
9
|
+
code="Hello world"
|
10
|
+
fileName="greetings.txt"
|
11
|
+
isModalOpen={true}
|
12
|
+
onEdit={jest.fn()}
|
13
|
+
handleModalToggle={jest.fn()}
|
14
|
+
/>
|
15
|
+
);
|
16
|
+
expect(screen.getByText('Preview attachment')).toBeTruthy();
|
17
|
+
expect(screen.getByText('greetings')).toBeTruthy();
|
18
|
+
expect(screen.getAllByText('TEXT')).toBeTruthy();
|
19
|
+
});
|
20
|
+
|
21
|
+
it('should call onEdit handler when edit button is pressed', () => {
|
22
|
+
const onEdit = jest.fn();
|
23
|
+
render(
|
24
|
+
<PreviewAttachment
|
25
|
+
code="Hello world"
|
26
|
+
fileName="greetings.txt"
|
27
|
+
isModalOpen={true}
|
28
|
+
onEdit={onEdit}
|
29
|
+
handleModalToggle={jest.fn()}
|
30
|
+
/>
|
31
|
+
);
|
32
|
+
fireEvent.click(screen.getByText('Edit'));
|
33
|
+
|
34
|
+
expect(onEdit).toHaveBeenCalled();
|
35
|
+
});
|
36
|
+
it('should call onDismiss handler when dismiss button is pressed', () => {
|
37
|
+
const onDismiss = jest.fn();
|
38
|
+
render(
|
39
|
+
<PreviewAttachment
|
40
|
+
code="Hello world"
|
41
|
+
fileName="greetings.txt"
|
42
|
+
isModalOpen={true}
|
43
|
+
onEdit={jest.fn()}
|
44
|
+
handleModalToggle={onDismiss}
|
45
|
+
/>
|
46
|
+
);
|
47
|
+
fireEvent.click(screen.getByText('Dismiss'));
|
48
|
+
|
49
|
+
expect(onDismiss).toHaveBeenCalled();
|
50
|
+
});
|
51
|
+
});
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { Button } from '@patternfly/react-core';
|
3
|
+
import { render, screen } from '@testing-library/react';
|
4
|
+
import { SettingsForm } from './SettingsForm';
|
5
|
+
|
6
|
+
describe('SettingsForm', () => {
|
7
|
+
it('should render settingsForm with custom classname', () => {
|
8
|
+
const { container } = render(<SettingsForm className="custom-settings" />);
|
9
|
+
expect(container.querySelector('.custom-settings')).toBeTruthy();
|
10
|
+
});
|
11
|
+
|
12
|
+
it('should render settingsForm with fields', () => {
|
13
|
+
const fields = [
|
14
|
+
{
|
15
|
+
id: 'archived-chat',
|
16
|
+
label: 'Archive chat',
|
17
|
+
field: (
|
18
|
+
<Button id="archived-chat" variant="secondary">
|
19
|
+
Archive chat
|
20
|
+
</Button>
|
21
|
+
)
|
22
|
+
}
|
23
|
+
];
|
24
|
+
render(<SettingsForm fields={fields} />);
|
25
|
+
|
26
|
+
expect(screen.getByRole('button', { name: 'Archive chat' })).toBeTruthy();
|
27
|
+
});
|
28
|
+
});
|