summaryrefslogtreecommitdiffstats
path: root/api/user_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'api/user_test.go')
-rw-r--r--api/user_test.go82
1 files changed, 82 insertions, 0 deletions
diff --git a/api/user_test.go b/api/user_test.go
index 7dabc8e9b..12390135e 100644
--- a/api/user_test.go
+++ b/api/user_test.go
@@ -1719,3 +1719,85 @@ func TestCheckMfa(t *testing.T) {
// need to add more test cases when enterprise bits can be loaded into tests
}
+
+func TestUserTyping(t *testing.T) {
+ th := Setup().InitBasic()
+ Client := th.BasicClient
+ WebSocketClient, err := th.CreateWebSocketClient()
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer WebSocketClient.Close()
+ WebSocketClient.Listen()
+
+ WebSocketClient.UserTyping("", "")
+ time.Sleep(300 * time.Millisecond)
+ if resp := <-WebSocketClient.ResponseChannel; resp.Error.Id != "api.websocket_handler.invalid_param.app_error" {
+ t.Fatal("should have been invalid param response")
+ }
+
+ th.LoginBasic2()
+ Client.Must(Client.JoinChannel(th.BasicChannel.Id))
+
+ WebSocketClient2, err2 := th.CreateWebSocketClient()
+ if err2 != nil {
+ t.Fatal(err2)
+ }
+ defer WebSocketClient2.Close()
+ WebSocketClient2.Listen()
+
+ WebSocketClient.UserTyping(th.BasicChannel.Id, "")
+
+ time.Sleep(300 * time.Millisecond)
+
+ stop := make(chan bool)
+ eventHit := false
+
+ go func() {
+ for {
+ select {
+ case resp := <-WebSocketClient2.EventChannel:
+ if resp.Event == model.WEBSOCKET_EVENT_TYPING && resp.UserId == th.BasicUser.Id {
+ eventHit = true
+ }
+ case <-stop:
+ return
+ }
+ }
+ }()
+
+ time.Sleep(300 * time.Millisecond)
+
+ stop <- true
+
+ if !eventHit {
+ t.Fatal("did not receive typing event")
+ }
+
+ WebSocketClient.UserTyping(th.BasicChannel.Id, "someparentid")
+
+ time.Sleep(300 * time.Millisecond)
+
+ eventHit = false
+
+ go func() {
+ for {
+ select {
+ case resp := <-WebSocketClient2.EventChannel:
+ if resp.Event == model.WEBSOCKET_EVENT_TYPING && resp.Data["parent_id"] == "someparentid" {
+ eventHit = true
+ }
+ case <-stop:
+ return
+ }
+ }
+ }()
+
+ time.Sleep(300 * time.Millisecond)
+
+ stop <- true
+
+ if !eventHit {
+ t.Fatal("did not receive typing event")
+ }
+}