BigW Consortium Gitlab

wiki.rb 5.51 KB
Newer Older
1
class Spinach::Features::ProjectWiki < Spinach::FeatureSteps
Nihad Abbasov committed
2 3 4 5 6
  include SharedAuthentication
  include SharedProject
  include SharedNote
  include SharedPaths

7
  step 'I click on the Cancel button' do
Douwe Maan committed
8
    page.within(:css, ".wiki-form .form-actions") do
9 10 11 12
      click_on "Cancel"
    end
  end

13
  step 'I should be redirected back to the Edit Home Wiki page' do
14
    expect(current_path).to eq namespace_project_wiki_path(project.namespace, project, :home)
15 16
  end

17
  step 'I create the Wiki Home page' do
18
    fill_in "wiki_content", with: '[link test](test)'
19
    click_on "Create page"
Nihad Abbasov committed
20 21
  end

22 23 24 25 26
  step 'I create the Wiki Home page with no content' do
    fill_in "wiki_content", with: ''
    click_on "Create page"
  end

27
  step 'I should see the newly created wiki page' do
28 29
    expect(page).to have_content "Home"
    expect(page).to have_content "link test"
Nihad Abbasov committed
30 31

    click_link "link test"
Douwe Maan committed
32
    expect(page).to have_content "Edit Page"
Nihad Abbasov committed
33
  end
34

35
  step 'I have an existing Wiki page' do
36 37 38 39
    wiki.create_page("existing", "content", :markdown, "first commit")
    @page = wiki.find_page("existing")
  end

40
  step 'I browse to that Wiki page' do
Vinnie Okada committed
41
    visit namespace_project_wiki_path(project.namespace, project, @page)
42 43
  end

44
  step 'I click on the Edit button' do
45 46 47
    click_on "Edit"
  end

48
  step 'I change the content' do
49
    fill_in "Content", with: 'Updated Wiki Content'
50
    click_on "Save changes"
51 52
  end

53
  step 'I should see the updated content' do
54
    expect(page).to have_content "Updated Wiki Content"
55 56
  end

57
  step 'I should be redirected back to that Wiki page' do
58
    expect(current_path).to eq namespace_project_wiki_path(project.namespace, project, @page)
59 60
  end

61
  step 'That page has two revisions' do
62 63 64
    @page.update("new content", :markdown, "second commit")
  end

65
  step 'I click the History button' do
66 67 68
    click_on "History"
  end

69
  step 'I should see both revisions' do
70 71 72
    expect(page).to have_content current_user.name
    expect(page).to have_content "first commit"
    expect(page).to have_content "second commit"
73 74
  end

75
  step 'I click on the "Delete this page" button' do
Douwe Maan committed
76
    click_on "Delete"
77 78
  end

79
  step 'The page should be deleted' do
80
    expect(page).to have_content "Page was successfully deleted"
81 82
  end

83
  step 'I click on the "Pages" button' do
84 85 86
    click_on "Pages"
  end

87
  step 'I should see the existing page in the pages list' do
88 89
    expect(page).to have_content current_user.name
    expect(page).to have_content @page.title
90 91
  end

92
  step 'I have an existing Wiki page with images linked on page' do
93
    wiki.create_page("pictures", "Look at this [image](image.jpg)\n\n ![alt text](image.jpg)", :markdown, "first commit")
94 95 96
    @wiki_page = wiki.find_page("pictures")
  end

97
  step 'I browse to wiki page with images' do
Vinnie Okada committed
98
    visit namespace_project_wiki_path(project.namespace, project, @wiki_page)
99 100
  end

101
  step 'I click on existing image link' do
Marin Jankovski committed
102 103 104
    file = Gollum::File.new(wiki.wiki)
    Gollum::Wiki.any_instance.stub(:file).with("image.jpg", "master", true).and_return(file)
    Gollum::File.any_instance.stub(:mime_type).and_return("image/jpeg")
105
    expect(page).to have_link('image', href: "#{wiki.wiki_base_path}/image.jpg")
106 107 108
    click_on "image"
  end

109
  step 'I should see the image from wiki repo' do
110 111
    expect(current_path).to match('wikis/image.jpg')
    expect(page).not_to have_xpath('/html') # Page should render the image which means there is no html involved
112 113
    Gollum::Wiki.any_instance.unstub(:file)
    Gollum::File.any_instance.unstub(:mime_type)
114 115
  end

116
  step 'Image should be shown on the page' do
117
    expect(page).to have_xpath("//img[@src=\"image.jpg\"]")
118 119
  end

120
  step 'I click on image link' do
121
    expect(page).to have_link('image', href: "#{wiki.wiki_base_path}/image.jpg")
122 123 124
    click_on "image"
  end

125
  step 'I should see the new wiki page form' do
126 127
    expect(current_path).to match('wikis/image.jpg')
    expect(page).to have_content('New Wiki Page')
128
    expect(page).to have_content('Edit Page')
129 130
  end

131 132
  step 'I create a New page with paths' do
    click_on 'New Page'
Stan Hu committed
133
    fill_in 'Page slug', with: 'one/two/three-test'
Douwe Maan committed
134
    click_on 'Create Page'
135 136
    fill_in "wiki_content", with: 'wiki content'
    click_on "Create page"
Stan Hu committed
137
    expect(current_path).to include 'one/two/three-test'
138 139 140
  end

  step 'I should see non-escaped link in the pages list' do
Stan Hu committed
141
    expect(page).to have_xpath("//a[@href='/#{project.path_with_namespace}/wikis/one/two/three-test']")
142 143 144
  end

  step 'I edit the Wiki page with a path' do
Phil Hughes committed
145
    expect(page).to have_content('three')
146
    click_on 'three'
Phil Hughes committed
147
    expect(find('.nav-text')).to have_content('Three')
148 149 150 151
    click_on 'Edit'
  end

  step 'I should see a non-escaped path' do
Stan Hu committed
152
    expect(current_path).to include 'one/two/three-test'
153 154 155
  end

  step 'I should see the Editing page' do
Douwe Maan committed
156
    expect(page).to have_content('Edit Page')
157 158 159 160 161 162 163
  end

  step 'I view the page history of a Wiki page that has a path' do
    click_on 'three'
    click_on 'Page History'
  end

Stan Hu committed
164 165 166 167
  step 'I click on Page History' do
    click_on 'Page History'
  end

168
  step 'I should see the page history' do
169 170 171
    page.within(:css, ".nav-text") do
      expect(page).to have_content('History')
    end
172 173
  end

174
  step 'I search for Wiki content' do
175
    fill_in "Search", with: "wiki_content"
176 177 178
    click_button "Search"
  end

Stan Hu committed
179 180 181 182
  step 'I should see a link with a version ID' do
    find('a[href*="?version_id"]')
  end

183 184 185 186 187
  step 'I should see a "Content can\'t be blank" error message' do
    expect(page).to have_content('The form contains the following error:')
    expect(page).to have_content('Content can\'t be blank')
  end

188
  def wiki
189
    @project_wiki = ProjectWiki.new(project, current_user)
190
  end
Nihad Abbasov committed
191
end