diff options
Diffstat (limited to 'spec/helpers/wiki_helper_spec.rb')
-rw-r--r-- | spec/helpers/wiki_helper_spec.rb | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/spec/helpers/wiki_helper_spec.rb b/spec/helpers/wiki_helper_spec.rb index 4b53823aaed..040368b5ebd 100644 --- a/spec/helpers/wiki_helper_spec.rb +++ b/spec/helpers/wiki_helper_spec.rb @@ -2,7 +2,39 @@ require 'spec_helper' -describe WikiHelper do +RSpec.describe WikiHelper do + describe '#wiki_page_title' do + let_it_be(:page) { create(:wiki_page) } + + it 'sets the title for the show action' do + expect(helper).to receive(:breadcrumb_title).with(page.human_title) + expect(helper).to receive(:wiki_breadcrumb_dropdown_links).with(page.slug) + expect(helper).to receive(:page_title).with(page.human_title, 'Wiki') + expect(helper).to receive(:add_to_breadcrumbs).with('Wiki', helper.wiki_path(page.wiki)) + + helper.wiki_page_title(page) + end + + it 'sets the title for a custom action' do + expect(helper).to receive(:breadcrumb_title).with(page.human_title) + expect(helper).to receive(:wiki_breadcrumb_dropdown_links).with(page.slug) + expect(helper).to receive(:page_title).with('Edit', page.human_title, 'Wiki') + expect(helper).to receive(:add_to_breadcrumbs).with('Wiki', helper.wiki_path(page.wiki)) + + helper.wiki_page_title(page, 'Edit') + end + + it 'sets the title for an unsaved page' do + expect(page).to receive(:persisted?).and_return(false) + expect(helper).not_to receive(:breadcrumb_title) + expect(helper).not_to receive(:wiki_breadcrumb_dropdown_links) + expect(helper).to receive(:page_title).with('Wiki') + expect(helper).to receive(:add_to_breadcrumbs).with('Wiki', helper.wiki_path(page.wiki)) + + helper.wiki_page_title(page) + end + end + describe '#breadcrumb' do context 'when the page is at the root level' do it 'returns the capitalized page name' do @@ -72,4 +104,24 @@ describe WikiHelper do expect(helper.wiki_sort_title('unknown')).to eq('Title') end end + + describe '#wiki_page_tracking_context' do + let_it_be(:page) { create(:wiki_page, title: 'path/to/page 💩', content: '💩', format: :markdown) } + + subject { helper.wiki_page_tracking_context(page) } + + it 'returns the tracking context' do + expect(subject).to eq( + 'wiki-format' => :markdown, + 'wiki-title-size' => 9, + 'wiki-content-size' => 4, + 'wiki-directory-nest-level' => 2 + ) + end + + it 'returns a nest level of zero for toplevel files' do + expect(page).to receive(:path).and_return('page') + expect(subject).to include('wiki-directory-nest-level' => 0) + end + end end |