Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-08-10 09:09:29 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-08-10 09:09:29 +0300
commit76c4dd062c4eeb853866ef8b6451c59f9e24221c (patch)
treefaf481c7b2f6da10c13234ad4e4a6ca1cb5a1030 /spec/frontend/lib
parentc2858333644a2bca10fd556a5a298b4a1aaedca2 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/lib')
-rw-r--r--spec/frontend/lib/print_markdown_dom_spec.js102
1 files changed, 102 insertions, 0 deletions
diff --git a/spec/frontend/lib/print_markdown_dom_spec.js b/spec/frontend/lib/print_markdown_dom_spec.js
new file mode 100644
index 00000000000..7f28417228e
--- /dev/null
+++ b/spec/frontend/lib/print_markdown_dom_spec.js
@@ -0,0 +1,102 @@
+import printJS from 'print-js';
+import printMarkdownDom from '~/lib/print_markdown_dom';
+
+jest.mock('print-js', () => jest.fn());
+
+describe('print util', () => {
+ describe('print markdown dom', () => {
+ beforeEach(() => {
+ document.body.innerHTML = `<div id='target'></div>`;
+ });
+
+ const getTarget = () => document.getElementById('target');
+
+ const contentValues = [
+ {
+ title: 'test title',
+ expectedTitle: '<h2 class="gl-mt-0 gl-mb-5">test title</h2>',
+ content: '',
+ expectedContent: '<div class="md"></div>',
+ },
+ {
+ title: 'test title',
+ expectedTitle: '<h2 class="gl-mt-0 gl-mb-5">test title</h2>',
+ content: '<p>test content</p>',
+ expectedContent: '<div class="md"><p>test content</p></div>',
+ },
+ {
+ title: 'test title',
+ expectedTitle: '<h2 class="gl-mt-0 gl-mb-5">test title</h2>',
+ content: '<details><summary>test detail</summary><p>test detail content</p></details>',
+ expectedContent:
+ '<div class="md"><details open=""><summary>test detail</summary><p>test detail content</p></details></div>',
+ },
+ {
+ title: undefined,
+ expectedTitle: '',
+ content: '',
+ expectedContent: '<div class="md"></div>',
+ },
+ {
+ title: undefined,
+ expectedTitle: '',
+ content: '<p>test content</p>',
+ expectedContent: '<div class="md"><p>test content</p></div>',
+ },
+ {
+ title: undefined,
+ expectedTitle: '',
+ content: '<details><summary>test detail</summary><p>test detail content</p></details>',
+ expectedContent:
+ '<div class="md"><details open=""><summary>test detail</summary><p>test detail content</p></details></div>',
+ },
+ ];
+
+ it.each(contentValues)(
+ 'should print with title ($title) and content ($content)',
+ async ({ title, expectedTitle, content, expectedContent }) => {
+ const target = getTarget();
+ target.innerHTML = content;
+ const stylesheet = 'test stylesheet';
+
+ await printMarkdownDom({
+ target,
+ title,
+ stylesheet,
+ });
+
+ expect(printJS).toHaveBeenCalledWith({
+ printable: expectedTitle + expectedContent,
+ type: 'raw-html',
+ documentTitle: title,
+ scanStyles: false,
+ css: stylesheet,
+ });
+ },
+ );
+ });
+
+ describe('ignore selectors', () => {
+ beforeEach(() => {
+ document.body.innerHTML = `<div id='target'><div><div class='ignore-me'></div></div></div>`;
+ });
+
+ it('should ignore dom if ignoreSelectors', async () => {
+ const target = document.getElementById('target');
+ const ignoreSelectors = ['.ignore-me'];
+
+ await printMarkdownDom({
+ target,
+ ignoreSelectors,
+ });
+
+ expect(printJS).toHaveBeenCalledWith({
+ printable: '<div class="md"><div></div></div>',
+ type: 'raw-html',
+ documentTitle: undefined,
+ scanStyles: false,
+ css: [],
+ });
+ });
+ });
+});