-
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.
test(index): adding testing coverage for the current class methods
- Loading branch information
1 parent
59c2a08
commit 9614138
Showing
1 changed file
with
101 additions
and
1 deletion.
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 |
---|---|---|
@@ -1 +1,101 @@ | ||
it.todo('write a test'); | ||
import { NativeModules, Platform } from 'react-native'; | ||
import { Zendesk } from '../index'; | ||
import type { StartChatOptions, ZendeskConfig } from '../ZendeskUnified.types'; | ||
|
||
jest.mock('react-native', () => { | ||
const reactNative = jest.requireActual('react-native'); | ||
|
||
reactNative.NativeModules.ZendeskUnified = { | ||
initialize: jest.fn(), | ||
healthCheck: jest.fn(() => Promise.resolve('OK')), | ||
setAnonymousIdentity: jest.fn(() => Promise.resolve(true)), | ||
setIdentity: jest.fn(() => Promise.resolve(true)), | ||
openHelpCenter: jest.fn(() => Promise.resolve()), | ||
openTicket: jest.fn(() => Promise.resolve()), | ||
openNewTicket: jest.fn(() => Promise.resolve()), | ||
listTickets: jest.fn(() => Promise.resolve()), | ||
openArticle: jest.fn(() => Promise.resolve()), | ||
setHelpCenterLocaleOverride: jest.fn(() => Promise.resolve()), | ||
changeTheme: jest.fn(() => Promise.resolve()), | ||
initializeChat: jest.fn(() => Promise.resolve()), | ||
startChat: jest.fn(() => Promise.resolve()), | ||
startAnswerBot: jest.fn(() => Promise.resolve()), | ||
}; | ||
|
||
return reactNative; | ||
}); | ||
|
||
const ZendeskUnified = NativeModules.ZendeskUnified; | ||
|
||
describe('Zendesk class', () => { | ||
const zendeskConfig: ZendeskConfig = { | ||
appId: 'appId', | ||
clientId: 'clientId', | ||
zendeskUrl: 'zendeskUrl', | ||
accountKey: 'accountKey', | ||
}; | ||
|
||
const zendesk = new Zendesk(zendeskConfig); | ||
|
||
it('should initialize ZendeskUnified with the provided config', () => { | ||
expect(zendesk).toBeDefined(); | ||
expect(zendesk instanceof Zendesk).toBe(true); | ||
expect(ZendeskUnified.initialize).toHaveBeenCalledWith(zendeskConfig); | ||
}); | ||
|
||
it('should perform health check', async () => { | ||
const result = await zendesk.healthCheck(); | ||
expect(result).toEqual('OK'); | ||
}); | ||
|
||
it('should set anonymous identity', async () => { | ||
const options = {}; | ||
const result = await zendesk.setAnonymousIdentity(options); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should set identity', async () => { | ||
const jwt = 'mock-jwt'; | ||
const result = await zendesk.setIdentity(jwt); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should open an article', async () => { | ||
const articleId = 123; | ||
await zendesk.openArticle(articleId); | ||
expect(ZendeskUnified.openArticle).toHaveBeenCalledWith( | ||
Platform.OS === 'ios' ? articleId.toString() : articleId | ||
); | ||
}); | ||
|
||
it('should set Help Center locale override', async () => { | ||
const locale = 'en_US'; | ||
await zendesk.setHelpCenterLocaleOverride(locale); | ||
expect(ZendeskUnified.setHelpCenterLocaleOverride).toHaveBeenCalledWith( | ||
locale | ||
); | ||
}); | ||
|
||
it('should change theme', async () => { | ||
const color = 'blue'; | ||
await zendesk.changeTheme(color); | ||
expect(ZendeskUnified.changeTheme).toHaveBeenCalledWith(color); | ||
}); | ||
|
||
it('should initialize chat', async () => { | ||
const accountKey = 'chat-account-key'; | ||
await zendesk.initializeChat(accountKey); | ||
expect(ZendeskUnified.initializeChat).toHaveBeenCalledWith(accountKey); | ||
}); | ||
|
||
it('should start chat', async () => { | ||
const options: StartChatOptions = { botName: 'bot-name' }; | ||
await zendesk.startChat(options); | ||
expect(ZendeskUnified.startChat).toHaveBeenCalledWith(options); | ||
}); | ||
|
||
it('should start Answer Bot', async () => { | ||
await zendesk.startAnswerBot(); | ||
expect(ZendeskUnified.startAnswerBot).toHaveBeenCalled(); | ||
}); | ||
}); |