BigW Consortium Gitlab

wiki.rb 5.03 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
  step 'I should see the newly created wiki page' do
23 24
    expect(page).to have_content "Home"
    expect(page).to have_content "link test"
Nihad Abbasov committed
25 26

    click_link "link test"
Douwe Maan committed
27
    expect(page).to have_content "Edit Page"
Nihad Abbasov committed
28
  end
29

30
  step 'I have an existing Wiki page' do
31 32 33 34
    wiki.create_page("existing", "content", :markdown, "first commit")
    @page = wiki.find_page("existing")
  end

35
  step 'I browse to that Wiki page' do
Vinnie Okada committed
36
    visit namespace_project_wiki_path(project.namespace, project, @page)
37 38
  end

39
  step 'I click on the Edit button' do
40 41 42
    click_on "Edit"
  end

43
  step 'I change the content' do
44
    fill_in "Content", with: 'Updated Wiki Content'
45
    click_on "Save changes"
46 47
  end

48
  step 'I should see the updated content' do
49
    expect(page).to have_content "Updated Wiki Content"
50 51
  end

52
  step 'I should be redirected back to that Wiki page' do
53
    expect(current_path).to eq namespace_project_wiki_path(project.namespace, project, @page)
54 55
  end

56
  step 'That page has two revisions' do
57 58 59
    @page.update("new content", :markdown, "second commit")
  end

60
  step 'I click the History button' do
61 62 63
    click_on "History"
  end

64
  step 'I should see both revisions' do
65 66 67
    expect(page).to have_content current_user.name
    expect(page).to have_content "first commit"
    expect(page).to have_content "second commit"
68 69
  end

70
  step 'I click on the "Delete this page" button' do
Douwe Maan committed
71
    click_on "Delete"
72 73
  end

74
  step 'The page should be deleted' do
75
    expect(page).to have_content "Page was successfully deleted"
76 77
  end

78
  step 'I click on the "Pages" button' do
79 80 81
    click_on "Pages"
  end

82
  step 'I should see the existing page in the pages list' do
83 84
    expect(page).to have_content current_user.name
    expect(page).to have_content @page.title
85 86
  end

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

92
  step 'I browse to wiki page with images' do
Vinnie Okada committed
93
    visit namespace_project_wiki_path(project.namespace, project, @wiki_page)
94 95
  end

96
  step 'I click on existing image link' do
Marin Jankovski committed
97 98 99
    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")
100
    expect(page).to have_link('image', href: "image.jpg")
101 102 103
    click_on "image"
  end

104
  step 'I should see the image from wiki repo' do
105 106
    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
107 108
    Gollum::Wiki.any_instance.unstub(:file)
    Gollum::File.any_instance.unstub(:mime_type)
109 110
  end

111
  step 'Image should be shown on the page' do
112
    expect(page).to have_xpath("//img[@src=\"image.jpg\"]")
113 114
  end

115
  step 'I click on image link' do
116
    expect(page).to have_link('image', href: "image.jpg")
117 118 119
    click_on "image"
  end

120
  step 'I should see the new wiki page form' do
121 122
    expect(current_path).to match('wikis/image.jpg')
    expect(page).to have_content('New Wiki Page')
123
    expect(page).to have_content('Edit Page')
124 125
  end

126 127 128
  step 'I create a New page with paths' do
    click_on 'New Page'
    fill_in 'Page slug', with: 'one/two/three'
Douwe Maan committed
129
    click_on 'Create Page'
130 131
    fill_in "wiki_content", with: 'wiki content'
    click_on "Create page"
132
    expect(current_path).to include 'one/two/three'
133 134 135
  end

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

  step 'I edit the Wiki page with a path' do
    click_on 'three'
    click_on 'Edit'
  end

  step 'I should see a non-escaped path' do
145
    expect(current_path).to include 'one/two/three'
146 147 148
  end

  step 'I should see the Editing page' do
Douwe Maan committed
149
    expect(page).to have_content('Edit Page')
150 151 152 153 154 155 156
  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
157 158 159 160
  step 'I click on Page History' do
    click_on 'Page History'
  end

161
  step 'I should see the page history' do
162 163 164
    page.within(:css, ".nav-text") do
      expect(page).to have_content('History')
    end
165 166
  end

167
  step 'I search for Wiki content' do
168
    fill_in "Search", with: "wiki_content"
169 170 171
    click_button "Search"
  end

Stan Hu committed
172 173 174 175
  step 'I should see a link with a version ID' do
    find('a[href*="?version_id"]')
  end

176
  def wiki
177
    @project_wiki = ProjectWiki.new(project, current_user)
178
  end
Nihad Abbasov committed
179
end