Project

General

Profile

Patch #43397 » 0001-Add-functional-and-system-tests-for-current-Gantt-behaviour.patch

Katsuya HIDAKA, 2025-10-26 18:24

View differences:

test/functional/gantts_controller_test.rb
215 215
      assert_select 'div.gantt_hdr>a', :text => /^[\d-]+$/, :count => 6
216 216
    end
217 217
  end
218

  
219
  test 'renders project tree with child issues and bars' do
220
    prepare_stable_gantt_data
221

  
222
    @request.session[:user_id] = 2
223

  
224
    project = projects(:projects_001)
225

  
226
    get(:show, params: { project_id: project.id })
227
    assert_response :success
228

  
229
    # eCookbook
230
    assert_subject_row('div.project-name', row: '0', text: project.name)
231
    assert_chart_row('div.task.project.task_todo', row: '0', style_substring: 'left:0px;width:138px')
232

  
233
    assert_issue_row(3, 'Bug #3', row: '1')
234
    assert_chart_row('div.task.leaf.task_todo', row: '1', style_substring: 'left:0px;width:38px')
235

  
236
    assert_issue_row(7, 'Bug #7', row: '2')
237
    assert_chart_row('div.task.leaf.task_todo', row: '2', style_substring: 'left:16px;width:42px')
238

  
239
    assert_issue_row(1, 'Bug #1', row: '3')
240
    assert_chart_row('div.task.leaf.task_todo', row: '3', style_substring: 'left:52px;width:46px')
241

  
242
    # Version 1.0
243
    assert_subject_row('div#version-2', row: '4', text: '1.0')
244
    assert_chart_row('div.task.version', row: '4', style_substring: 'left:48px;width:90px')
245

  
246
    assert_issue_row(2, 'Feature request #2', row: '5')
247
    assert_chart_row('div.task.leaf.task_todo', row: '5', style_substring: 'left:48px;width:90px')
248

  
249
    # Private child of eCookbook
250
    assert_subject_row(
251
      'div.project-name[data-collapse-expand*="project-5"]',
252
      row: '6',
253
      text: projects(:projects_005).name
254
    )
255
    assert_chart_row('div.task.project.task_todo', row: '6', style_substring: 'left:56px;width:6px')
256

  
257
    assert_issue_row(6, 'Bug #6', row: '7')
258
    assert_chart_row('div.task.leaf.task_todo', row: '7', style_substring: 'left:56px;width:6px')
259

  
260
    assert_issue_row(9, 'Bug #9', row: '8')
261
    assert_chart_row('div.task.leaf.task_todo', row: '8', style_substring: 'left:56px;width:6px')
262

  
263
    assert_issue_row(10, 'Bug #10', row: '9')
264
    assert_chart_row('div.task.leaf.task_todo', row: '9', style_substring: 'left:56px;width:6px')
265
    assert_select 'div.task[id=?][data-rels*=9]', 'task-todo-issue-10'
266

  
267
    # eCookbook Subproject1
268
    assert_subject_row(
269
      'div.project-name[data-collapse-expand*="project-3"]',
270
      row: '10',
271
      text: projects(:projects_003).name
272
    )
273
    assert_issue_row(5, 'Bug #5', row: '11')
274
    assert_issue_row(13, 'Bug #13', row: '12')
275
    assert_issue_row(14, 'Bug #14', row: '13')
276
  end
277

  
278
  test 'renders chart with selected start month and year' do
279
    prepare_stable_gantt_data
280

  
281
    @request.session[:user_id] = 2
282

  
283
    project = projects(:projects_005)
284

  
285
    selected_start = User.current.today.prev_month.beginning_of_month
286
    get(
287
      :show,
288
      params: {
289
        project_id: project.id,
290
        month: selected_start.month,
291
        year: selected_start.year
292
      }
293
    )
294
    assert_response :success
295

  
296
    assert_select 'select#month option[selected=selected][value=?]', selected_start.month.to_s
297
    assert_select 'select#year option[selected=selected][value=?]', selected_start.year.to_s
298

  
299
    6.times do |offset|
300
      m = selected_start.since(offset.month)
301
      assert_select 'div.gantt_hdr > a', text: "#{m.year}-#{m.month}"
