@@ -13,19 +13,23 @@ describe("Tabs Component", () => {
13
13
) ;
14
14
15
15
const tabsComponent = container . querySelector ( ".derivs-primary-tabs" )
16
+ const tabTitle = screen . getByText ( "Tab 1" )
16
17
const tab1Content = screen . getByText ( "Tab 1 Content" )
18
+ expect ( tabTitle ) . toBeInTheDocument ( ) ;
17
19
expect ( tabsComponent ) . toBeInTheDocument ( ) ;
18
20
expect ( tab1Content ) . toBeInTheDocument ( ) ;
19
21
expect ( tabsComponent ) . toHaveClass ( "derivs-primary-tabs" ) ;
20
22
} ) ;
21
23
22
- it ( "changes active tab when clicked" , ( ) => {
24
+ it ( "changes active tab when clicked and checks active tab content showing " , ( ) => {
23
25
render (
24
- < Tabs >
26
+ < Tabs activeTab = "Tab 1" >
25
27
< Tab title = "Tab 1" > Tab 1 Content</ Tab >
26
28
< Tab title = "Tab 2" > Tab 2 Content</ Tab >
27
29
</ Tabs >
28
30
) ;
31
+ const tab1 = screen . getByText ( "Tab 1 Content" )
32
+ expect ( tab1 ) . toBeInTheDocument ( ) ;
29
33
const tab2 = screen . getByText ( "Tab 2" ) ;
30
34
fireEvent . click ( tab2 ) ;
31
35
const activeButton = screen . getAllByRole ( "button" ) [ 1 ] ;
@@ -34,6 +38,43 @@ describe("Tabs Component", () => {
34
38
expect ( activeButton ) . toHaveClass ( "derivs-primary-tabs__btn--active" ) ;
35
39
} ) ;
36
40
41
+ it ( "should render tabs with correct variant" , ( ) => {
42
+ const { container } = render (
43
+ < Tabs variant = "secondary" >
44
+ < Tab title = "Tab 1" > Tab 1 Content</ Tab >
45
+ < Tab title = "Tab 2" > Tab 2 Content</ Tab >
46
+ </ Tabs >
47
+ ) ;
48
+ const tabsComponent = container . querySelector ( ".derivs-secondary-tabs" )
49
+ expect ( tabsComponent ) . toBeInTheDocument ( ) ;
50
+ } ) ;
51
+
52
+ it ( "should render tabs with correct title font size" , ( ) => {
53
+ const { container } = render (
54
+ < Tabs TitleFontSize = "lg" >
55
+ < Tab title = "Tab 1" > Tab 1 Content</ Tab >
56
+ < Tab title = "Tab 2" > Tab 2 Content</ Tab >
57
+ </ Tabs >
58
+ ) ;
59
+
60
+ const tabsComponent = container . querySelector ( ".derivs-primary-tabs" )
61
+
62
+ expect ( tabsComponent ) . toHaveStyle ( "font-size: lg;" ) ;
63
+ } ) ;
64
+
65
+ it ( "should call onChange handler when a tab is clicked" , ( ) => {
66
+ const mockOnChange = jest . fn ( ) ;
67
+ const { getByText } = render (
68
+ < Tabs onChange = { mockOnChange } >
69
+ < Tab title = "Tab 1" > Tab 1 Content</ Tab >
70
+ < Tab title = "Tab 2" > Tab 2 Content</ Tab >
71
+ </ Tabs >
72
+ ) ;
73
+ const tabTitle = getByText ( "Tab 1" ) ;
74
+ fireEvent . click ( tabTitle ) ;
75
+ expect ( mockOnChange ) . toHaveBeenCalled ( ) ;
76
+ } ) ;
77
+
37
78
it ( "applies custom class to wrapper" , ( ) => {
38
79
const { container } = render (
39
80
< Tabs wrapperClassName = "custom-wrapper" >
0 commit comments