require 'spec_helper' require 'webmock/rspec' describe "Musician Hover", :js => true, :type => :feature, :capybara_feature => true do let(:user1) { FactoryGirl.create(:user) } let(:user2) { FactoryGirl.create(:user) } let(:latency_data_uri) { /\S+\/dev\/user_latencies/ } before(:all) do WebMock.disable_net_connect!(allow_localhost: true) end before(:each) do fast_signin(user1, "/client") wait_until_curtain_gone end describe "Latency badge" do it "show FAILED" do response_body = latency_response(user2, -3) #sessionUtils.LATENCY.FAILED: {description: "FAILED", style: "latency-failed", min: -3, max: -3} stub_request(:post, latency_data_uri) .to_return( body: response_body, status: 200) site_search(user2.first_name, expand: true) find("#search-results a[user-id=\"#{user2.id}\"][hoveraction=\"musician\"]", text: user2.name).hover_intent find('h3', text: user2.name) find("#musician-latency-badge div.latency", text: 'FAILED') end end it "show GOOD" do response_body = latency_response(user2, 40) #sessionUtils.LATENCY.GOOD : {description: "GOOD", style: "latency-good", min: 0.0, max: 40.0}, stub_request(:post, latency_data_uri) .to_return( body: response_body, status: 200) site_search(user2.first_name, expand: true) find("#search-results a[user-id=\"#{user2.id}\"][hoveraction=\"musician\"]", text: user2.name).hover_intent find('h3', text: user2.name) find("#musician-latency-badge div.latency", text: 'GOOD') end def latency_response(user, latency) { "users": [ { "user_id": user.id, "first_name": user.first_name, "last_name": user.last_name, "audio_latency": 4.0, "audio_latency_unknown": false, "ars": { "internet_latency": latency, "total_latency": latency }, "p2p": { "internet_latency": latency, "total_latency": latency }, "wifi": false } ], "my_audio_latency": 4.0, "my_audio_latency_unknown": false }.to_json end end