@ -1,6 +1,6 @@
import React from 'react' ;
import mountTest from '../../../tests/shared/mountTest' ;
import { render , fireEvent , getByText , waitFakeTimer } from '../../../tests/utils' ;
import { render , fireEvent , getByText , waitFakeTimer , act } from '../../../tests/utils' ;
import Wave from '../wave' ;
( global as any ) . isVisible = true ;
@ -13,12 +13,29 @@ jest.mock('rc-util/lib/Dom/isVisible', () => {
describe ( 'Wave component' , ( ) = > {
mountTest ( Wave ) ;
let obCnt = 0 ;
let disCnt = 0 ;
beforeAll ( ( ) = > {
/* eslint-disable class-methods-use-this */
class FakeResizeObserver {
observe = ( ) = > {
obCnt += 1 ;
} ;
disconnect = ( ) = > {
disCnt += 1 ;
} ;
}
( window as any ) . ResizeObserver = FakeResizeObserver ;
jest . useFakeTimers ( ) ;
} ) ;
afterAll ( ( ) = > {
jest . useRealTimers ( ) ;
expect ( obCnt ) . not . toBe ( 0 ) ;
expect ( disCnt ) . not . toBe ( 0 ) ;
} ) ;
beforeEach ( ( ) = > {
@ -47,6 +64,12 @@ describe('Wave component', () => {
return styleObj ;
}
function waitRaf() {
act ( ( ) = > {
jest . advanceTimersByTime ( 100 ) ;
} ) ;
}
it ( 'work' , async ( ) = > {
const { container , unmount } = render (
< Wave >
@ -55,6 +78,7 @@ describe('Wave component', () => {
) ;
fireEvent . click ( container . querySelector ( 'button' ) ! ) ;
waitRaf ( ) ;
expect ( document . querySelector ( '.ant-wave' ) ) . toBeTruthy ( ) ;
// Match deadline
@ -74,6 +98,7 @@ describe('Wave component', () => {
) ;
fireEvent . click ( container . querySelector ( 'button' ) ! ) ;
waitRaf ( ) ;
expect ( document . querySelector ( '.ant-wave' ) ) . toBeFalsy ( ) ;
unmount ( ) ;
@ -92,6 +117,7 @@ describe('Wave component', () => {
) ;
fireEvent . click ( container . querySelector ( 'button' ) ! ) ;
waitRaf ( ) ;
const style = getWaveStyle ( ) ;
@ -110,6 +136,7 @@ describe('Wave component', () => {
) ;
fireEvent . click ( container . querySelector ( 'button' ) ! ) ;
waitRaf ( ) ;
const style = getWaveStyle ( ) ;
expect ( style [ '--wave-color' ] ) . toEqual ( 'red' ) ;
@ -125,6 +152,7 @@ describe('Wave component', () => {
) ;
fireEvent . click ( getByText ( container , 'button' ) ! ) ;
waitRaf ( ) ;
const style = getWaveStyle ( ) ;
expect ( style [ '--wave-color' ] ) . toEqual ( 'blue' ) ;
@ -140,6 +168,7 @@ describe('Wave component', () => {
) ;
fireEvent . click ( getByText ( container , 'button' ) ! ) ;
waitRaf ( ) ;
const style = getWaveStyle ( ) ;
expect ( style [ '--wave-color' ] ) . toEqual ( 'green' ) ;
@ -155,6 +184,7 @@ describe('Wave component', () => {
) ;
fireEvent . click ( getByText ( container , 'button' ) ! ) ;
waitRaf ( ) ;
const style = getWaveStyle ( ) ;
expect ( style [ '--wave-color' ] ) . toEqual ( 'yellow' ) ;
@ -172,6 +202,7 @@ describe('Wave component', () => {
) ;
fireEvent . click ( container . querySelector ( 'button' ) ! ) ;
waitRaf ( ) ;
expect ( document . querySelector ( '.ant-wave' ) ) . toBeFalsy ( ) ;
unmount ( ) ;
@ -202,6 +233,7 @@ describe('Wave component', () => {
) ;
fireEvent . click ( container . querySelector ( 'button' ) ! ) ;
waitRaf ( ) ;
expect ( document . querySelector ( '.ant-wave' ) ) . toBeFalsy ( ) ;
} ) ;
@ -213,6 +245,7 @@ describe('Wave component', () => {
) ;
fireEvent . click ( container . querySelector ( 'input' ) ! ) ;
waitRaf ( ) ;
expect ( document . querySelector ( '.ant-wave' ) ) . toBeFalsy ( ) ;
} ) ;
@ -224,11 +257,15 @@ describe('Wave component', () => {
< / Wave > ,
) ;
fireEvent . click ( container ) ;
waitRaf ( ) ;
} ) . not . toThrow ( ) ;
} ) ;
it ( 'should not throw when no children' , ( ) = > {
expect ( ( ) = > render ( < Wave / > ) ) . not . toThrow ( ) ;
expect ( ( ) = > {
render ( < Wave / > ) ;
waitRaf ( ) ;
} ) . not . toThrow ( ) ;
} ) ;
it ( 'wave color should inferred if border is transparent and background is not' , ( ) = > {
@ -240,6 +277,7 @@ describe('Wave component', () => {
< / Wave > ,
) ;
fireEvent . click ( container . querySelector ( 'button' ) ! ) ;
waitRaf ( ) ;
const style = getWaveStyle ( ) ;
expect ( style [ '--wave-color' ] ) . toEqual ( 'red' ) ;
@ -257,6 +295,7 @@ describe('Wave component', () => {
) ;
fireEvent . click ( container . querySelector ( 'button' ) ! ) ;
waitRaf ( ) ;
const style = getWaveStyle ( ) ;
expect ( style [ '--wave-color' ] ) . toEqual ( 'red' ) ;
@ -282,6 +321,7 @@ describe('Wave component', () => {
// Click should not throw
fireEvent . click ( elem ) ;
waitRaf ( ) ;
expect ( container . querySelector ( '.ant-wave' ) ) . toBeTruthy ( ) ;
} ) ;