-
-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5090 from rubyforgood/5070-update-banner-creation-ux
5070 - Update banner creation UX
- Loading branch information
Showing
13 changed files
with
240 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module BannerHelper | ||
def conditionally_add_hidden_class(current_banner_is_active) | ||
unless current_banner_is_active && current_organization.has_alternate_active_banner?(@banner.id) | ||
"d-none" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<%= render 'banners/form', banner: @banner %> | ||
<%= render 'banners/form', banner: @banner, org_has_alternate_active_banner: @org_has_alternate_active_banner %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<%= render 'banners/form', banner: @banner %> | ||
<%= render 'banners/form', banner: @banner, org_has_alternate_active_banner: @org_has_alternate_active_banner %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe BannerHelper do | ||
describe "#conditionally_add_hidden_class" do | ||
it "returns d-none if current banner is inactive" do | ||
current_organization = double | ||
allow(helper).to receive(:current_organization).and_return(current_organization) | ||
banner = double(id: 1) | ||
assign(:banner, banner) | ||
|
||
allow(current_organization).to receive(:has_alternate_active_banner?).and_return(true) | ||
|
||
expect(helper.conditionally_add_hidden_class(false)).to eq("d-none") | ||
end | ||
|
||
it "returns d-none if current banner is active and org does not have an alternate active banner" do | ||
current_organization = double | ||
allow(helper).to receive(:current_organization).and_return(current_organization) | ||
banner = double(id: 1) | ||
assign(:banner, banner) | ||
|
||
allow(current_organization).to receive(:has_alternate_active_banner?).and_return(false) | ||
|
||
expect(helper.conditionally_add_hidden_class(true)).to eq("d-none") | ||
end | ||
|
||
it "returns nil if current banner is active and org has an alternate active banner" do | ||
current_organization = double | ||
allow(helper).to receive(:current_organization).and_return(current_organization) | ||
banner = double(id: 1) | ||
assign(:banner, banner) | ||
|
||
allow(current_organization).to receive(:has_alternate_active_banner?).and_return(true) | ||
|
||
expect(helper.conditionally_add_hidden_class(true)).to eq(nil) | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "Banners", type: :system, js: true do | ||
let(:admin) { create(:casa_admin) } | ||
let(:organization) { admin.casa_org } | ||
|
||
it "adds a banner" do | ||
sign_in admin | ||
|
||
visit banners_path | ||
click_on "New Banner" | ||
fill_in "Name", with: "Volunteer Survey Announcement" | ||
check "Active?" | ||
fill_in_rich_text_area "banner_content", with: "Please fill out this survey." | ||
click_on "Submit" | ||
|
||
visit banners_path | ||
expect(page).to have_text("Volunteer Survey Announcement") | ||
|
||
visit banners_path | ||
within "#banners" do | ||
click_on "Edit", match: :first | ||
end | ||
fill_in "Name", with: "Better Volunteer Survey Announcement" | ||
click_on "Submit" | ||
|
||
visit banners_path | ||
expect(page).to have_text("Better Volunteer Survey Announcement") | ||
|
||
visit root_path | ||
expect(page).to have_text("Please fill out this survey.") | ||
end | ||
|
||
describe "when an organization has an active banner" do | ||
let(:admin) { create(:casa_admin) } | ||
let(:organization) { create(:casa_org) } | ||
let(:active_banner) { create(:banner, casa_org: organization) } | ||
|
||
context "when a banner is submitted as active" do | ||
it "deactivates and replaces the current active banner" do | ||
active_banner | ||
|
||
sign_in admin | ||
|
||
visit banners_path | ||
expect(page).to have_text(active_banner.content.body.to_plain_text) | ||
click_on "New Banner" | ||
fill_in "Name", with: "New active banner name" | ||
check "Active?" | ||
fill_in_rich_text_area "banner_content", with: "New active banner content." | ||
click_on "Submit" | ||
|
||
visit banners_path | ||
within("table#banners") do | ||
already_existing_banner_row = find("tr", text: active_banner.name) | ||
|
||
expect(already_existing_banner_row).to have_selector("td.min-width", text: "No") | ||
end | ||
|
||
expect(page).to have_text("New active banner content.") | ||
end | ||
end | ||
|
||
context "when a banner is submitted as inactive" do | ||
it "does not deactivate the current active banner" do | ||
active_banner | ||
|
||
sign_in admin | ||
|
||
visit banners_path | ||
expect(page).to have_text(active_banner.content.body.to_plain_text) | ||
click_on "New Banner" | ||
fill_in "Name", with: "New active banner name" | ||
fill_in_rich_text_area "banner_content", with: "New active banner content." | ||
click_on "Submit" | ||
|
||
visit banners_path | ||
|
||
within("table#banners") do | ||
already_existing_banner_row = find("tr", text: active_banner.name) | ||
|
||
expect(already_existing_banner_row).to have_selector("td.min-width", text: "Yes") | ||
end | ||
|
||
expect(page).to have_text(active_banner.content.body.to_plain_text) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "banners/new", type: :view do | ||
context "when new banner is marked as inactive" do | ||
it "does not warn that current active banner will be deactivated" do | ||
user = build_stubbed(:casa_admin) | ||
current_organization = user.casa_org | ||
current_organization_banner = build(:banner, active: true, casa_org: current_organization) | ||
|
||
allow(view).to receive(:current_user).and_return(user) | ||
allow(view).to receive(:current_organization).and_return(current_organization) | ||
allow(current_organization).to receive(:has_alternate_active_banner?).and_return(true) | ||
|
||
assign :banners, [current_organization_banner] | ||
assign :banner, Banner.new(active: false) | ||
|
||
render template: "banners/new" | ||
|
||
expect(rendered).not_to have_checked_field("banner_active") | ||
expect(rendered).to have_css("span.d-none", text: "Warning: This will replace your current active banner") | ||
end | ||
end | ||
|
||
context "when organization has an active banner" do | ||
context "when new banner is marked as active" do | ||
it "warns that current active banner will be deactivated" do | ||
user = build_stubbed(:casa_admin) | ||
current_organization = user.casa_org | ||
current_organization_banner = build(:banner, active: true, casa_org: current_organization) | ||
|
||
allow(view).to receive(:current_user).and_return(user) | ||
allow(view).to receive(:current_organization).and_return(current_organization) | ||
allow(current_organization).to receive(:has_alternate_active_banner?).and_return(true) | ||
|
||
assign :banners, [current_organization_banner] | ||
assign :banner, Banner.new(active: true) | ||
|
||
render template: "banners/new" | ||
|
||
expect(rendered).to have_checked_field("banner_active") | ||
expect(rendered).not_to have_css("span.d-none", text: "Warning: This will replace your current active banner") | ||
end | ||
end | ||
end | ||
|
||
context "when organization has no active banner" do | ||
context "when new banner is marked as active" do | ||
it "does not warn that current active banner will be deactivated" do | ||
user = build_stubbed(:casa_admin) | ||
current_organization = user.casa_org | ||
|
||
allow(view).to receive(:current_user).and_return(user) | ||
allow(view).to receive(:current_organization).and_return(current_organization) | ||
allow(current_organization).to receive(:has_alternate_active_banner?).and_return(false) | ||
|
||
assign :banners, [] | ||
assign :banner, Banner.new(active: true) | ||
|
||
render template: "banners/new" | ||
|
||
expect(rendered).to have_checked_field("banner_active") | ||
expect(rendered).to have_css("span.d-none", text: "Warning: This will replace your current active banner") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters