@microsoft/connected-workbooks 3.1.2-beta.2 → 3.2.0-beta
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/README.md +2 -2
- package/dist/main.js +357 -106
- package/dist/src/generators.js +7 -6
- package/dist/src/types.d.ts +1 -0
- package/dist/src/utils/arrayUtils.js +26 -21
- package/dist/src/utils/constants.js +20 -8
- package/dist/src/utils/documentUtils.js +92 -42
- package/dist/src/utils/gridUtils.js +23 -23
- package/dist/src/utils/htmlUtils.js +8 -8
- package/dist/src/utils/mashupDocumentParser.js +110 -67
- package/dist/src/utils/pqUtils.js +158 -65
- package/dist/src/utils/tableUtils.js +118 -74
- package/dist/src/utils/xmlInnerPartsUtils.js +213 -152
- package/dist/src/utils/xmlPartsUtils.js +116 -50
- package/dist/tests/arrayUtils.test.js +21 -21
- package/dist/tests/documentUtils.test.js +37 -8
- package/dist/tests/gridUtils.test.js +9 -9
- package/dist/tests/htmlUtils.test.js +48 -47
- package/dist/tests/mashupDocumentParser.test.js +91 -38
- package/dist/tests/mocks/PqMock.js +1 -1
- package/dist/tests/mocks/section1mSimpleQueryMock.js +5 -15
- package/dist/tests/mocks/xmlMocks.js +2 -2
- package/dist/tests/tableUtils.test.js +18 -18
- package/dist/tests/workbookQueryTemplate.test.js +127 -45
- package/dist/tests/workbookTableTemplate.test.js +104 -33
- package/dist/tests/xmlInnerPartsUtils.test.js +118 -37
- package/dist/utils/constants.js +3 -1
- package/dist/utils/pqUtils.js +63 -45
- package/dist/workbookManager.d.ts +1 -0
- package/dist/workbookManager.js +31 -9
- package/package.json +1 -1
|
@@ -2,20 +2,20 @@
|
|
|
2
2
|
// Copyright (c) Microsoft Corporation.
|
|
3
3
|
// Licensed under the MIT license.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
describe("Table Utils tests", ()
|
|
8
|
-
test("tests workbookXML contains initial data dimensions", ()
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
var utils_1 = require("../src/utils");
|
|
6
|
+
var mocks_1 = require("./mocks");
|
|
7
|
+
describe("Table Utils tests", function () {
|
|
8
|
+
test("tests workbookXML contains initial data dimensions", function () {
|
|
9
|
+
var defaultString = '<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x15 xr xr6 xr10 xr2" xmlns:x15="http://schemas.microsoft.com/office/spreadsheetml/2010/11/main" xmlns:xr="http://schemas.microsoft.com/office/spreadsheetml/2014/revision" xmlns:xr6="http://schemas.microsoft.com/office/spreadsheetml/2016/revision6" xmlns:xr10="http://schemas.microsoft.com/office/spreadsheetml/2016/revision10" xmlns:xr2="http://schemas.microsoft.com/office/spreadsheetml/2015/revision2"><fileVersion appName="xl" lastEdited="7" lowestEdited="7" rupBuild="24729"/><workbookPr codeName="ThisWorkbook" defaultThemeVersion="166925"/><mc:AlternateContent><mc:Choice Requires="x15"><x15ac:absPath url="C:Usersv-ahmadsbeihDesktop" xmlns:x15ac="http://schemas.microsoft.com/office/spreadsheetml/2010/11/ac"/></mc:Choice></mc:AlternateContent><xr:revisionPtr revIDLastSave="0" documentId="13_ncr:1_{93EF201C-7856-4B60-94D4-65DDB8F3F16A}" xr6:coauthVersionLast="47" xr6:coauthVersionMax="47" xr10:uidLastSave="{00000000-0000-0000-0000-000000000000}"/><bookViews><workbookView xWindow="28680" yWindow="-120" windowWidth="29040" windowHeight="15990" xr2:uid="{DB915CB9-8DD9-492A-A471-C61E61200113}"/></bookViews><sheets><sheet name="Query1" sheetId="2" r:id="rId1"/><sheet name="Sheet1" sheetId="1" r:id="rId2"/></sheets><definedNames><definedName name="ExternalData_1" localSheetId="0" hidden="1">Sheet1!$A$1:$B$2</definedName></definedNames><calcPr calcId="191029"/><extLst><ext uri="{140A7094-0E35-4892-8432-C4D2E57EDEB5}"><x15:workbookPr chartTrackingRefBase="1"/></ext><ext uri="{B58B0392-4F1F-4190-BB64-5DF3571DCE5F}" xmlns:xcalcf="http://schemas.microsoft.com/office/spreadsheetml/2018/calcfeatures"><xcalcf:calcFeatures><xcalcf:feature name="microsoft.com:RD"/><xcalcf:feature name="microsoft.com:FV"/><xcalcf:feature name="microsoft.com:LET_WF"/><xcalcf:feature name="microsoft.com:LAMBDA_WF"/></xcalcf:calcFeatures></ext></extLst></workbook>';
|
|
10
|
+
var worksheetXml = utils_1.tableUtils.updateWorkbookInitialData(defaultString, {
|
|
11
11
|
columnNames: ["Column1", "Column2"],
|
|
12
12
|
rows: [["1", "2"]],
|
|
13
13
|
});
|
|
14
14
|
expect(worksheetXml).toContain(mocks_1.workbookXmlMock);
|
|
15
15
|
});
|
|
16
|
-
test("tests Pivot Tables contain initial data", ()
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
test("tests Pivot Tables contain initial data", function () {
|
|
17
|
+
var defaultString = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\r\n<table xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="xr xr3" xmlns:xr="http://schemas.microsoft.com/office/spreadsheetml/2014/revision" xmlns:xr3="http://schemas.microsoft.com/office/spreadsheetml/2016/revision3" id="1" xr:uid="{D8539CF6-04E5-464D-9950-5A36C5A1FCFE}" name="Query1" displayName="Query1" ref="A1:A2" tableType="queryTable" totalsRowShown="0"><autoFilter ref="A1:A2" xr:uid="{D8539CF6-04E5-464D-9950-5A36C5A1FCFE}"/><tableColumns count="1"><tableColumn id="1" xr3:uid="{D1084858-8AE5-4728-A9BE-FE78821CDFFF}" uniqueName="1" name="Query1" queryTableFieldId="1" dataDxfId="0"/></tableColumns><tableStyleInfo name="TableStyleMedium7" showFirstColumn="0" showLastColumn="0" showRowStripes="1" showColumnStripes="0"/></table>';
|
|
18
|
+
var tableXmlSheet = utils_1.tableUtils.updateTablesInitialData(defaultString, {
|
|
19
19
|
columnNames: ["Column1", "Column2"],
|
|
20
20
|
rows: [["1", "2"]],
|
|
21
21
|
}, true);
|
|
@@ -28,9 +28,9 @@ describe("Table Utils tests", () => {
|
|
|
28
28
|
expect(tableXmlSheet).toContain('name="Column2"');
|
|
29
29
|
expect(tableXmlSheet).toContain('queryTableFieldId="2"');
|
|
30
30
|
});
|
|
31
|
-
test("tests blank Table contain initial data", ()
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
test("tests blank Table contain initial data", function () {
|
|
32
|
+
var defaultString = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\r\n<table xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="xr xr3" xmlns:xr="http://schemas.microsoft.com/office/spreadsheetml/2014/revision" xmlns:xr3="http://schemas.microsoft.com/office/spreadsheetml/2016/revision3" id="1" xr:uid="{D8539CF6-04E5-464D-9950-5A36C5A1FCFE}" name="Query1" displayName="Query1" ref="A1:A2" tableType="queryTable" totalsRowShown="0"><autoFilter ref="A1:A2" xr:uid="{D8539CF6-04E5-464D-9950-5A36C5A1FCFE}"/><tableColumns count="1"><tableColumn id="1" xr3:uid="{D1084858-8AE5-4728-A9BE-FE78821CDFFF}" uniqueName="1" name="Query1" queryTableFieldId="1" dataDxfId="0"/></tableColumns><tableStyleInfo name="TableStyleMedium7" showFirstColumn="0" showLastColumn="0" showRowStripes="1" showColumnStripes="0"/></table>';
|
|
33
|
+
var tableXmlSheet = utils_1.tableUtils.updateTablesInitialData(defaultString, {
|
|
34
34
|
columnNames: ["Column1", "Column2"],
|
|
35
35
|
rows: [["1", "2"]],
|
|
36
36
|
}, false);
|
|
@@ -44,17 +44,17 @@ describe("Table Utils tests", () => {
|
|
|
44
44
|
expect(tableXmlSheet).not.toContain('uniqueName="2"');
|
|
45
45
|
expect(tableXmlSheet).not.toContain('queryTableFieldId="2"');
|
|
46
46
|
});
|
|
47
|
-
test("test valid initial data in SheetsXML", ()
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
test("test valid initial data in SheetsXML", function () {
|
|
48
|
+
var defaultString = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x14ac xr xr2 xr3" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac" xmlns:xr="http://schemas.microsoft.com/office/spreadsheetml/2014/revision" xmlns:xr2="http://schemas.microsoft.com/office/spreadsheetml/2015/revision2" xmlns:xr3="http://schemas.microsoft.com/office/spreadsheetml/2016/revision3" xr:uid="{EDF0138E-D216-4CD1-8EFA-1396A1BB4478}"><sheetPr codeName="Sheet1"/><dimension ref="A1:B2"/><sheetViews><sheetView tabSelected="1" workbookViewId="0"><selection sqref="A1:B2"/></sheetView></sheetViews><sheetFormatPr defaultRowHeight="14.4" x14ac:dyDescent="0.3"/><cols><col min="1" max="1" width="9.6640625" bestFit="1" customWidth="1"/></cols><sheetData><row r="1" spans="1:1" x14ac:dyDescent="0.3"><c r="A1" t="s"><v>0</v></c></row><row r="2" spans="1:1" x14ac:dyDescent="0.3"><c r="A2" t="s"><v>1</v></c></row></sheetData><pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/><tableParts count="1"><tablePart r:id="rId1"/></tableParts></worksheet>';
|
|
49
|
+
var sheetsXmlString = utils_1.tableUtils.updateSheetsInitialData(defaultString, {
|
|
50
50
|
columnNames: ["Column1", "Column2"],
|
|
51
51
|
rows: [["1", "2"]],
|
|
52
52
|
});
|
|
53
53
|
expect(sheetsXmlString).toContain(mocks_1.sheetsXmlMock);
|
|
54
54
|
});
|
|
55
|
-
test("tests Query Tables contain initial data", ()
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
test("tests Query Tables contain initial data", function () {
|
|
56
|
+
var defaultString = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\r\n<queryTable xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="xr16" xmlns:xr16="http://schemas.microsoft.com/office/spreadsheetml/2017/revision16" name="ExternalData_1" connectionId="1" xr16:uid="{24C17B89-3CD3-4AA5-B84F-9FF5F35245D7}" autoFormatId="16" applyNumberFormats="0" applyBorderFormats="0" applyFontFormats="0" applyPatternFormats="0" applyAlignmentFormats="0" applyWidthHeightFormats="0"><queryTableRefresh nextId="2"><queryTableFields count="1"><queryTableField id="1" name="Query1" tableColumnId="1"/></queryTableFields></queryTableRefresh></queryTable>';
|
|
57
|
+
var queryTableXmlSheet = utils_1.tableUtils.updateQueryTablesInitialData(defaultString, {
|
|
58
58
|
columnNames: ["Column1", "Column2"],
|
|
59
59
|
rows: [["1", "2"]],
|
|
60
60
|
});
|
|
@@ -10,55 +10,137 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
11
|
});
|
|
12
12
|
};
|
|
13
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
14
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
15
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
16
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
17
|
+
function step(op) {
|
|
18
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
19
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
20
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
21
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
22
|
+
switch (op[0]) {
|
|
23
|
+
case 0: case 1: t = op; break;
|
|
24
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
25
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
26
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
27
|
+
default:
|
|
28
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
29
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
30
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
31
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
32
|
+
if (t[2]) _.ops.pop();
|
|
33
|
+
_.trys.pop(); continue;
|
|
34
|
+
}
|
|
35
|
+
op = body.call(thisArg, _);
|
|
36
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
37
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
38
|
+
}
|
|
39
|
+
};
|
|
13
40
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
41
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
42
|
};
|
|
16
43
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return
|
|
25
|
-
|
|
44
|
+
var utils_1 = require("../src/utils");
|
|
45
|
+
var constants_1 = require("../src/utils/constants");
|
|
46
|
+
var mashupDocumentParser_1 = require("../src/utils/mashupDocumentParser");
|
|
47
|
+
var workbookTemplate_1 = require("../src/workbookTemplate");
|
|
48
|
+
var mocks_1 = require("./mocks");
|
|
49
|
+
var jszip_1 = __importDefault(require("jszip"));
|
|
50
|
+
var getZip = function (template) { return __awaiter(void 0, void 0, void 0, function () {
|
|
51
|
+
return __generator(this, function (_a) {
|
|
52
|
+
switch (_a.label) {
|
|
53
|
+
case 0: return [4 /*yield*/, jszip_1.default.loadAsync(template, {
|
|
54
|
+
base64: true,
|
|
55
|
+
})];
|
|
56
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
57
|
+
}
|
|
26
58
|
});
|
|
27
|
-
});
|
|
28
|
-
describe("Single query template tests", ()
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
beforeAll(()
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
59
|
+
}); };
|
|
60
|
+
describe("Single query template tests", function () {
|
|
61
|
+
var singleQueryDefaultTemplate = workbookTemplate_1.SIMPLE_QUERY_WORKBOOK_TEMPLATE;
|
|
62
|
+
var defaultZipFile;
|
|
63
|
+
beforeAll(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
64
|
+
return __generator(this, function (_a) {
|
|
65
|
+
switch (_a.label) {
|
|
66
|
+
case 0:
|
|
67
|
+
expect(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
68
|
+
switch (_a.label) {
|
|
69
|
+
case 0: return [4 /*yield*/, getZip(singleQueryDefaultTemplate)];
|
|
70
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
71
|
+
}
|
|
72
|
+
}); }); }).not.toThrow();
|
|
73
|
+
return [4 /*yield*/, getZip(singleQueryDefaultTemplate)];
|
|
74
|
+
case 1:
|
|
75
|
+
defaultZipFile = _a.sent();
|
|
76
|
+
return [2 /*return*/];
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}); });
|
|
80
|
+
test("Default template is a valid zip file", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
81
|
+
return __generator(this, function (_a) {
|
|
82
|
+
expect(defaultZipFile).toBeTruthy();
|
|
83
|
+
return [2 /*return*/];
|
|
84
|
+
});
|
|
85
|
+
}); });
|
|
86
|
+
test("DataMashup XML exists, and valid PQ Base64 can be extracted", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
87
|
+
var _a, found, path, value;
|
|
88
|
+
return __generator(this, function (_b) {
|
|
89
|
+
switch (_b.label) {
|
|
90
|
+
case 0:
|
|
91
|
+
expect(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
92
|
+
switch (_a.label) {
|
|
93
|
+
case 0: return [4 /*yield*/, utils_1.pqUtils.getDataMashupFile(defaultZipFile)];
|
|
94
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
95
|
+
}
|
|
96
|
+
}); }); }).not.toThrowError();
|
|
97
|
+
return [4 /*yield*/, utils_1.pqUtils.getDataMashupFile(defaultZipFile)];
|
|
98
|
+
case 1:
|
|
99
|
+
_a = _b.sent(), found = _a.found, path = _a.path, value = _a.value;
|
|
100
|
+
expect(found).toBeTruthy();
|
|
101
|
+
expect(value).toEqual(mocks_1.pqEmptySingleQueryBase64);
|
|
102
|
+
expect(path).toEqual(mocks_1.item1Path);
|
|
103
|
+
return [2 /*return*/];
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}); });
|
|
107
|
+
test("ConnectedWorkbook XML exists as item1.xml", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
108
|
+
var _a, found, path, xmlString;
|
|
109
|
+
return __generator(this, function (_b) {
|
|
110
|
+
switch (_b.label) {
|
|
111
|
+
case 0: return [4 /*yield*/, utils_1.pqUtils.getCustomXmlFile(defaultZipFile, constants_1.URLS.CONNECTED_WORKBOOK)];
|
|
112
|
+
case 1:
|
|
113
|
+
_a = _b.sent(), found = _a.found, path = _a.path, xmlString = _a.xmlString;
|
|
114
|
+
expect(found).toBeTruthy();
|
|
115
|
+
expect(xmlString).toEqual(mocks_1.connectedWorkbookXmlMock);
|
|
116
|
+
expect(path).toEqual(mocks_1.item2Path);
|
|
117
|
+
return [2 /*return*/];
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}); });
|
|
121
|
+
test("A single blank query named Query1 exists", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
122
|
+
var base64Str, packageOPC, packageZip, section1m, hasQuery1;
|
|
52
123
|
var _a;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
124
|
+
return __generator(this, function (_b) {
|
|
125
|
+
switch (_b.label) {
|
|
126
|
+
case 0: return [4 /*yield*/, utils_1.pqUtils.getBase64(defaultZipFile)];
|
|
127
|
+
case 1:
|
|
128
|
+
base64Str = _b.sent();
|
|
129
|
+
packageOPC = (0, mashupDocumentParser_1.getPackageComponents)(base64Str).packageOPC;
|
|
130
|
+
return [4 /*yield*/, jszip_1.default.loadAsync(packageOPC)];
|
|
131
|
+
case 2:
|
|
132
|
+
packageZip = _b.sent();
|
|
133
|
+
return [4 /*yield*/, ((_a = packageZip.file(constants_1.section1mPath)) === null || _a === void 0 ? void 0 : _a.async(constants_1.textResultType))];
|
|
134
|
+
case 3:
|
|
135
|
+
section1m = _b.sent();
|
|
136
|
+
if (section1m == undefined) {
|
|
137
|
+
throw new Error("section1m is undefined");
|
|
138
|
+
}
|
|
139
|
+
hasQuery1 = section1m.includes("Query1");
|
|
140
|
+
expect(hasQuery1).toBeTruthy();
|
|
141
|
+
expect(section1m).toEqual(mocks_1.section1mBlankQueryMock);
|
|
142
|
+
return [2 /*return*/];
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
}); });
|
|
64
146
|
});
|
|
@@ -10,45 +10,116 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
11
|
});
|
|
12
12
|
};
|
|
13
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
14
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
15
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
16
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
17
|
+
function step(op) {
|
|
18
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
19
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
20
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
21
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
22
|
+
switch (op[0]) {
|
|
23
|
+
case 0: case 1: t = op; break;
|
|
24
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
25
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
26
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
27
|
+
default:
|
|
28
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
29
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
30
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
31
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
32
|
+
if (t[2]) _.ops.pop();
|
|
33
|
+
_.trys.pop(); continue;
|
|
34
|
+
}
|
|
35
|
+
op = body.call(thisArg, _);
|
|
36
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
37
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
38
|
+
}
|
|
39
|
+
};
|
|
13
40
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
41
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
42
|
};
|
|
16
43
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return
|
|
23
|
-
|
|
44
|
+
var workbookTemplate_1 = require("../src/workbookTemplate");
|
|
45
|
+
var utils_1 = require("../src/utils");
|
|
46
|
+
var constants_1 = require("../src/utils/constants");
|
|
47
|
+
var jszip_1 = __importDefault(require("jszip"));
|
|
48
|
+
var getZip = function (template) { return __awaiter(void 0, void 0, void 0, function () {
|
|
49
|
+
return __generator(this, function (_a) {
|
|
50
|
+
switch (_a.label) {
|
|
51
|
+
case 0: return [4 /*yield*/, jszip_1.default.loadAsync(template, {
|
|
52
|
+
base64: true,
|
|
53
|
+
})];
|
|
54
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
55
|
+
}
|
|
24
56
|
});
|
|
25
|
-
});
|
|
26
|
-
describe("Single blank table template tests", ()
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
beforeAll(()
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
57
|
+
}); };
|
|
58
|
+
describe("Single blank table template tests", function () {
|
|
59
|
+
var simpleTableDefaultTemplate = workbookTemplate_1.SIMPLE_BLANK_TABLE_TEMPLATE;
|
|
60
|
+
var defaultZipFile;
|
|
61
|
+
beforeAll(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
62
|
+
return __generator(this, function (_a) {
|
|
63
|
+
switch (_a.label) {
|
|
64
|
+
case 0:
|
|
65
|
+
expect(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
66
|
+
switch (_a.label) {
|
|
67
|
+
case 0: return [4 /*yield*/, getZip(simpleTableDefaultTemplate)];
|
|
68
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
69
|
+
}
|
|
70
|
+
}); }); }).not.toThrow();
|
|
71
|
+
return [4 /*yield*/, getZip(simpleTableDefaultTemplate)];
|
|
72
|
+
case 1:
|
|
73
|
+
defaultZipFile = _a.sent();
|
|
74
|
+
return [2 /*return*/];
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}); });
|
|
78
|
+
test("Default template is a valid zip file", function () {
|
|
34
79
|
expect(defaultZipFile).toBeTruthy();
|
|
35
80
|
});
|
|
36
|
-
test("DataMashup XML doesn't exists", ()
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
81
|
+
test("DataMashup XML doesn't exists", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
82
|
+
var error_1;
|
|
83
|
+
return __generator(this, function (_a) {
|
|
84
|
+
switch (_a.label) {
|
|
85
|
+
case 0:
|
|
86
|
+
_a.trys.push([0, 2, , 3]);
|
|
87
|
+
return [4 /*yield*/, utils_1.pqUtils.getDataMashupFile(defaultZipFile)];
|
|
88
|
+
case 1:
|
|
89
|
+
_a.sent();
|
|
90
|
+
return [3 /*break*/, 3];
|
|
91
|
+
case 2:
|
|
92
|
+
error_1 = _a.sent();
|
|
93
|
+
expect(error_1).toBeTruthy();
|
|
94
|
+
return [3 /*break*/, 3];
|
|
95
|
+
case 3: return [2 /*return*/];
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}); });
|
|
99
|
+
test("A single blank table exists", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
100
|
+
var tableXml;
|
|
101
|
+
var _a;
|
|
102
|
+
return __generator(this, function (_b) {
|
|
103
|
+
switch (_b.label) {
|
|
104
|
+
case 0: return [4 /*yield*/, ((_a = defaultZipFile.file(constants_1.tableXmlPath)) === null || _a === void 0 ? void 0 : _a.async(constants_1.textResultType))];
|
|
105
|
+
case 1:
|
|
106
|
+
tableXml = _b.sent();
|
|
107
|
+
expect(tableXml).toContain('name="Table1" displayName="Table1" ref="A1:A2"');
|
|
108
|
+
return [2 /*return*/];
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}); });
|
|
112
|
+
test("Does not contains query table", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
113
|
+
var queryTableXml;
|
|
45
114
|
var _a;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
115
|
+
return __generator(this, function (_b) {
|
|
116
|
+
switch (_b.label) {
|
|
117
|
+
case 0: return [4 /*yield*/, ((_a = defaultZipFile.file(constants_1.queryTableXmlPath)) === null || _a === void 0 ? void 0 : _a.async(constants_1.textResultType))];
|
|
118
|
+
case 1:
|
|
119
|
+
queryTableXml = _b.sent();
|
|
120
|
+
expect(queryTableXml).toBeFalsy();
|
|
121
|
+
return [2 /*return*/];
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}); });
|
|
54
125
|
});
|
|
@@ -10,42 +10,123 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
11
|
});
|
|
12
12
|
};
|
|
13
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
14
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
15
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
16
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
17
|
+
function step(op) {
|
|
18
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
19
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
20
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
21
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
22
|
+
switch (op[0]) {
|
|
23
|
+
case 0: case 1: t = op; break;
|
|
24
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
25
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
26
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
27
|
+
default:
|
|
28
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
29
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
30
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
31
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
32
|
+
if (t[2]) _.ops.pop();
|
|
33
|
+
_.trys.pop(); continue;
|
|
34
|
+
}
|
|
35
|
+
op = body.call(thisArg, _);
|
|
36
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
37
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
38
|
+
}
|
|
39
|
+
};
|
|
13
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
describe("Workbook Manager tests", ()
|
|
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
|
-
|
|
41
|
+
var mocks_1 = require("./mocks");
|
|
42
|
+
var utils_1 = require("../src/utils");
|
|
43
|
+
describe("Workbook Manager tests", function () {
|
|
44
|
+
var mockConnectionString = "<connections xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:xr16=\"http://schemas.microsoft.com/office/spreadsheetml/2017/revision16\" mc:Ignorable=\"xr16\">\n <connection id=\"1\" xr16:uid=\"{86BA784C-6640-4989-A85E-EB4966B9E741}\" keepAlive=\"1\" name=\"Query - Query1\" description=\"Connection to the 'Query1' query in the workbook.\" type=\"5\" refreshedVersion=\"7\" background=\"1\" saveData=\"1\">\n <dbPr connection=\"Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Query1;\" command=\"SELECT * FROM [Query1]\"/></connection></connections>";
|
|
45
|
+
test("Connection XML attributes contain new query name", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
46
|
+
var connectionXmlFileString;
|
|
47
|
+
return __generator(this, function (_a) {
|
|
48
|
+
switch (_a.label) {
|
|
49
|
+
case 0: return [4 /*yield*/, utils_1.xmlInnerPartsUtils.updateConnections(mockConnectionString, "newQueryName", true)];
|
|
50
|
+
case 1:
|
|
51
|
+
connectionXmlFileString = (_a.sent()).connectionXmlFileString;
|
|
52
|
+
expect(connectionXmlFileString.replace(/ /g, "")).toContain('command="SELECT * FROM [newQueryName]'.replace(/ /g, ""));
|
|
53
|
+
expect(connectionXmlFileString.replace(/ /g, "")).toContain('name="Query - newQueryName"'.replace(/ /g, ""));
|
|
54
|
+
expect(connectionXmlFileString.replace(/ /g, "")).toContain("description=\"Connection to the 'newQueryName' query in the workbook.\"".replace(/ /g, ""));
|
|
55
|
+
return [2 /*return*/];
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}); });
|
|
59
|
+
test("Connection XML attributes contain refreshOnLoad value", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
60
|
+
var connectionXmlFileString;
|
|
61
|
+
return __generator(this, function (_a) {
|
|
62
|
+
switch (_a.label) {
|
|
63
|
+
case 0: return [4 /*yield*/, utils_1.xmlInnerPartsUtils.updateConnections(mockConnectionString, "newQueryName", true)];
|
|
64
|
+
case 1:
|
|
65
|
+
connectionXmlFileString = (_a.sent()).connectionXmlFileString;
|
|
66
|
+
expect(connectionXmlFileString.replace(/ /g, "")).toContain('refreshOnLoad="1"');
|
|
67
|
+
return [2 /*return*/];
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}); });
|
|
71
|
+
test("SharedStrings XML contains new query name", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
72
|
+
var newSharedStrings;
|
|
73
|
+
return __generator(this, function (_a) {
|
|
74
|
+
switch (_a.label) {
|
|
75
|
+
case 0: return [4 /*yield*/, utils_1.xmlInnerPartsUtils.updateSharedStrings('<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="1" uniqueCount="1"><si><t>Query1</t></si><si><t/></si></sst>', "newQueryName")];
|
|
76
|
+
case 1:
|
|
77
|
+
newSharedStrings = (_a.sent()).newSharedStrings;
|
|
78
|
+
expect(newSharedStrings.replace(/ /g, "")).toContain(mocks_1.sharedStringsXmlMock.replace(/ /g, ""));
|
|
79
|
+
return [2 /*return*/];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}); });
|
|
83
|
+
test("Tests SharedStrings update when XML contains query name", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
84
|
+
var newSharedStrings;
|
|
85
|
+
return __generator(this, function (_a) {
|
|
86
|
+
switch (_a.label) {
|
|
87
|
+
case 0: return [4 /*yield*/, utils_1.xmlInnerPartsUtils.updateSharedStrings('<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="1" uniqueCount="1"><si><t>newQueryName</t></si><si><t/></si></sst>', "newQueryName")];
|
|
88
|
+
case 1:
|
|
89
|
+
newSharedStrings = (_a.sent()).newSharedStrings;
|
|
90
|
+
expect(newSharedStrings.replace(/ /g, "")).toContain(mocks_1.existingSharedStringsXmlMock.replace(/ /g, ""));
|
|
91
|
+
return [2 /*return*/];
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}); });
|
|
95
|
+
test("SharedStrings XML returns new index", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
96
|
+
var sharedStringIndex;
|
|
97
|
+
return __generator(this, function (_a) {
|
|
98
|
+
switch (_a.label) {
|
|
99
|
+
case 0: return [4 /*yield*/, utils_1.xmlInnerPartsUtils.updateSharedStrings('<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="1" uniqueCount="1"><si><t>Query1</t></si><si><t/></si></sst>', "newQueryName")];
|
|
100
|
+
case 1:
|
|
101
|
+
sharedStringIndex = (_a.sent()).sharedStringIndex;
|
|
102
|
+
expect(sharedStringIndex).toEqual(2);
|
|
103
|
+
return [2 /*return*/];
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}); });
|
|
107
|
+
test("SharedStrings XML returns existing index", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
108
|
+
var sharedStringIndex;
|
|
109
|
+
return __generator(this, function (_a) {
|
|
110
|
+
switch (_a.label) {
|
|
111
|
+
case 0: return [4 /*yield*/, utils_1.xmlInnerPartsUtils.updateSharedStrings('<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="1" uniqueCount="1"><si><t>newQueryName</t></si><si><t/></si></sst>', "newQueryName")];
|
|
112
|
+
case 1:
|
|
113
|
+
sharedStringIndex = (_a.sent()).sharedStringIndex;
|
|
114
|
+
expect(sharedStringIndex).toEqual(1);
|
|
115
|
+
return [2 /*return*/];
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}); });
|
|
119
|
+
test("Table XML contains refrshonload value", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
120
|
+
var _a, sharedStringIndex, newSharedStrings;
|
|
121
|
+
return __generator(this, function (_b) {
|
|
122
|
+
switch (_b.label) {
|
|
123
|
+
case 0: return [4 /*yield*/, utils_1.xmlInnerPartsUtils.updateSharedStrings('<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="1" uniqueCount="1"><si><t>Query1</t></si><si><t/></si></sst>', "newQueryName")];
|
|
124
|
+
case 1:
|
|
125
|
+
_a = _b.sent(), sharedStringIndex = _a.sharedStringIndex, newSharedStrings = _a.newSharedStrings;
|
|
126
|
+
expect(sharedStringIndex).toEqual(2);
|
|
127
|
+
expect(newSharedStrings.replace(/ /g, "")).toContain(mocks_1.sharedStringsXmlMock.replace(/ /g, ""));
|
|
128
|
+
return [2 /*return*/];
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}); });
|
|
51
132
|
});
|