Skip to content

Commit 79a44ad

Browse files
committed
Some more test fixing.. There is light and the end of the tunnel :fingers_crossed:
1 parent b943d56 commit 79a44ad

File tree

4 files changed

+73
-66
lines changed

4 files changed

+73
-66
lines changed

app/components/open_project/common/inplace_edit_fields/display_fields/calculated_value_input_component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def render_calculation_error
4949

5050
render(Primer::OpenProject::FlexLayout.new(
5151
align_items: :flex_start,
52-
data: { test_selector: "error-cf-#{custom_field.id}" }
52+
data: { test_selector: "error--custom_field_#{custom_field.id}" }
5353
)) do |container|
5454
container.with_column do
5555
render Primer::Beta::Octicon.new(icon: :"alert-fill", color: :danger)

spec/features/projects/project_custom_fields/overview_page/inputs_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,15 @@ def dialog = overview_page.open_modal_for_custom_field(custom_field).dialog
158158
shared_examples "a rich text custom field input" do
159159
it "shows the correct value if given" do
160160
dialog.within_async_content(close_after_yield: true) do
161-
field.expect_value(expected_initial_value)
161+
form_field.expect_value(expected_initial_value)
162162
end
163163
end
164164

165165
it "shows a blank input if no value or default value is given" do
166166
custom_field.custom_values.destroy_all
167167

168168
dialog.within_async_content(close_after_yield: true) do
169-
field.expect_value(expected_blank_value)
169+
form_field.expect_value(expected_blank_value)
170170
end
171171
end
172172

@@ -175,7 +175,7 @@ def dialog = overview_page.open_modal_for_custom_field(custom_field).dialog
175175
custom_field.update!(default_value:)
176176

177177
dialog.within_async_content(close_after_yield: true) do
178-
field.expect_value(default_value)
178+
form_field.expect_value(default_value)
179179
end
180180
end
181181

@@ -244,7 +244,7 @@ def dialog = overview_page.open_modal_for_custom_field(custom_field).dialog
244244
let(:default_value) { "https://openproject.org" }
245245
let(:expected_blank_value) { "" }
246246
let(:expected_initial_value) { "https://www.openproject.org" }
247-
let(:field) { FormFields::Primerized::InputField.new(custom_field) }
247+
let(:form_field) { FormFields::Primerized::InputField.new(custom_field) }
248248

249249
it_behaves_like "a custom field input"
250250

spec/features/projects/project_custom_fields/overview_page/validation_spec.rb

Lines changed: 55 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,22 @@
4646
it "keeps showing only activated custom fields (tricky regression)" do
4747
custom_field = string_project_custom_field
4848
custom_field.update!(is_required: true)
49-
field = FormFields::Primerized::InputField.new(custom_field)
49+
form_field = FormFields::Primerized::InputField.new(custom_field)
5050

51-
dialog = overview_page.open_modal_for_custom_field(custom_field)
51+
field = overview_page.open_inplace_edit_field_for_custom_field(custom_field)
5252

53-
dialog.within_async_content do
53+
field.within_field do
5454
expect(page).to have_text("String field")
5555
expect(page).to have_no_text(boolean_project_custom_field_activated_in_other_project.name)
5656
end
5757

58-
field.fill_in(with: "") # this will trigger the validation
58+
form_field.fill_in(with: "") # this will trigger the validation
5959

60-
dialog.submit
60+
field.submit
6161

62-
field.expect_error(I18n.t("activerecord.errors.messages.blank"))
62+
form_field.expect_error(I18n.t("activerecord.errors.messages.blank"))
6363

64-
dialog.within_async_content do
64+
field.within_field do
6565
expect(page).to have_text("String field")
6666
expect(page).to have_no_text(boolean_project_custom_field_activated_in_other_project.name)
6767
end
@@ -71,9 +71,9 @@
7171
shared_examples "keeps the unpersisted values" do
7272
it "keeps the value" do
7373
invalid_custom_field.update!(is_required: true)
74-
dialog = overview_page.open_modal_for_custom_field(invalid_custom_field)
74+
field = overview_page.open_inplace_edit_field_for_custom_field(invalid_custom_field)
7575
invalid_field.clear
76-
dialog.submit
76+
field.submit
7777

7878
invalid_field.expect_error(I18n.t("activerecord.errors.messages.blank"))
7979
invalid_field.expect_blank
@@ -147,25 +147,19 @@
147147
end
148148

149149
describe "editing multiple fields" do
150-
let(:input_fields_dialog) do
151-
Components::Projects::ProjectCustomFields::Dialog.new(project, section_for_input_fields)
152-
end
153-
let(:select_fields_dialog) do
154-
Components::Projects::ProjectCustomFields::Dialog.new(project, section_for_select_fields)
155-
end
156-
let(:field) { FormFields::Primerized::AutocompleteField.new(list_project_custom_field) }
150+
let(:form_field) { FormFields::Primerized::AutocompleteField.new(list_project_custom_field) }
157151

158152
it "displays validation errors, when the previous modal was canceled (Regression)" do
159153
list_project_custom_field.update!(is_required: true)
160154
list_project_custom_field.custom_values.destroy_all
161155

