From 4f9ffa6a808ee294c7cd3eaa1c5ba046b2d21442 Mon Sep 17 00:00:00 2001 From: Nuwan Date: Sun, 30 May 2021 07:14:54 +0530 Subject: [PATCH] testing hover latency badge --- web/spec/features/musician_hover_spec.rb | 186 ++++++++++++----------- 1 file changed, 98 insertions(+), 88 deletions(-) diff --git a/web/spec/features/musician_hover_spec.rb b/web/spec/features/musician_hover_spec.rb index 551d4ed1b..22537431f 100644 --- a/web/spec/features/musician_hover_spec.rb +++ b/web/spec/features/musician_hover_spec.rb @@ -7,23 +7,25 @@ describe "Musician Hover", :js => true, :type => :feature, :capybara_feature => let(:latency_data_uri) { /\S+\/dev\/user_latencies/ } - before(:all) do - Capybara.current_driver = :jamkazam + before do + #Capybara.current_driver = :jamkazam WebMock.disable_net_connect!(allow_localhost: true) end - after(:all) do - Capybara.use_default_driver + after do + #Capybara.use_default_driver end before(:each) do fast_signin(user1, "/client") wait_until_curtain_gone + #sleep(1) end + describe "Latency badge" do - it "show FAILED" do + xit "show FAILED", focus: true 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) @@ -32,89 +34,97 @@ describe "Musician Hover", :js => true, :type => :feature, :capybara_feature => 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') + sleep(1) end - end - - it "show GOOD" do - response_body = latency_response(user2, 0.0) #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 - - it "show MEDIUM" do - response_body = latency_response(user2, 41) #MEDIUM : {description: "FAIR", style: "latency-fair", min: 40.0, max: 70.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: 'MEDIUM') - end - - - it "show POOR" do - response_body = latency_response(user2, 71) #POOR : {description: "POOR", style: "latency-poor", min: 70.0, max: 100}, - 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: 'POOR') - end - - it "show UNACCEPTABLE" do - response_body = latency_response(user2, 101) #UNACCEPTABLE : {description: "UNACCEPTABLE", style: "latency-unacceptable", min: 100.0, max: 10000000}, - 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: 'UNACCEPTABLE') - end - - it "show UNKNOWN" do - response_body = latency_response(user2, -2) #UNKNOWN: {description: "UNKNOWN", style: "latency-unknown", min: -2, max: -2} - 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: 'UNKNOWN') - 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 + it "show POOR", focus: true do + response_body = latency_response(user2, 71.0) #sessionUtils.LATENCY.POOR : {description: "POOR", style: "latency-poor", min: 70.0, max: 100}, + 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: 'POOR') + sleep(1) + end + + it "show GOOD", focus: true do + response_body = 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) + .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') + sleep(1) + end + + it "show FAIR", focus: true do + response_body = 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) + .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') + sleep(1) + end + + + it "show UNACCEPTABLE", focus: true do + response_body = latency_response(user2, 101.0) #sessionUtils.LATENCY.UNACCEPTABLE : {description: "UNACCEPTABLE", style: "latency-unacceptable", min: 100.0, max: 10000000}, + 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: 'UNACCEPTABLE') + sleep(1) + end + + it "show UNKNOWN", focus: true do + response_body = latency_response(user2, nil) #sessionUtils.LATENCY.UNKNOWN: {description: "UNKNOWN", style: "latency-unknown", min: -2, max: -2} + 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: 'UNKNOWN') + sleep(1) + end + + def latency_response(user, 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 + } + #resp[:users][0][:ars][:total_latency] = latency unless latency.nil? + resp.to_json + end + + end + +end