Files
astuto/spec/system/post_spec.rb

101 lines
3.2 KiB
Ruby
Raw Normal View History

2019-09-14 16:05:54 +02:00
require 'rails_helper'
feature 'post', type: :system, js: true do
let(:post) { FactoryBot.create(:post) }
let(:mod) { FactoryBot.create(:moderator) }
let(:post_container_selector) { '.postAndCommentsContainer' }
let(:post_edit_form_selector) { '.postEditForm' }
2023-03-19 19:57:53 +01:00
let(:select_picker_board) { 'selectPickerBoard' }
let(:select_picker_status) { 'selectPickerStatus' }
2019-09-21 12:54:57 +02:00
it 'renders post title, description, board and status' do
2019-09-14 16:05:54 +02:00
visit post_path(post)
expect(page).to have_content(/#{post.title}/i)
expect(page).to have_content(/#{post.description}/i)
2019-09-21 12:54:57 +02:00
expect(page).to have_content(/#{post.board.name}/i)
2019-09-14 16:05:54 +02:00
expect(page).to have_content(/#{post.post_status.name}/i)
end
# TODO: Fix this test
# it 'lets edit the post' do
# mod.confirm
# sign_in mod
# new_title = 'New Post Title'
# new_description = 'New Post Description'
# new_board = FactoryBot.create(:board)
# new_post_status = FactoryBot.create(:post_status)
2023-03-19 19:57:53 +01:00
# visit post_path(post)
2023-03-19 19:57:53 +01:00
# within post_container_selector do
# expect(page).not_to have_content(new_title)
# expect(page).not_to have_content(new_description)
# expect(page).not_to have_content(new_board.name.upcase)
# expect(page).not_to have_content(new_post_status.name.upcase)
# end
2023-03-19 19:57:53 +01:00
# expect(post.title).not_to eq(new_title)
# expect(post.description).not_to eq(new_description)
# expect(post.board.id).not_to eq(new_board.id)
# expect(post.post_status.id).not_to eq(new_post_status.id)
2023-03-19 19:57:53 +01:00
# within post_container_selector do
# find('.editAction').click
2023-03-19 19:57:53 +01:00
# expect(page).to have_css(post_edit_form_selector)
# expect(page).to have_select(select_picker_board,
# selected: post.board.name,
# with_options: [post.board.name, new_board.name]
# )
2019-09-21 12:54:57 +02:00
# expect(page).to have_select(select_picker_status,
# selected: post.post_status.name,
# with_options: [post.post_status.name, new_post_status.name, 'None']
# )
# find('.postTitle').fill_in with: new_title
# find('.postDescription').fill_in with: new_description
# select new_board.name, from: select_picker_board
# select new_post_status.name, from: select_picker_status
# click_button 'Save'
# end
# within post_container_selector do
# expect(page).not_to have_css(post_edit_form_selector)
# expect(page).to have_content(new_title)
# expect(page).to have_content(new_description)
# expect(page).to have_content(new_board.name.upcase)
# expect(page).to have_content(new_post_status.name.upcase)
# end
# post.reload
# expect(post.title).to eq(new_title)
# expect(post.description).to eq(new_description)
# expect(post.board.id).to eq(new_board.id)
# expect(post.post_status.id).to eq(new_post_status.id)
# end
it 'lets delete the post' do
2019-09-14 16:05:54 +02:00
mod.confirm
sign_in mod
2023-03-19 19:57:53 +01:00
2019-09-14 16:05:54 +02:00
visit post_path(post)
post_count = Post.count
2019-09-14 16:05:54 +02:00
within post_container_selector do
find('.deleteAction').click
2019-09-14 16:05:54 +02:00
alert = page.driver.browser.switch_to.alert
expect(alert.text).to eq('Are you sure?')
alert.accept
2023-03-19 19:57:53 +01:00
end
expect(page).to have_current_path(board_path(post.board))
expect(Post.count).to eq(post_count - 1)
2019-09-14 16:05:54 +02:00
end
end