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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
# 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_equal 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_equal 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_equal tags.map(&:name), [tags(:tag1).name]
end
test 'you have a link to go back at creating a thing' do
visit thing_url(things(:thing1))
click_on I18n.t('things.create-another')
assert_text I18n.t('activerecord.attributes.thing.title')
assert_equal 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: 'whatever title'
fill_in I18n.t('activerecord.attributes.thing.authors'), with: 'author'
fill_in I18n.t('activerecord.attributes.thing.target'), with: things(:thing1).target
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.target')} " \
"#{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_equal 2, things(:thing1).tag_references.size
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_equal tags.map(&:id), [tags(:tag2).id]
end
test 'you get feedback from wrong values when updating a thing' do
visit edit_thing_url(things(:thing1))
fill_in I18n.t('activerecord.attributes.thing.target'), with: things(:thing2).target
click_on I18n.t('helpers.submit.update')
assert_text "#{I18n.t('activerecord.attributes.thing.target')} " \
"#{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
test '"access" appears/disappears whenever "url" is set/unset' do
visit edit_thing_url(things(:thing1))
assert_text I18n.t('activerecord.attributes.thing.access')
fill_in I18n.t('activerecord.attributes.thing.url'), with: ''
assert_text I18n.t('activerecord.attributes.thing.access'), count: 0
fill_in I18n.t('activerecord.attributes.thing.url'), with: 'whatever'
assert_text I18n.t('activerecord.attributes.thing.access')
end
test 'js: "target" gets generated from last name' do
visit new_thing_url
fill_in I18n.t('activerecord.attributes.thing.authors'), with: 'Name LastName'
text = find_field(I18n.t('activerecord.attributes.thing.target')).value
assert_equal 'LastName', text
end
test 'js: "target" gets generated from last name and year' do
visit new_thing_url
fill_in I18n.t('activerecord.attributes.thing.authors'), with: 'Name LastName'
fill_in I18n.t('activerecord.attributes.thing.year'), with: '2024'
text = find_field(I18n.t('activerecord.attributes.thing.target')).value
assert_equal 'LastName2024', text
end
test 'js: "target" gets generated from multiple names and year' do
visit new_thing_url
fill_in I18n.t('activerecord.attributes.thing.authors'), with: 'Name LastName, John Smith'
fill_in I18n.t('activerecord.attributes.thing.year'), with: '2024'
text = find_field(I18n.t('activerecord.attributes.thing.target')).value
assert_equal 'LastNameSmith2024', text
end
test 'js: hyphenated names are treated together on "target" automation' do
visit new_thing_url
fill_in I18n.t('activerecord.attributes.thing.authors'), with: 'Name Last-Other, John Smith'
fill_in I18n.t('activerecord.attributes.thing.year'), with: '2024'
text = find_field(I18n.t('activerecord.attributes.thing.target')).value
assert_equal 'LastOtherSmith2024', text
end
test 'js: names surrounded by underscores are treated together on "target" automation' do
visit new_thing_url
fill_in I18n.t('activerecord.attributes.thing.authors'), with: 'Name _Last Other_, John Smith'
fill_in I18n.t('activerecord.attributes.thing.year'), with: '2024'
text = find_field(I18n.t('activerecord.attributes.thing.target')).value
assert_equal 'LastOtherSmith2024', text
end
end
|