From 20fd4c598796d434aa4328518621a6d6e25952f3 Mon Sep 17 00:00:00 2001 From: Nicole Kennedy Date: Wed, 19 Jun 2019 13:14:13 -0400 Subject: [PATCH] progress bar --- lib/app/endpoint/home.rb | 1 + lib/app/endpoint/oauth2_endpoints.rb | 25 ++++++++++++-------- lib/app/endpoint/test_set_endpoints.rb | 2 ++ lib/app/helpers/browser_logic.rb | 13 +++++++++-- lib/app/models/sequence_result.rb | 2 ++ lib/app/models/testing_instance.rb | 6 +++++ lib/app/views/default.erb | 5 ++-- lib/app/views/guided.erb | 5 ++-- public/css/styles.css | 32 ++++++++++++++++++++++---- 9 files changed, 70 insertions(+), 21 deletions(-) diff --git a/lib/app/endpoint/home.rb b/lib/app/endpoint/home.rb index 3dd157a3f..6be121db3 100644 --- a/lib/app/endpoint/home.rb +++ b/lib/app/endpoint/home.rb @@ -10,6 +10,7 @@ class Endpoint # Home serves the main web application. class Home < Endpoint helpers Sinatra::Cookies + # Set the url prefix these routes will map to set :prefix, "/#{base_path}" diff --git a/lib/app/endpoint/oauth2_endpoints.rb b/lib/app/endpoint/oauth2_endpoints.rb index d251cae1d..b4fc5632e 100644 --- a/lib/app/endpoint/oauth2_endpoints.rb +++ b/lib/app/endpoint/oauth2_endpoints.rb @@ -60,13 +60,14 @@ def resume_execution client = FHIR::Client.for_testing_instance(@instance) sequence = test_case.sequence.new(@instance, client, settings.disable_tls_tests, sequence_result) - first_test_count = sequence.test_count timer_count = 0 stayalive_timer_seconds = 20 finished = false + total_tests = sequence_result.group_run ? test_group.test_cases.map { |test| test.sequence.test_count }.reduce(:+) : sequence.test_count + stream :keep_open do |out| EventMachine::PeriodicTimer.new(stayalive_timer_seconds) do timer_count += 1 @@ -85,19 +86,25 @@ def resume_execution out << js_hide_wait_modal out << js_show_test_modal - count = sequence_result.result_count - submitted_test_cases_count = sequence_result.next_test_cases.split(',') - total_tests = submitted_test_cases_count.reduce(first_test_count) do |total, set| - sequence_test_count = test_set.test_case_by_id(set).sequence.test_count - total + sequence_test_count - end + previous_test_sequence_ids = sequence_result.group_run ? test_group.test_cases.map(&:id)&.split(sequence_result.test_case_id)&.first : [] + previous_test_sequence_ids << sequence_result.test_case_id + previous_test_results = @instance.previous_test_results(previous_test_sequence_ids) + prev_count = previous_test_results.length + count = prev_count sequence_result = sequence.resume(request, headers, request.params, @error_message) do |result| + if count > prev_count + rerun = nil + else + previous_test_results[-1] = result.result + rerun = previous_test_results + end count += 1 - out << js_update_result(sequence, test_set, result, count, sequence.test_count, count, total_tests) + out << js_update_result(sequence, test_set, result, count, sequence.test_count, count, total_tests, rerun) @instance.save! end + all_test_cases << test_case.id failed_test_cases << test_case.id if sequence_result.fail? @instance.sequence_results.push(sequence_result) @@ -119,7 +126,7 @@ def resume_execution # continue processesing any afterwards - test_count = first_test_count + test_count = count until next_test_case.nil? test_case = test_set.test_case_by_id(next_test_case) diff --git a/lib/app/endpoint/test_set_endpoints.rb b/lib/app/endpoint/test_set_endpoints.rb index 05d7d38d4..7646dfb19 100644 --- a/lib/app/endpoint/test_set_endpoints.rb +++ b/lib/app/endpoint/test_set_endpoints.rb @@ -133,6 +133,7 @@ def self.included(klass) sequence_test_count = test_set.test_case_by_id(set).sequence.test_count total + sequence_test_count end + total_test_sequences = submitted_test_cases.count test_group = nil test_group = test_set.test_case_by_id(submitted_test_cases.first).test_group @@ -184,6 +185,7 @@ def self.included(klass) end sequence_result.next_test_cases = ([next_test_case] + submitted_test_cases).join(',') + sequence_result.group_run = total_test_sequences > 1 all_test_cases << test_case.id failed_test_cases << test_case.id if sequence_result.fail? diff --git a/lib/app/helpers/browser_logic.rb b/lib/app/helpers/browser_logic.rb index 053080902..1282190f2 100644 --- a/lib/app/helpers/browser_logic.rb +++ b/lib/app/helpers/browser_logic.rb @@ -16,7 +16,7 @@ def js_stayalive(time) "" end - def js_update_result(sequence, _test_set, _result, set_count, set_total, count, total) + def js_update_result(sequence, _test_set, result, set_count, set_total, count, total, rerun = nil) cancel_button = if sequence.sequence_result "Cancel Sequence" @@ -24,13 +24,22 @@ def js_update_result(sequence, _test_set, _result, set_count, set_total, count, '' end + width = (1.0 / total) * 100 + rerun_html = '' + if rerun.present? + rerun.each { |run| rerun_html += "
" } + end + result_html = "
" + %( ) end diff --git a/lib/app/models/sequence_result.rb b/lib/app/models/sequence_result.rb index 2e9dc88e0..b5515aff7 100644 --- a/lib/app/models/sequence_result.rb +++ b/lib/app/models/sequence_result.rb @@ -35,6 +35,8 @@ class SequenceResult property :created_at, DateTime, default: proc { DateTime.now } + property :group_run, Boolean + has n, :test_results, order: [:test_index.asc] belongs_to :testing_instance diff --git a/lib/app/models/testing_instance.rb b/lib/app/models/testing_instance.rb index e91bb7e93..d88b03151 100644 --- a/lib/app/models/testing_instance.rb +++ b/lib/app/models/testing_instance.rb @@ -58,6 +58,12 @@ class TestingInstance has n, :supported_resources, order: [:index.asc] has n, :resource_references + def previous_test_results(previous_sequence_ids) + previous_test_cases = previous_sequence_ids.map { |sequence_id| latest_results_by_case[sequence_id.to_s] } + previous_test_results = previous_test_cases.map { |test_case| test_case&.test_results&.map(&:result) } + previous_test_results.flatten + end + def latest_results sequence_results.each_with_object({}) do |result, hash| hash[result.name] = result if hash[result.name].nil? || hash[result.name].created_at < result.created_at diff --git a/lib/app/views/default.erb b/lib/app/views/default.erb index be834ea43..aae6ea392 100644 --- a/lib/app/views/default.erb +++ b/lib/app/views/default.erb @@ -381,9 +381,8 @@ diff --git a/lib/app/views/guided.erb b/lib/app/views/guided.erb index 1ab37188a..1536b7ad9 100644 --- a/lib/app/views/guided.erb +++ b/lib/app/views/guided.erb @@ -549,9 +549,8 @@ diff --git a/public/css/styles.css b/public/css/styles.css index b7538e2fc..c2c6d3502 100644 --- a/public/css/styles.css +++ b/public/css/styles.css @@ -249,10 +249,6 @@ body { } -.progress .progress-bar.active { - background-color: #f98718; -} - #PrerequisitesModal label { margin-bottom: .1rem; text-transform: uppercase; @@ -1173,6 +1169,34 @@ body { /* background-image: url("../images/guided-background.png"); */ } +#progress-bar .progress-bar-pass { + background-color: #28a745; +} + +#progress-bar .progress-bar-fail { + background-color: #cb2431; +} + +#progress-bar .progress-bar-skip { + background-color: #00e1e1; +} + +#progress-bar .progress-bar-error { + background-color: #f0f; +} + +#progress-bar .progress-bar-omit { + background-color: #999; +} + +#progress-bar .progress-bar-wait { + background-color: #999; +} + +#progress-bar .progress-bar-todo { + background-color: #999; +} + .tab-pane { display:none; }