From a7791635aa98f012d35f97c3c5288494bbb28e38 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Wed, 13 Mar 2024 18:03:43 +0100 Subject: Initial commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- test/system/comments_test.rb | 103 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 test/system/comments_test.rb (limited to 'test/system/comments_test.rb') diff --git a/test/system/comments_test.rb b/test/system/comments_test.rb new file mode 100644 index 0000000..b2490b4 --- /dev/null +++ b/test/system/comments_test.rb @@ -0,0 +1,103 @@ +# frozen_string_literal: true + +require 'application_system_test_case' + +class CommentsTest < ApplicationSystemTestCase + setup { sign_in! } + + ## + # In things#show + + test 'things#show: the hidden form is shown when clicking the proper button' do + visit thing_url(things(:thing1)) + + click_on I18n.t('comments.new') + assert_text I18n.t('tags.new-action'), count: 1 + + click_on I18n.t('general.cancel') + assert_text I18n.t('tags.new-action'), count: 0 + end + + test 'things#show: you can add a new comment' do + visit thing_url(things(:thing1)) + + click_on I18n.t('comments.new') + find(:css, '#comment_content').set('a new comment') + find("#comment_tag_ids_#{tags(:tag1).id}").click + find("#comment_tag_ids_#{tags(:tag2).id}").click + + click_on I18n.t('helpers.submit.create') + + assert_text "#{I18n.t('comments.title')} #2" + assert_text 'a new comment' + assert_text "#{I18n.t('tags.title')}: #{tags(:tag1).name}, #{tags(:tag2).name}" + assert page.current_path == thing_path(things(:thing1)) + end + + test 'things#show: you can update a comment' do + visit thing_url(things(:thing1)) + + click_on I18n.t('general.edit').capitalize + find(:css, '#comment_content').set('updated comment') + + find("#comment_#{comments(:comment1).id} input[type=submit]").click + assert_text 'updated comment' + assert page.current_path == thing_path(things(:thing1)) + end + + test 'things#show: you can delete a comment' do + visit thing_url(things(:thing1)) + + all('.delete-comment').last.click + assert_text I18n.t('comments.none') + assert page.current_path == thing_path(things(:thing1)) + end + + ## + # In things#edit + + test 'things#edit: the hidden form is shown when clicking the proper button' do + visit edit_thing_url(things(:thing1)) + + click_on I18n.t('comments.new') + assert_text I18n.t('tags.new-action'), count: 2 + + click_on I18n.t('general.cancel') + assert_text I18n.t('tags.new-action'), count: 1 + end + + test 'things#edit: you can add a new comment' do + visit edit_thing_url(things(:thing1)) + + click_on I18n.t('comments.new') + find(:css, '#comment_content').set('a new comment') + find("#comment_tag_ids_#{tags(:tag1).id}").click + find("#comment_tag_ids_#{tags(:tag2).id}").click + + click_on I18n.t('helpers.submit.create') + + assert_text "#{I18n.t('comments.title')} #2" + assert_text 'a new comment' + assert_text "#{I18n.t('tags.title')}: #{tags(:tag1).name}, #{tags(:tag2).name}" + assert page.current_path == edit_thing_path(things(:thing1)) + end + + test 'things#edit: you can update a comment' do + visit edit_thing_url(things(:thing1)) + + click_on I18n.t('general.edit').capitalize + find(:css, '#comment_content').set('updated comment') + + find("#comment_#{comments(:comment1).id} input[type=submit]").click + assert_text 'updated comment' + assert page.current_path == edit_thing_path(things(:thing1)) + end + + test 'things#edit: you can delete a comment' do + visit edit_thing_url(things(:thing1)) + + all('.delete-comment').last.click + assert_text I18n.t('comments.none') + assert page.current_path == edit_thing_path(things(:thing1)) + end +end -- cgit v1.2.3