Skip to content

Commit

Permalink
decidim_awesome spec file
Browse files Browse the repository at this point in the history
  • Loading branch information
HHassig committed Jun 27, 2024
1 parent cb7264b commit 2501100
Showing 1 changed file with 119 additions and 0 deletions.
119 changes: 119 additions & 0 deletions spec/system/decidim_awesome/custom_styles_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# frozen_string_literal: true

require "rails_helper"

describe "Custom styles" do
let(:organization) { create(:organization) }
let!(:participatory_process) { create(:participatory_process, organization:) }
let!(:config) { create(:awesome_config, organization:, var: :scoped_styles, value: styles) }
let(:config_helper) { create(:awesome_config, organization:, var: :scoped_style_bar) }
let(:styles) do
{
"bar" => "body {background: red;}"
}
end

before do
switch_to_host(organization.host)
visit decidim.root_path
end

shared_examples "extra css is added" do
it "css is present" do
expect(page.body).to have_content("body {background: red;}")
end

it "css is applied" do
expect(page.execute_script("return window.getComputedStyle($('body')[0]).backgroundColor")).to eq("rgb(255, 0, 0)")
end
end

shared_examples "no extra css is added" do
it "css is no present" do
expect(page.body).not_to have_content("body {background: red;}")
end

it "css is not applyied" do
expect(page.execute_script("return window.getComputedStyle($('body')[0]).backgroundColor")).to eq("rgba(0, 0, 0, 0)")
end
end

context "when there are custom styles" do
it_behaves_like "extra css is added"
end

context "when there are empty css boxes" do
let(:styles) do
{}
end

it_behaves_like "no extra css is added"
end

context "when constraints are present" do
let!(:constraint) { create(:config_constraint, awesome_config: config_helper, settings:) }
let!(:other_constraint) { create(:config_constraint, awesome_config: config_helper, settings: other_settings) }
let(:settings) do
{}
end

let(:other_settings) do
{ "participatory_space_manifest" => "other" }
end

before do
visit decidim.root_path
end

context "when there are custom styles" do
it_behaves_like "extra css is added"
end

context "and there are no custom styles" do
let(:styles) do
{}
end

it_behaves_like "no extra css is added"
end

context "and custom styles are scoped" do
let(:settings) do
{ "participatory_space_manifest" => "participatory_processes" }
end

context "and page do not match the scope" do
it_behaves_like "no extra css is added"
end

context "and page matches the scope" do
before do
click_link_or_button "Processes"
end

it_behaves_like "extra css is added"

context "and none constraint is present" do
let(:other_settings) do
{ "participatory_space_manifest" => "none" }
end

it_behaves_like "no extra css is added"
end
end
end
end

context "when there are custom styles with special characters" do
let(:css) { %(body > a[href="hey"] { color: blue; }) }
let(:styles) do
{
"special" => css
}
end

it "decodes them correctly" do
expect(page.body).to have_content(css)
end
end
end

0 comments on commit 2501100

Please sign in to comment.