2020-08-06 00:09:53 +00:00
|
|
|
/* eslint-disable no-useless-escape */
|
|
|
|
import templater from '~/static_site_editor/services/templater';
|
|
|
|
|
|
|
|
describe('templater', () => {
|
2020-08-07 00:09:52 +00:00
|
|
|
const source = `Below this line is a simple ERB (single-line erb block) example.
|
2020-08-06 00:09:53 +00:00
|
|
|
|
|
|
|
<% some erb code %>
|
|
|
|
|
2020-08-07 00:09:52 +00:00
|
|
|
Below this line is a complex ERB (multi-line erb block) example.
|
2020-08-06 00:09:53 +00:00
|
|
|
|
|
|
|
<% if apptype.maturity && (apptype.maturity != "planned") %>
|
|
|
|
<% maturity = "This application type is at the \"#{apptype.maturity}\" level of maturity." %>
|
|
|
|
<% end %>
|
|
|
|
|
2020-08-07 00:09:52 +00:00
|
|
|
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>
|
2020-08-10 15:09:49 +00:00
|
|
|
|
|
|
|
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>
|
|
|
|
\`\`\`
|
2020-09-30 21:10:09 +00:00
|
|
|
|
|
|
|
Below this line is a iframe that should be ignored and preserved
|
|
|
|
|
|
|
|
<iframe></iframe>
|
2020-08-06 00:09:53 +00:00
|
|
|
`;
|
2020-08-07 00:09:52 +00:00
|
|
|
const sourceTemplated = `Below this line is a simple ERB (single-line erb block) example.
|
2020-08-06 00:09:53 +00:00
|
|
|
|
|
|
|
\`\`\` sse
|
|
|
|
<% some erb code %>
|
|
|
|
\`\`\`
|
|
|
|
|
2020-08-07 00:09:52 +00:00
|
|
|
Below this line is a complex ERB (multi-line erb block) example.
|
2020-08-06 00:09:53 +00:00
|
|
|
|
|
|
|
\`\`\` sse
|
|
|
|
<% if apptype.maturity && (apptype.maturity != "planned") %>
|
|
|
|
<% maturity = "This application type is at the \"#{apptype.maturity}\" level of maturity." %>
|
|
|
|
<% end %>
|
|
|
|
\`\`\`
|
|
|
|
|
2020-08-07 00:09:52 +00:00
|
|
|
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>
|
|
|
|
\`\`\`
|
2020-08-10 15:09:49 +00:00
|
|
|
|
|
|
|
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>
|
|
|
|
\`\`\`
|
2020-09-30 21:10:09 +00:00
|
|
|
|
|
|
|
Below this line is a iframe that should be ignored and preserved
|
|
|
|
|
|
|
|
<iframe></iframe>
|
2020-08-06 00:09:53 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
fn | initial | target
|
|
|
|
${'wrap'} | ${source} | ${sourceTemplated}
|
|
|
|
${'wrap'} | ${sourceTemplated} | ${sourceTemplated}
|
|
|
|
${'unwrap'} | ${sourceTemplated} | ${source}
|
|
|
|
${'unwrap'} | ${source} | ${source}
|
|
|
|
`(
|
2020-08-07 00:09:52 +00:00
|
|
|
'wraps $initial in a templated sse codeblocks if $fn is wrap, unwraps otherwise',
|
2020-08-06 00:09:53 +00:00
|
|
|
({ fn, initial, target }) => {
|
|
|
|
expect(templater[fn](initial)).toMatch(target);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|