UNPKG

2.44 kBJavaScriptView Raw
1import React from 'react';
2import { screen, render } from '@testing-library/react';
3import { TabContent, TabPane } from '..';
4import '@testing-library/jest-dom';
5
6let activeTab = '1';
7describe('Tabs', () => {
8 it('should render', () => {
9 render(
10 <TabContent activeTab="1">
11 <TabPane tabId="1">Destiny</TabPane>
12 <TabPane tabId="2">Death</TabPane>
13 </TabContent>,
14 );
15 expect(screen.getByText('Destiny')).toBeInTheDocument();
16 expect(screen.getByText('Death')).toBeInTheDocument();
17 });
18
19 it('should have tab1 as active', () => {
20 render(
21 <TabContent activeTab="1">
22 <TabPane tabId="1">Dream</TabPane>
23 <TabPane tabId="2">Destruction</TabPane>
24 </TabContent>,
25 );
26 expect(screen.getByText('Dream')).toHaveClass('active');
27 expect(screen.getByText('Destruction')).not.toHaveClass('active');
28 });
29
30 it('should switch to tab2 as active', () => {
31 render(
32 <TabContent activeTab="2">
33 <TabPane tabId="1">Desire</TabPane>
34 <TabPane tabId="2">Despair</TabPane>
35 </TabContent>,
36 );
37 expect(screen.getByText('Desire')).not.toHaveClass('active');
38 expect(screen.getByText('Despair')).toHaveClass('active');
39 });
40
41 it('should show no active tabs if active tab id is unknown', () => {
42 render(
43 <TabContent activeTab="3">
44 <TabPane tabId="1">Delirium</TabPane>
45 <TabPane tabId="2">Delight</TabPane>
46 </TabContent>,
47 );
48 expect(screen.getByText('Delirium')).not.toHaveClass('active');
49 expect(screen.getByText('Delight')).not.toHaveClass('active');
50 /* Not sure if this is what we want. Toggling to an unknown tab id should
51 render all tabs as inactive and should show no content.
52 This could be a warning during development that the user is not having a proper tab ids.
53 NOTE: Should this be different?
54 */
55 });
56
57 it('should render custom TabContent tag', () => {
58 render(
59 <TabContent tag="main" activeTab={activeTab} data-testid="endless">
60 <TabPane tabId="1">Tab Content 1</TabPane>
61 <TabPane tabId="2">TabContent 2</TabPane>
62 </TabContent>,
63 );
64
65 expect(screen.getByTestId('endless').tagName).toBe('MAIN');
66 });
67
68 it('should render custom TabPane tag', () => {
69 render(
70 <TabPane tag="main" tabId="1">
71 Tab Content 1
72 </TabPane>,
73 );
74
75 expect(screen.getByText('Tab Content 1').tagName).toBe('MAIN');
76 });
77});