# frozen_string_literal: true require 'spec_helper' RSpec.describe Banzai::Pipeline::WikiPipeline do let_it_be(:namespace) { create(:namespace, name: "wiki_link_ns") } let_it_be(:project) { create(:project, :public, name: "wiki_link_project", namespace: namespace) } let_it_be(:wiki) { ProjectWiki.new(project, nil) } let_it_be(:page) { build(:wiki_page, wiki: wiki, title: 'nested/twice/start-page') } describe 'TableOfContents' do it 'replaces the tag with the TableOfContentsFilter result' do markdown = <<-MD.strip_heredoc [[_TOC_]] ## Header Foo MD result = described_class.call(markdown, project: project, wiki: wiki) aggregate_failures do expect(result[:output].text).not_to include '[[' expect(result[:output].text).not_to include 'TOC' expect(result[:output].to_html).to include(result[:toc]) end end it 'is not case-sensitive' do markdown = <<-MD.strip_heredoc [[_toc_]] # Header 1 Foo MD result = described_class.call(markdown, project: project, wiki: wiki) expect(result[:output].to_html).to include(result[:toc]) end it 'works with alternative [toc] tag' do markdown = <<-MD.strip_heredoc [toc] # Header 1 Foo MD result = described_class.call(markdown, project: project, wiki: wiki) expect(result[:output].to_html).to include(result[:toc]) end it 'handles an empty pipeline result' do # No Markdown headers in this doc, so `result[:toc]` will be empty markdown = <<-MD.strip_heredoc [[_TOC_]] Foo MD output = described_class.to_html(markdown, project: project, wiki: wiki) aggregate_failures do expect(output).not_to include('