-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from amazon-connect/add-typing-throttle
throttle typing event
- Loading branch information
Showing
6 changed files
with
90 additions
and
17 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -58,7 +58,8 @@ | |
"json", | ||
"html", | ||
"cobertura", | ||
"lcov" | ||
"lcov", | ||
"text" | ||
] | ||
}, | ||
"author": "Amazon Web Services", | ||
|
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,54 @@ | ||
import { ChatClientFactory } from "./client"; | ||
import { CONTENT_TYPE } from "../constants"; | ||
import { jest } from "@jest/globals"; | ||
|
||
describe("client test cases", () => { | ||
describe("event throttling test cases", () => { | ||
const options = {}; | ||
const logMetaData = {}; | ||
const connectionToken = "connectionToken"; | ||
const content = "content"; | ||
|
||
var chatClient = ChatClientFactory.getCachedClient(options, logMetaData); | ||
|
||
beforeEach(() => { | ||
jest.spyOn(chatClient, "_submitEvent").mockImplementation(() => {}); | ||
jest.useFakeTimers(); | ||
jest.clearAllTimers(); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test("typing event should be throttled if content type is typing", () => { | ||
let count = 0; | ||
let typingInterval = setInterval(() => { | ||
if (count > 8) { | ||
clearInterval(typingInterval); | ||
} | ||
count++; | ||
chatClient.sendEvent(connectionToken, CONTENT_TYPE.typing, content); | ||
}, 100); | ||
jest.advanceTimersByTime(900); | ||
expect(chatClient._submitEvent).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test("Other events should not be throttled", () => { | ||
for (let key in CONTENT_TYPE) { | ||
jest.clearAllTimers(); | ||
jest.clearAllMocks(); | ||
if (key === "typing") { | ||
continue; | ||
} | ||
let count = 0; | ||
let typingInterval = setInterval(() => { | ||
if (count > 8) { | ||
clearInterval(typingInterval); | ||
} | ||
count++; | ||
chatClient.sendEvent(connectionToken, CONTENT_TYPE[key], content); | ||
}, 100); | ||
jest.advanceTimersByTime(900); | ||
expect(chatClient._submitEvent).toHaveBeenCalledTimes(9); | ||
} | ||
}); | ||
}); | ||
}); |
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