This repository was archived by the owner on May 13, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +93
-5
lines changed
CustomAccordion/__tests__ Expand file tree Collapse file tree 4 files changed +93
-5
lines changed Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import { cleanup , render , screen } from '@testing-library/react' ;
3
+ import CustomAccordion from '..' ;
4
+ import userEvent from '@testing-library/user-event' ;
5
+
6
+ const mock_accordion_items = [
7
+ { header : 'header_1' , content : 'content 1' } ,
8
+ { header : 'header_2' , content : 'content 2' } ,
9
+ ] ;
10
+
11
+ describe ( 'CustomAccordion' , ( ) => {
12
+ beforeEach ( ( ) => {
13
+ render ( < CustomAccordion items = { mock_accordion_items } /> ) ;
14
+ } ) ;
15
+
16
+ afterEach ( ( ) => {
17
+ cleanup ( ) ;
18
+ } ) ;
19
+
20
+ it ( 'should render the custom accordion' , ( ) => {
21
+ const header = screen . getByText ( 'header_1' ) ;
22
+ expect ( header ) . toBeInTheDocument ( ) ;
23
+ } ) ;
24
+
25
+ it ( 'should open accordion content on click' , async ( ) => {
26
+ const header = screen . getByText ( 'header_2' ) ;
27
+ await userEvent . click ( header ) ;
28
+ const content = screen . getByText ( 'content 2' ) ;
29
+ expect ( content ) . toBeInTheDocument ( ) ;
30
+ } ) ;
31
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import { cleanup , render , screen } from '@testing-library/react' ;
3
+ import CustomTabs from '..' ;
4
+ import userEvent from '@testing-library/user-event' ;
5
+
6
+ const mock_tabs = [
7
+ { label : 'tab_1' , content : 'content 1' } ,
8
+ { label : 'tab_2' , content : 'content 2' } ,
9
+ ] ;
10
+
11
+ describe ( 'CustomTabs' , ( ) => {
12
+ beforeEach ( ( ) => {
13
+ render ( < CustomTabs tabs = { mock_tabs } > </ CustomTabs > ) ;
14
+ } ) ;
15
+
16
+ afterEach ( ( ) => {
17
+ cleanup ( ) ;
18
+ } ) ;
19
+
20
+ it ( 'should render the custom tabs' , ( ) => {
21
+ const tab = screen . getByText ( 'tab_1' ) ;
22
+ expect ( tab ) . toBeInTheDocument ( ) ;
23
+ } ) ;
24
+
25
+ it ( 'should change tab content on different tab click' , async ( ) => {
26
+ const tab = screen . getByText ( 'tab_2' ) ;
27
+ await userEvent . click ( tab ) ;
28
+ const content = screen . getByText ( 'content 2' ) ;
29
+ expect ( content ) . toBeInTheDocument ( ) ;
30
+ } ) ;
31
+ } ) ;
Original file line number Diff line number Diff line change @@ -9,10 +9,6 @@ const CustomTabs: React.FC<{
9
9
} > = ( { tabs } ) => {
10
10
const [ activeTab , setActiveTab ] = useState ( 0 ) ;
11
11
12
- const handleTabClick = ( index ) => {
13
- setActiveTab ( index ) ;
14
- } ;
15
-
16
12
return (
17
13
< div className = 'tabs' >
18
14
< div className = 'tabs_header' >
@@ -21,7 +17,7 @@ const CustomTabs: React.FC<{
21
17
< div
22
18
key = { index }
23
19
className = { `tabs_header__item ${ activeTab === index ? 'active' : '' } ` }
24
- onClick = { ( ) => handleTabClick ( index ) }
20
+ onClick = { ( ) => setActiveTab ( index ) }
25
21
>
26
22
{ tab . label }
27
23
</ div >
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import { cleanup , render , screen } from '@testing-library/react' ;
3
+ import CustomTooltip from '..' ;
4
+ import userEvent from '@testing-library/user-event' ;
5
+
6
+ describe ( 'CustomTooltip' , ( ) => {
7
+ beforeEach ( ( ) => {
8
+ render (
9
+ < CustomTooltip text = 'tooltip text' >
10
+ < div > outer text</ div >
11
+ </ CustomTooltip > ,
12
+ ) ;
13
+ } ) ;
14
+
15
+ afterEach ( ( ) => {
16
+ cleanup ( ) ;
17
+ } ) ;
18
+
19
+ it ( 'should render the custom tooltip with children' , ( ) => {
20
+ const text = screen . getByText ( 'outer text' ) ;
21
+ expect ( text ) . toBeInTheDocument ( ) ;
22
+ } ) ;
23
+
24
+ it ( 'should render the tooltip text on hover' , async ( ) => {
25
+ const text = screen . getByText ( 'outer text' ) ;
26
+ await userEvent . hover ( text ) ;
27
+ const tooltip_text = screen . getAllByText ( 'tooltip text' ) ;
28
+ expect ( tooltip_text [ 0 ] ) . toBeInTheDocument ( ) ;
29
+ } ) ;
30
+ } ) ;
You can’t perform that action at this time.
0 commit comments