Skip to content

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.rb
index fdb6c82f1c2..a9e51d94bf7 100644
--- a/spec/support/system_helpers.rb
+++ b/spec/support/system_helpers.rb
@@ -351,17 +351,14 @@ module SystemHelpers
end
def 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
+ end
end
# should be used only on very rare occasion when you need to wait for something
diff --git a/spec/system/admin_color_palette_config_area_spec.rb b/spec/system/admin_color_palette_config_area_spec.rb
index 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 do
visible: 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)})",
+ )
end
it "doesn't apply changes when editing a palette that's not currently active" do