forked from deriv-com/deriv-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BOT] Maryia/[Test Coverage]test: journal-notifications.js, help-cont…
…ent.config.js (deriv-com#14046) * test: help-content file * test: journal-notifications * test: fix some of test cases of journal-notifications * chore: remove some things * chore: remove help-content.config.spec.ts
- Loading branch information
1 parent
5c2f41e
commit a7c039c
Showing
1 changed file
with
114 additions
and
0 deletions.
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
packages/bot-web-ui/src/utils/__tests__/journal-notifications.spec.tsx
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,114 @@ | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { render } from '@testing-library/react'; | ||
import { messageWithButton } from 'Components/notify-item'; | ||
import { isCustomJournalMessage } from '../journal-notifications'; | ||
import { localize } from '@deriv/translations'; | ||
|
||
describe('isCustomJournalMessage', () => { | ||
const centerAndHighlightBlock = jest.fn(); | ||
const showErrorMessage = jest.fn(() => | ||
render( | ||
messageWithButton({ | ||
unique_id: 1, | ||
type: 'error', | ||
message: '', | ||
btn_text: localize('Go to block'), | ||
onClick: () => { | ||
centerAndHighlightBlock(); | ||
}, | ||
}) | ||
) | ||
); | ||
|
||
const pushMessage = jest.fn(); | ||
|
||
beforeEach(() => { | ||
showErrorMessage.mockClear(); | ||
centerAndHighlightBlock.mockClear(); | ||
pushMessage.mockClear(); | ||
}); | ||
|
||
it('should show error message with button when message is undefined and variable_name is not null', () => { | ||
const message = { | ||
message: undefined, | ||
block_id: 123, | ||
variable_name: 'testVariable', | ||
}; | ||
|
||
isCustomJournalMessage(message, showErrorMessage, centerAndHighlightBlock, pushMessage); | ||
|
||
expect(showErrorMessage).toHaveBeenCalledWith(expect.any(Object)); | ||
}); | ||
|
||
it('should show error message with button when message is not undefined and variable_name is null', () => { | ||
const message = { | ||
message: [['item1']], | ||
block_id: 123, | ||
variable_name: 'null', | ||
}; | ||
|
||
isCustomJournalMessage(message, showErrorMessage, centerAndHighlightBlock, pushMessage); | ||
|
||
expect(pushMessage).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should push "NULL" message when message is null', () => { | ||
const message = { | ||
message: null, | ||
block_id: 123, | ||
variable_name: 'testVariable', | ||
}; | ||
|
||
isCustomJournalMessage(message, showErrorMessage, centerAndHighlightBlock, pushMessage); | ||
|
||
expect(pushMessage).toHaveBeenCalledWith('NULL'); | ||
}); | ||
|
||
it('should show error message with button when message is NaN', () => { | ||
const message = { | ||
message: NaN, | ||
block_id: 123, | ||
variable_name: 'testVariable', | ||
}; | ||
|
||
isCustomJournalMessage(message, showErrorMessage, centerAndHighlightBlock, pushMessage); | ||
|
||
expect(showErrorMessage).toHaveBeenCalledWith(expect.any(Object)); | ||
}); | ||
|
||
it('should push array as message when message is an array', () => { | ||
const message = { | ||
message: [['item1']], | ||
block_id: 123, | ||
variable_name: 'testVariable', | ||
}; | ||
|
||
isCustomJournalMessage(message, showErrorMessage, centerAndHighlightBlock, pushMessage); | ||
|
||
expect(pushMessage).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should push boolean value as message when message is a boolean', () => { | ||
const message = { | ||
message: true, | ||
block_id: 123, | ||
variable_name: 'testVariable', | ||
}; | ||
|
||
isCustomJournalMessage(message, showErrorMessage, centerAndHighlightBlock, pushMessage); | ||
|
||
expect(pushMessage).toHaveBeenCalledWith('true'); | ||
}); | ||
|
||
it('should return false when message type is not recognized', () => { | ||
const message = { | ||
message: 123, | ||
block_id: 123, | ||
variable_name: 'testVariable', | ||
}; | ||
|
||
const result = isCustomJournalMessage(message, showErrorMessage, centerAndHighlightBlock, pushMessage); | ||
|
||
expect(result).toBe(false); | ||
}); | ||
}); |