162-
dialog = overview_page.open_modal_for_custom_field(string_project_custom_field)
163-
dialog.close
156+
field = overview_page.open_inplace_edit_field_for_custom_field(string_project_custom_field)
157+
field.close
164158

165-
dialog = overview_page.open_modal_for_custom_field(list_project_custom_field)
166-
dialog.submit
159+
field = overview_page.open_inplace_edit_field_for_custom_field(list_project_custom_field)
160+
field.submit
167161

168-
field.expect_error(I18n.t("activerecord.errors.messages.blank"))
162+
form_field.expect_error(I18n.t("activerecord.errors.messages.blank"))
169163
end
170164

171165
context "with required custom fields in different sections" do
@@ -185,44 +179,44 @@
185179

186180
it "validates required fields only within their respective sections" do
187181
# Test 1: Multi-select field can be saved even when other required fields are invalid
188-
multi_list_field_dialog =
189-
overview_page.open_modal_for_custom_field(multi_list_project_custom_field)
182+
multi_list_inplace_field =
183+
overview_page.open_inplace_edit_field_for_custom_field(multi_list_project_custom_field)
190184

191-
multi_list_field_dialog.submit
192-
multi_list_field_dialog.expect_closed
185+
multi_list_inplace_field.submit
186+
multi_list_inplace_field.expect_closed
193187

194188
# Test 2: Edit the required string field
195-
string_field_dialog =
196-
overview_page.open_modal_for_custom_field(string_project_custom_field)
189+
string_field_inplace_field =
190+
overview_page.open_inplace_edit_field_for_custom_field(string_project_custom_field)
197191

198192
# Submit without filling - should show error
199-
string_field_dialog.submit
193+
string_field_inplace_field.submit
200194
string_field.expect_error(I18n.t("activerecord.errors.messages.blank"))
201-
string_field_dialog.close
195+
string_field_inplace_field.close
202196

203197
# Test 3: Edit the required list field
204-
list_field_dialog =
205-
overview_page.open_modal_for_custom_field(list_project_custom_field)
198+
list_field_inplace_field =
199+
overview_page.open_inplace_edit_field_for_custom_field(list_project_custom_field)
206200

207201
# Submit without filling - should show error
208-
list_field_dialog.submit
202+
list_field_inplace_field.submit
209203
list_field.expect_error(I18n.t("activerecord.errors.messages.blank"))
210204

211205
# Test 4: Fill required field and submit successfully
212206
list_field.select_option("Option 1")
213-
list_field_dialog.submit
214-
list_field_dialog.expect_closed
207+
list_field_inplace_field.submit
208+
list_field_inplace_field.expect_closed
215209

216210
# Test 5: The required string field dialog still fails validation when empty
217-
string_field_dialog =
218-
overview_page.open_modal_for_custom_field(string_project_custom_field)
219-
string_field_dialog.submit
211+
string_field_inplace_field =
212+
overview_page.open_inplace_edit_field_for_custom_field(string_project_custom_field)
213+
string_field_inplace_field.submit
220214
string_field.expect_error(I18n.t("activerecord.errors.messages.blank"))
221215

222216
# Test 6: Complete the required string field and expect to pass validation
223217
string_field.fill_in(with: "Test value")
224-
string_field_dialog.submit
225-
string_field_dialog.expect_closed
218+
string_field_inplace_field.submit
219+
string_field_inplace_field.expect_closed
226220
end
227221
end
228222
end
@@ -233,47 +227,47 @@
233227
custom_field.update!(is_required: true)
234228
custom_field.custom_values.destroy_all
235229

236-
dialog = overview_page.open_modal_for_custom_field(custom_field)
230+
field = overview_page.open_inplace_edit_field_for_custom_field(custom_field)
237231

238-
dialog.submit
232+
field.submit
239233

240-
field.expect_error(I18n.t("activerecord.errors.messages.blank"))
234+
form_field.expect_error(I18n.t("activerecord.errors.messages.blank"))
241235
end
242236
end
243237

244238
# boolean CFs can not be validated
245239

246240
describe "with string CF" do
247241
let(:custom_field) { string_project_custom_field }
248-
let(:field) { FormFields::Primerized::InputField.new(custom_field) }
242+
let(:form_field) { FormFields::Primerized::InputField.new(custom_field) }
249243

250244
it_behaves_like "a custom field input"
251245
end
252246

253247
describe "with integer CF" do
254248
let(:custom_field) { integer_project_custom_field }
255-
let(:field) { FormFields::Primerized::InputField.new(custom_field) }
249+
let(:form_field) { FormFields::Primerized::InputField.new(custom_field) }
256250

257251
it_behaves_like "a custom field input"
258252
end
259253

260254
describe "with float CF" do
261255
let(:custom_field) { float_project_custom_field }
262-
let(:field) { FormFields::Primerized::InputField.new(custom_field) }
256+
let(:form_field) { FormFields::Primerized::InputField.new(custom_field) }
263257

264258
it_behaves_like "a custom field input"
265259
end
266260

