Merge pull request #5276 from consuldemocracy/order-cards
Allow sorting homepage cards
This commit is contained in:
@@ -35,4 +35,28 @@ describe SDG::Goals::IndexComponent do
|
||||
expect(page).to have_content "Planning"
|
||||
expect(page).to have_content "Monitoring"
|
||||
end
|
||||
|
||||
describe "Cards are ordered" do
|
||||
scenario "by order field" do
|
||||
create(:widget_card, cardable: SDG::Phase["planning"], title: "Card One", order: 3)
|
||||
create(:widget_card, cardable: SDG::Phase["planning"], title: "Card Two", order: 2)
|
||||
create(:widget_card, cardable: SDG::Phase["planning"], title: "Card Three", order: 1)
|
||||
|
||||
render_inline component
|
||||
|
||||
expect("Card Three").to appear_before("Card Two")
|
||||
expect("Card Two").to appear_before("Card One")
|
||||
end
|
||||
|
||||
scenario "by created_at with cards have same order" do
|
||||
create(:widget_card, cardable: SDG::Phase["planning"], title: "Card One", order: 1)
|
||||
create(:widget_card, cardable: SDG::Phase["planning"], title: "Card Two", order: 1)
|
||||
create(:widget_card, cardable: SDG::Phase["planning"], title: "Card Three", order: 1)
|
||||
|
||||
render_inline component
|
||||
|
||||
expect("Card One").to appear_before("Card Two")
|
||||
expect("Card Two").to appear_before("Card Three")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -18,6 +18,16 @@ describe Widget::Card do
|
||||
expect(build(:widget_card, title: "")).not_to be_valid
|
||||
end
|
||||
|
||||
describe "order" do
|
||||
it "is not valid without an order" do
|
||||
expect(build(:widget_card, order: nil)).not_to be_valid
|
||||
end
|
||||
|
||||
it "is not valid with an order less than 1" do
|
||||
expect(build(:widget_card, order: 0)).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
context "regular cards" do
|
||||
it "is not valid without a link_url" do
|
||||
card = build(:widget_card, header: false, link_url: nil)
|
||||
@@ -76,5 +86,14 @@ describe Widget::Card do
|
||||
expect(Widget::Card.body).not_to include(header)
|
||||
expect(Widget::Card.body).not_to include(page_card)
|
||||
end
|
||||
|
||||
it "returns cards sorted by defined order, then by 'created_at' when order is equal" do
|
||||
card1 = create(:widget_card, order: 1)
|
||||
card2 = create(:widget_card, order: 3)
|
||||
card3 = create(:widget_card, order: 2)
|
||||
card4 = create(:widget_card, order: 3)
|
||||
|
||||
expect(Widget::Card.body).to eq [card1, card3, card2, card4]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,7 +11,8 @@ describe "Cards", :admin do
|
||||
fill_in "Title", with: "Card text"
|
||||
fill_in "Description", with: "Card description"
|
||||
fill_in "Link text", with: "Link text"
|
||||
fill_in "widget_card_link_url", with: "consul.dev"
|
||||
fill_in "Link URL", with: "consul.dev"
|
||||
fill_in "Position", with: "12"
|
||||
attach_image_to_card
|
||||
click_button "Create card"
|
||||
|
||||
@@ -25,6 +26,7 @@ describe "Cards", :admin do
|
||||
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_css "td", exact_text: "12"
|
||||
expect(page).to have_link "Show image", title: "clippy.jpg"
|
||||
end
|
||||
end
|
||||
@@ -87,7 +89,8 @@ describe "Cards", :admin do
|
||||
fill_in "Link text", with: "Link text updated"
|
||||
end
|
||||
|
||||
fill_in "widget_card_link_url", with: "consul.dev updated"
|
||||
fill_in "Link URL", with: "consul.dev updated"
|
||||
fill_in "Position", with: "2"
|
||||
click_button "Save card"
|
||||
|
||||
expect(page).to have_content "Card updated successfully"
|
||||
@@ -101,6 +104,7 @@ describe "Cards", :admin do
|
||||
expect(page).to have_content "Card description updated"
|
||||
expect(page).to have_content "Link text updated"
|
||||
expect(page).to have_content "consul.dev updated"
|
||||
expect(page).to have_css "td", exact_text: "2"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -125,6 +129,8 @@ describe "Cards", :admin do
|
||||
visit admin_homepage_path
|
||||
click_link "Create header"
|
||||
|
||||
expect(page).not_to have_field "Position"
|
||||
|
||||
fill_in "Label (optional)", with: "Header label"
|
||||
fill_in "Title", with: "Header text"
|
||||
fill_in "Description", with: "Header description"
|
||||
@@ -136,6 +142,7 @@ describe "Cards", :admin do
|
||||
|
||||
within("#header") do
|
||||
expect(page).to have_css(".homepage-card", count: 1)
|
||||
expect(page).not_to have_css "th", exact_text: "Position"
|
||||
expect(page).to have_content "Header label"
|
||||
expect(page).to have_content "Header text"
|
||||
expect(page).to have_content "Header description"
|
||||
@@ -174,10 +181,13 @@ describe "Cards", :admin do
|
||||
|
||||
fill_in "Title", with: "Card for a custom page"
|
||||
fill_in "Link URL", with: "/any_path"
|
||||
fill_in "Position", with: "12"
|
||||
click_button "Create card"
|
||||
|
||||
expect(page).to have_current_path admin_site_customization_page_widget_cards_path(custom_page)
|
||||
expect(page).to have_content "Card for a custom page"
|
||||
expect(page).to have_content "12"
|
||||
expect(page).to have_css "th", exact_text: "Position"
|
||||
end
|
||||
|
||||
scenario "Show" do
|
||||
@@ -239,12 +249,14 @@ describe "Cards", :admin do
|
||||
within(".translatable-fields") do
|
||||
fill_in "Title", with: "Updated title"
|
||||
end
|
||||
fill_in "Position", with: "2"
|
||||
|
||||
click_button "Save card"
|
||||
|
||||
expect(page).to have_current_path admin_site_customization_page_widget_cards_path(custom_page)
|
||||
expect(page).to have_content "Updated title"
|
||||
expect(page).not_to have_content "Original title"
|
||||
expect(page).to have_css "td", exact_text: "2"
|
||||
end
|
||||
|
||||
scenario "Destroy" do
|
||||
|
||||
@@ -143,6 +143,21 @@ describe "Home" do
|
||||
expect(page).not_to have_css(".title", text: "Featured")
|
||||
end
|
||||
|
||||
scenario "cards are first sorted by 'order' field, then by 'created_at' when order is equal" do
|
||||
create(:widget_card, title: "Card one", order: 1)
|
||||
create(:widget_card, title: "Card two", order: 3)
|
||||
create(:widget_card, title: "Card three", order: 2)
|
||||
create(:widget_card, title: "Card four", order: 3)
|
||||
|
||||
visit root_path
|
||||
|
||||
within(".cards-container") do
|
||||
expect("CARD ONE").to appear_before("CARD THREE")
|
||||
expect("CARD THREE").to appear_before("CARD TWO")
|
||||
expect("CARD TWO").to appear_before("CARD FOUR")
|
||||
end
|
||||
end
|
||||
|
||||
describe "Header Card" do
|
||||
scenario "if there is header card with link, the link content is rendered" do
|
||||
create(:widget_card, :header, link_text: "Link text", link_url: "consul.dev")
|
||||
|
||||
@@ -21,12 +21,18 @@ describe "SDG homepage configuration" do
|
||||
visit sdg_management_homepage_path
|
||||
click_link "Create planning card"
|
||||
|
||||
expect(page).to have_field "Number of columns"
|
||||
expect(page).to have_field "Position"
|
||||
|
||||
within(".translatable-fields") { fill_in "Title", with: "My planning card" }
|
||||
fill_in "Link URL", with: "/any_path"
|
||||
fill_in "Position", with: "2"
|
||||
click_button "Create card"
|
||||
|
||||
within(".planning-cards") do
|
||||
expect(page).to have_content "My planning card"
|
||||
expect(page).to have_css "th", exact_text: "Position"
|
||||
expect(page).to have_css "td", exact_text: "2"
|
||||
end
|
||||
|
||||
within(".sensitization-cards") do
|
||||
@@ -54,13 +60,17 @@ describe "SDG homepage configuration" do
|
||||
visit sdg_management_homepage_path
|
||||
click_link "Create header"
|
||||
|
||||
expect(page).not_to have_field "Number of columns"
|
||||
expect(page).not_to have_field "Position"
|
||||
|
||||
within(".translatable-fields") { fill_in "Title", with: "My header" }
|
||||
fill_in "Link URL", with: "/any_path"
|
||||
click_button "Create card"
|
||||
click_button "Create header"
|
||||
|
||||
within(".sdg-header") do
|
||||
expect(page).to have_content "My header"
|
||||
expect(page).not_to have_content "Create header"
|
||||
expect(page).not_to have_css "th", exact_text: "Position"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -72,7 +82,7 @@ describe "SDG homepage configuration" do
|
||||
end
|
||||
|
||||
within(".translatable-fields") { fill_in "Title", with: "My header update" }
|
||||
click_button "Save card"
|
||||
click_button "Save header"
|
||||
|
||||
expect(page).to have_content "My header update"
|
||||
end
|
||||
|
||||
@@ -94,11 +94,14 @@ describe "Custom Pages" do
|
||||
|
||||
scenario "Show widget cards for that page" do
|
||||
custom_page = create(:site_customization_page, :published)
|
||||
create(:widget_card, cardable: custom_page, title: "Card Highlights")
|
||||
create(:widget_card, cardable: custom_page, title: "Medium prominent card", order: 2)
|
||||
create(:widget_card, cardable: custom_page, title: "Less prominent card", order: 2)
|
||||
create(:widget_card, cardable: custom_page, title: "Card Highlights", order: 1)
|
||||
|
||||
visit custom_page.url
|
||||
|
||||
expect(page).to have_content "CARD HIGHLIGHTS"
|
||||
expect("CARD HIGHLIGHTS").to appear_before("MEDIUM PROMINENT CARD")
|
||||
expect("MEDIUM PROMINENT CARD").to appear_before("LESS PROMINENT CARD")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user