-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(tabs): init tabs with custom active index other than zero
- Loading branch information
remi.jacquart@axa.fr
committed
Sep 11, 2020
1 parent
e953283
commit 3246fd0
Showing
4 changed files
with
75 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,55 @@ | ||
import { onChangeEvent, TabsContainerState } from './TabsCore'; | ||
import * as React from 'react'; | ||
import { create } from 'react-test-renderer'; | ||
import TabsCore, { onChangeEvent } from './TabsCore'; | ||
import Tab from './Tab'; | ||
|
||
describe('TabsCore tests suite', () => { | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should init activate index in state function', () => { | ||
|
||
// given | ||
const givenActivateIndex = '3'; | ||
|
||
const setStateMock = jest.fn(); | ||
const useStateMock: any = jest.fn().mockImplementation((initState: any) => { | ||
return [initState, setStateMock]; | ||
}); | ||
|
||
jest.spyOn(React, 'useState').mockImplementation(useStateMock); | ||
|
||
const onChangeMock = jest.fn(x => {}); | ||
|
||
create( | ||
<TabsCore | ||
onChange={onChangeMock} | ||
activeIndex={givenActivateIndex} | ||
> | ||
<Tab title="title tab1" classModifier="modifier 1"> | ||
<span>Content</span> | ||
</Tab> | ||
<Tab title="title tab2" classModifier="modifier"> | ||
<span>Content</span> | ||
</Tab> | ||
<Tab title="title tab3" classModifier="modifier 1"> | ||
<span>Content</span> | ||
</Tab> | ||
</TabsCore> | ||
); | ||
|
||
expect(useStateMock).toHaveBeenNthCalledWith(1, givenActivateIndex); | ||
}); | ||
|
||
it('should return correct onChange function', () => { | ||
const onChangeMock = jest.fn(x => {}); | ||
const setStateMock = jest.fn(x => {}); | ||
const fakeState: TabsContainerState = { | ||
activeIndex: '0', | ||
}; | ||
onChangeEvent(onChangeMock)(setStateMock )(fakeState)( | ||
onChangeEvent(onChangeMock)(setStateMock )( | ||
{ id: '3' } | ||
); | ||
expect(setStateMock).toBeCalledWith({activeIndex: '3'}); | ||
expect(setStateMock).toBeCalledWith('3'); | ||
expect(onChangeMock).toBeCalledWith('3'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters