A platform for community discussion. Free, open, simple.
DEV: more resilient get_rgb_color (#35080)
Joffrey JAFFEUXe61dbabcc4ab
diff --git a/spec/support/system_helpers.rb b/spec/support/system_helpers.rbindex fdb6c82f1c2..a9e51d94bf7 100644--- a/spec/support/system_helpers.rb+++ b/spec/support/system_helpers.rb@@ -351,17 +351,14 @@ module SystemHelpersenddef get_rgb_color(element, property = "backgroundColor")- element.native.evaluate(<<~JS)- (el) => {- const color = window.getComputedStyle(el).#{property};- const tempDiv = document.createElement('div');- tempDiv.style.#{property} = color;- document.body.appendChild(tempDiv);- const rgbColor = window.getComputedStyle(tempDiv).#{property};- document.body.removeChild(tempDiv);- return rgbColor;- }- JS+ css_property = property.underscore.dasherize++ try_until_success do+ style_hash = element.style(css_property)+ color = style_hash[css_property]+ raise Capybara::ExpectationNotMet if color.blank?+ color+ endend# should be used only on very rare occasion when you need to wait for somethingdiff --git a/spec/system/admin_color_palette_config_area_spec.rb b/spec/system/admin_color_palette_config_area_spec.rbindex 46f38b36177..6502fdb4bf5 100644--- a/spec/system/admin_color_palette_config_area_spec.rb+++ b/spec/system/admin_color_palette_config_area_spec.rb@@ -171,11 +171,9 @@ describe "Admin Color Palette Config Area Page", type: :system dovisible: false,)- try_until_success(timeout: Capybara.default_max_wait_time * 2) do- expect(get_rgb_color(find("html"), "backgroundColor")).to eq(- "rgb(#{"aa".to_i(16)}, #{"33".to_i(16)}, #{"9f".to_i(16)})",- )- end+ expect(get_rgb_color(find("html"), "backgroundColor")).to eq(+ "rgb(#{"aa".to_i(16)}, #{"33".to_i(16)}, #{"9f".to_i(16)})",+ )endit "doesn't apply changes when editing a palette that's not currently active" do