Skip to content

Commit

Permalink
Add tests and try to fix flaky
Browse files Browse the repository at this point in the history
  • Loading branch information
AyakorK committed Sep 14, 2023
1 parent 84ebb24 commit a7254a0
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 1 deletion.
1 change: 1 addition & 0 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
core
proposals
budgets
blogs
debates
meetings
accountability
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/tasks/decidim_app/k8s/dump_db_tasks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
end

it "invokes the configuration exporter" do
expect(DecidimApp::K8s::ConfigurationExporter).to receive(:dump_db).and_return(true)
expect(DecidimApp::K8s::ConfigurationExporter).to receive(:dump_db).at_least(:once).and_return(true)

task.execute
end
Expand Down
107 changes: 107 additions & 0 deletions spec/system/explore_posts_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# frozen_string_literal: true

require "spec_helper"

describe "Explore posts", type: :system do
include_context "with a component"
let(:manifest_name) { "blogs" }

let!(:old_post) { create(:post, component: component, created_at: Time.current - 2.days) }
let!(:new_post) { create(:post, component: component, created_at: Time.current) }

let!(:image) { create(:attachment, attached_to: old_post) }

describe "index" do
it "shows all posts for the given process" do
visit_component
expect(page).to have_selector(".card", count: 2)
expect(page).to have_selector(".card--post", text: translated(new_post.title))
expect(page).to have_selector(".card--post", text: translated(old_post.title))
end

it "shows comment counts" do
visit_component
expect(page).to have_selector('a[title="comments"]', text: "comment".pluralize(new_post.comments.count))
expect(page).to have_selector('a[title="comments"]', text: "comment".pluralize(old_post.comments.count))
end

it "shows endorsement counts" do
visit_component
expect(page).to have_selector('a[title="endorsements"]', text: "endorsement".pluralize(new_post.endorsements.count))
expect(page).to have_selector('a[title="endorsements"]', text: "endorsement".pluralize(old_post.endorsements.count))
end

it "shows images" do
visit_component
expect(page).to have_selector(".card--post img.card__image")
end

context "when paginating" do
let(:collection_size) { 10 }
let!(:collection) { create_list :post, collection_size, component: component }
let!(:resource_selector) { ".card--post" }

before do
visit_component
end

it "lists 4 resources per page by default" do
expect(page).to have_css(resource_selector, count: 4)
expect(page).to have_css(".pagination .page", count: 3)
end
end
end

describe "show" do
let(:posts_count) { 1 }
let(:body) { { en: "Short description", ca: "Descripció curta", es: "Descripción corta" } }
let!(:post) { create(:post, component: component, body: body) }

before do
visit resource_locator(post).path
end

it "show post info" do
expect(page).to have_i18n_content(post.title)
expect(page).to have_i18n_content(post.body)
expect(page).to have_content(post.author.name)
expect(page).to have_content(post.created_at.strftime("%d/%m/%Y %H:%M "))
end

it "shows the back button" do
expect(page).to have_link(href: "#{main_component_path(component)}posts")
end

context "when clicking the back button" do
before do
click_link(href: "#{main_component_path(component)}posts")
end

it "redirect the user to component index" do
expect(page).to have_current_path("#{main_component_path(component)}posts")
end
end

it_behaves_like "has embedded video in description", :body
end

describe "most commented" do
context "when ordering by 'most_commented'" do
let!(:post_more_comments) { create(:post, component: component) }
let!(:post_less_comments) { create(:post, component: component) }
let!(:more_comments) { create_list(:comment, 7, commentable: post_more_comments) }
let!(:less_comments) { create_list(:comment, 3, commentable: post_less_comments) }

before do
visit_component
end

it "lists the posts ordered by comments count" do
within "#most-commented" do
expect(page).to have_content(translated(post_more_comments.title))
expect(page).to have_content(translated(post_less_comments.title))
end
end
end
end
end

0 comments on commit a7254a0

Please sign in to comment.