diff --git a/test/system/post_test.rb b/test/system/post_test.rb index 3fd5f8c808f0ec4216ce838e8cde701c7477031b..73aa0cda8459c300b8741f17ade77111ae128b0e 100644 --- a/test/system/post_test.rb +++ b/test/system/post_test.rb @@ -12,7 +12,7 @@ class PostTest < ApplicationSystemTestCase assert_current_path new_user_session_url end - test 'Signed in user can create a post' do + test 'Signed in user can create a question' do category = categories(:meta) log_in :standard_user visit category_path(category) @@ -29,7 +29,79 @@ class PostTest < ApplicationSystemTestCase end end - # TODO: Post validations + test 'Creating a question is blocked when body is too short' do + category = categories(:meta) + log_in :standard_user + visit category_path(category) + click_on 'Create Post' + + fill_in 'Summarize your post with a title:', with: 'Initial title is of sufficient length' + post_form_select_tag tags(:faq).name + fill_in 'Body', with: 'Short' + + # Check that the button is disabled + find_button "Save Post in #{category.name}", disabled: true + + # After filling out body correctly, verify that the button becomes enabled + fill_in 'Body', with: 'This body should pass the minimum length requirements for questions in the meta category.' + find_button "Save Post in #{category.name}", disabled: false + end + + test 'Creating a question is blocked when title is too short' do + category = categories(:meta) + log_in :standard_user + visit category_path(category) + click_on 'Create Post' + + fill_in 'Body', with: 'This body should pass the minimum length requirements for questions in the meta category.' + post_form_select_tag tags(:faq).name + fill_in 'Summarize your post with a title:', with: 'Too short' + + # Check that the button is disabled + find_button "Save Post in #{category.name}", disabled: true + + # After filling out the title, verify that the button becomes enabled + fill_in 'Summarize your post with a title:', with: 'Updated title is of sufficient length' + find_button "Save Post in #{category.name}", disabled: false + end + + test 'Signed in user gets to pick post type for post creation in categories with multiple types' do + category = categories(:main) + log_in :standard_user + visit category_path(category) + click_on 'Create Post' + + # All the top level post types set should be present + category.post_types.where(is_top_level: true).each do |pt| + assert_link pt.name.underscore.humanize + end + + # Pick a non-question post type + post_type = category.post_types.where(is_top_level: true).where.not(name: 'Question').first + + # After clicking on a post type, we should be on the creation page of the correct category and post type. + click_on post_type.name.underscore.humanize + assert_current_path new_category_post_url(post_type.id, category.id) + end + + test 'Signed in user can answer question' do + log_in :standard_user + post = posts(:question_two) + visit post_path(post) + + # Answer the question + answer_text = 'You can do this by running the rails system tests, rails test:system.' + fill_in 'Body', with: answer_text + assert_difference 'Post.count' do + click_on "Save Post in #{post.category.name}" + end + + # We should now be looking at our answer, look for the text on the page + assert_text answer_text + + # The original post should also still be on the page + assert_text post.body + end # ------------------------------------------------------- # Show