From c13ac854731e883622561e5770d56b39ff617769 Mon Sep 17 00:00:00 2001 From: riggraz Date: Sat, 14 Sep 2019 16:05:54 +0200 Subject: [PATCH] Add tests for Post component --- .../components/Post/PostStatusSelect.tsx | 34 +++++++++------- spec/system/post_spec.rb | 40 +++++++++++++++++++ 2 files changed, 59 insertions(+), 15 deletions(-) create mode 100644 spec/system/post_spec.rb diff --git a/app/javascript/components/Post/PostStatusSelect.tsx b/app/javascript/components/Post/PostStatusSelect.tsx index f18085ae..be89ea91 100644 --- a/app/javascript/components/Post/PostStatusSelect.tsx +++ b/app/javascript/components/Post/PostStatusSelect.tsx @@ -17,21 +17,25 @@ const PostStatusSelect = ({ selectedPostStatusId, handleChange, }: Props) => ( - + + + + ); export default PostStatusSelect; \ No newline at end of file diff --git a/spec/system/post_spec.rb b/spec/system/post_spec.rb new file mode 100644 index 00000000..2bd97f37 --- /dev/null +++ b/spec/system/post_spec.rb @@ -0,0 +1,40 @@ +require 'rails_helper' + +feature 'post', type: :system, js: true do + let(:post) { FactoryBot.create(:post) } + let(:mod) { FactoryBot.create(:moderator) } + + it 'renders post title, description and status' do + visit post_path(post) + + expect(page).to have_content(/#{post.title}/i) + expect(page).to have_content(/#{post.description}/i) + expect(page).to have_content(/#{post.post_status.name}/i) + end + + it 'enables admins and mods to edit post status' do + mod.confirm + sign_in mod + post_status1 = FactoryBot.create(:post_status) + + visit post_path(post) + + expect(post.post_status_id).not_to eq(post_status1.id) + expect(page).to have_select 'Status:', + selected: post.post_status.name, + options: [post.post_status.name, post_status1.name, 'None'] + + select post_status1.name, from: 'Status:' + expect(page).to have_select 'Status:', selected: post_status1.name + expect(post.reload.post_status_id).to eq(post_status1.id) + + select 'None', from: 'Status:' + expect(page).to have_select 'Status:', selected: 'None' + expect(post.reload.post_status_id).to be_nil + end + + it 'does not show status selection to users' do + visit post_path(post) + expect(page).to have_no_select 'Status:' + end +end \ No newline at end of file