@@ -2,28 +2,29 @@ import React from 'react';
22import { cleanup , fireEvent , render } from '@testing-library/react' ;
33import '@testing-library/jest-dom/extend-expect' ;
44
5- import BlockHeader , { SizeType } from '../index' ;
5+ import BlockHeader , { IBlockHeaderProps , SizeType } from '../index' ;
66
7- const props = {
7+ const props : IBlockHeaderProps = {
88 title : '标题1' ,
99} ;
10- const props2 = {
10+ const props2 : IBlockHeaderProps = {
1111 title : '标题2' ,
12- beforeTitle : < span > Icon</ span > ,
13- afterTitle : '说明文字' ,
12+ addonBefore : < span > Icon</ span > ,
13+ description : '说明文字' ,
1414 addonAfter : < div className = "test-button-after" > 新增按钮</ div > ,
1515 size : 'small' as SizeType ,
16- titleRowClassName : 'test-row-className' ,
17- titleClassName : 'test-title-className' ,
16+ className : 'test__className' ,
17+ style : { height : '100px' } ,
18+ hasBottom : true ,
1819} ;
19- const props3 = {
20+ const props3 : IBlockHeaderProps = {
2021 title : 'hover' ,
2122 tooltip : 'hover 展示' ,
2223} ;
23- const props4 = {
24+ const props4 : IBlockHeaderProps = {
2425 title : 'hover' ,
2526 tooltip : 'hover 展示' ,
26- afterTitle : '我的优先级更高 ' ,
27+ description : '说明文字 ' ,
2728} ;
2829const prefixCls = 'dtc-block-header' ;
2930
@@ -42,21 +43,10 @@ describe('test BlockHeader render', () => {
4243 expect ( getByText ( '标题2' ) ) . toBeTruthy ( ) ;
4344 } ) ;
4445 test ( 'should render BlockHeader props default in BlockHeader' , ( ) => {
45- const { container } = render ( < BlockHeader title = "测试" showBackground /> ) ;
46+ const { container } = render ( < BlockHeader title = "测试" background /> ) ;
4647 const wrap = container . firstChild ;
47- expect ( wrap ! . firstChild ! . firstChild ! . firstChild ) . toHaveClass ( `${ prefixCls } -before-title` ) ;
48- fireEvent . click ( document . getElementsByClassName ( `${ prefixCls } -title-row` ) [ 0 ] ) ;
49- } ) ;
50- test ( 'should render BlockHeader with different props' , ( ) => {
51- const { container, getByText } = render ( < BlockHeader { ...props2 } /> ) ;
52- const wrap = container . firstChild ;
53- expect ( wrap ) . toHaveClass ( `${ prefixCls } ` ) ;
54- expect ( wrap ! . lastChild ) . toHaveClass ( `${ prefixCls } -content` ) ;
55- expect ( wrap ! . firstChild ) . toHaveClass ( `test-row-className` ) ;
56- expect ( getByText ( '标题2' ) ) . toHaveClass ( 'test-title-className' ) ;
57- expect ( getByText ( '说明文字' ) ) . toHaveClass ( `${ prefixCls } -after-title` ) ;
58- expect ( getByText ( '新增按钮' ) ) . toHaveClass ( `test-button-after` ) ;
59- expect ( getByText ( 'Icon' ) ) . toBeTruthy ( ) ;
48+ expect ( wrap ! . firstChild ! . firstChild ! . firstChild ) . toHaveClass ( 'title__addon-before' ) ;
49+ fireEvent . click ( document . getElementsByClassName ( `${ prefixCls } __title` ) [ 0 ] ) ;
6050 } ) ;
6151 test ( 'should render BlockHeader test click event' , ( ) => {
6252 const onChange = jest . fn ( ) ;
@@ -66,7 +56,7 @@ describe('test BlockHeader render', () => {
6656 </ BlockHeader >
6757 ) ;
6858 expect ( getByText ( '收起' ) ) . toBeTruthy ( ) ;
69- fireEvent . click ( document . getElementsByClassName ( `${ prefixCls } -title-row ` ) [ 0 ] ) ;
59+ fireEvent . click ( document . getElementsByClassName ( `${ prefixCls } __title ` ) [ 0 ] ) ;
7060 expect ( getByText ( '展开' ) ) . toBeTruthy ( ) ;
7161 expect ( onChange ) . toHaveBeenCalledTimes ( 1 ) ;
7262 } ) ;
@@ -77,33 +67,30 @@ describe('test BlockHeader render', () => {
7767 </ BlockHeader >
7868 ) ;
7969 expect ( getByText ( '收起' ) ) . toBeTruthy ( ) ;
80- fireEvent . click ( document . getElementsByClassName ( `${ prefixCls } -title-row ` ) [ 0 ] ) ;
70+ fireEvent . click ( document . getElementsByClassName ( `${ prefixCls } __title ` ) [ 0 ] ) ;
8171 expect ( getByText ( '展开' ) ) . toBeTruthy ( ) ;
8272 } ) ;
8373 test ( 'should render BlockHeader with different props' , ( ) => {
8474 const { container, getByText } = render ( < BlockHeader { ...props2 } /> ) ;
8575 const wrap = container . firstChild ;
86- expect ( wrap ) . toHaveClass ( `${ prefixCls } ` ) ;
87- expect ( wrap ! . lastChild ) . toHaveClass ( `${ prefixCls } -content` ) ;
88- expect ( wrap ! . firstChild ) . toHaveClass ( `test-row-className` ) ;
89- expect ( getByText ( '标题2' ) ) . toHaveClass ( 'test-title-className' ) ;
90- expect ( getByText ( '说明文字' ) ) . toHaveClass ( `${ prefixCls } -after-title` ) ;
76+ expect ( wrap ) . toHaveClass ( `${ prefixCls } test__className` ) ;
77+ expect ( wrap ) . toHaveStyle ( { height : '100px' , marginBottom : '16px' } ) ;
78+ expect ( getByText ( '标题2' ) ) . toHaveClass ( 'title__text' ) ;
79+ expect ( getByText ( '说明文字' ) ) . toHaveClass ( 'title__description' ) ;
9180 expect ( getByText ( 'Icon' ) ) . toBeTruthy ( ) ;
9281 } ) ;
93- test ( 'should render BlockHeader className when isSmall is small ' , ( ) => {
94- const props = { title : '测试1' , showBackground : false } ;
82+ test ( 'should render BlockHeader background success ' , ( ) => {
83+ const props = { title : '测试1' , background : false } ;
9584 const { container } = render ( < BlockHeader { ...props } /> ) ;
9685 const wrap = container . firstChild ;
9786 expect ( wrap ! . firstChild ) . not . toHaveClass ( `background` ) ;
9887 } ) ;
9988 test ( 'should render BlockHeader className when isSmall is small' , ( ) => {
10089 const { container, getByText } = render ( < BlockHeader { ...props2 } /> ) ;
10190 const wrap = container . firstChild ! ;
102- expect ( wrap ) . toHaveClass ( `${ prefixCls } ` ) ;
103- expect ( wrap . lastChild ) . toHaveClass ( `${ prefixCls } -content` ) ;
104- expect ( wrap . firstChild ) . toHaveClass ( `test-row-className` ) ;
105- expect ( getByText ( '标题2' ) ) . toHaveClass ( 'test-title-className' ) ;
106- expect ( getByText ( '说明文字' ) ) . toHaveClass ( `${ prefixCls } -after-title` ) ;
91+ expect ( wrap ) . toHaveClass ( `${ prefixCls } test__className` ) ;
92+ expect ( getByText ( '标题2' ) ) . toHaveClass ( 'title__text' ) ;
93+ expect ( getByText ( '说明文字' ) ) . toHaveClass ( 'title__description' ) ;
10794 expect ( getByText ( 'Icon' ) ) . toBeTruthy ( ) ;
10895 } ) ;
10996
@@ -114,32 +101,32 @@ describe('test BlockHeader render', () => {
114101 expect ( afterTitleWrap ! . firstChild ) . toHaveClass ( 'anticon-question-circle' ) ;
115102 } ) ;
116103
117- test ( 'should render BlockHeader tooltip and afterTitle success' , ( ) => {
104+ test ( 'should render BlockHeader tooltip and desc success' , ( ) => {
118105 const { container } = render ( < BlockHeader { ...props4 } /> ) ;
119106 const wrap = container . firstChild ! ;
120107 const afterTitleWrap = wrap . firstChild ! . firstChild ! . lastChild ;
121- expect ( afterTitleWrap ) . toHaveTextContent ( '我的优先级更高 ' ) ;
108+ expect ( afterTitleWrap ) . toHaveTextContent ( '说明文字 ' ) ;
122109 } ) ;
123110 test ( 'should render BlockHeader correct dom length' , ( ) => {
124- const { container } = render ( < BlockHeader title = "分类级别" beforeTitle = "" /> ) ;
111+ const { container } = render ( < BlockHeader title = "分类级别" addonBefore = "" /> ) ;
125112 const titleBoxWrap = container . firstChild ! . firstChild ! . firstChild ;
126113 expect ( titleBoxWrap ! . childNodes . length ) . toEqual ( 1 ) ;
127114
128115 const { container : container1 } = render (
129- < BlockHeader title = "分类级别" afterTitle = "测试" />
116+ < BlockHeader title = "分类级别" description = "测试" />
130117 ) ;
131118 const titleBoxWrap1 = container1 . firstChild ! . firstChild ! . firstChild ;
132119 expect ( titleBoxWrap1 ! . childNodes . length ) . toEqual ( 3 ) ;
133120 } ) ;
134121 test ( 'should render BlockHeader correct margin-bottom' , ( ) => {
135- const { container : noStyle } = render ( < BlockHeader title = "分类级别" beforeTitle = "" /> ) ;
122+ const { container : noStyle } = render ( < BlockHeader title = "分类级别" addonBefore = "" /> ) ;
136123 expect ( noStyle . querySelector ( '.dtc-block-header' ) ) . not . toHaveAttribute ( 'style' ) ;
137124 const { container : defaultBottom } = render (
138- < BlockHeader title = "分类级别" beforeTitle = "" />
125+ < BlockHeader title = "分类级别" addonBefore = "" />
139126 ) ;
140127 expect ( defaultBottom . querySelector ( '.dtc-block-header' ) ) . toHaveStyle ( { marginBottom : 16 } ) ;
141128 const { container : customizeBottom } = render (
142- < BlockHeader title = "分类级别" beforeTitle = "" hasBottom spaceBottom = { 10 } />
129+ < BlockHeader title = "分类级别" addonBefore = "" hasBottom spaceBottom = { 10 } />
143130 ) ;
144131 expect ( customizeBottom . querySelector ( '.dtc-block-header' ) ) . toHaveStyle ( {
145132 marginBottom : 10 ,
0 commit comments