1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# 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_equal 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_equal 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_equal 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_equal 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_predicate Search, :none?
end
end
|