| 2 |
2 |
|
| 3 |
3 |
require_relative '../application_system_test_case'
|
| 4 |
4 |
|
| 5 |
|
class ListIndentSystemTest < ApplicationSystemTestCase
|
|
5 |
class SelectionIndentSystemTest < ApplicationSystemTestCase
|
| 6 |
6 |
def setup
|
| 7 |
7 |
super
|
| 8 |
8 |
log_user('jsmith', 'jsmith')
|
| 9 |
9 |
end
|
| 10 |
10 |
|
| 11 |
|
# Tab: inserts 2 spaces for bullet lists, 4 spaces for ordered lists
|
| 12 |
|
def test_tab_indents_common_mark_bullet_list
|
|
11 |
def test_tab_indents_selected_text
|
| 13 |
12 |
with_settings :text_formatting => 'common_mark' do
|
| 14 |
13 |
visit '/projects/ecookbook/issues/new'
|
| 15 |
14 |
|
| 16 |
15 |
within('form#issue-form') do
|
|
16 |
text = "hello"
|
| 17 |
17 |
el = find('#issue_description')
|
| 18 |
18 |
el.click
|
| 19 |
|
set_textarea_value 'issue_description', "- item", selection: [0, text.length]
|
|
19 |
set_textarea_value 'issue_description', text, selection: [0, text.length]
|
| 20 |
20 |
el.send_keys(:tab)
|
| 21 |
|
assert_equal " - item", el.value
|
|
21 |
assert_equal " hello", el.value
|
| 22 |
22 |
end
|
| 23 |
23 |
end
|
| 24 |
24 |
end
|
| 25 |
25 |
|
| 26 |
|
def test_tab_indents_common_mark_ordered_list
|
|
26 |
def test_tab_indents_multiple_selected_lines
|
| 27 |
27 |
with_settings :text_formatting => 'common_mark' do
|
| 28 |
28 |
visit '/projects/ecookbook/issues/new'
|
| 29 |
29 |
|
| 30 |
30 |
within('form#issue-form') do
|
|
31 |
text = "hello\nworld"
|
| 31 |
32 |
el = find('#issue_description')
|
| 32 |
33 |
el.click
|
| 33 |
|
set_textarea_value 'issue_description', "1. item", selection: [0, text.length]
|
|
34 |
set_textarea_value 'issue_description', text, selection: [0, text.length]
|
| 34 |
35 |
el.send_keys(:tab)
|
| 35 |
|
assert_equal " 1. item", el.value
|
|
36 |
assert_equal " hello\n world", el.value
|
| 36 |
37 |
end
|
| 37 |
38 |
end
|
| 38 |
39 |
end
|
| 39 |
40 |
|
| 40 |
|
# Shift+Tab: removes indentation
|
| 41 |
|
def test_shift_tab_unindents_common_mark_bullet_list
|
|
41 |
def test_tab_indents_only_lines_within_selection
|
| 42 |
42 |
with_settings :text_formatting => 'common_mark' do
|
| 43 |
43 |
visit '/projects/ecookbook/issues/new'
|
| 44 |
44 |
|
| 45 |
45 |
within('form#issue-form') do
|
|
46 |
text = "line1\nline2\nline3"
|
|
47 |
start = text.index("line2")
|
| 46 |
48 |
el = find('#issue_description')
|
| 47 |
49 |
el.click
|
| 48 |
|
set_textarea_value 'issue_description', "- parent\n - child", selection: [0, text.length]
|
| 49 |
|
el.send_keys([:shift, :tab])
|
| 50 |
|
assert_equal "- parent\n- child", el.value
|
| 51 |
|
end
|
| 52 |
|
end
|
| 53 |
|
end
|
| 54 |
|
|
| 55 |
|
def test_shift_tab_removes_partial_indent_on_common_mark_list
|
| 56 |
|
# Removes only as many spaces as exist when indent is less than the step size
|
| 57 |
|
with_settings :text_formatting => 'common_mark' do
|
| 58 |
|
visit '/projects/ecookbook/issues/new'
|
| 59 |
|
|
| 60 |
|
within('form#issue-form') do
|
| 61 |
|
el = find('#issue_description')
|
| 62 |
|
el.click
|
| 63 |
|
set_textarea_value 'issue_description', "- parent\n - child", selection: [0, text.length]
|
| 64 |
|
el.send_keys([:shift, :tab])
|
| 65 |
|
assert_equal "- parent\n- child", el.value
|
| 66 |
|
end
|
| 67 |
|
end
|
| 68 |
|
end
|
| 69 |
|
|
| 70 |
|
def test_shift_tab_does_nothing_on_common_mark_list_with_no_indent
|
| 71 |
|
with_settings :text_formatting => 'common_mark' do
|
| 72 |
|
visit '/projects/ecookbook/issues/new'
|
| 73 |
|
|
| 74 |
|
within('form#issue-form') do
|
| 75 |
|
el = find('#issue_description')
|
| 76 |
|
el.click
|
| 77 |
|
set_textarea_value 'issue_description', "- item", selection: [0, text.length]
|
| 78 |
|
el.send_keys([:shift, :tab])
|
| 79 |
|
assert_equal "- item", el.value
|
|
50 |
set_textarea_value 'issue_description', text, selection: [start, start + "line2".length]
|
|
51 |
el.send_keys(:tab)
|
|
52 |
assert_equal "line1\n line2\nline3", el.value
|
| 80 |
53 |
end
|
| 81 |
54 |
end
|
| 82 |
55 |
end
|
| 83 |
56 |
|
| 84 |
|
def test_tab_indents_multiple_lines_when_selected
|
|
57 |
def test_tab_does_not_indent_without_selection
|
| 85 |
58 |
with_settings :text_formatting => 'common_mark' do
|
| 86 |
59 |
visit '/projects/ecookbook/issues/new'
|
| 87 |
60 |
|
| 88 |
61 |
within('form#issue-form') do
|
|
62 |
fill_in 'Description', with: "hello"
|
| 89 |
63 |
el = find('#issue_description')
|
| 90 |
64 |
el.click
|
| 91 |
|
set_textarea_value 'issue_description', "- item1\n- item2", selection: [0, text.length]
|
| 92 |
65 |
el.send_keys(:tab)
|
| 93 |
|
assert_equal " - item1\n - item2", el.value
|
|
66 |
assert_equal "hello", el.value
|
| 94 |
67 |
end
|
| 95 |
68 |
end
|
| 96 |
69 |
end
|
| 97 |
70 |
|
| 98 |
|
def test_tab_does_not_indent_without_list_or_selection
|
|
71 |
def test_shift_tab_unindents_selected_text
|
| 99 |
72 |
with_settings :text_formatting => 'common_mark' do
|
| 100 |
73 |
visit '/projects/ecookbook/issues/new'
|
| 101 |
74 |
|
| 102 |
75 |
within('form#issue-form') do
|
| 103 |
|
fill_in 'Description', with: "normal text"
|
|
76 |
text = " hello\n world"
|
| 104 |
77 |
el = find('#issue_description')
|
| 105 |
78 |
el.click
|
| 106 |
|
el.send_keys(:tab)
|
| 107 |
|
assert_equal "normal text", el.value
|
|
79 |
set_textarea_value 'issue_description', text, selection: [0, text.length]
|
|
80 |
el.send_keys([:shift, :tab])
|
|
81 |
assert_equal "hello\nworld", el.value
|
| 108 |
82 |
end
|
| 109 |
83 |
end
|
| 110 |
84 |
end
|
| 111 |
85 |
|
| 112 |
|
def test_tab_indents_only_selected_lines_block
|
|
86 |
def test_shift_tab_removes_partial_indent
|
|
87 |
# Removes only as many spaces as exist when indent is less than the step size
|
| 113 |
88 |
with_settings :text_formatting => 'common_mark' do
|
| 114 |
89 |
visit '/projects/ecookbook/issues/new'
|
| 115 |
90 |
|
| 116 |
91 |
within('form#issue-form') do
|
| 117 |
|
text = "- item1\n- item2\n- item3"
|
| 118 |
|
start = text.index("- item2")
|
| 119 |
|
finish = start + "- item2".length
|
|
92 |
text = " hello\n world"
|
| 120 |
93 |
el = find('#issue_description')
|
| 121 |
94 |
el.click
|
| 122 |
|
set_textarea_value 'issue_description', text, selection: [start, finish]
|
| 123 |
|
el.send_keys(:tab)
|
| 124 |
|
assert_equal "- item1\n - item2\n- item3", el.value
|
|
95 |
set_textarea_value 'issue_description', text, selection: [0, text.length]
|
|
96 |
el.send_keys([:shift, :tab])
|
|
97 |
assert_equal "hello\nworld", el.value
|
| 125 |
98 |
end
|
| 126 |
99 |
end
|
| 127 |
100 |
end
|
| 128 |
101 |
|
| 129 |
|
def test_tab_indents_only_selected_lines_block_ordered_list
|
|
102 |
def test_shift_tab_does_nothing_when_no_indent
|
| 130 |
103 |
with_settings :text_formatting => 'common_mark' do
|
| 131 |
104 |
visit '/projects/ecookbook/issues/new'
|
| 132 |
105 |
|
| 133 |
106 |
within('form#issue-form') do
|
| 134 |
|
text = "1. item1\n1. item2\n1. item3"
|
| 135 |
|
start = text.index("1. item2") + 5
|
| 136 |
|
finish = start + 1
|
|
107 |
text = "hello"
|
| 137 |
108 |
el = find('#issue_description')
|
| 138 |
109 |
el.click
|
| 139 |
|
set_textarea_value 'issue_description', text, selection: [start, finish]
|
| 140 |
|
el.send_keys(:tab)
|
| 141 |
|
assert_equal "1. item1\n 1. item2\n1. item3", el.value
|
|
110 |
set_textarea_value 'issue_description', text, selection: [0, text.length]
|
|
111 |
el.send_keys([:shift, :tab])
|
|
112 |
assert_equal "hello", el.value
|
| 142 |
113 |
end
|
| 143 |
114 |
end
|
| 144 |
115 |
end
|