1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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: [],
});
});
});
});
|