summaryrefslogtreecommitdiff
path: root/spec/features/projects/wiki/user_views_wiki_pages_spec.rb
blob: 6740df1d4edcb96483a847ec33967cc6dc1c9060 (plain)
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
# frozen_string_literal: true

require 'spec_helper'

describe 'User views wiki pages' do
  include WikiHelpers

  let(:user) { create(:user) }
  let(:project) { create(:project, :wiki_repo, namespace: user.namespace) }

  let!(:wiki_page1) do
    create(:wiki_page, wiki: project.wiki, attrs: { title: '3 home', content: '3' })
  end
  let!(:wiki_page2) do
    create(:wiki_page, wiki: project.wiki, attrs: { title: '1 home', content: '1' })
  end
  let!(:wiki_page3) do
    create(:wiki_page, wiki: project.wiki, attrs: { title: '2 home', content: '2' })
  end

  let(:pages) do
    page.find('.wiki-pages-list').all('li').map { |li| li.find('a') }
  end

  before do
    project.add_maintainer(user)
    sign_in(user)
    visit(project_wikis_pages_path(project))
  end

  context 'ordered by title' do
    let(:pages_ordered_by_title) { [wiki_page2, wiki_page3, wiki_page1] }

    context 'asc' do
      it 'pages are displayed in direct order' do
        pages.each.with_index do |page_title, index|
          expect(page_title.text).to eq(pages_ordered_by_title[index].title)
        end
      end
    end

    context 'desc' do
      before do
        page.within('.wiki-sort-dropdown') do
          page.find('.rspec-reverse-sort').click
        end
      end

      it 'pages are displayed in reversed order' do
        pages.reverse_each.with_index do |page_title, index|
          expect(page_title.text).to eq(pages_ordered_by_title[index].title)
        end
      end
    end
  end

  context 'ordered by created_at' do
    let(:pages_ordered_by_created_at) { [wiki_page1, wiki_page2, wiki_page3] }

    before do
      page.within('.wiki-sort-dropdown') do
        click_button('Title')
        click_link('Created date')
      end
    end

    context 'asc' do
      it 'pages are displayed in direct order' do
        pages.each.with_index do |page_title, index|
          expect(page_title.text).to eq(pages_ordered_by_created_at[index].title)
        end
      end
    end

    context 'desc' do
      before do
        page.within('.wiki-sort-dropdown') do
          page.find('.rspec-reverse-sort').click
        end
      end

      it 'pages are displayed in reversed order' do
        pages.reverse_each.with_index do |page_title, index|
          expect(page_title.text).to eq(pages_ordered_by_created_at[index].title)
        end
      end
    end
  end
end