mirror of
https://github.com/Safe-Support-Chat/ocrcc-chatbox
synced 2024-11-23 11:15:01 +00:00
update tests
This commit is contained in:
parent
91bec23c48
commit
dbbe188adc
@ -24,7 +24,13 @@ export const mockInitCrypto = jest.fn()
|
||||
export const mockStartClient = jest.fn(() => {
|
||||
return Promise.resolve('value');
|
||||
});
|
||||
export const mockOnce = jest.fn()
|
||||
export const mockOnce = jest
|
||||
.fn()
|
||||
.mockImplementation((event, callback) => {
|
||||
if (event === 'sync') {
|
||||
callback('PREPARED')
|
||||
}
|
||||
})
|
||||
export const mockStopClient = jest.fn(() => {
|
||||
return Promise.resolve('value');
|
||||
});
|
||||
|
@ -170,7 +170,9 @@ class ChatBox extends React.Component {
|
||||
window.clearInterval(this.state.waitIntervalId) // no more waiting messages
|
||||
}
|
||||
|
||||
this.state.localStorage.clear()
|
||||
if (this.state.localStorage) {
|
||||
this.state.localStorage.clear()
|
||||
}
|
||||
|
||||
if (resetState) {
|
||||
this.setState(this.initialState)
|
||||
|
@ -115,9 +115,7 @@ describe('Chatbox', () => {
|
||||
expect(createClient).toHaveBeenCalled()
|
||||
expect(mockInitCrypto).toHaveBeenCalled()
|
||||
expect(mockStartClient).toHaveBeenCalled()
|
||||
expect(mockCreateRoom).toHaveBeenCalled()
|
||||
expect(mockSetPowerLevel).toHaveBeenCalled()
|
||||
expect(mockOn).toHaveBeenCalled()
|
||||
expect(mockOnce).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
test('rejecting terms should not start chat', async () => {
|
||||
@ -146,6 +144,10 @@ describe('Chatbox', () => {
|
||||
|
||||
acceptButton.simulate('click')
|
||||
|
||||
await waitForExpect(() => {
|
||||
expect(mockOnce).toHaveBeenCalled()
|
||||
});
|
||||
|
||||
await waitForExpect(() => {
|
||||
expect(mockCreateRoom).toHaveBeenCalled()
|
||||
});
|
||||
@ -169,7 +171,7 @@ describe('Chatbox', () => {
|
||||
})
|
||||
|
||||
|
||||
test('decryption failure should lead to a new unencrypted chat', async () => {
|
||||
test('decryption failure should handle the message event and save the event ID in state', async () => {
|
||||
const chatbox = mount(<Chatbox {...testConfig} />)
|
||||
const dock = chatbox.find('button.dock')
|
||||
const instance = chatbox.instance()
|
||||
@ -183,25 +185,25 @@ describe('Chatbox', () => {
|
||||
acceptButton.simulate('click')
|
||||
|
||||
await waitForExpect(() => {
|
||||
expect(mockCreateRoom).toHaveBeenCalled()
|
||||
expect(mockOnce).toHaveBeenCalled()
|
||||
});
|
||||
|
||||
jest.spyOn(instance, 'initializeUnencryptedChat')
|
||||
instance.handleDecryptionError()
|
||||
jest.spyOn(instance, 'handleMessageEvent')
|
||||
|
||||
instance.handleDecryptionError({
|
||||
getId: () => 'test_event_id',
|
||||
getType: () => 'm.message',
|
||||
getSender: () => 'sender',
|
||||
getRoomId: () => 'room id',
|
||||
getContent: () => ({ body: 'test msg' }),
|
||||
getTs: () => '123',
|
||||
})
|
||||
|
||||
await waitForExpect(() => {
|
||||
expect(mockLeave).toHaveBeenCalled()
|
||||
});
|
||||
expect(instance.handleMessageEvent).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
await waitForExpect(() => {
|
||||
expect(mockStopClient).toHaveBeenCalled()
|
||||
});
|
||||
|
||||
await waitForExpect(() => {
|
||||
expect(mockClearStores).toHaveBeenCalled()
|
||||
});
|
||||
|
||||
expect(instance.initializeUnencryptedChat).toHaveBeenCalled()
|
||||
expect(chatbox.state().decryptionErrors).toEqual({ 'test_event_id': true })
|
||||
})
|
||||
|
||||
test('creating an unencrypted chat', async () => {
|
||||
|
Loading…
Reference in New Issue
Block a user