aboutsummaryrefslogtreecommitdiff
path: root/test/system/comments_test.rb
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <msabate@suse.com>2024-03-13 18:03:43 +0100
committerMiquel Sabaté Solà <msabate@suse.com>2024-03-13 18:03:43 +0100
commita7791635aa98f012d35f97c3c5288494bbb28e38 (patch)
treebad987e6b4d10ad2f7cd02e40658d464907595ee /test/system/comments_test.rb
downloadoperum-a7791635aa98f012d35f97c3c5288494bbb28e38.tar.gz
operum-a7791635aa98f012d35f97c3c5288494bbb28e38.zip
Initial commit
Signed-off-by: Miquel Sabaté Solà <msabate@suse.com>
Diffstat (limited to 'test/system/comments_test.rb')
-rw-r--r--test/system/comments_test.rb103
1 files changed, 103 insertions, 0 deletions
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