@elisra-devops/docgen-skins 0.3.4 → 0.4.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.
Files changed (66) hide show
  1. package/.github/sonar-project.properties +4 -4
  2. package/.github/workflows/ci.yml +23 -18
  3. package/.github/workflows/release.yml +47 -45
  4. package/Readme.md +6 -6
  5. package/bin/index.d.ts +15 -0
  6. package/bin/index.js +277 -0
  7. package/bin/index.js.map +1 -0
  8. package/bin/models/json/JSONRun.d.ts +7 -0
  9. package/bin/models/json/JSONRun.js +84 -0
  10. package/bin/models/json/JSONRun.js.map +1 -0
  11. package/bin/models/json/default.d.ts +3 -0
  12. package/bin/models/json/default.js +25 -0
  13. package/bin/models/json/default.js.map +1 -0
  14. package/bin/models/json/html/JSONHtml.d.ts +6 -0
  15. package/bin/models/json/html/JSONHtml.js +13 -0
  16. package/bin/models/json/html/JSONHtml.js.map +1 -0
  17. package/bin/models/json/paragraph/JSONParagraph.d.ts +9 -0
  18. package/bin/models/json/paragraph/JSONParagraph.js +62 -0
  19. package/bin/models/json/paragraph/JSONParagraph.js.map +1 -0
  20. package/bin/models/json/paragraph/JSONRichTextParagraph.d.ts +9 -0
  21. package/bin/models/json/paragraph/JSONRichTextParagraph.js +72 -0
  22. package/bin/models/json/paragraph/JSONRichTextParagraph.js.map +1 -0
  23. package/bin/models/json/paragraph/JSONTestSuiteHeaderParagraph.d.ts +10 -0
  24. package/bin/models/json/paragraph/JSONTestSuiteHeaderParagraph.js +76 -0
  25. package/bin/models/json/paragraph/JSONTestSuiteHeaderParagraph.js.map +1 -0
  26. package/bin/models/json/table/JSONTable.d.ts +9 -0
  27. package/bin/models/json/table/JSONTable.js +60 -0
  28. package/bin/models/json/table/JSONTable.js.map +1 -0
  29. package/bin/models/json/table/JSONTableCell.d.ts +8 -0
  30. package/bin/models/json/table/JSONTableCell.js +105 -0
  31. package/bin/models/json/table/JSONTableCell.js.map +1 -0
  32. package/bin/models/json/table/JSONTableRow.d.ts +7 -0
  33. package/bin/models/json/table/JSONTableRow.js +27 -0
  34. package/bin/models/json/table/JSONTableRow.js.map +1 -0
  35. package/bin/models/json/wordJsonModels.d.ts +97 -0
  36. package/bin/models/json/wordJsonModels.js +3 -0
  37. package/bin/models/json/wordJsonModels.js.map +1 -0
  38. package/bin/services/logger.d.ts +3 -0
  39. package/bin/services/logger.js +46 -0
  40. package/bin/services/logger.js.map +1 -0
  41. package/bin/snippets/free-runs.d.ts +1 -0
  42. package/bin/snippets/free-runs.js +58 -0
  43. package/bin/snippets/free-runs.js.map +1 -0
  44. package/bin/test/skins.test.d.ts +1 -0
  45. package/bin/test/skins.test.js +116 -0
  46. package/bin/test/skins.test.js.map +1 -0
  47. package/package.json +46 -46
  48. package/samples/document-skins-examples/document-attchament-table.json +25 -25
  49. package/samples/document-skins-examples/documentExample.json +66 -66
  50. package/samples/document-skins-examples/paragraphExample.json +16 -16
  51. package/samples/document-skins-examples/tableExample.json +29 -29
  52. package/src/index.ts +338 -401
  53. package/src/models/json/JSONRun.ts +80 -80
  54. package/src/models/json/default.ts +23 -23
  55. package/src/models/json/html/JSONHtml.ts +13 -13
  56. package/src/models/json/paragraph/JSONParagraph.ts +76 -76
  57. package/src/models/json/paragraph/JSONRichTextParagraph.ts +84 -84
  58. package/src/models/json/paragraph/JSONTestSuiteHeaderParagraph.ts +94 -94
  59. package/src/models/json/table/JSONTable.ts +74 -74
  60. package/src/models/json/table/JSONTableCell.ts +117 -117
  61. package/src/models/json/table/JSONTableRow.ts +34 -34
  62. package/src/models/json/wordJsonModels.ts +97 -97
  63. package/src/services/logger.ts +26 -26
  64. package/src/snippets/free-runs.ts +53 -53
  65. package/src/test/skins.test.ts +171 -171
  66. package/tsconfig.json +61 -61
