From aa7ef577cbc8db1d0d8916fde0958f5b382de851 Mon Sep 17 00:00:00 2001 From: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com> Date: Mon, 2 Nov 2020 12:50:03 -0700 Subject: [PATCH] Adds a Default Color Hex Value to the Admin Tags Color Field (#11105) [deploy] * Adds a default color hex value to the /admin/tags/show color picker * Rebased against color-picker changes and adds default color to edit.html.erb * Adds a system spec for admin/tags and adjusts the filename for admin_creates_new_page_spec * Uses .blank? in place of .nil? in admin/tags/show.html.erb * Refactors test in admin_updates_tag_spec.rb --- app/views/admin/tags/show.html.erb | 2 +- ...page.rb => admin_creates_new_page_spec.rb} | 0 spec/system/admin/admin_updates_tag_spec.rb | 38 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) rename spec/system/admin/{admin_creates_new_page.rb => admin_creates_new_page_spec.rb} (100%) create mode 100644 spec/system/admin/admin_updates_tag_spec.rb diff --git a/app/views/admin/tags/show.html.erb b/app/views/admin/tags/show.html.erb index a4a14c84e..0423973c1 100644 --- a/app/views/admin/tags/show.html.erb +++ b/app/views/admin/tags/show.html.erb @@ -86,7 +86,7 @@
<%= f.label :text_color_hex %> - <%= f.color_field :text_color_hex, class: "form-control", required: true %> + <%= f.color_field :text_color_hex, class: "form-control", required: true, value: @tag.text_color_hex.presence || "#ffffff" %>
<%= f.submit class: "btn btn-primary float-right" %> <% end %> diff --git a/spec/system/admin/admin_creates_new_page.rb b/spec/system/admin/admin_creates_new_page_spec.rb similarity index 100% rename from spec/system/admin/admin_creates_new_page.rb rename to spec/system/admin/admin_creates_new_page_spec.rb diff --git a/spec/system/admin/admin_updates_tag_spec.rb b/spec/system/admin/admin_updates_tag_spec.rb new file mode 100644 index 000000000..f2657235b --- /dev/null +++ b/spec/system/admin/admin_updates_tag_spec.rb @@ -0,0 +1,38 @@ +require "rails_helper" + +RSpec.describe "Admin updates a tag", type: :system do + let(:super_admin) { create(:user, :super_admin) } + let(:tag) { create(:tag) } + + context "when no colors have been choosen for the tag" do + before do + sign_in super_admin + visit "/admin/tags/#{tag.id}" + end + + it "defaults to white text for the color picker" do + expect(page).to have_field("tag_text_color_hex", with: "#ffffff") + end + + it "defaults to black and white upon update" do + check "Supported" + click_button("Update Tag") + tag.reload + expect(tag.bg_color_hex).to eq("#000000") + expect(tag.text_color_hex).to eq("#ffffff") + end + end + + context "when colors have already been choosen for the tag" do + before do + sign_in super_admin + visit "/admin/tags/#{tag.id}" + end + + it "remains the same color it was unless otherwise updated via the color picker" do + click_button("Update Tag") + expect(tag.bg_color_hex).to eq(tag.bg_color_hex) + expect(tag.text_color_hex).to eq(tag.text_color_hex) + end + end +end