require 'spec_helper' describe 'Copy as GFM', feature: true, js: true do include GitlabMarkdownHelper include ActionView::Helpers::JavaScriptHelper before do @feat = MarkdownFeature.new # `markdown` helper expects a `@project` variable @project = @feat.project visit namespace_project_issue_path(@project.namespace, @project, @feat.issue) end # The filters referenced in lib/banzai/pipeline/gfm_pipeline.rb convert GitLab Flavored Markdown (GFM) to HTML. # The handlers defined in app/assets/javascripts/copy_as_gfm.js.es6 consequently convert that same HTML to GFM. # To make sure these filters and handlers are properly aligned, this spec tests the GFM-to-HTML-to-GFM cycle # by verifying (`html_to_gfm(gfm_to_html(gfm)) == gfm`) for a number of examples of GFM for every filter, using the `verify` helper. # These are all in a single `it` for performance reasons. it 'works', :aggregate_failures do verify( 'nesting', '> 1. [x] **[$`2 + 2`$ {-=-}{+=+} 2^2 ~~:thumbsup:~~](http://google.com)**' ) verify( 'a real world example from the gitlab-ce README', <<-GFM.strip_heredoc # GitLab [![Build status](https://gitlab.com/gitlab-org/gitlab-ce/badges/master/build.svg)](https://gitlab.com/gitlab-org/gitlab-ce/commits/master) [![CE coverage report](https://gitlab.com/gitlab-org/gitlab-ce/badges/master/coverage.svg?job=coverage)](https://gitlab-org.gitlab.io/gitlab-ce/coverage-ruby) [![Code Climate](https://codeclimate.com/github/gitlabhq/gitlabhq.svg)](https://codeclimate.com/github/gitlabhq/gitlabhq) [![Core Infrastructure Initiative Best Practices](https://bestpractices.coreinfrastructure.org/projects/42/badge)](https://bestpractices.coreinfrastructure.org/projects/42) ## Canonical source The canonical source of GitLab Community Edition is [hosted on GitLab.com](https://gitlab.com/gitlab-org/gitlab-ce/). ## Open source software to collaborate on code To see how GitLab looks please see the [features page on our website](https://about.gitlab.com/features/). - Manage Git repositories with fine grained access controls that keep your code secure - Perform code reviews and enhance collaboration with merge requests - Complete continuous integration (CI) and CD pipelines to builds, test, and deploy your applications - Each project can also have an issue tracker, issue board, and a wiki - Used by more than 100,000 organizations, GitLab is the most popular solution to manage Git repositories on-premises - Completely free and open source (MIT Expat license) GFM ) verify( 'InlineDiffFilter', '{-Deleted text-}', '{+Added text+}' ) verify( 'TaskListFilter', '- [ ] Unchecked task', '- [x] Checked task', '1. [ ] Unchecked numbered task', '1. [x] Checked numbered task' ) verify( 'ReferenceFilter', # issue reference @feat.issue.to_reference, # full issue reference @feat.issue.to_reference(full: true), # issue URL namespace_project_issue_url(@project.namespace, @project, @feat.issue), # issue URL with note anchor namespace_project_issue_url(@project.namespace, @project, @feat.issue, anchor: 'note_123'), # issue link "[Issue](#{namespace_project_issue_url(@project.namespace, @project, @feat.issue)})", # issue link with note anchor "[Issue](#{namespace_project_issue_url(@project.namespace, @project, @feat.issue, anchor: 'note_123')})", ) verify( 'AutolinkFilter', 'https://example.com' ) verify( 'TableOfContentsFilter', '[[_TOC_]]' ) verify( 'EmojiFilter', ':thumbsup:' ) verify( 'ImageLinkFilter', '![Image](https://example.com/image.png)' ) verify( 'VideoLinkFilter', '![Video](https://example.com/video.mp4)' ) verify( 'MathFilter: math as converted from GFM to HTML', '$`c = \pm\sqrt{a^2 + b^2}`$', # math block <<-GFM.strip_heredoc ```math c = \pm\sqrt{a^2 + b^2} ``` GFM ) aggregate_failures('MathFilter: math as transformed from HTML to KaTeX') do gfm = '$`c = \pm\sqrt{a^2 + b^2}`$' html = <<-HTML.strip_heredoc HTML output_gfm = html_to_gfm(html) expect(output_gfm.strip).to eq(gfm.strip) end verify( 'SanitizationFilter', <<-GFM.strip_heredoc sub
qsamp var ruby abbr