Merge pull request #2641 from consul/homepage
Add customization of homepage from admin section
This commit is contained in:
131
spec/features/admin/homepage/homepage_spec.rb
Normal file
131
spec/features/admin/homepage/homepage_spec.rb
Normal file
@@ -0,0 +1,131 @@
|
||||
require 'rails_helper'
|
||||
|
||||
feature 'Homepage' do
|
||||
|
||||
background do
|
||||
admin = create(:administrator).user
|
||||
login_as(admin)
|
||||
|
||||
Setting['feature.homepage.widgets.feeds.proposals'] = false
|
||||
Setting['feature.homepage.widgets.feeds.debates'] = false
|
||||
Setting['feature.homepage.widgets.feeds.processes'] = false
|
||||
Setting['feature.user.recommendations'] = false
|
||||
end
|
||||
|
||||
let!(:proposals_feed) { create(:widget_feed, kind: "proposals") }
|
||||
let!(:debates_feed) { create(:widget_feed, kind: "debates") }
|
||||
let!(:processes_feed) { create(:widget_feed, kind: "processes") }
|
||||
|
||||
let(:user_recommendations) { Setting.where(key: 'feature.user.recommendations').first }
|
||||
let(:user) { create(:user) }
|
||||
|
||||
scenario "Header" do
|
||||
end
|
||||
|
||||
context "Feeds" do
|
||||
|
||||
scenario "Proposals", :js do
|
||||
5.times { create(:proposal) }
|
||||
|
||||
visit admin_homepage_path
|
||||
|
||||
within("#widget_feed_#{proposals_feed.id}") do
|
||||
select '1', from: 'widget_feed_limit'
|
||||
accept_confirm { click_button "Enable" }
|
||||
end
|
||||
|
||||
visit root_path
|
||||
|
||||
expect(page).to have_content "Most active proposals"
|
||||
expect(page).to have_css(".proposal", count: 1)
|
||||
end
|
||||
|
||||
scenario "Debates", :js do
|
||||
5.times { create(:debate) }
|
||||
|
||||
visit admin_homepage_path
|
||||
within("#widget_feed_#{debates_feed.id}") do
|
||||
select '2', from: 'widget_feed_limit'
|
||||
accept_confirm { click_button "Enable" }
|
||||
end
|
||||
|
||||
visit root_path
|
||||
|
||||
expect(page).to have_content "Most active debates"
|
||||
expect(page).to have_css(".debate", count: 2)
|
||||
end
|
||||
|
||||
scenario "Processes", :js do
|
||||
5.times { create(:legislation_process) }
|
||||
|
||||
visit admin_homepage_path
|
||||
within("#widget_feed_#{processes_feed.id}") do
|
||||
select '3', from: 'widget_feed_limit'
|
||||
accept_confirm { click_button "Enable" }
|
||||
end
|
||||
|
||||
visit root_path
|
||||
|
||||
expect(page).to have_content "Open processes"
|
||||
expect(page).to have_css(".legislation_process", count: 3)
|
||||
end
|
||||
|
||||
xscenario "Deactivate"
|
||||
|
||||
end
|
||||
|
||||
scenario "Cards" do
|
||||
card1 = create(:widget_card, label: "Card1 label",
|
||||
title: "Card1 text",
|
||||
description: "Card1 description",
|
||||
link_text: "Link1 text",
|
||||
link_url: "consul1.dev")
|
||||
|
||||
card2 = create(:widget_card, label: "Card2 label",
|
||||
title: "Card2 text",
|
||||
description: "Card2 description",
|
||||
link_text: "Link2 text",
|
||||
link_url: "consul2.dev")
|
||||
|
||||
visit root_path
|
||||
|
||||
expect(page).to have_css(".card", count: 2)
|
||||
|
||||
within("#widget_card_#{card1.id}") do
|
||||
expect(page).to have_content("Card1 label")
|
||||
expect(page).to have_content("Card1 text")
|
||||
expect(page).to have_content("Card1 description")
|
||||
expect(page).to have_content("Link1 text")
|
||||
expect(page).to have_link(href: "consul1.dev")
|
||||
expect(page).to have_css("img[alt='#{card1.image.title}']")
|
||||
end
|
||||
|
||||
within("#widget_card_#{card2.id}") do
|
||||
expect(page).to have_content("Card2 label")
|
||||
expect(page).to have_content("Card2 text")
|
||||
expect(page).to have_content("Card2 description")
|
||||
expect(page).to have_content("Link2 text")
|
||||
expect(page).to have_link(href: "consul2.dev")
|
||||
expect(page).to have_css("img[alt='#{card2.image.title}']")
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Recomendations" do
|
||||
proposal1 = create(:proposal, tag_list: "Sport")
|
||||
proposal2 = create(:proposal, tag_list: "Sport")
|
||||
create(:follow, followable: proposal1, user: user)
|
||||
|
||||
visit admin_homepage_path
|
||||
within("#setting_#{user_recommendations.id}") do
|
||||
click_button "Enable"
|
||||
end
|
||||
|
||||
expect(page).to have_content "Value updated"
|
||||
|
||||
login_as(user)
|
||||
visit root_path
|
||||
|
||||
expect(page).to have_content("Recommendations that may interest you")
|
||||
end
|
||||
|
||||
end
|
||||
138
spec/features/admin/widgets/cards_spec.rb
Normal file
138
spec/features/admin/widgets/cards_spec.rb
Normal file
@@ -0,0 +1,138 @@
|
||||
require 'rails_helper'
|
||||
|
||||
feature 'Cards' do
|
||||
|
||||
background do
|
||||
admin = create(:administrator).user
|
||||
login_as(admin)
|
||||
end
|
||||
|
||||
scenario "Create", :js do
|
||||
visit admin_homepage_path
|
||||
click_link "Create card"
|
||||
|
||||
fill_in "widget_card_label", with: "Card label"
|
||||
fill_in "widget_card_title", with: "Card text"
|
||||
fill_in "widget_card_description", with: "Card description"
|
||||
fill_in "widget_card_link_text", with: "Link text"
|
||||
fill_in "widget_card_link_url", with: "consul.dev"
|
||||
attach_image_to_card
|
||||
click_button "Create card"
|
||||
|
||||
expect(page).to have_content "Success"
|
||||
expect(page).to have_css(".homepage-card", count: 1)
|
||||
|
||||
card = Widget::Card.last
|
||||
within("#widget_card_#{card.id}") do
|
||||
expect(page).to have_content "Card label"
|
||||
expect(page).to have_content "Card text"
|
||||
expect(page).to have_content "Card description"
|
||||
expect(page).to have_content "Link text"
|
||||
expect(page).to have_content "consul.dev"
|
||||
expect(page).to have_link("Show image", href: card.image_url(:large))
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Index" do
|
||||
3.times { create(:widget_card) }
|
||||
|
||||
visit admin_homepage_path
|
||||
|
||||
expect(page).to have_css(".homepage-card", count: 3)
|
||||
|
||||
cards = Widget::Card.all
|
||||
cards.each do |card|
|
||||
expect(page).to have_content card.title
|
||||
expect(page).to have_content card.description
|
||||
expect(page).to have_content card.link_text
|
||||
expect(page).to have_content card.link_url
|
||||
expect(page).to have_link("Show image", href: card.image_url(:large))
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Edit" do
|
||||
card = create(:widget_card)
|
||||
|
||||
visit admin_homepage_path
|
||||
|
||||
within("#widget_card_#{card.id}") do
|
||||
click_link "Edit"
|
||||
end
|
||||
|
||||
fill_in "widget_card_label", with: "Card label updated"
|
||||
fill_in "widget_card_title", with: "Card text updated"
|
||||
fill_in "widget_card_description", with: "Card description updated"
|
||||
fill_in "widget_card_link_text", with: "Link text updated"
|
||||
fill_in "widget_card_link_url", with: "consul.dev updated"
|
||||
click_button "Save card"
|
||||
|
||||
expect(page).to have_content "Updated"
|
||||
|
||||
expect(page).to have_css(".homepage-card", count: 1)
|
||||
within("#widget_card_#{Widget::Card.last.id}") do
|
||||
expect(page).to have_content "Card label updated"
|
||||
expect(page).to have_content "Card text updated"
|
||||
expect(page).to have_content "Card description updated"
|
||||
expect(page).to have_content "Link text updated"
|
||||
expect(page).to have_content "consul.dev updated"
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Remove", :js do
|
||||
card = create(:widget_card)
|
||||
|
||||
visit admin_homepage_path
|
||||
|
||||
within("#widget_card_#{card.id}") do
|
||||
accept_confirm do
|
||||
click_link "Delete"
|
||||
end
|
||||
end
|
||||
|
||||
expect(page).to have_content "Removed"
|
||||
expect(page).to have_css(".homepage-card", count: 0)
|
||||
end
|
||||
|
||||
context "Header Card" do
|
||||
|
||||
scenario "Create" do
|
||||
visit admin_homepage_path
|
||||
click_link "Create header"
|
||||
|
||||
fill_in "widget_card_label", with: "Header label"
|
||||
fill_in "widget_card_title", with: "Header text"
|
||||
fill_in "widget_card_description", with: "Header description"
|
||||
fill_in "widget_card_link_text", with: "Link text"
|
||||
fill_in "widget_card_link_url", with: "consul.dev"
|
||||
click_button "Create header"
|
||||
|
||||
expect(page).to have_content "Success"
|
||||
|
||||
within("#header") do
|
||||
expect(page).to have_css(".homepage-card", count: 1)
|
||||
expect(page).to have_content "Header label"
|
||||
expect(page).to have_content "Header text"
|
||||
expect(page).to have_content "Header description"
|
||||
expect(page).to have_content "Link text"
|
||||
expect(page).to have_content "consul.dev"
|
||||
end
|
||||
|
||||
within("#cards") do
|
||||
expect(page).to have_css(".homepage-card", count: 0)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
pending "add image expectactions"
|
||||
|
||||
def attach_image_to_card
|
||||
click_link "Add image"
|
||||
image_input = all(".image").last.find("input[type=file]", visible: false)
|
||||
attach_file(
|
||||
image_input[:id],
|
||||
Rails.root.join('spec/fixtures/files/clippy.jpg'),
|
||||
make_visible: true)
|
||||
expect(page).to have_field('widget_card_image_attributes_title', with: "clippy.jpg")
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user