@elisra-devops/docgen-skins 0.22.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +18 -9
- package/bin/index.d.ts +8 -1
- package/bin/index.js +86 -37
- package/bin/index.js.map +1 -1
- package/bin/models/json/JSONRun.js.map +1 -1
- package/bin/models/json/file/JSONFile.js.map +1 -1
- package/bin/models/json/paragraph/JSONParagraph.js.map +1 -1
- package/bin/models/json/paragraph/JSONRichTextParagraph.js.map +1 -1
- package/bin/models/json/paragraph/JSONTestSuiteHeaderParagraph.js.map +1 -1
- package/bin/models/json/table/JSONTable.d.ts +2 -1
- package/bin/models/json/table/JSONTable.js +20 -6
- package/bin/models/json/table/JSONTable.js.map +1 -1
- package/bin/models/json/table/JSONTableCell.js.map +1 -1
- package/bin/models/json/table/JSONTableRow.js.map +1 -1
- package/bin/services/logger.js +17 -7
- package/bin/services/logger.js.map +1 -1
- package/bin/test/JSONFile.test.js +48 -0
- package/bin/test/JSONFile.test.js.map +1 -0
- package/bin/test/JSONRun.test.d.ts +1 -0
- package/bin/test/JSONRun.test.js +93 -0
- package/bin/test/JSONRun.test.js.map +1 -0
- package/bin/test/JSONTable.test.d.ts +1 -0
- package/bin/test/JSONTable.test.js +79 -0
- package/bin/test/JSONTable.test.js.map +1 -0
- package/bin/test/JSONTableCell.test.d.ts +1 -0
- package/bin/test/JSONTableCell.test.js +129 -0
- package/bin/test/JSONTableCell.test.js.map +1 -0
- package/bin/test/JSONTableRow.test.d.ts +1 -0
- package/bin/test/JSONTableRow.test.js +40 -0
- package/bin/test/JSONTableRow.test.js.map +1 -0
- package/bin/test/JSONTestSuiteHeaderParagraph.test.d.ts +1 -0
- package/bin/test/JSONTestSuiteHeaderParagraph.test.js +39 -0
- package/bin/test/JSONTestSuiteHeaderParagraph.test.js.map +1 -0
- package/bin/test/SkinsEdgeCases.test.d.ts +1 -0
- package/bin/test/SkinsEdgeCases.test.js +399 -0
- package/bin/test/SkinsEdgeCases.test.js.map +1 -0
- package/bin/test/integration/skins.integration.test.d.ts +1 -0
- package/bin/test/integration/skins.integration.test.js +492 -0
- package/bin/test/integration/skins.integration.test.js.map +1 -0
- package/package.json +5 -5
- package/src/index.ts +94 -41
- package/src/models/json/table/JSONTable.ts +19 -3
- package/src/test/JSONFile.test.ts +59 -0
- package/src/test/JSONRun.test.ts +118 -0
- package/src/test/JSONTable.test.ts +126 -0
- package/src/test/JSONTableCell.test.ts +150 -0
- package/src/test/JSONTableRow.test.ts +42 -0
- package/src/test/JSONTestSuiteHeaderParagraph.test.ts +40 -0
- package/src/test/SkinsEdgeCases.test.ts +530 -0
- package/src/test/integration/skins.integration.test.ts +608 -0
- package/tsconfig.json +2 -2
- package/bin/test/skins.test.js +0 -126
- package/bin/test/skins.test.js.map +0 -1
- package/src/test/skins.test.ts +0 -189
- /package/bin/test/{skins.test.d.ts → JSONFile.test.d.ts} +0 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import JSONTableCell from '../models/json/table/JSONTableCell';
|
|
2
|
+
import logger from '../services/logger';
|
|
3
|
+
|
|
4
|
+
jest.mock('../services/logger', () => ({
|
|
5
|
+
__esModule: true,
|
|
6
|
+
default: {
|
|
7
|
+
debug: jest.fn(),
|
|
8
|
+
info: jest.fn(),
|
|
9
|
+
warn: jest.fn(),
|
|
10
|
+
error: jest.fn(),
|
|
11
|
+
},
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
const getMockLogger = () =>
|
|
15
|
+
logger as unknown as {
|
|
16
|
+
debug: jest.Mock;
|
|
17
|
+
info: jest.Mock;
|
|
18
|
+
warn: jest.Mock;
|
|
19
|
+
error: jest.Mock;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const baseStyles = {
|
|
23
|
+
isBold: false,
|
|
24
|
+
IsItalic: false,
|
|
25
|
+
IsUnderline: false,
|
|
26
|
+
Size: 10,
|
|
27
|
+
Uri: null as string | null,
|
|
28
|
+
Font: 'Arial',
|
|
29
|
+
InsertLineBreak: false,
|
|
30
|
+
InsertSpace: true,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
describe('JSONTableCell', () => {
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
jest.clearAllMocks();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('creates picture attachment when value contains picture link and respects isFlattened', () => {
|
|
39
|
+
const shading = { color: 'auto', fill: 'FF0000', themeFillShade: 'BF' } as any;
|
|
40
|
+
|
|
41
|
+
const data: any = {
|
|
42
|
+
name: 'AttachmentCell',
|
|
43
|
+
value: [
|
|
44
|
+
{
|
|
45
|
+
attachmentLink: 'http://server/image.png',
|
|
46
|
+
tableCellAttachmentLink: 'http://server/image-render.png',
|
|
47
|
+
attachmentFileName: 'image.png',
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
attachmentType: 'asEmbedded',
|
|
51
|
+
includeAttachmentContent: true,
|
|
52
|
+
width: '50%',
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const cell = new JSONTableCell(data, { ...baseStyles }, false, shading, true);
|
|
56
|
+
const json = cell.getJsonCell() as any;
|
|
57
|
+
|
|
58
|
+
expect(json.shading).toEqual(shading);
|
|
59
|
+
expect(json.attachments).toHaveLength(1);
|
|
60
|
+
expect(json.attachments[0]).toMatchObject({
|
|
61
|
+
type: 'Picture',
|
|
62
|
+
path: 'http://server/image-render.png',
|
|
63
|
+
name: 'image',
|
|
64
|
+
isFlattened: true,
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('creates file attachment with link flags for non-picture attachment', () => {
|
|
69
|
+
const data: any = {
|
|
70
|
+
name: 'AttachmentCell',
|
|
71
|
+
value: [
|
|
72
|
+
{
|
|
73
|
+
attachmentLink: 'http://server/doc1.pdf',
|
|
74
|
+
attachmentFileName: 'doc1.pdf',
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
attachmentType: 'asLink',
|
|
78
|
+
includeAttachmentContent: false,
|
|
79
|
+
width: '50%',
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const cell = new JSONTableCell(data, { ...baseStyles }, false, undefined, true);
|
|
83
|
+
const json = cell.getJsonCell() as any;
|
|
84
|
+
|
|
85
|
+
expect(json.attachments).toHaveLength(1);
|
|
86
|
+
expect(json.attachments[0]).toMatchObject({
|
|
87
|
+
type: 'File',
|
|
88
|
+
path: 'http://server/doc1.pdf',
|
|
89
|
+
name: 'doc1',
|
|
90
|
+
isLinkedFile: true,
|
|
91
|
+
includeAttachmentContent: false,
|
|
92
|
+
isFlattened: true,
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('creates HTML cell when value contains HTML markup', () => {
|
|
97
|
+
const shading = { color: 'auto', fill: '00FF00' } as any;
|
|
98
|
+
|
|
99
|
+
const data: any = {
|
|
100
|
+
name: 'HtmlCell',
|
|
101
|
+
value: '<p>Hello</p>',
|
|
102
|
+
width: '30%',
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const cell = new JSONTableCell(data, { ...baseStyles }, false, shading, false);
|
|
106
|
+
const json = cell.getJsonCell() as any;
|
|
107
|
+
|
|
108
|
+
expect(json.Html).toMatchObject({
|
|
109
|
+
type: 'html',
|
|
110
|
+
Html: '<p>Hello</p>',
|
|
111
|
+
font: 'Arial',
|
|
112
|
+
fontSize: 10,
|
|
113
|
+
});
|
|
114
|
+
expect(json.shading).toEqual(shading);
|
|
115
|
+
expect(json.attachments).toHaveLength(0);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('creates text runs when value is simple text', () => {
|
|
119
|
+
const data: any = {
|
|
120
|
+
name: 'TextCell',
|
|
121
|
+
value: 'Plain text',
|
|
122
|
+
width: '20%',
|
|
123
|
+
url: 'http://example.com/field',
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const cell = new JSONTableCell(data, { ...baseStyles }, false, undefined, false);
|
|
127
|
+
const json = cell.getJsonCell() as any;
|
|
128
|
+
|
|
129
|
+
expect(json.Html).toBeUndefined();
|
|
130
|
+
expect(json.attachments).toHaveLength(0);
|
|
131
|
+
expect(json.Paragraphs[0].Runs.length).toBeGreaterThan(0);
|
|
132
|
+
const text = json.Paragraphs[0].Runs.map((r: any) => r.text).join('');
|
|
133
|
+
expect(text).toContain('Plain text');
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test('logs error and falls back to error run when value is invalid non-array object', () => {
|
|
137
|
+
const data: any = {
|
|
138
|
+
name: 'BadCell',
|
|
139
|
+
value: { not: 'an array' },
|
|
140
|
+
width: '10%',
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const cell = new JSONTableCell(data, { ...baseStyles }, false, undefined, false);
|
|
144
|
+
const json = cell.getJsonCell() as any;
|
|
145
|
+
|
|
146
|
+
expect(getMockLogger().error).toHaveBeenCalled();
|
|
147
|
+
const text = json.Paragraphs[0].Runs.map((r: any) => r.text).join('');
|
|
148
|
+
expect(text).toContain('Docgen Error: Invalid data value');
|
|
149
|
+
});
|
|
150
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import JSONTableRow from '../models/json/table/JSONTableRow';
|
|
2
|
+
import logger from '../services/logger';
|
|
3
|
+
|
|
4
|
+
jest.mock('../services/logger', () => ({
|
|
5
|
+
__esModule: true,
|
|
6
|
+
default: {
|
|
7
|
+
debug: jest.fn(),
|
|
8
|
+
info: jest.fn(),
|
|
9
|
+
warn: jest.fn(),
|
|
10
|
+
error: jest.fn(),
|
|
11
|
+
},
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
const baseStyles = {
|
|
15
|
+
isBold: false,
|
|
16
|
+
IsItalic: false,
|
|
17
|
+
IsUnderline: false,
|
|
18
|
+
Size: 10,
|
|
19
|
+
Uri: null as string | null,
|
|
20
|
+
Font: 'Arial',
|
|
21
|
+
InsertLineBreak: false,
|
|
22
|
+
InsertSpace: true,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
describe('JSONTableRow', () => {
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
jest.clearAllMocks();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('throws error when WIData has no fields', () => {
|
|
31
|
+
const data: any = {
|
|
32
|
+
url: '',
|
|
33
|
+
level: 0,
|
|
34
|
+
Source: 1,
|
|
35
|
+
// fields is intentionally missing to trigger the error path
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
expect(() => new JSONTableRow(data, { ...baseStyles } as any)).toThrow(
|
|
39
|
+
'no fields to add for the table row'
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import JSONTestSuiteHeaderParagraph from '../models/json/paragraph/JSONTestSuiteHeaderParagraph';
|
|
2
|
+
import logger from '../services/logger';
|
|
3
|
+
|
|
4
|
+
jest.mock('../services/logger', () => ({
|
|
5
|
+
__esModule: true,
|
|
6
|
+
default: {
|
|
7
|
+
debug: jest.fn(),
|
|
8
|
+
info: jest.fn(),
|
|
9
|
+
warn: jest.fn(),
|
|
10
|
+
error: jest.fn(),
|
|
11
|
+
},
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
const baseStyles = {
|
|
15
|
+
isBold: true,
|
|
16
|
+
IsItalic: false,
|
|
17
|
+
IsUnderline: false,
|
|
18
|
+
Size: 14,
|
|
19
|
+
Uri: null as string | null,
|
|
20
|
+
Font: 'Arial',
|
|
21
|
+
InsertLineBreak: false,
|
|
22
|
+
InsertSpace: true,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
describe('JSONTestSuiteHeaderParagraph', () => {
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
jest.clearAllMocks();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('creates runs for non-title/id/description fields and sets heading level', () => {
|
|
31
|
+
const fields: any[] = [{ name: 'Custom', value: 'Value', url: 'http://example.com' }];
|
|
32
|
+
|
|
33
|
+
const paragraph = new JSONTestSuiteHeaderParagraph(fields, { ...baseStyles }, 1, 2);
|
|
34
|
+
const json = paragraph.getJSONParagraph() as any;
|
|
35
|
+
|
|
36
|
+
expect(json.type).toBe('paragraph');
|
|
37
|
+
expect(json.headingLevel).toBe(2);
|
|
38
|
+
expect(json.runs.length).toBeGreaterThan(0);
|
|
39
|
+
});
|
|
40
|
+
});
|