Merged in VRFS-5181_latency_in_musician_hover_bubble (pull request #28)
VRFS-5181 show latency score badge on musician hover Approved-by: Seth Call
This commit is contained in:
commit
4a296825e3
|
|
@ -22,3 +22,4 @@ artifacts
|
|||
BUILD_NUMBER
|
||||
# Gemfile.lock
|
||||
Gemfile.alt.lock
|
||||
.byebug_history
|
||||
|
|
|
|||
|
|
@ -22,3 +22,4 @@ vendor
|
|||
*~
|
||||
*.swp
|
||||
*.iml
|
||||
.byebug_history
|
||||
|
|
|
|||
|
|
@ -42,3 +42,4 @@ public/assets
|
|||
public/uploads
|
||||
/log/*.out
|
||||
BUILD_NUMBER
|
||||
.byebug_history
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
var logger = context.JK.logger;
|
||||
var rest = context.JK.Rest();
|
||||
var hoverSelector = "#musician-hover";
|
||||
var latencyBadgeSelector = '#musician-latency-badge';
|
||||
var $templateLatency = null;
|
||||
var sessionUtils = context.JK.SessionUtils;
|
||||
|
||||
|
|
@ -91,11 +92,11 @@
|
|||
full_score: fullScore
|
||||
});
|
||||
|
||||
var latencyBadge = context._.template(
|
||||
$templateLatency.html(),
|
||||
$.extend(response, sessionUtils.createLatency(response)),
|
||||
{variable: 'data'}
|
||||
);
|
||||
// var latencyBadge = context._.template(
|
||||
// $templateLatency.html(),
|
||||
// $.extend(response, sessionUtils.createLatency(response)),
|
||||
// {variable: 'data'}
|
||||
// );
|
||||
|
||||
var musicianHtml = context.JK.fillTemplate(template, {
|
||||
userId: response.id,
|
||||
|
|
@ -112,7 +113,7 @@
|
|||
session_display: sessionDisplayStyle,
|
||||
join_display: joinDisplayStyle,
|
||||
sessionId: sessionId,
|
||||
latency_badge: latencyBadge,
|
||||
// latency_badge: latencyBadge,
|
||||
//friendAction: response.is_friend ? "removeMusicianFriend" : (response.pending_friend_request ? "" : "sendMusicianFriendRequest"),
|
||||
friendAction: response.is_friend ? "" : (response.pending_friend_request ? "" : "sendMusicianFriendRequest"),
|
||||
followAction: response.is_following ? "removeMusicianFollowing" : "addMusicianFollowing",
|
||||
|
|
@ -130,6 +131,11 @@
|
|||
|
||||
$(hoverSelector).css(css);
|
||||
$(hoverSelector).fadeIn(500);
|
||||
|
||||
bindUserLatencyUpdate(userId);
|
||||
LatencyActions.resolve([userId]);
|
||||
|
||||
bindUserLatencyFail();
|
||||
})
|
||||
.fail(function(xhr) {
|
||||
if(xhr.status >= 500) {
|
||||
|
|
@ -180,8 +186,77 @@
|
|||
|
||||
}
|
||||
|
||||
function bindUserLatencyUpdate(userId){
|
||||
var latency;
|
||||
$(document).one('user_latency_update', function(e, latencyResp){
|
||||
latency = latencyResp['users'][0];
|
||||
//logger.debug("bindUserLatencyUpdate", latency)
|
||||
if(latency != undefined){
|
||||
if(latency['user_id'] === userId){
|
||||
showLatencyBadge(latency)
|
||||
}
|
||||
}else{
|
||||
showUnknownLatencyBadge(userId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function bindUserLatencyFail(){
|
||||
$(document).one('user_latency_fail', function(e, failedUserIds){
|
||||
//logger.debug("bindUserLatencyFail", failedUserIds)
|
||||
if(_.contains(failedUserIds, userId)){
|
||||
showFailedLatencyBadge(userId)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function showLatencyBadge(latency){
|
||||
var latencyData = sessionUtils.changeLatencyDataStructure(latency);
|
||||
$templateLatency = $("#template-account-session-latency");
|
||||
var latencyBadge = context._.template(
|
||||
$templateLatency.html(),
|
||||
$.extend(latencyData, sessionUtils.createLatency(latencyData)),
|
||||
{ variable: 'data' }
|
||||
);
|
||||
$(latencyBadgeSelector).html(latencyBadge)
|
||||
}
|
||||
|
||||
function showFailedLatencyBadge(userId){
|
||||
var failedLatency = {
|
||||
"user_id": userId,
|
||||
"audio_latency": 0,
|
||||
"ars": {
|
||||
"internet_latency": 0,
|
||||
"total_latency": -3.0
|
||||
}
|
||||
};
|
||||
showLatencyBadge(failedLatency);
|
||||
}
|
||||
|
||||
function showUnknownLatencyBadge(userId){
|
||||
var unknownLatency = {
|
||||
"user_id": userId,
|
||||
"audio_latency": 0,
|
||||
"ars": {
|
||||
"internet_latency": 0,
|
||||
"total_latency": -2
|
||||
}
|
||||
};
|
||||
showLatencyBadge(unknownLatency);
|
||||
}
|
||||
|
||||
function unbindUserLatencyUpdate(){
|
||||
$(document).off('user_latency_update');
|
||||
}
|
||||
|
||||
function unbindUserLatencyFail(){
|
||||
$(document).off('user_latency_fail');
|
||||
}
|
||||
|
||||
this.hideBubble = function() {
|
||||
$(hoverSelector).hide();
|
||||
unbindUserLatencyUpdate();
|
||||
unbindUserLatencyFail();
|
||||
$(hoverSelector).hide();
|
||||
};
|
||||
|
||||
this.id = function() {
|
||||
|
|
|
|||
|
|
@ -1773,6 +1773,17 @@
|
|||
});
|
||||
}
|
||||
|
||||
function getLatencyToUsers(options) {
|
||||
var id = getId(options);
|
||||
return $.ajax({
|
||||
type: "GET",
|
||||
url: '/api/users/' + id + '/latencies',
|
||||
dataType: "json",
|
||||
contentType: 'application/json',
|
||||
data: options
|
||||
});
|
||||
}
|
||||
|
||||
function updateAudioLatency(options) {
|
||||
var id = getId(options);
|
||||
return $.ajax({
|
||||
|
|
@ -3204,6 +3215,7 @@
|
|||
this.cancelSubscription= cancelSubscription;
|
||||
this.listInvoices = listInvoices;
|
||||
this.getVideoConferencingRoomUrl = getVideoConferencingRoomUrl;
|
||||
this.getLatencyToUsers = getLatencyToUsers;
|
||||
return this;
|
||||
};
|
||||
})(window, jQuery);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ SessionsActions = @SessionsActions
|
|||
`<div className="find-session-help">
|
||||
<h3>How This Page Works</h3>
|
||||
<p>This page will show only public jam sessions.</p>
|
||||
<p>Most recent sessions are shown an the top.</p>
|
||||
<p>Most recent sessions are shown at the top.</p>
|
||||
<p>This list of public sessions does not auto-update. You will have to push the REFRESH button to see new sessions.</p>
|
||||
</div>`
|
||||
else if this.props.mode == 'my'
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
context = window
|
||||
|
||||
@LatencyActions = Reflux.createActions({
|
||||
resolve: {}
|
||||
fail: {}
|
||||
})
|
||||
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
$ = jQuery
|
||||
context = window
|
||||
logger = context.JK.logger
|
||||
rest = new context.JK.Rest()
|
||||
|
||||
@LatencyStore = Reflux.createStore(
|
||||
{
|
||||
latencies: []
|
||||
|
||||
listenables: @LatencyActions
|
||||
|
||||
init: ->
|
||||
this.listenTo(context.AppStore, this.onAppInit)
|
||||
|
||||
onAppInit: (@app) ->
|
||||
|
||||
changed: () ->
|
||||
$(document).triggerHandler("user_latency_update", @latencies)
|
||||
@trigger(@latencies)
|
||||
|
||||
onResolve: (user_ids) ->
|
||||
rest.getLatencyToUsers({user_ids: user_ids}).done((response) => @onLoaded(response)).fail((jqXHR) => @onLatencyFail(jqXHR, [user_ids]))
|
||||
|
||||
onLoaded: (response) ->
|
||||
logger.debug("LatencyStore.onLoaded", response);
|
||||
@latencies.push(response)
|
||||
@changed()
|
||||
|
||||
onLatencyFail:(jqXHR, user_ids) ->
|
||||
LatencyActions.fail(user_ids)
|
||||
|
||||
onFail:(user_ids) ->
|
||||
$(document).triggerHandler("user_latency_fail", user_ids)
|
||||
@trigger(user_ids)
|
||||
|
||||
getState:() ->
|
||||
{ latencies: @latencies }
|
||||
}
|
||||
)
|
||||
|
|
@ -18,7 +18,8 @@
|
|||
MEDIUM : {description: "FAIR", style: "latency-fair", min: 40.0, max: 70.0},
|
||||
POOR : {description: "POOR", style: "latency-poor", min: 70.0, max: 100},
|
||||
UNACCEPTABLE: {description: "UNACCEPTABLE", style: "latency-unacceptable", min: 100, max: 10000000},
|
||||
UNKNOWN: {description: "UNKNOWN", style: "latency-unknown", min: -2, max: -2}
|
||||
UNKNOWN: {description: "UNKNOWN", style: "latency-unknown", min: -2, max: -2},
|
||||
FAILED: {description: "FAILED", style: "latency-failed", min: -3, max: -3}
|
||||
};
|
||||
|
||||
sessionUtils.setAutoOpenJamTrack = function(jamTrack) {
|
||||
|
|
@ -78,6 +79,16 @@
|
|||
}
|
||||
}
|
||||
|
||||
sessionUtils.changeLatencyDataStructure = function(data) {
|
||||
var alteredData = {
|
||||
id: data.user_id,
|
||||
audio_latency: data.audio_latency,
|
||||
full_score: data.ars['total_latency'],
|
||||
internet_score: data.ars['internet_latency']
|
||||
}
|
||||
return alteredData;
|
||||
}
|
||||
|
||||
sessionUtils.scoreInfo = function(full_score, isSameUser) {
|
||||
var latencyDescription;
|
||||
var latencyStyle;
|
||||
|
|
@ -90,7 +101,19 @@
|
|||
iconName = 'purple';
|
||||
description = 'me';
|
||||
}
|
||||
else if (!full_score) {
|
||||
else if (full_score <= LATENCY.FAILED.max) {
|
||||
latencyDescription = LATENCY.FAILED.description;
|
||||
latencyStyle = LATENCY.FAILED.style;
|
||||
iconName = 'gray';
|
||||
description = 'failed';
|
||||
}
|
||||
// else if (!full_score) {
|
||||
// latencyDescription = LATENCY.UNKNOWN.description;
|
||||
// latencyStyle = LATENCY.UNKNOWN.style;
|
||||
// iconName = 'purple';
|
||||
// description = 'missing';
|
||||
// }
|
||||
else if (!full_score || full_score <= LATENCY.UNKNOWN.max) {
|
||||
latencyDescription = LATENCY.UNKNOWN.description;
|
||||
latencyStyle = LATENCY.UNKNOWN.style;
|
||||
iconName = 'purple';
|
||||
|
|
@ -114,13 +137,13 @@
|
|||
iconName = 'red';
|
||||
description = 'poor';
|
||||
}
|
||||
else {
|
||||
else if (full_score > LATENCY.UNACCEPTABLE.min) {
|
||||
latencyStyle = LATENCY.UNACCEPTABLE.style;
|
||||
latencyDescription = LATENCY.UNACCEPTABLE.description;
|
||||
iconName = 'blue';
|
||||
description = 'unacceptable';
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
latency_style: latencyStyle,
|
||||
latency_text: latencyDescription,
|
||||
|
|
@ -128,6 +151,7 @@
|
|||
description: description
|
||||
};
|
||||
}
|
||||
|
||||
sessionUtils.createLatency = function(user) {
|
||||
return sessionUtils.scoreInfo(user.full_score, user.id === context.JK.currentUserId)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ $latencyBadgeFair: #cc9900;
|
|||
$latencyBadgePoor: #980006;
|
||||
$latencyBadgeUnacceptable: #868686;
|
||||
$latencyBadgeUnknown: #868686;
|
||||
$latencyBadgeFailed: #868686;
|
||||
|
||||
$good: #71a43b;
|
||||
$unknown: #868686;
|
||||
|
|
|
|||
|
|
@ -120,4 +120,8 @@
|
|||
.latency-poor {
|
||||
background-color:$latencyBadgePoor;
|
||||
}
|
||||
|
||||
.latency-failed {
|
||||
background-color:$latencyBadgeFailed;
|
||||
}
|
||||
}
|
||||
|
|
@ -129,6 +129,10 @@
|
|||
background-color:$latencyBadgePoor;
|
||||
}
|
||||
|
||||
.latency-failed {
|
||||
background-color:$latencyBadgeFailed;
|
||||
}
|
||||
|
||||
/**
|
||||
.latency {
|
||||
font-size: 15px;
|
||||
|
|
|
|||
|
|
@ -63,6 +63,16 @@ table.findsession-table, table.local-recordings, table.open-jam-tracks, table.op
|
|||
background-color:$latencyBadgePoor;
|
||||
text-align:center;
|
||||
}
|
||||
|
||||
.latency-failed{
|
||||
width: 40px;
|
||||
height: 10px;
|
||||
font-family:Arial, Helvetica, sans-serif;
|
||||
font-weight:200;
|
||||
font-size:11px;
|
||||
background-color:$latencyBadgeFailed;
|
||||
text-align:center;
|
||||
}
|
||||
}
|
||||
table.findsession-table, table.local-recordings, table.open-jam-tracks, table.open-backing-tracks, table.cart-items, table.payment-table, table.jamtable {
|
||||
width:98%;
|
||||
|
|
|
|||
|
|
@ -43,6 +43,10 @@ body.web.session_info {
|
|||
background-color:$latencyBadgePoor;
|
||||
}
|
||||
|
||||
.latency-failed {
|
||||
background-color:$latencyBadgeFailed;
|
||||
}
|
||||
|
||||
.latency-me {
|
||||
width: 40px;
|
||||
height: 10px;
|
||||
|
|
|
|||
|
|
@ -937,33 +937,56 @@ class ApiUsersController < ApiController
|
|||
|
||||
#fetch latency information from latency-graph serverless
|
||||
def get_latencies
|
||||
query_str = params[:user_ids].split(',').inject(""){|q, id| q.concat("id=#{id}&")}
|
||||
latency_url = "#{Rails.application.config.latency_data_host}/dev/user_latencies/#{current_user.id}?#{query_str}"
|
||||
url = URI(latency_url)
|
||||
user_ids = params[:user_ids]
|
||||
latency_url = "#{Rails.application.config.latency_data_host}/user_latencies"
|
||||
uri = URI(latency_url)
|
||||
begin
|
||||
http = Net::HTTP.new(url.host, url.port)
|
||||
http = Net::HTTP.new(uri.host, uri.port)
|
||||
http.use_ssl = true if Rails.application.config.latency_data_host.start_with?("https://")
|
||||
request = Net::HTTP::Get.new(url)
|
||||
request["Authorization"] = "Basic #{Rails.application.config.latency_data_host_auth_code}"
|
||||
response = http.request(request)
|
||||
req = Net::HTTP::Post.new(uri)
|
||||
req["Authorization"] = "Basic #{Rails.application.config.latency_data_host_auth_code}"
|
||||
req["Content-Type"] = "application/json"
|
||||
req.body = {
|
||||
my_user_id: current_user.id,
|
||||
my_public_ip: request.remote_ip,
|
||||
my_device_id: nil,
|
||||
my_client_id: nil,
|
||||
users: user_ids
|
||||
}.to_json
|
||||
|
||||
response = http.request(req)
|
||||
#debugger
|
||||
|
||||
if response.is_a?(Net::HTTPOK) || response.is_a?(Net::HTTPSuccess)
|
||||
render json: response.body, status: 200
|
||||
else
|
||||
Bugsnag.notify(exception) do |report|
|
||||
report.severity = "error"
|
||||
logger.debug("Latency response failed: #{response}")
|
||||
Bugsnag.notify("LatencyResponseFailed") do |report|
|
||||
report.severity = "faliure"
|
||||
report.add_tab(:latency, {
|
||||
user_id: current_user.id,
|
||||
name: current_user.name,
|
||||
user_ids: params[:user_ids],
|
||||
url: latency_url,
|
||||
body: response.body
|
||||
code: response.code,
|
||||
body: response.body,
|
||||
})
|
||||
end
|
||||
render json: {}, status: 422
|
||||
render json: { user_ids: params[:user_ids] }, status: 422
|
||||
end
|
||||
rescue
|
||||
Bugsnag.notify("Latency server returned code: #{response.code}")
|
||||
render json: {}, status: 500
|
||||
rescue => exception
|
||||
#debugger
|
||||
logger.debug("Latency exception: #{exception.message}")
|
||||
Bugsnag.notify(exception) do |report|
|
||||
report.severity = "error"
|
||||
report.add_tab(:latency, {
|
||||
user_id: current_user.id,
|
||||
name: current_user.name,
|
||||
user_ids: params[:user_ids],
|
||||
url: latency_url,
|
||||
})
|
||||
end
|
||||
render json: { user_ids: params[:user_ids] }, status: 500
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -117,7 +117,8 @@
|
|||
<br />
|
||||
<div class="f11">{biography}</div><br />
|
||||
<div class="left f11 musician-latency">
|
||||
Your latency to {first_name} is: {latency_badge}
|
||||
Your latency to {first_name} is:
|
||||
<span id="musician-latency-badge"></span>
|
||||
</div>
|
||||
<br clear="both"/>
|
||||
<br clear="both"/>
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ tests=(
|
|||
"spec/features/affiliate_program_spec.rb"
|
||||
"spec/features/affiliate_visit_tracking_spec.rb"
|
||||
"spec/features/affiliate_referral_spec.rb"
|
||||
"spec/features/musician_hover_spec_1.rb"
|
||||
"spec/features/musician_hover_spec_2.rb"
|
||||
"spec/controllers/api_affiliate_controller_spec.rb"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -114,6 +114,6 @@ SampleApp::Application.configure do
|
|||
|
||||
config.video_conferencing_host = "https://webrtc-demo.jamkazam.com"
|
||||
config.use_video_conferencing_server = true
|
||||
config.latency_data_host = "http://localhost:4001"
|
||||
config.latency_data_host = "http://localhost:4001/dev"
|
||||
config.latency_data_host_auth_code = "c2VydmVyOnBhc3N3b3Jk"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ SampleApp::Application.configure do
|
|||
|
||||
config.video_conferencing_host = "https://webrtc-demo.jamkazam.com"
|
||||
config.use_video_conferencing_server = false
|
||||
config.latency_data_host = "http://localhost:4001"
|
||||
config.latency_data_host = "http://localhost:4001/test"
|
||||
config.latency_data_host_auth_code = "c2VydmVyOnBhc3N3b3Jk"
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -314,12 +314,13 @@ describe ApiUsersController, type: :controller do
|
|||
describe "get_latencies" do
|
||||
let(:user1) { FactoryGirl.create(:user) }
|
||||
let(:user2) { FactoryGirl.create(:user) }
|
||||
let(:latency_data_uri) { /\/dev\/user_latencies\// }
|
||||
let(:response_body) { File.open('./spec/fixtures/latency_reponse.json') }
|
||||
let(:latency_data_uri) { /\S+\/dev\/user_latencies/ }
|
||||
let(:response_body) { File.open('./spec/fixtures/latency_response.json') }
|
||||
|
||||
it "fetch latency graph data" do
|
||||
stub_request(:get, latency_data_uri)
|
||||
stub_request(:post, latency_data_uri)
|
||||
.to_return( body: response_body, status: 200)
|
||||
|
||||
get :get_latencies, id: user.id, user_ids: [user1, user2].map(&:id).join(',')
|
||||
response.should be_success
|
||||
JSON.parse(response.body)['users'].size.should eq(2)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,75 @@
|
|||
require 'spec_helper'
|
||||
require 'webmock/rspec'
|
||||
|
||||
#NOTE: The rest of the tests related to musician latency badge are in
|
||||
#musician_hover_spec_2.rb file. For some uncertain issue getting all these
|
||||
#tests in a single file doesn't work because some of them fail without a reason.
|
||||
#Probably because of webmock behaving wiredly.
|
||||
|
||||
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 do
|
||||
Capybara.default_max_wait_time = 30 # these tests are SLOOOOOW
|
||||
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 ME (same user)" do
|
||||
response_body = mock_latency_response(user1, 1.0) #sessionUtils.LATENCY.UNKNOWN: {description: "UNKNOWN", style: "latency-unknown", min: -2, max: -2}
|
||||
stub_request(:post, latency_data_uri)
|
||||
.with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'})
|
||||
.to_return( body: response_body, status: 200)
|
||||
|
||||
site_search(user1.first_name, expand: true)
|
||||
find("#search-results a[user-id=\"#{user1.id}\"][hoveraction=\"musician\"]", text: user1.name).hover_intent
|
||||
find('h3', text: user1.name)
|
||||
find("#musician-latency-badge div.latency", text: 'ME')
|
||||
end
|
||||
|
||||
it "show FAILED" do
|
||||
stub_request(:post, latency_data_uri)
|
||||
.with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'})
|
||||
.to_raise("some error")
|
||||
|
||||
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", text: 'FAILED')
|
||||
end
|
||||
|
||||
it "show UNKNOWN" do
|
||||
response_body = mock_latency_response(user2, nil) #sessionUtils.LATENCY.UNKNOWN: {description: "UNKNOWN", style: "latency-unknown", min: -2, max: -2}
|
||||
stub_request(:post, latency_data_uri)
|
||||
.with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'})
|
||||
.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: 'UNKNOWN')
|
||||
end
|
||||
|
||||
it "show GOOD" do
|
||||
response_body = mock_latency_response(user2, 1.0) #sessionUtils.LATENCY.GOOD : {description: "GOOD", style: "latency-good", min: 0.0, max: 40.0},
|
||||
stub_request(:post, latency_data_uri)
|
||||
.with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'})
|
||||
.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
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
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 do
|
||||
Capybara.default_max_wait_time = 30 # these tests are SLOOOOOW
|
||||
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 POOR" do
|
||||
response_body = mock_latency_response(user2, 71.0) #sessionUtils.LATENCY.POOR : {description: "POOR", style: "latency-poor", min: 70.0, max: 100},
|
||||
stub_request(:post, latency_data_uri)
|
||||
.with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'})
|
||||
.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: 'POOR')
|
||||
end
|
||||
|
||||
it "show FAIR" do
|
||||
response_body = mock_latency_response(user2, 41.0) #sessionUtils.LATENCY.FAIR : {description: "FAIR", style: "latency-fair", min: 40.0, max: 70.0},
|
||||
stub_request(:post, latency_data_uri)
|
||||
.with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'})
|
||||
.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: 'FAIR')
|
||||
end
|
||||
|
||||
it "show UNACCEPTABLE", focus: true do
|
||||
response_body = mock_latency_response(user2, 101.0) #sessionUtils.LATENCY.UNACCEPTABLE : {description: "UNACCEPTABLE", style: "latency-unacceptable", min: 100.0, max: 10000000},
|
||||
stub_request(:post, latency_data_uri)
|
||||
.with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'})
|
||||
.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: 'UNACCEPTABLE')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -795,4 +795,37 @@ end
|
|||
def nav_profile_history(user)
|
||||
visit Nav.profile(user)
|
||||
find('#history-link').trigger(:click)
|
||||
end
|
||||
|
||||
def mock_latency_response(user, latency)
|
||||
resp = nil
|
||||
if latency
|
||||
resp = {
|
||||
"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
|
||||
}
|
||||
else
|
||||
resp = {
|
||||
"users": []
|
||||
}
|
||||
end
|
||||
return resp.to_json
|
||||
end
|
||||
|
|
@ -25,3 +25,4 @@ log/*
|
|||
target
|
||||
vendor
|
||||
BUILD_NUMBER
|
||||
.byebug_history
|
||||
|
|
|
|||
|
|
@ -578,6 +578,7 @@ DEPENDENCIES
|
|||
newrelic_rpm
|
||||
nokogiri (= 1.10.10)
|
||||
oj (= 3.1.3)
|
||||
pg (= 0.17.1)
|
||||
postgres-copy
|
||||
postgres_ext
|
||||
protected_attributes
|
||||
|
|
|
|||
Loading…
Reference in New Issue