|
| 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