forked from zulip/zulip-mobile
-
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.
queueMarkAsRead, test: Check messageFlags is not called in less than 2s.
- Loading branch information
1 parent
de731dd
commit 529f982
Showing
3 changed files
with
53 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
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,40 @@ | ||
/* @flow strict-local */ | ||
import queueMarkAsRead, { resetAll } from '../queueMarkAsRead'; | ||
import * as messagesFlags from '../messages/messagesFlags'; | ||
import { eg } from '../../__tests__/exampleData'; | ||
|
||
// $FlowFixMe Make flow understand about mocking | ||
messagesFlags.default = jest.fn(() => {}); | ||
|
||
describe('queueMarkAsRead', () => { | ||
beforeEach(() => { | ||
resetAll(); | ||
jest.clearAllMocks(); | ||
jest.clearAllTimers(); | ||
}); | ||
|
||
test('should not call messagesFlags on consecutive calls of queueMarkAsRead', () => { | ||
queueMarkAsRead(eg.selfAuth, [1, 2, 3]); | ||
queueMarkAsRead(eg.selfAuth, [4, 5, 6]); | ||
queueMarkAsRead(eg.selfAuth, [7, 8, 9]); | ||
queueMarkAsRead(eg.selfAuth, [10, 11, 12]); | ||
|
||
expect(messagesFlags.default).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('should call messagesFlags, if calls to queueMarkAsRead are 2s apart', async () => { | ||
const currentDate = Date.now(); | ||
const secondCall = currentDate + 2100; | ||
// $FlowFixMe Make flow understand about mocking | ||
Date.now = jest.fn().mockReturnValue(currentDate); | ||
|
||
queueMarkAsRead(eg.selfAuth, [13, 14, 15]); | ||
|
||
// $FlowFixMe Make flow understand about mocking | ||
Date.now = jest.fn().mockReturnValue(secondCall); | ||
|
||
queueMarkAsRead(eg.selfAuth, [16, 17, 18]); | ||
|
||
expect(messagesFlags.default).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