PageRenderTime 20ms CodeModel.GetById 1ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

/spec/features/projects/wiki/user_views_wiki_pages_spec.rb

https://gitlab.com/tnir/gitlab-ce
Ruby | 89 lines | 73 code | 15 blank | 1 comment | 0 complexity | 228bee58eb7ade8bd4cf7075b13c8dfe MD5 | raw file
 1# frozen_string_literal: true
 2
 3require 'spec_helper'
 4
 5describe 'User views wiki pages' do
 6  include WikiHelpers
 7
 8  let(:user) { create(:user) }
 9  let(:project) { create(:project, :wiki_repo, namespace: user.namespace) }
10
11  let!(:wiki_page1) do
12    create(:wiki_page, wiki: project.wiki, title: '3 home', content: '3')
13  end
14  let!(:wiki_page2) do
15    create(:wiki_page, wiki: project.wiki, title: '1 home', content: '1')
16  end
17  let!(:wiki_page3) do
18    create(:wiki_page, wiki: project.wiki, title: '2 home', content: '2')
19  end
20
21  let(:pages) do
22    page.find('.wiki-pages-list').all('li').map { |li| li.find('a') }
23  end
24
25  before do
26    project.add_maintainer(user)
27    sign_in(user)
28    visit(project_wikis_pages_path(project))
29  end
30
31  context 'ordered by title' do
32    let(:pages_ordered_by_title) { [wiki_page2, wiki_page3, wiki_page1] }
33
34    context 'asc' do
35      it 'pages are displayed in direct order' do
36        pages.each.with_index do |page_title, index|
37          expect(page_title.text).to eq(pages_ordered_by_title[index].title)
38        end
39      end
40    end
41
42    context 'desc' do
43      before do
44        page.within('.wiki-sort-dropdown') do
45          page.find('.rspec-reverse-sort').click
46        end
47      end
48
49      it 'pages are displayed in reversed order' do
50        pages.reverse_each.with_index do |page_title, index|
51          expect(page_title.text).to eq(pages_ordered_by_title[index].title)
52        end
53      end
54    end
55  end
56
57  context 'ordered by created_at' do
58    let(:pages_ordered_by_created_at) { [wiki_page1, wiki_page2, wiki_page3] }
59
60    before do
61      page.within('.wiki-sort-dropdown') do
62        click_button('Title')
63        click_link('Created date')
64      end
65    end
66
67    context 'asc' do
68      it 'pages are displayed in direct order' do
69        pages.each.with_index do |page_title, index|
70          expect(page_title.text).to eq(pages_ordered_by_created_at[index].title)
71        end
72      end
73    end
74
75    context 'desc' do
76      before do
77        page.within('.wiki-sort-dropdown') do
78          page.find('.rspec-reverse-sort').click
79        end
80      end
81
82      it 'pages are displayed in reversed order' do
83        pages.reverse_each.with_index do |page_title, index|
84          expect(page_title.text).to eq(pages_ordered_by_created_at[index].title)
85        end
86      end
87    end
88  end
89end