-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/state-mgmt-migration-1' into fix/ignored-state-update
- Loading branch information
Showing
7 changed files
with
141 additions
and
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { cloneMessage } from '../cloneMessage'; | ||
|
||
describe('cloneMessage', () => { | ||
it('Should return a clone message', () => { | ||
const oldMessage = { | ||
isAdminMessage: true, | ||
isUserMessage: true, | ||
isFileMessage: true, | ||
isMultipleFilesMessage: true, | ||
applyParentMessage: true, | ||
applyReactionEvent: true, | ||
applyThreadInfoUpdateEvent: true, | ||
extraProps: { | ||
field1: true, | ||
field2: 'test', | ||
field3: 42, | ||
}, | ||
}; | ||
|
||
const newMessage = cloneMessage(oldMessage); | ||
|
||
expect(newMessage).toEqual(oldMessage); | ||
}); | ||
}); |
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,29 @@ | ||
import { changeColorToClassName, Colors } from '../color'; | ||
import { truncateString } from '../index'; | ||
|
||
describe('color', () => { | ||
it('check all color enum exist', () => { | ||
expect(Colors.ONBACKGROUND_1).not.toBe(undefined); | ||
expect(Colors.ONBACKGROUND_2).not.toBe(undefined); | ||
expect(Colors.ONBACKGROUND_3).not.toBe(undefined); | ||
expect(Colors.ONBACKGROUND_4).not.toBe(undefined); | ||
expect(Colors.ONCONTENT_1).not.toBe(undefined); | ||
expect(Colors.PRIMARY).not.toBe(undefined); | ||
expect(Colors.ERROR).not.toBe(undefined); | ||
}); | ||
|
||
it('change color enum to proper className', () => { | ||
for (const color of Object.values(Colors)) { | ||
expect(changeColorToClassName(color)).toBe(`sendbird-color--${color.toLowerCase().replace('_', '-')}`); | ||
} | ||
|
||
const nonColor = 'not-existing-color-enum-value'; | ||
expect(changeColorToClassName(nonColor)).toBe(''); | ||
}); | ||
}); | ||
|
||
describe('truncateString', () => { | ||
it('truncate string properly by the given parameter', () => { | ||
expect(truncateString('this is full string', 10)).toBe('this...ing'); | ||
}); | ||
}); |
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 { render, waitFor, screen } from '@testing-library/react'; | ||
import useDidMountEffect from '../useDidMountEffect'; | ||
import React, { useState } from 'react'; | ||
|
||
describe('useDidMountEffect', () => { | ||
beforeEach(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
it('ignore callback if didMount was false', () => { | ||
const mockCallback = jest.fn(); | ||
|
||
const TestComponent = () => { | ||
const [counter, setCounter] = useState(0); | ||
useDidMountEffect(mockCallback, [counter]); | ||
return (<button onClick={() => setCounter(counter + 1)}>increment</button>); | ||
}; | ||
|
||
render(<TestComponent />); | ||
|
||
expect(mockCallback).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('call callback if didMount was true', async () => { | ||
const mockCallback = jest.fn(); | ||
|
||
const TestComponent = () => { | ||
const [counter, setCounter] = useState(0); | ||
useDidMountEffect(mockCallback, [counter]); | ||
return (<button onClick={() => setCounter(counter + 1)}>increment</button>); | ||
}; | ||
|
||
render(<TestComponent />); | ||
const button = screen.getByText('increment'); | ||
|
||
await waitFor(() => { | ||
button.click(); | ||
}); | ||
|
||
await waitFor(() => { | ||
button.click(); | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(mockCallback).toHaveBeenCalledTimes(2); | ||
}); | ||
}); | ||
}); |
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