267261
describe "with date CF" do
268262
let(:custom_field) { date_project_custom_field }
269-
let(:field) { FormFields::Primerized::InputField.new(custom_field) }
263+
let(:form_field) { FormFields::Primerized::InputField.new(custom_field) }
270264

271265
it_behaves_like "a custom field input"
272266
end
273267

274268
describe "with text CF" do
275269
let(:custom_field) { text_project_custom_field }
276-
let(:field) { FormFields::Primerized::EditorFormField.new(custom_field) }
270+
let(:form_field) { FormFields::Primerized::EditorFormField.new(custom_field) }
277271

278272
it_behaves_like "a custom field input"
279273
end
@@ -283,11 +277,11 @@
283277
it "allows saving the dialog even if the calculated custom field is invalid" do
284278
custom_field.custom_values.destroy_all
285279

286-
dialog = overview_page.open_modal_for_custom_field(custom_field)
280+
field = overview_page.open_inplace_edit_field_for_custom_field(custom_field)
287281

288-
dialog.submit
282+
field.submit
289283

290-
dialog.expect_closed
284+
field.expect_closed
291285
end
292286

293287
it "displays the custom field label without the required asterisk" do
@@ -331,31 +325,31 @@
331325
custom_field.update!(is_required: true)
332326
custom_field.custom_values.destroy_all
333327

334-
dialog = overview_page.open_modal_for_custom_field(custom_field)
328+
dialog = overview_page.open_inplace_edit_field_for_custom_field(custom_field)
335329

336330
dialog.submit
337331

338-
field.expect_error(I18n.t("activerecord.errors.messages.blank"))
332+
form_field.expect_error(I18n.t("activerecord.errors.messages.blank"))
339333
end
340334
end
341335

342336
describe "with list CF" do
343337
let(:custom_field) { list_project_custom_field }
344-
let(:field) { FormFields::Primerized::AutocompleteField.new(custom_field) }
338+
let(:form_field) { FormFields::Primerized::AutocompleteField.new(custom_field) }
345339

346340
it_behaves_like "a custom field select"
347341
end
348342

349343
describe "with version CF" do
350344
let(:custom_field) { version_project_custom_field }
351-
let(:field) { FormFields::Primerized::AutocompleteField.new(custom_field) }
345+
let(:form_field) { FormFields::Primerized::AutocompleteField.new(custom_field) }
352346

353347
it_behaves_like "a custom field select"
354348
end
355349

356350
describe "with user CF" do
357351
let(:custom_field) { user_project_custom_field }
358-
let(:field) { FormFields::Primerized::AutocompleteField.new(custom_field) }
352+
let(:form_field) { FormFields::Primerized::AutocompleteField.new(custom_field) }
359353

360354
it_behaves_like "a custom field select"
361355
end
@@ -367,31 +361,31 @@
367361
custom_field.update!(is_required: true)
368362
custom_field.custom_values.destroy_all
369363

370-
dialog = overview_page.open_modal_for_custom_field(custom_field)
364+
field = overview_page.open_inplace_edit_field_for_custom_field(custom_field)
371365

372-
dialog.submit
366+
field.submit
373367

374-
field.expect_error(I18n.t("activerecord.errors.messages.blank"))
368+
form_field.expect_error(I18n.t("activerecord.errors.messages.blank"))
375369
end
376370
end
377371

378372
describe "with multi list CF" do
379373
let(:custom_field) { multi_list_project_custom_field }
380-
let(:field) { FormFields::Primerized::AutocompleteField.new(custom_field) }
374+
let(:form_field) { FormFields::Primerized::AutocompleteField.new(custom_field) }
381375

382376
it_behaves_like "a custom field multi select"
383377
end
384378

385379
describe "with multi version CF" do
386380
let(:custom_field) { multi_version_project_custom_field }
387-
let(:field) { FormFields::Primerized::AutocompleteField.new(custom_field) }
381+
let(:form_field) { FormFields::Primerized::AutocompleteField.new(custom_field) }
388382

389383
it_behaves_like "a custom field multi select"
390384
end
391385

392386
describe "with multi user CF" do
393387
let(:custom_field) { multi_user_project_custom_field }
394-
let(:field) { FormFields::Primerized::AutocompleteField.new(custom_field) }
388+
let(:form_field) { FormFields::Primerized::AutocompleteField.new(custom_field) }
395389

396390
it_behaves_like "a custom field multi select"
397391
end

spec/support/components/common/inplace_edit_field.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@ def click_help_text_link_for_label(label_text)
9595
link.click
9696
end
9797

98+
def expect_error(string)
99+
within_field do
100+
expect(page).to have_css(".FormControl-inlineValidation", text: string)
101+
end
102+
end
103+
104+
def expect_calculation_error(string)
105+
within_field do
106+
expect(page).to have_test_selector("error--#{attribute.name}")
107+
expect(page).to have_content(string)
108+
end
109+
end
110+
98111
def fill_and_submit_value(name:, val:, ckeditor: false)
99112
if ckeditor
100113
find(".ck-content").base.send_keys val

0 commit comments

Comments
 (0)