302
    end
303

  
304
    # eCookbook
305
    assert_subject_row('div.project-name', row: '0', text: projects(:projects_001).name)
306
    assert_chart_row('div.task.project.task_todo', row: '0', style_substring: 'left:0px;width:258px')
307

  
308
    # Private child of eCookbook
309
    assert_subject_row(
310
      'div.project-name[data-collapse-expand*="project-5"]',
311
      row: '1',
312
      text: project.name
313
    )
314
    assert_chart_row('div.task.project.task_todo', row: '1', style_substring: 'left:176px;width:6px')
315

  
316
    # Bug #6
317
    assert_issue_row(6, 'Bug #6', row: '2')
318
    assert_chart_row('div.task.leaf.task_todo', row: '2', style_substring: 'left:176px;width:6px')
319

  
320
    # Bug #9
321
    assert_issue_row(9, 'Bug #9', row: '3')
322
    assert_chart_row('div.task.leaf.task_todo', row: '3', style_substring: 'left:176px;width:6px')
323

  
324
    # Bug #10
325
    assert_issue_row(10, 'Bug #10', row: '4')
326
    assert_chart_row('div.task.leaf.task_todo', row: '4', style_substring: 'left:176px;width:6px')
327

  
328
    assert_select 'div.task[id=?][data-rels*=9]', 'task-todo-issue-10'
329
  end
330

  
331
  test 'shows six months starting from current month' do
332
    prepare_stable_gantt_data
333

  
334
    @request.session[:user_id] = 2
335

  
336
    project = projects(:projects_001)
337

  
338
    get :show, params: { project_id: project.id }
339
    assert_response :success
340

  
341
    start_of_month = User.current.today.beginning_of_month
342
    6.times do |offset|
343
      m = start_of_month.since(offset.months)
344

  
345
      assert_select 'div.gantt_hdr > a', text: "#{m.year}-#{m.month}"
346
    end
347

  
348
    assert_select 'input#months[value=?]', '6'
349
    assert_select 'select#month option[selected=selected][value=?]', User.current.today.month.to_s
350
    assert_select 'select#year option[selected=selected][value=?]', User.current.today.year.to_s
351
    assert_select 'input#zoom[value=?]', '2'
352
  end
353

  
354
  private
355

  
356
  def assert_subject_row(selector, row:, text:)
357
    assert_select "div.gantt_subjects form #{selector}[data-number-of-rows=?]", row do
358
      assert_select 'a', text: text
359
    end
360
  end
361

  
362
  def assert_issue_row(issue_id, link_text, row:)
363
    selector = "div.gantt_subjects form div#issue-#{issue_id}[data-number-of-rows=\"#{row}\"]"
364
    assert_select selector do
365
      assert_select 'a.issue', text: link_text
366
    end
367
  end
368

  
369
  def assert_chart_row(selector, row:, style_substring:)
370
    matcher = "#gantt_area #{selector}[data-number-of-rows=?][style*=?]"
371
    assert_select matcher, row, style_substring, minimum: 1
372
  end
373

  
374
  # Freezes today and resets the start and due dates of issues and versions in the eCookbook project and its descendants to fixed values
375
  # so the Gantt layout uses deterministic dates, bar positions stay stable across runs, and the tests remain easy to execute.
376
  def prepare_stable_gantt_data
377
    issues(:issues_003).update!(start_date: Date.new(2025, 9, 30), due_date: Date.new(2025, 10, 10))
378
    issues(:issues_007).update!(start_date: Date.new(2025, 10, 5), due_date: Date.new(2025, 10, 15))
379
    issues(:issues_001).update!(start_date: Date.new(2025, 10, 14), due_date: Date.new(2025, 10, 25))
380
    issues(:issues_002).update!(start_date: Date.new(2025, 10, 13), due_date: nil)
381
    issues(:issues_006).update!(start_date: Date.new(2025, 10, 15), due_date: Date.new(2025, 10, 16))
382
    issues(:issues_009).update!(start_date: Date.new(2025, 10, 15), due_date: Date.new(2025, 10, 16))
383
    issues(:issues_010).update!(start_date: Date.new(2025, 10, 15), due_date: Date.new(2025, 10, 16))
