-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CLNP-4657] Provider migration - P0 items (#1269)
Addresses P0 items in https://sendbird.atlassian.net/browse/CLNP-4657 This PR is for merging a mega branch `feat/state-mgmt-migration-1` into `main`. --------- Co-authored-by: Baek EunSeo <[email protected]> Co-authored-by: Junyoung Lim <[email protected]> Co-authored-by: junyoung.lim <[email protected]> Co-authored-by: Chris Heo <[email protected]>
- Loading branch information
1 parent
79bfe84
commit 9be7a49
Showing
341 changed files
with
14,805 additions
and
5,321 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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { act, renderHook } from '@testing-library/react'; | ||
import { useAsyncRequest } from '../useAsyncRequest'; | ||
|
||
describe('useAsyncRequest', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('handle request with no response correctly', async () => { | ||
const mockPromise = Promise.resolve(); | ||
const mockRequest = jest.fn().mockReturnValue(mockPromise); | ||
|
||
const { result } = renderHook(() => useAsyncRequest(mockRequest)); | ||
|
||
await act(async () => { | ||
await mockPromise; | ||
}); | ||
|
||
expect(result.current.loading).toBe(false); | ||
}); | ||
|
||
it('handle request with response correctly', async () => { | ||
const mockResponse = { code: 'ok' }; | ||
const mockPromise = Promise.resolve(mockResponse); | ||
const mockRequest = jest.fn().mockReturnValue(mockPromise); | ||
|
||
const { result } = renderHook(() => useAsyncRequest(mockRequest)); | ||
|
||
await act(async () => { | ||
await mockPromise; | ||
}); | ||
|
||
expect(result.current.response).toBe(mockResponse); | ||
expect(result.current.loading).toBe(false); | ||
}); | ||
|
||
it('cancel request correctly', async () => { | ||
const mockCancel = jest.fn(); | ||
const mockRequest = { cancel: mockCancel }; | ||
|
||
const { unmount } = renderHook(() => useAsyncRequest(mockRequest)); | ||
|
||
unmount(); | ||
|
||
expect(mockCancel).toBeCalled(); | ||
}); | ||
|
||
}); |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { renderHook } from '@testing-library/react'; | ||
import { useDebounce } from '../useDebounce'; | ||
|
||
describe('useAsyncRequest', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('handle useDebounce correctly', async () => { | ||
const mockFunction = jest.fn(); | ||
const { result } = renderHook(() => useDebounce(mockFunction, 1000)); | ||
|
||
const debounceFunction = result.current; | ||
|
||
debounceFunction(); | ||
debounceFunction(); | ||
debounceFunction(); | ||
debounceFunction(); | ||
debounceFunction(); | ||
|
||
await new Promise(resolve => { | ||
setTimeout(resolve, 1000); | ||
}); | ||
|
||
expect(mockFunction).toBeCalledTimes(1); | ||
}); | ||
|
||
}); |
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React from 'react'; | ||
import { renderHook, screen, fireEvent, render, waitFor } from '@testing-library/react'; | ||
import useLongPress from '../useLongPress'; | ||
|
||
describe('useLongPress', () => { | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('handle long press correctly', async () => { | ||
const mockOnLongPress = jest.fn(); | ||
const mockOnClick = jest.fn(); | ||
|
||
const { result } = renderHook(() => useLongPress({ | ||
onLongPress: mockOnLongPress, | ||
onClick: mockOnClick, | ||
})); | ||
const { onTouchStart, onTouchEnd } = result.current; | ||
|
||
const targetComponent = <div id="target" onTouchStart={onTouchStart} onTouchEnd={onTouchEnd}>touch this</div>; | ||
render(targetComponent); | ||
|
||
const element = screen.getByText('touch this'); | ||
fireEvent.touchStart(element); | ||
await new Promise(resolve => { | ||
setTimeout(resolve, 1000); | ||
}); | ||
fireEvent.touchEnd(element); | ||
|
||
await waitFor(() => { | ||
expect(mockOnLongPress).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
it('cancel long press if touch is too short', async () => { | ||
const mockOnLongPress = jest.fn(); | ||
const mockOnClick = jest.fn(); | ||
|
||
const { result } = renderHook(() => useLongPress({ | ||
onLongPress: mockOnLongPress, | ||
onClick: mockOnClick, | ||
})); | ||
const { onTouchStart, onTouchEnd } = result.current; | ||
|
||
const targetComponent = <div id="target" onTouchStart={onTouchStart} onTouchEnd={onTouchEnd}>touch this</div>; | ||
render(targetComponent); | ||
|
||
const element = screen.getByText('touch this'); | ||
fireEvent.touchStart(element); | ||
await new Promise(resolve => { | ||
setTimeout(resolve, 100); | ||
}); | ||
fireEvent.touchEnd(element); | ||
|
||
await waitFor(() => { | ||
expect(mockOnClick).toHaveBeenCalled(); | ||
expect(mockOnLongPress).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
}); |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
import { renderHook, screen, fireEvent, render, waitFor } from '@testing-library/react'; | ||
import useMouseHover from '../useMouseHover'; | ||
|
||
describe('useMouseHover', () => { | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('handle mouse over and out correctly', async () => { | ||
const mockSetHover = jest.fn(); | ||
|
||
const targetComponent = <div id="target">hover</div>; | ||
render(targetComponent); | ||
|
||
const hoverElement = screen.getByText('hover'); | ||
const ref = { | ||
current: hoverElement, | ||
}; | ||
|
||
renderHook(() => useMouseHover({ | ||
ref, | ||
setHover: mockSetHover, | ||
})); | ||
|
||
fireEvent.mouseEnter(hoverElement); | ||
fireEvent.mouseLeave(hoverElement); | ||
|
||
await waitFor(() => { | ||
expect(mockSetHover).toHaveBeenCalledTimes(2); | ||
expect(mockSetHover).toHaveBeenCalledWith(true); | ||
expect(mockSetHover).toHaveBeenCalledWith(false); | ||
}); | ||
}); | ||
|
||
}); |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react'; | ||
import { renderHook, screen, fireEvent, render, waitFor } from '@testing-library/react'; | ||
import useOutsideAlerter from '../useOutsideAlerter'; | ||
|
||
describe('useOutsideAlerter', () => { | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('handle click outside correctly', async () => { | ||
const mockClickOutside = jest.fn(); | ||
|
||
const targetComponent = <div id="target">inside</div>; | ||
render(targetComponent); | ||
|
||
const insideElement = screen.getByText('inside'); | ||
const ref = { | ||
current: insideElement, | ||
}; | ||
|
||
renderHook(() => useOutsideAlerter({ | ||
ref, | ||
callback: mockClickOutside, | ||
})); | ||
|
||
fireEvent.mouseDown(insideElement); | ||
|
||
await waitFor(() => { | ||
expect(mockClickOutside).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
|
||
}); |
Oops, something went wrong.