package/src/index.ts CHANGED
@@ -1,401 +1,338 @@
1
- import {
2
- DocumentSkin,
3
- WIQueryResults,
4
- WIData,
5
- WIProperty,
6
- StyleOptions,
7
- } from "./models/json/wordJsonModels";
8
- import logger from "./services/logger";
9
- import JSONTable from "./models/json/table/JSONTable";
10
- import JSONParagraph from "./models/json/paragraph/JSONParagraph";
11
- import JSONHeaderParagraph from "./models/json/paragraph/JSONTestSuiteHeaderParagraph";
12
- import JSONRichTextParagraph from "./models/json/paragraph/JSONRichTextParagraph";
13
- import {
14
- DescriptionandProcedureStyle
15
- } from "./models/json/default";
16
-
17
- export default class Skins {
18
- SKIN_TYPE_TABLE = "table";
19
- SKIN_TYPE_PARAGRAPH = "paragraph";
20
- SKIN_TYPE_TEST_PLAN = "test-plan";
21
-
22
- documentSkin: DocumentSkin = {
23
- templatePath: "",
24
- contentControls: [],
25
- };
26
-
27
- skinFormat: string = "json";
28
-
29
- constructor(skinFormat: string = "json", templatePath: string) {
30
- this.documentSkin.templatePath = templatePath;
31
- this.skinFormat = skinFormat;
32
- }
33
-
34
- async addNewContentToDocumentSkin(
35
- contetnControlTitle: string,
36
- skinType: string,
37
- data: any,
38
- styles: StyleOptions,
39
- headingLvl: number = 0,
40
- includeAttachments: boolean = true
41
- ): Promise<any> {
42
- try {
43
- let populatedSkin;
44
-
45
- switch (skinType) {
46
- case this.SKIN_TYPE_TABLE:
47
- populatedSkin = this.generateQueryBasedTable(
48
- data,
49
- styles,
50
- headingLvl
51
- );
52
- if (populatedSkin === false) {
53
- logger.error(
54
- `Could not generate table for content control :${contetnControlTitle}`
55
- );
56
- return false;
57
- }
58
- break;
59
- case this.SKIN_TYPE_PARAGRAPH:
60
- populatedSkin = this.generateQueryBasedParagraphs(
61
- data,
62
- styles,
63
- headingLvl
64
- );
65
- if (populatedSkin === false) {
66
- logger.error(
67
- `Could not generate paragraph for content control :${contetnControlTitle}`
68
- );
69
- return false;
70
- }
71
- break;
72
- case this.SKIN_TYPE_TEST_PLAN:
73
- populatedSkin = this.generateTestBasedSkin(
74
- data,
75
- styles,
76
- headingLvl,
77
- includeAttachments
78
- );
79
- if (populatedSkin === false) {
80
- logger.error(
81
- `Could not generate test skin for content control :${contetnControlTitle}`
82
- );
83
- return false;
84
- }
85
- break;
86
- default:
87
- logger.error(
88
- `Unknown skinType : ${skinType} - not appended to document skin`
89
- );
90
- return false;
91
- }
92
-
93
- return populatedSkin;
94
-
95
- // await this.validateAndAppendContentControl(
96
- // contetnControlTitle,
97
- // populatedSkin
98
- // );
99
- } catch (error) {
100
- logger.error(
101
- `Fatal error happened when generate skin for : ${contetnControlTitle}`
102
- );
103
- return false;
104
- }
105
- } //addNewContentToDocumentSkin
106
-
107
- // iterates on content controls array:
108
- // if finds return true else creates content control and returns true
109
- // on error returns false
110
- async validateAndAppendContentControl(
111
- contetnControlTitle: string,
112
- populatedSkin: any
113
- ): Promise<boolean> {
114
- try {
115
- let isContetnControlExists: boolean[] = await Promise.all(
116
- this.documentSkin.contentControls.map((contentControl, i) => {
117
- if (contentControl.title === contetnControlTitle) {
118
- logger.debug(`Content control - ${contetnControlTitle} found on index ${i}
119
- populating with: ${contetnControlTitle}`);
120
- this.documentSkin.contentControls[i].wordObjects = [
121
- ...this.documentSkin.contentControls[i].wordObjects,
122
- ...populatedSkin,
123
- ];
124
- return true;
125
- }
126
- return false;
127
- }) //.map
128
- ); //Promise.all
129
-
130
- if (!isContetnControlExists.includes(true)) {
131
- let contentControlToAppend = {
132
- title: contetnControlTitle,
133
- wordObjects: populatedSkin,
134
- };
135
-
136
- logger.debug(`Content control - ${contetnControlTitle} not found
137
- appending to document title:
138
- ${JSON.stringify(contetnControlTitle)}`);
139
- this.documentSkin.contentControls.unshift(contentControlToAppend);
140
- }
141
- logger.info(
142
- `Appended new content control document: ${contetnControlTitle}`
143
- );
144
- return true;
145
- } catch (error) {
146
- logger.error(`Error validating and appending to content control`);
147
- console.log(error);
148
- }
149
- } //validateAndAppendContentControl
150
-
151
- //parses data to the class skin format and returns the parsed data
152
- //returns false if supplied an invalid type or error occurd during parsing
153
- generateQueryBasedTable(
154
- data: WIQueryResults,
155
- styles: StyleOptions,
156
- headingLvl: number = 0
157
- ) {
158
- logger.debug(`Generating table as ${this.skinFormat}`);
159
-
160
- switch (this.skinFormat) {
161
- case "json":
162
- let tableSkin = new JSONTable(data, styles, headingLvl);
163
- return [tableSkin.getJSONTable()];
164
- case "html":
165
- logger.info(`Generating html table!`);
166
- break;
167
- default:
168
- return false;
169
- } //switch
170
- } //generateTable
171
-
172
- generateQueryBasedParagraphs(
173
- data: any,
174
- styles: StyleOptions,
175
- headingLvl: number = 0
176
- ) {
177
- logger.debug(`Generating paragraph as ${this.skinFormat}`);
178
-
179
- switch (this.skinFormat) {
180
- case "json":
181
- let paragraphs: any[] = [];
182
- data.forEach((wi: WIData) => {
183
- wi.fields.forEach((field: WIProperty) => {
184
- //Description and Test Description are handled in richText handler
185
- if (
186
- field.name === "Description: " ||
187
- field.name === "Test Description:"
188
- ) {
189
- let paragraphSkin = new JSONRichTextParagraph(
190
- field,
191
- styles,
192
- wi.Source,
193
- headingLvl + wi.level
194
- );
195
- paragraphs.push(paragraphSkin.getJSONRichTextParagraph());
196
- }
197
-
198
- //making sure ID is not printed
199
- //excluding Description and Test Description are handled in richText handler
200
- if (
201
- field.name !== "ID" &&
202
- field.name !== "Description: " &&
203
- field.name !== "Test Description:"
204
- ) {
205
- let paragraphSkin = new JSONParagraph(
206
- field,
207
- styles,
208
- wi.Source,
209
- headingLvl + wi.level
210
- );
211
- paragraphs.push(paragraphSkin.getJSONParagraph());
212
- }
213
- });
214
- });
215
- return paragraphs;
216
- case "html":
217
- logger.info(`Generating html paragraphs!`);
218
- break;
219
- default:
220
- return false;
221
- } //switch
222
- } //generateParagraph
223
-
224
- generateTestBasedSkin(
225
- data: any,
226
- styles: StyleOptions,
227
- headingLvl: number = 0,
228
- includeAttachments: boolean = true
229
- ) {
230
- logger.debug(`Generating testSkin as ${this.skinFormat}`);
231
- switch (this.skinFormat) {
232
- case "json":
233
- let testSkin: any[] = [];
234
- //create suite Header pragraph
235
- data.forEach((testSuite: any) => {
236
- let SuiteStyles = {
237
- isBold: true,
238
- IsItalic: false,
239
- IsUnderline: false,
240
- Size: 16,
241
- Uri: null,
242
- Font: "Arial",
243
- InsertLineBreak: false,
244
- InsertSpace: true,
245
- };
246
- let testSuiteParagraphSkin = new JSONHeaderParagraph(
247
- testSuite.suiteSkinData.fields,
248
- SuiteStyles,
249
- testSuite.suiteSkinData.id || 0,
250
- testSuite.suiteSkinData.level
251
- ? headingLvl + testSuite.suiteSkinData.level
252
- : headingLvl
253
- ? headingLvl
254
- : 1
255
- );
256
- testSkin.push(testSuiteParagraphSkin.getJSONParagraph());
257
-
258
- testSuite.testCases.forEach((testcase) => {
259
- //create testcase Header paragraph
260
- let testCaseHeaderFields = [
261
- testcase.testCaseHeaderSkinData.fields[0],
262
- testcase.testCaseHeaderSkinData.fields[1],
263
- ];
264
- let TestCaseStyles = {
265
- isBold: true,
266
- IsItalic: false,
267
- IsUnderline: false,
268
- Size: 14,
269
- Uri: null,
270
- Font: "Arial",
271
- InsertLineBreak: false,
272
- InsertSpace: true,
273
- };
274
- let testCaseParagraphSkin = new JSONHeaderParagraph(
275
- testCaseHeaderFields,
276
- TestCaseStyles,
277
- testcase.id || 0,
278
- testcase.testCaseHeaderSkinData.level
279
- ? headingLvl + testcase.testCaseHeaderSkinData.level
280
- : headingLvl
281
- ? headingLvl
282
- : 1
283
- );
284
- testSkin.push(testCaseParagraphSkin.getJSONParagraph());
285
-
286
- let testDescriptionTitleParagraph = new JSONParagraph(
287
- { name: "Title", value: "Test Description:" },
288
- DescriptionandProcedureStyle,
289
- testcase.id || 0,
290
- 0
291
- );
292
- testSkin.push(testDescriptionTitleParagraph.getJSONParagraph());
293
- let testDescriptionParagraph = new JSONRichTextParagraph(
294
- testcase.testCaseHeaderSkinData.fields[2],
295
- styles,
296
- testcase.id || 0,
297
- 0
298
- );
299
- let richTextSkin: any[] =
300
- testDescriptionParagraph.getJSONRichTextParagraph();
301
- testSkin = [...testSkin, ...richTextSkin];
302
-
303
- if (testcase.testCaseRequirements) {
304
- if (
305
- testcase.testCaseRequirements.length > 0
306
- ) {
307
-
308
- let testDescriptionTitleParagraph = new JSONParagraph(
309
- { name: "Title", value: "Covered Requirements:" },
310
- DescriptionandProcedureStyle,
311
- testcase.id || 0,
312
- 0
313
- );
314
- testSkin.push(testDescriptionTitleParagraph.getJSONParagraph());
315
- //create test steps table
316
- let tableSkin = new JSONTable(
317
- testcase.testCaseRequirements,
318
- styles,
319
- headingLvl
320
- );
321
-
322
- let populatedTableSkin = tableSkin.getJSONTable();
323
-
324
- testSkin.push(populatedTableSkin);
325
- }
326
- }
327
-
328
- try {
329
- if (testcase.testCaseStepsSkinData.length > 0) {
330
- let testProcedureTitleParagraph = new JSONParagraph(
331
- { name: "Title", value: "Test Procedure:" },
332
- DescriptionandProcedureStyle,
333
- testcase.id || 0,
334
- 0
335
- );
336
- let TableContentStyles = {
337
- isBold: false,
338
- IsItalic: false,
339
- IsUnderline: false,
340
- Size: 12,
341
- Uri: null,
342
- Font: "Arial",
343
- InsertLineBreak: false,
344
- InsertSpace: true,
345
- };
346
- testSkin.push(testProcedureTitleParagraph.getJSONParagraph());
347
- //create test steps table
348
- let tableSkin = new JSONTable(
349
- testcase.testCaseStepsSkinData,
350
- TableContentStyles,
351
- headingLvl
352
- );
353
- let populatedTableSkin = tableSkin.getJSONTable();
354
- testSkin.push(populatedTableSkin);
355
- }
356
- } catch (error) {
357
- logger.warn(
358
- `For suite id : ${testSuite.suiteSkinData.fields[0].value} , the testCaseStepsSkinData is not defined for ${testcase.testCaseHeaderSkinData.fields[0].value} `
359
- );
360
- }
361
-
362
- //attachments table
363
- if (testcase.testCaseAttachments) {
364
- if (
365
- testcase.testCaseAttachments.length > 0 &&
366
- includeAttachments == true
367
- ) {
368
-
369
- let testDescriptionTitleParagraph = new JSONParagraph(
370
- { name: "Title", value: "Test Case Attachments:" },
371
- styles,
372
- testcase.id || 0,
373
- 0
374
- );
375
- testSkin.push(testDescriptionTitleParagraph.getJSONParagraph());
376
- //create test steps table
377
- let tableSkin = new JSONTable(
378
- testcase.testCaseAttachments,
379
- styles,
380
- headingLvl
381
- );
382
- let populatedTableSkin = tableSkin.getJSONTable();
383
- testSkin.push(populatedTableSkin);
384
- }
385
- }
386
- });
387
- });
388
- return testSkin;
389
- break;
390
- case "html":
391
- logger.info(`Generating html test data!`);
392
- break;
393
- default:
394
- return false;
395
- } //switch
396
- } //generateTestBasedSkin
397
-
398
- getDocumentSkin(): DocumentSkin {
399
- return this.documentSkin;
400
- } //getDocumentSkin
401
- }
1
+ import { DocumentSkin, WIQueryResults, WIData, WIProperty, StyleOptions } from './models/json/wordJsonModels';
2
+ import logger from './services/logger';
3
+ import JSONTable from './models/json/table/JSONTable';
4
+ import JSONParagraph from './models/json/paragraph/JSONParagraph';
5
+ import JSONHeaderParagraph from './models/json/paragraph/JSONTestSuiteHeaderParagraph';
6
+ import JSONRichTextParagraph from './models/json/paragraph/JSONRichTextParagraph';
7
+ import { DescriptionandProcedureStyle } from './models/json/default';
8
+
9
+ export default class Skins {
10
+ SKIN_TYPE_TABLE = 'table';
11
+ SKIN_TYPE_PARAGRAPH = 'paragraph';
12
+ SKIN_TYPE_TEST_PLAN = 'test-plan';
13
+
14
+ documentSkin: DocumentSkin = {
15
+ templatePath: '',
16
+ contentControls: [],
17
+ };
18
+
19
+ skinFormat: string = 'json';
20
+
21
+ constructor(skinFormat: string = 'json', templatePath: string) {
22
+ this.documentSkin.templatePath = templatePath;
23
+ this.skinFormat = skinFormat;
24
+ }
25
+
26
+ async addNewContentToDocumentSkin(
27
+ contetnControlTitle: string,
28
+ skinType: string,
29
+ data: any,
30
+ styles: StyleOptions,
31
+ headingLvl: number = 0,
32
+ includeAttachments: boolean = true
33
+ ): Promise<any> {
34
+ try {
35
+ let populatedSkin;
36
+
37
+ switch (skinType) {
38
+ case this.SKIN_TYPE_TABLE:
39
+ populatedSkin = this.generateQueryBasedTable(data, styles, headingLvl);
40
+ if (populatedSkin === false) {
41
+ logger.error(`Could not generate table for content control :${contetnControlTitle}`);
42
+ return false;
43
+ }
44
+ break;
45
+ case this.SKIN_TYPE_PARAGRAPH:
46
+ populatedSkin = this.generateQueryBasedParagraphs(data, styles, headingLvl);
47
+ if (populatedSkin === false) {
48
+ logger.error(`Could not generate paragraph for content control :${contetnControlTitle}`);
49
+ return false;
50
+ }
51
+ break;
52
+ case this.SKIN_TYPE_TEST_PLAN:
53
+ populatedSkin = this.generateTestBasedSkin(data, styles, headingLvl, includeAttachments);
54
+ if (populatedSkin === false) {
55
+ logger.error(`Could not generate test skin for content control :${contetnControlTitle}`);
56
+ return false;
57
+ }
58
+ break;
59
+ default:
60
+ logger.error(`Unknown skinType : ${skinType} - not appended to document skin`);
61
+ return false;
62
+ }
63
+
64
+ return populatedSkin;
65
+
66
+ // await this.validateAndAppendContentControl(
67
+ // contetnControlTitle,
68
+ // populatedSkin
69
+ // );
70
+ } catch (error) {
71
+ logger.error(`Fatal error happened when generate skin for : ${contetnControlTitle}`);
72
+ return false;
73
+ }
74
+ } //addNewContentToDocumentSkin
75
+
76
+ // iterates on content controls array:
77
+ // if finds return true else creates content control and returns true
78
+ // on error returns false
79
+ async validateAndAppendContentControl(contetnControlTitle: string, populatedSkin: any): Promise<boolean> {
80
+ try {
81
+ let isContetnControlExists: boolean[] = await Promise.all(
82
+ this.documentSkin.contentControls.map((contentControl, i) => {
83
+ if (contentControl.title === contetnControlTitle) {
84
+ logger.debug(`Content control - ${contetnControlTitle} found on index ${i}
85
+ populating with: ${contetnControlTitle}`);
86
+ this.documentSkin.contentControls[i].wordObjects = [
87
+ ...this.documentSkin.contentControls[i].wordObjects,
88
+ ...populatedSkin,
89
+ ];
90
+ return true;
91
+ }
92
+ return false;
93
+ }) //.map
94
+ ); //Promise.all
95
+
96
+ if (!isContetnControlExists.includes(true)) {
97
+ let contentControlToAppend = {
98
+ title: contetnControlTitle,
99
+ wordObjects: populatedSkin,
100
+ };
101
+
102
+ logger.debug(`Content control - ${contetnControlTitle} not found
103
+ appending to document title:
104
+ ${JSON.stringify(contetnControlTitle)}`);
105
+ this.documentSkin.contentControls.unshift(contentControlToAppend);
106
+ }
107
+ logger.info(`Appended new content control document: ${contetnControlTitle}`);
108
+ return true;
109
+ } catch (error) {
110
+ logger.error(`Error validating and appending to content control`);
111
+ console.log(error);
112
+ }
113
+ } //validateAndAppendContentControl
114
+
115
+ //parses data to the class skin format and returns the parsed data
116
+ //returns false if supplied an invalid type or error occurd during parsing
117
+ generateQueryBasedTable(data: WIQueryResults, styles: StyleOptions, headingLvl: number = 0) {
118
+ logger.debug(`Generating table as ${this.skinFormat}`);
119
+
120
+ switch (this.skinFormat) {
121
+ case 'json':
122
+ let tableSkin = new JSONTable(data, styles, headingLvl);
123
+ return [tableSkin.getJSONTable()];
124
+ case 'html':
125
+ logger.info(`Generating html table!`);
126
+ break;
127
+ default:
128
+ return false;
129
+ } //switch
130
+ } //generateTable
131
+
132
+ generateQueryBasedParagraphs(data: any, styles: StyleOptions, headingLvl: number = 0) {
133
+ logger.debug(`Generating paragraph as ${this.skinFormat}`);
134
+
135
+ switch (this.skinFormat) {
136
+ case 'json':
137
+ let paragraphs: any[] = [];
138
+ data.forEach((wi: WIData) => {
139
+ wi.fields.forEach((field: WIProperty) => {
140
+ //Description and Test Description are handled in richText handler
141
+ if (field.name === 'Description: ' || field.name === 'Test Description:') {
142
+ let paragraphSkin = new JSONRichTextParagraph(field, styles, wi.Source, headingLvl + wi.level);
143
+ paragraphs.push(paragraphSkin.getJSONRichTextParagraph());
144
+ }
145
+
146
+ //making sure ID is not printed
147
+ //excluding Description and Test Description are handled in richText handler
148
+ if (field.name !== 'ID' && field.name !== 'Description: ' && field.name !== 'Test Description:') {
149
+ let paragraphSkin = new JSONParagraph(field, styles, wi.Source, headingLvl + wi.level);
150
+ paragraphs.push(paragraphSkin.getJSONParagraph());
151
+ }
152
+ });
153
+ });
154
+ return paragraphs;
155
+ case 'html':
156
+ logger.info(`Generating html paragraphs!`);
157
+ break;
158
+ default:
159
+ return false;
160
+ } //switch
161
+ } //generateParagraph
162
+
163
+ generateTestBasedSkin(
164
+ data: any,
165
+ styles: StyleOptions,
166
+ headingLvl: number = 0,
167
+ includeAttachments: boolean = true
168
+ ) {
169
+ logger.debug(`Generating testSkin as ${this.skinFormat}`);
170
+ switch (this.skinFormat) {
171
+ case 'json':
172
+ let testSkin: any[] = [];
173
+ //create suite Header pragraph
174
+ data.forEach((testSuite: any) => {
175
+ let SuiteStyles = {
176
+ isBold: true,
177
+ IsItalic: false,
178
+ IsUnderline: false,
179
+ Size: 16,
180
+ Uri: null,
181
+ Font: 'Arial',
182
+ InsertLineBreak: false,
183
+ InsertSpace: true,
184
+ };
185
+ let testSuiteParagraphSkin = new JSONHeaderParagraph(
186
+ testSuite.suiteSkinData.fields,
187
+ SuiteStyles,
188
+ testSuite.suiteSkinData.id || 0,
189
+ testSuite.suiteSkinData.level
190
+ ? headingLvl + testSuite.suiteSkinData.level
191
+ : headingLvl
192
+ ? headingLvl
193
+ : 1
194
+ );
195
+ testSkin.push(testSuiteParagraphSkin.getJSONParagraph());
196
+
197
+ testSuite.testCases.forEach((testcase) => {
198
+ //create testcase Header paragraph
199
+ let testCaseHeaderFields = [
200
+ testcase.testCaseHeaderSkinData.fields[0],
201
+ testcase.testCaseHeaderSkinData.fields[1],
202
+ ];
203
+ let TestCaseStyles = {
204
+ isBold: true,
205
+ IsItalic: false,
206
+ IsUnderline: false,
207
+ Size: 14,
208
+ Uri: null,
209
+ Font: 'Arial',
210
+ InsertLineBreak: false,
211
+ InsertSpace: true,
212
+ };
213
+ let testCaseParagraphSkin = new JSONHeaderParagraph(
214
+ testCaseHeaderFields,
215
+ TestCaseStyles,
216
+ testcase.id || 0,
217
+ testcase.testCaseHeaderSkinData.level
218
+ ? headingLvl + testcase.testCaseHeaderSkinData.level
219
+ : headingLvl
220
+ ? headingLvl
221
+ : 1
222
+ );
223
+ testSkin.push(testCaseParagraphSkin.getJSONParagraph());
224
+
225
+ let testDescriptionTitleParagraph = new JSONParagraph(
226
+ { name: 'Title', value: 'Test Description:' },
227
+ DescriptionandProcedureStyle,
228
+ testcase.id || 0,
229
+ 0
230
+ );
231
+ testSkin.push(testDescriptionTitleParagraph.getJSONParagraph());
232
+ let testDescriptionParagraph = new JSONRichTextParagraph(
233
+ testcase.testCaseHeaderSkinData.fields[2],
234
+ styles,
235
+ testcase.id || 0,
236
+ 0
237
+ );
238
+ let richTextSkin: any[] = testDescriptionParagraph.getJSONRichTextParagraph();
239
+ testSkin = [...testSkin, ...richTextSkin];
240
+
241
+ if (testcase.testCaseRequirements) {
242
+ if (testcase.testCaseRequirements.length > 0) {
243
+ let testDescriptionTitleParagraph = new JSONParagraph(
244
+ { name: 'Title', value: 'Covered Requirements:' },
245
+ DescriptionandProcedureStyle,
246
+ testcase.id || 0,
247
+ 0
248
+ );
249
+ testSkin.push(testDescriptionTitleParagraph.getJSONParagraph());
250
+ //create test steps table
251
+ let tableSkin = new JSONTable(testcase.testCaseRequirements, styles, headingLvl);
252
+
253
+ let populatedTableSkin = tableSkin.getJSONTable();
254
+
255
+ testSkin.push(populatedTableSkin);
256
+ }
257
+ }
258
+
259
+ if (testcase.testCaseBugs) {
260
+ if (testcase.testCaseBugs.length > 0) {
261
+ let testDescriptionTitleParagraph = new JSONParagraph(
262
+ { name: 'Title', value: 'Linked Bugs:' },
263
+ DescriptionandProcedureStyle,
264
+ testcase.id || 0,
265
+ 0
266
+ );
267
+ testSkin.push(testDescriptionTitleParagraph.getJSONParagraph());
268
+ //create test steps table
269
+ let tableSkin = new JSONTable(testcase.testCaseBugs, styles, headingLvl);
270
+
271
+ let populatedTableSkin = tableSkin.getJSONTable();
272
+
273
+ testSkin.push(populatedTableSkin);
274
+ }
275
+ }
276
+
277
+ try {
278
+ if (testcase.testCaseStepsSkinData.length > 0) {
279
+ let testProcedureTitleParagraph = new JSONParagraph(
280
+ { name: 'Title', value: 'Test Procedure:' },
281
+ DescriptionandProcedureStyle,
282
+ testcase.id || 0,
283
+ 0
284
+ );
285
+ let TableContentStyles = {
286
+ isBold: false,
287
+ IsItalic: false,
288
+ IsUnderline: false,
289
+ Size: 12,
290
+ Uri: null,
291
+ Font: 'Arial',
292
+ InsertLineBreak: false,
293
+ InsertSpace: true,
294
+ };
295
+ testSkin.push(testProcedureTitleParagraph.getJSONParagraph());
296
+ //create test steps table
297
+ let tableSkin = new JSONTable(testcase.testCaseStepsSkinData, TableContentStyles, headingLvl);
298
+ let populatedTableSkin = tableSkin.getJSONTable();
299
+ testSkin.push(populatedTableSkin);
300
+ }
301
+ } catch (error) {
302
+ logger.warn(
303
+ `For suite id : ${testSuite.suiteSkinData.fields[0].value} , the testCaseStepsSkinData is not defined for ${testcase.testCaseHeaderSkinData.fields[0].value} `
304
+ );
305
+ }
306
+
307
+ //attachments table
308
+ if (testcase.testCaseAttachments) {
309
+ if (testcase.testCaseAttachments.length > 0 && includeAttachments == true) {
310
+ let testDescriptionTitleParagraph = new JSONParagraph(
311
+ { name: 'Title', value: 'Test Case Attachments:' },
312
+ styles,
313
+ testcase.id || 0,
314
+ 0
315
+ );
316
+ testSkin.push(testDescriptionTitleParagraph.getJSONParagraph());
317
+ //create test steps table
318
+ let tableSkin = new JSONTable(testcase.testCaseAttachments, styles, headingLvl);
319
+ let populatedTableSkin = tableSkin.getJSONTable();
320
+ testSkin.push(populatedTableSkin);
321
+ }
322
+ }
323
+ });
324
+ });
325
+ return testSkin;
326
+ break;
327
+ case 'html':
328
+ logger.info(`Generating html test data!`);
329
+ break;
330
+ default:
331
+ return false;
332
+ } //switch
333
+ } //generateTestBasedSkin
334
+
335
+ getDocumentSkin(): DocumentSkin {
336
+ return this.documentSkin;
337
+ } //getDocumentSkin
338
+ }