384

  
385
    Version.find(2).update!(effective_date: Date.new(2025, 11, 4))
386

  
387
    travel_to Date.new(2025, 10, 15)
388
  end
218 389
end
test/system/gantt_test.rb
1
# frozen_string_literal: true
2

  
3
require_relative '../application_system_test_case'
4

  
5
class GanttSystemTest < ApplicationSystemTestCase
6
  setup do
7
    log_user('jsmith', 'jsmith')
8
  end
9

  
10
  test 'columns display toggle shows status priority assignee updated' do
11
    visit_gantt
12
    expand_options
13

  
14
    assert_no_selector('td#status', visible: :visible)
15
    assert_no_selector('td#priority', visible: :visible)
16
    assert_no_selector('td#assigned_to', visible: :visible)
17
    assert_no_selector('td#updated_on', visible: :visible)
18

  
19
    find('#draw_selected_columns').check
20

  
21
    assert_selector('div.gantt_subjects_container.draw_selected_columns')
22
    assert_selector('td#status', visible: :visible)
23
    assert_selector('td#priority', visible: :visible)
24
    assert_selector('td#assigned_to', visible: :visible)
25
    assert_selector('td#updated_on', visible: :visible)
26
  end
27

  
28
  test 'related issues toggle displays and hides relation arrows' do
29
    visit_gantt
30
    expand_options
31

  
32
    assert_selector('#gantt_draw_area path', minimum: 1)
33

  
34
    find('#draw_relations').uncheck
35

  
36
    assert_no_selector('#gantt_draw_area path')
37

  
38
    find('#draw_relations').check
39

  
40
    assert_selector('#gantt_draw_area path', minimum: 1)
41
  end
42

  
43
  test 'progress line toggle draws zigzag line' do
44
    visit_gantt
45
    expand_options
46

  
47
    find('#draw_relations').uncheck
48
    assert_no_selector('#gantt_draw_area path')
49

  
50
    find('#draw_progress_line').check
51

  
52
    assert_selector('#gantt_draw_area path', minimum: 1)
53
  end
54

  
55
  test 'selected columns can be resized by dragging' do
56
    visit_gantt
57
    expand_options
58

  
59
    find('#draw_selected_columns').check
60

  
61
    width_before = column_width('status')
62
    drag_column_resizer('status', 80)
63
    width_after = column_width('status')
64

  
65
    assert width_after > width_before
66
  end
67

  
68
  test 'context menu and tooltip interactions' do
69
    visit_gantt
70

  
71
    issue_subject = find('div.issue-subject.hascontextmenu', match: :first)
72
    issue_reference = issue_subject.find('a.issue', match: :first).text
73
    task_area = find('div.tooltip.hascontextmenu', match: :first, visible: :all)
74

  
75
    task_area.hover
76
    assert_selector('div.tooltip span.tip', text: issue_reference, visible: :visible)
77

  
78
    issue_subject.right_click
79

  
80
    assert_selector('#context-menu', visible: :visible)
81
    assert_selector('#context-menu a.icon-edit', visible: :visible)
82

  
83
    page.send_keys(:escape)
84

  
85
    task_area = find('div.tooltip.hascontextmenu', match: :first, visible: :all)
86
    task_area.right_click
87

  
88
    assert_selector('#context-menu', visible: :visible)
89
    assert_selector('#context-menu a.icon-edit', visible: :visible)
90

  
91
    page.send_keys(:escape)
92
  end
93

  
94
  private
95

  
96
  def visit_gantt
97
    visit '/projects/ecookbook/issues/gantt'
98
  end
99

  
100
  def expand_options
101
    legend = find('fieldset#options legend')
102
    legend.click if legend[:class].to_s.include?('collapsed')
103
  end
104

  
105
  def column_width(id)
106
    page.evaluate_script("document.querySelector('td##{id}').offsetWidth")
107
  end
108

  
109
  def drag_column_resizer(column_id, distance)
110
    handle = find("td##{column_id} .ui-resizable-e", visible: :visible)
111
    page.driver.browser.action.click_and_hold(handle.native).move_by(distance, 0).release.perform
112
  end
113
end
(1-1/5)