diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 18:42:06 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 18:42:06 +0000 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/frontend/static_site_editor/services | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) | |
download | gitlab-ce-6e4e1050d9dba2b7b2523fdd1768823ab85feef4.tar.gz |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/frontend/static_site_editor/services')
3 files changed, 131 insertions, 1 deletions
diff --git a/spec/frontend/static_site_editor/services/formatter_spec.js b/spec/frontend/static_site_editor/services/formatter_spec.js new file mode 100644 index 00000000000..b7600798db9 --- /dev/null +++ b/spec/frontend/static_site_editor/services/formatter_spec.js @@ -0,0 +1,26 @@ +import formatter from '~/static_site_editor/services/formatter'; + +describe('formatter', () => { + const source = `Some text +<br> + +And some more text + + +<br> + + +And even more text`; + const sourceWithoutBrTags = `Some text + +And some more text + + + + +And even more text`; + + it('removes extraneous <br> tags', () => { + expect(formatter(source)).toMatch(sourceWithoutBrTags); + }); +}); diff --git a/spec/frontend/static_site_editor/services/submit_content_changes_spec.js b/spec/frontend/static_site_editor/services/submit_content_changes_spec.js index a9169eb3e16..645ccedf7e7 100644 --- a/spec/frontend/static_site_editor/services/submit_content_changes_spec.js +++ b/spec/frontend/static_site_editor/services/submit_content_changes_spec.js @@ -1,6 +1,6 @@ +import { mockTracking, unmockTracking } from 'helpers/tracking_helper'; import Api from '~/api'; import { convertObjectPropsToSnakeCase } from '~/lib/utils/common_utils'; -import { mockTracking, unmockTracking } from 'helpers/tracking_helper'; import { DEFAULT_TARGET_BRANCH, diff --git a/spec/frontend/static_site_editor/services/templater_spec.js b/spec/frontend/static_site_editor/services/templater_spec.js new file mode 100644 index 00000000000..1e7ae872b7e --- /dev/null +++ b/spec/frontend/static_site_editor/services/templater_spec.js @@ -0,0 +1,104 @@ +/* eslint-disable no-useless-escape */ +import templater from '~/static_site_editor/services/templater'; + +describe('templater', () => { + const source = `Below this line is a simple ERB (single-line erb block) example. + +<% some erb code %> + +Below this line is a complex ERB (multi-line erb block) example. + +<% if apptype.maturity && (apptype.maturity != "planned") %> + <% maturity = "This application type is at the \"#{apptype.maturity}\" level of maturity." %> +<% end %> + +Below this line is a non-erb (single-line HTML) markup example that also has erb. + +<a href="<%= compensation_roadmap.role_path %>"><%= compensation_roadmap.role_path %></a> + +Below this line is a non-erb (multi-line HTML block) markup example that also has erb. + +<ul> +<% compensation_roadmap.recommendation.recommendations.each do |recommendation| %> + <li><%= recommendation %></li> +<% end %> +</ul> + +Below this line is a block of HTML. + +<div> + <h1>Heading</h1> + <p>Some paragraph...</p> +</div> + +Below this line is a codeblock of the same HTML that should be ignored and preserved. + +\`\`\` html +<div> + <h1>Heading</h1> + <p>Some paragraph...</p> +</div> +\`\`\` +`; + const sourceTemplated = `Below this line is a simple ERB (single-line erb block) example. + +\`\`\` sse +<% some erb code %> +\`\`\` + +Below this line is a complex ERB (multi-line erb block) example. + +\`\`\` sse +<% if apptype.maturity && (apptype.maturity != "planned") %> + <% maturity = "This application type is at the \"#{apptype.maturity}\" level of maturity." %> +<% end %> +\`\`\` + +Below this line is a non-erb (single-line HTML) markup example that also has erb. + +\`\`\` sse +<a href="<%= compensation_roadmap.role_path %>"><%= compensation_roadmap.role_path %></a> +\`\`\` + +Below this line is a non-erb (multi-line HTML block) markup example that also has erb. + +\`\`\` sse +<ul> +<% compensation_roadmap.recommendation.recommendations.each do |recommendation| %> + <li><%= recommendation %></li> +<% end %> +</ul> +\`\`\` + +Below this line is a block of HTML. + +\`\`\` sse +<div> + <h1>Heading</h1> + <p>Some paragraph...</p> +</div> +\`\`\` + +Below this line is a codeblock of the same HTML that should be ignored and preserved. + +\`\`\` html +<div> + <h1>Heading</h1> + <p>Some paragraph...</p> +</div> +\`\`\` +`; + + it.each` + fn | initial | target + ${'wrap'} | ${source} | ${sourceTemplated} + ${'wrap'} | ${sourceTemplated} | ${sourceTemplated} + ${'unwrap'} | ${sourceTemplated} | ${source} + ${'unwrap'} | ${source} | ${source} + `( + 'wraps $initial in a templated sse codeblocks if $fn is wrap, unwraps otherwise', + ({ fn, initial, target }) => { + expect(templater[fn](initial)).toMatch(target); + }, + ); +}); |