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
|
# frozen_string_literal: true
# Requires a context containing:
# wiki
# user
RSpec.shared_examples 'User views wiki sidebar' do
include WikiHelpers
before do
sign_in(user)
end
context 'when there are some existing pages' do
before do
create(:wiki_page, wiki: wiki, title: 'home', content: 'home')
create(:wiki_page, wiki: wiki, title: 'another', content: 'another')
end
context 'when there is no custom sidebar' do
before do
visit wiki_path(wiki)
end
it 'renders a default sidebar' do
within('.right-sidebar') do
expect(page).to have_content('another')
expect(page).not_to have_link('View All Pages')
end
end
it 'can create a custom sidebar', :js do
click_on 'Edit sidebar'
fill_in :wiki_content, with: 'My custom sidebar'
click_on 'Create page'
within('.right-sidebar') do
expect(page).to have_content('My custom sidebar')
expect(page).not_to have_content('another')
end
end
end
context 'when there is a custom sidebar' do
before do
create(:wiki_page, wiki: wiki, title: '_sidebar', content: 'My custom sidebar')
visit wiki_path(wiki)
end
it 'renders the custom sidebar instead of the default one' do
within('.right-sidebar') do
expect(page).to have_content('My custom sidebar')
expect(page).not_to have_content('another')
end
end
it 'can edit the custom sidebar', :js do
click_on 'Edit sidebar'
expect(page).to have_field(:wiki_content, with: 'My custom sidebar')
fill_in :wiki_content, with: 'My other custom sidebar'
click_on 'Save changes'
within('.right-sidebar') do
expect(page).to have_content('My other custom sidebar')
end
end
end
end
context 'when there are 15 existing pages' do
before do
(1..5).each { |i| create(:wiki_page, wiki: wiki, title: "my page #{i}") }
(6..10).each { |i| create(:wiki_page, wiki: wiki, title: "parent/my page #{i}") }
(11..15).each { |i| create(:wiki_page, wiki: wiki, title: "grandparent/parent/my page #{i}") }
end
it 'shows all pages in the sidebar' do
visit wiki_path(wiki)
(1..15).each { |i| expect(page).to have_content("my page #{i}") }
expect(page).not_to have_link('View All Pages')
end
it 'shows all collapse buttons in the sidebar' do
visit wiki_path(wiki)
within('.right-sidebar') do
expect(page.all("[data-testid='chevron-down-icon']").size).to eq(3)
end
end
it 'collapses/expands children when click collapse/expand button in the sidebar', :js do
visit wiki_path(wiki)
within('.right-sidebar') do
first("[data-testid='chevron-down-icon']").click
(11..15).each { |i| expect(page).not_to have_content("my page #{i}") }
expect(page.all("[data-testid='chevron-down-icon']").size).to eq(1)
expect(page.all("[data-testid='chevron-right-icon']").size).to eq(1)
first("[data-testid='chevron-right-icon']").click
(11..15).each { |i| expect(page).to have_content("my page #{i}") }
expect(page.all("[data-testid='chevron-down-icon']").size).to eq(3)
expect(page.all("[data-testid='chevron-right-icon']").size).to eq(0)
end
end
it 'shows create child page button when hover to the page title in the sidebar', :js do
visit wiki_path(wiki)
within('.right-sidebar') do
first_wiki_list = first("[data-testid='wiki-list']")
wiki_link = first("[data-testid='wiki-list'] a:last-of-type")['href']
first_wiki_list.hover
wiki_new_page_link = first("[data-testid='wiki-list'] a")['href']
expect(wiki_new_page_link).to eq "#{wiki_link}/%7Bnew_page_title%7D"
end
end
context 'when there are more than 15 existing pages' do
before do
create(:wiki_page, wiki: wiki, title: 'my page 16')
end
it 'shows the first 15 pages in the sidebar' do
visit wiki_path(wiki)
expect(page).to have_text('my page', count: 15)
expect(page).to have_link('View All Pages')
end
end
end
end
|