Skip to content

Commit 4ca3def

Browse files
committed
js stuff
1 parent 68f2cf4 commit 4ca3def

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
sessions: 'admins/sessions'
99
}
1010

11+
# remove these if you do not want the websocket endpoints
1112
get 'websocket', to: 'websocket#index'
1213
match 'connect', to: 'websocket#connect', via: %i[get connect]
1314

spec/browser/websocket_spec.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# frozen_string_literal: true
2+
3+
require 'browser_helper'
4+
5+
RSpec.describe 'Websockets', :js, type: :browser do
6+
let(:admin) { create(:admin) }
7+
8+
it 'can send' do
9+
visit('/websocket')
10+
fill_in 'chat', with: 'awsaws'
11+
sleep(1) if ENV['SLEEP']
12+
find('#chat').native.send_keys(:return)
13+
sleep(1) if ENV['SLEEP']
14+
expect(page.body).to match 'awsaws'
15+
sleep(1) if ENV['SLEEP']
16+
end
17+
18+
it 'sends in one tab and receives in another' do
19+
cur_window = current_window
20+
visit('/websocket')
21+
sleep(1) if ENV['SLEEP']
22+
23+
new_window = open_new_window
24+
switch_to_window(new_window)
25+
visit('/websocket')
26+
sleep(1) if ENV['SLEEP']
27+
28+
fill_in 'chat', with: 'foo'
29+
find('#chat').native.send_keys(:return)
30+
sleep(1) if ENV['SLEEP']
31+
32+
switch_to_window(cur_window)
33+
sleep(1) if ENV['SLEEP']
34+
expect(page.body).to match 'foo'
35+
fill_in 'chat', with: 'bar'
36+
find('#chat').native.send_keys(:return)
37+
sleep(1) if ENV['SLEEP']
38+
39+
switch_to_window(new_window)
40+
sleep(1) if ENV['SLEEP']
41+
expect(page.body).to match 'bar'
42+
sleep(1) if ENV['SLEEP']
43+
end
44+
end

0 commit comments

Comments
 (0)