Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
antopalidi committed May 24, 2024
1 parent f56c8f9 commit 4deedce
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ def metadata_cell_instance
end

def resource_image_path
return unless model.component.settings.attachments_allowed?

model.attachments.first&.url || proposal_image_placeholder
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
}

#proposals {
.view-layout__links{
.view-layout__links {
svg {
@apply inline-block w-5 h-5;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# frozen_string_literal: true

require "spec_helper"

module Decidim::Proposals
describe ProposalGCell, type: :cell do
controller Decidim::Proposals::ProposalsController

subject(:cell_html) { my_cell.call }

let(:my_cell) { cell("decidim/proposals/proposal_g", proposal, card_size: :g) }
let(:component) { create(:proposal_component, :with_attachments_allowed) }
let!(:proposal) { create(:proposal, :evaluating, component:) }
let(:user) { create(:user, organization: proposal.participatory_space.organization) }

before do
allow(controller).to receive(:current_user).and_return(user)
end

describe "show" do
it "renders the proposal state item with appropriate class" do
expect(subject).to have_css("span.warning", text: "Evaluating")
end

it "renders the proposal title" do
expect(subject).to have_content(translated_attribute(proposal.title))
end

context "when the proposal has an image" do
let!(:attachment) { create(:attachment, attached_to: proposal) }

it "renders the proposal with an image" do
expect(subject).to have_css("img[src*='city']")
end
end

context "when the proposal has no image" do
before { allow(proposal).to receive(:attachments).and_return([]) }

it "renders a placeholder image" do
expect(subject).to have_css("img[src*='proposal_image_placeholder']")
end
end
end
end
end
53 changes: 53 additions & 0 deletions decidim-proposals/spec/system/proposals_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -643,4 +643,57 @@
it_behaves_like "an uncommentable component"
end
end

describe "viewing mode for proposals" do
let!(:proposal) { create(:proposal, :evaluating, component:) }

context "when participants interact with the proposal view" do
it "provides an option for toggling between list and grid views" do
visit_component
expect(page).to have_css("use[href*='layout-grid-fill']")
expect(page).to have_css("use[href*='list-check']")
end
end

context "when participants are viewing a grid of proposals" do
it "shows a grid of proposals with images" do
visit_component
find("a[href*='view_mode=grid']").click
expect(page).to have_css(".card__grid-grid")
expect(page).to have_css(".card__grid-img img, .card__grid-img svg")
end
end

context "when participants are viewing a list of proposals" do
it "shows a list of proposals" do
visit_component
find("a[href*='view_mode=list']").click
expect(page).to have_css(".card__list-list")
end
end

context "when proposals does not have attachments" do
it "shows a placeholder image" do
visit_component
find("a[href*='view_mode=grid']").click
expect(page).to have_css(".card__grid-img img[src*='proposal_image_placeholder']")
end
end

context "when proposals have attachments" do
let!(:proposal) { create(:proposal, component:) }
let!(:attachment) { create(:attachment, attached_to: proposal) }

before do
component.update!(settings: { attachments_allowed: true })
end

it "shows the proposal image" do
visit_component

expect(page).to have_no_css(".card__grid-img img[src*='proposal_image_placeholder.svg']")
expect(page).to have_css(".card__grid-img img")
end
end
end
end

0 comments on commit 4deedce

Please sign in to comment.