diff options
Diffstat (limited to 'test/system')
| -rw-r--r-- | test/system/comments_test.rb | 103 | ||||
| -rw-r--r-- | test/system/exports_test.rb | 27 | ||||
| -rw-r--r-- | test/system/licenses_test.rb | 11 | ||||
| -rw-r--r-- | test/system/searches_test.rb | 123 | ||||
| -rw-r--r-- | test/system/sessions_test.rb | 27 | ||||
| -rw-r--r-- | test/system/shared_searches_test.rb | 34 | ||||
| -rw-r--r-- | test/system/tags_test.rb | 40 | ||||
| -rw-r--r-- | test/system/things_test.rb | 102 |
8 files changed, 467 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 diff --git a/test/system/exports_test.rb b/test/system/exports_test.rb new file mode 100644 index 0000000..b324321 --- /dev/null +++ b/test/system/exports_test.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'application_system_test_case' + +class ExportsTest < ApplicationSystemTestCase + setup do + sign_in! + end + + test 'can access exports from the hidden menu' do + find('#toggle-hidden-global-menu').click + assert_text I18n.t('searches.export.action') + + click_on I18n.t('searches.export.action') + assert_text I18n.t('searches.export.note-msg') + assert page.current_path == new_search_exports_path(0) + end + + test 'can export using multiple formats' do + visit new_search_exports_path(0) + + assert find('#export-format-button')[:href].ends_with?('/searches/0/exports.csv') + + find('#export-select-format').select('UOC') + assert find('#export-format-button')[:href].ends_with?('/searches/0/exports.uoc') + end +end diff --git a/test/system/licenses_test.rb b/test/system/licenses_test.rb new file mode 100644 index 0000000..1e26664 --- /dev/null +++ b/test/system/licenses_test.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'application_system_test_case' + +class LicensesTest < ApplicationSystemTestCase + test 'can reach #show without login' do + visit license_url + + assert_text 'AGPLv3' + end +end diff --git a/test/system/searches_test.rb b/test/system/searches_test.rb new file mode 100644 index 0000000..a400e71 --- /dev/null +++ b/test/system/searches_test.rb @@ -0,0 +1,123 @@ +# frozen_string_literal: true + +require 'application_system_test_case' + +class SearchesTest < ApplicationSystemTestCase + setup do + # All actions will require the user to be logged in. + sign_in! + end + + test 'root url is searches#index, which contains all things plus the tabs we expect' do + visit root_url + + # All searches are listed. + assert_text I18n.t('searches.home') + searches.each { |s| assert_text s.name } + + # All things are listed + things.each { |t| assert_text t.title } + end + + test 'the hidden menu should allow us to go into the searches#new url' do + find('#toggle-hidden-global-menu').click + assert_text I18n.t('searches.title') + + click_on I18n.t('searches.object') + assert find('#search_body') + assert page.current_path == new_search_path + end + + test 'can perform a new search' do + visit new_search_url + + # Fill in the body input and press enter, otherwise the javascript + # controller won't fire up. + fill_in 'search_body', with: 'Miquel' + find('#search_body').native.send_keys(:return) + + # It's actually a pretty generous search: it should give us all thing and a + # comment. + assert_text I18n.t('searches.save') + assert_text things(:thing1).title + assert_text things(:thing2).title + assert_text I18n.t('comments.title') + assert_text tags(:tag1).name + end + + test 'can save a new search' do + visit new_search_url + + # Fill in the body input and press enter, otherwise the javascript + # controller won't fire up. + fill_in 'search_body', with: 'Autor' + find('#search_body').native.send_keys(:return) + + # Hit the save button so the hidden form appears. + assert_text I18n.t('searches.save') + find('#save-search').click + assert_text I18n.t('searches.public') + + fill_in 'Name', with: 'Nova cerca' + click_on I18n.t('helpers.submit.create') + + assert_text 'Nova cerca' + assert page.current_path == search_path(Search.find_by(name: 'Nova cerca')) + end + + test 'can edit a search that is not the Home' do + # Home cannot be edited. + find('#toggle-hidden-global-menu').click + assert_selector 'a', text: I18n.t('general.edit'), count: 0 + + # Select search1 + click_on searches(:search1).name + assert_selector 'a', text: things(:thing1).title, count: 2 + find('#toggle-hidden-global-menu').click + + # It can be edited! + assert_text I18n.t('general.edit') + click_on I18n.t('general.edit') + + # If you click on it, you will be on the edit page for it. + assert find('#search_body') + assert page.current_path == edit_search_path(searches(:search1)) + end + + test 'edit an existing search works' do + visit edit_search_url(searches(:search1)) + + find('#search_body').native.send_keys(:return) + + # Hit the save button so the hidden form appears. + assert_text I18n.t('searches.save') + find('#save-search').click + assert_text I18n.t('searches.public') + + # Update the name. + fill_in 'Name', with: 'Nova cerca' + click_on I18n.t('helpers.submit.update') + + # We have been redirected to search#show, and the name has been refreshed. + assert_selector 'a', text: searches(:search1).name, count: 0 + assert_text 'Nova cerca' + assert page.current_path == search_path(searches(:search1)) + end + + test 'can delete a search that is not the Home' do + # Home cannot be deleted. + find('#toggle-hidden-global-menu').click + assert_selector 'a', text: I18n.t('general.delete'), count: 0 + + # Select search1 + click_on searches(:search1).name + assert_selector 'a', text: things(:thing1).title, count: 2 + find('#toggle-hidden-global-menu').click + + # It can be deleted! + assert_text I18n.t('general.delete') + accept_alert { click_on I18n.t('general.delete') } + assert_selector 'a', text: searches(:search1).name, count: 0 + assert Search.none? + end +end diff --git a/test/system/sessions_test.rb b/test/system/sessions_test.rb new file mode 100644 index 0000000..2d01eef --- /dev/null +++ b/test/system/sessions_test.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'application_system_test_case' + +class SessionsTest < ApplicationSystemTestCase + test 'logs in successfully' do + sign_in! + end + + test 'fails to log in with wrong password' do + visit new_sessions_url + + fill_in I18n.t('activerecord.attributes.user.username'), with: users(:user).username + fill_in I18n.t('activerecord.attributes.user.password'), with: 'I AM ERROR' + click_on I18n.t('sessions.sign-in') + + assert_text I18n.t('sessions.wrong-credentials') + end + + test 'logs out successfully' do + sign_in! + + click_on I18n.t('sessions.sign-out') + + assert_text I18n.t('sessions.title') + end +end diff --git a/test/system/shared_searches_test.rb b/test/system/shared_searches_test.rb new file mode 100644 index 0000000..0cfc4bd --- /dev/null +++ b/test/system/shared_searches_test.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +require 'application_system_test_case' + +class SharedSearchesTest < ApplicationSystemTestCase + test 'can access shared_searches#index from the hidden menu' do + sign_in! + + find('#toggle-hidden-global-menu').click + assert_text I18n.t('searches.shared.title').downcase + + click_on I18n.t('searches.shared.title').downcase + assert_text I18n.t('searches.shared.none') + end + + test 'cannot access shared_searches#index if not logged in' do + sign_out_maybe! + + visit shared_searches_path + assert_text I18n.t('sessions.title') + assert page.current_path == new_sessions_path + end + + test 'shared_searches#show gives us the expected results' do + # NOTE: not logged in! + + searches(:search1).update!(shared: true) + + visit search_shared_path(searches(:search1)) + assert_text things(:thing1).title + assert_text things(:thing2).title + assert_text I18n.t('comments.title') + end +end diff --git a/test/system/tags_test.rb b/test/system/tags_test.rb new file mode 100644 index 0000000..1ee83a9 --- /dev/null +++ b/test/system/tags_test.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +require 'application_system_test_case' + +class SharedSearchesTest < ApplicationSystemTestCase + setup { sign_in! } + + test 'lists all the tags' do + visit tags_url + + tags.each { |t| assert_text t.name } + end + + test 'can create a new tag' do + visit new_tag_url + + fill_in I18n.t('activerecord.attributes.tag.name'), with: 'whatever' + assert_difference 'Tag.count' do + click_on I18n.t('helpers.submit.create') + assert_text 'whatever' + end + end + + test 'gives feedback on errors' do + visit new_tag_url + + fill_in I18n.t('activerecord.attributes.tag.name'), with: tags(:tag1).name + click_on I18n.t('helpers.submit.create') + assert_text "#{I18n.t('activerecord.attributes.tag.name')} #{I18n.t('errors.messages.taken')}" + end + + test 'can delete an existing tag' do + visit tags_url + + assert_difference 'Tag.count', -1 do + click_link(I18n.t('general.delete'), match: :first) + assert_text I18n.t('tags.title') + end + end +end diff --git a/test/system/things_test.rb b/test/system/things_test.rb new file mode 100644 index 0000000..9dd482d --- /dev/null +++ b/test/system/things_test.rb @@ -0,0 +1,102 @@ +# frozen_string_literal: true + +require 'application_system_test_case' + +class ThingsTest < ApplicationSystemTestCase + setup { sign_in! } + + test 'the hidden menu has a things#new link' do + find('#toggle-hidden-global-menu').click + assert_text I18n.t('things.object').downcase + + click_on I18n.t('things.object').downcase + assert_text I18n.t('activerecord.attributes.thing.title') + + assert page.current_path == new_thing_path + end + + test 'you can click on a thing listed on the search to go to the its #show page' do + click_on things(:thing1).title + + assert_text I18n.t('activerecord.attributes.thing.title') + + assert page.current_path == edit_thing_path(things(:thing1)) + end + + test 'you can create a new thing' do + visit new_thing_url + + fill_in I18n.t('activerecord.attributes.thing.title'), with: 'new title' + fill_in I18n.t('activerecord.attributes.thing.authors'), with: 'author' + fill_in I18n.t('activerecord.attributes.thing.target'), with: 'identifier' + fill_in I18n.t('activerecord.attributes.thing.rate'), with: 5 + find("#thing_tag_ids_#{tags(:tag1).id}").click + + click_on I18n.t('helpers.submit.create') + + assert_text I18n.t('things.create-success') + + # Ensure that tag references are properly created. + tags = Thing.find_by(title: 'new title').tags + assert tags.size == 1 + assert tags.first.name == tags(:tag1).name + + # You can go back to create another thing with a convenient link. + click_on I18n.t('things.create-another') + assert_text I18n.t('activerecord.attributes.thing.title') + assert page.current_path == new_thing_path + end + + test 'you get feedback from wrong values for a new thing' do + visit new_thing_url + + fill_in I18n.t('activerecord.attributes.thing.title'), with: things(:thing1).title + fill_in I18n.t('activerecord.attributes.thing.authors'), with: 'author' + fill_in I18n.t('activerecord.attributes.thing.target'), with: 'identifier' + fill_in I18n.t('activerecord.attributes.thing.rate'), with: 5 + find("#thing_tag_ids_#{tags(:tag1).id}").click + + click_on I18n.t('helpers.submit.create') + + assert_text "#{I18n.t('activerecord.attributes.thing.title')} " \ + "#{I18n.t('errors.messages.taken')}" + end + + test 'you can update a value from a thing' do + visit edit_thing_url(things(:thing1)) + + # Originally :thing1 has references to :tag1 and :tag2. This test will + # remove the reference to :tag1. + assert things(:thing1).tag_references.size == 2 + + fill_in I18n.t('activerecord.attributes.thing.title'), with: 'another thing entirely' + find("#thing_tag_ids_#{tags(:tag1).id}").click + click_on I18n.t('helpers.submit.update') + + assert_text I18n.t('things.update-success') + + # Tag references updated: only one reference (:tag2). + tags = things(:thing1).reload.tags + assert tags.size == 1 + assert tags.first.id = tags(:tag2).id + end + + test 'you get feedback from wrong values for a thing' do + visit edit_thing_url(things(:thing1)) + + fill_in I18n.t('activerecord.attributes.thing.title'), with: things(:thing2).title + click_on I18n.t('helpers.submit.update') + + assert_text "#{I18n.t('activerecord.attributes.thing.title')} " \ + "#{I18n.t('errors.messages.taken')}" + end + + test 'you can delete a thing' do + visit edit_thing_url(things(:thing1)) + + assert_difference 'Thing.count', -1 do + accept_alert { click_on I18n.t('general.delete').capitalize, match: :first } + assert_text I18n.t('things.destroy-success') + end + end +end |
