@mcpher/gas-fakes 2.5.4 → 2.5.6
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/.claspignore +1 -1
- package/README.md +27 -1
- package/exgcp.sh +63 -0
- package/package.json +1 -1
- package/src/services/advslides/fakeadvslides.js +20 -1
- package/src/services/documentapp/appenderhelpers.js +8 -3
- package/src/services/documentapp/elementhelpers.js +148 -7
- package/src/services/documentapp/elementoptions.js +40 -0
- package/src/services/documentapp/elements.js +7 -0
- package/src/services/documentapp/fakebookmark.js +1 -3
- package/src/services/documentapp/fakecontainerelement.js +188 -0
- package/src/services/documentapp/fakedate.js +92 -0
- package/src/services/documentapp/fakedocument.js +51 -0
- package/src/services/documentapp/fakedocumenttab.js +9 -25
- package/src/services/documentapp/fakeelement.js +453 -90
- package/src/services/documentapp/fakeequation.js +28 -0
- package/src/services/documentapp/fakeequationfunction.js +37 -0
- package/src/services/documentapp/fakeequationfunctionargumentseparator.js +28 -0
- package/src/services/documentapp/fakeequationsymbol.js +37 -0
- package/src/services/documentapp/fakefootersection.js +64 -1
- package/src/services/documentapp/fakeheadersection.js +64 -0
- package/src/services/documentapp/fakeperson.js +67 -0
- package/src/services/documentapp/fakerangeelement.js +27 -1
- package/src/services/documentapp/fakerichlink.js +79 -0
- package/src/services/documentapp/fakesectionelement.js +51 -12
- package/src/services/documentapp/faketablecell.js +98 -0
- package/src/services/documentapp/nrhelpers.js +2 -1
- package/src/services/documentapp/shadowdocument.js +19 -2
- package/src/services/spreadsheetapp/fakeembeddedchartbuilder.js +2 -7
- package/src/support/sxslides.js +5 -4
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Provides a fake implementation of the Date class.
|
|
3
|
+
*/
|
|
4
|
+
import { Proxies } from '../../support/proxies.js';
|
|
5
|
+
import { signatureArgs } from '../../support/helpers.js';
|
|
6
|
+
import { Utils } from '../../support/utils.js';
|
|
7
|
+
import { FakeElement } from './fakeelement.js';
|
|
8
|
+
import { registerElement } from './elementRegistry.js';
|
|
9
|
+
|
|
10
|
+
const { is } = Utils;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new proxied FakeDate instance.
|
|
14
|
+
* @param {...any} args The arguments for the FakeDate constructor.
|
|
15
|
+
* @returns {FakeDate} A new proxied FakeDate instance.
|
|
16
|
+
*/
|
|
17
|
+
export const newFakeDate = (...args) => {
|
|
18
|
+
return Proxies.guard(new FakeDate(...args));
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A fake implementation of the Date class for DocumentApp.
|
|
23
|
+
* @class FakeDate
|
|
24
|
+
* @extends {FakeElement}
|
|
25
|
+
* @implements {GoogleAppsScript.Document.Date}
|
|
26
|
+
* @see https://developers.google.com/apps-script/reference/document/date
|
|
27
|
+
*/
|
|
28
|
+
export class FakeDate extends FakeElement {
|
|
29
|
+
/**
|
|
30
|
+
* @param {import('./shadowdocument.js').ShadowDocument} shadowDocument The shadow document manager.
|
|
31
|
+
* @param {string|object} nameOrItem The name of the element or the element's API resource.
|
|
32
|
+
* @private
|
|
33
|
+
*/
|
|
34
|
+
constructor(shadowDocument, nameOrItem) {
|
|
35
|
+
super(shadowDocument, nameOrItem);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Returns the display value that's rendered in the document.
|
|
40
|
+
* @returns {string} The display value.
|
|
41
|
+
*/
|
|
42
|
+
getDisplayText() {
|
|
43
|
+
const { nargs, matchThrow } = signatureArgs(arguments, 'Date.getDisplayText');
|
|
44
|
+
if (nargs !== 0) matchThrow();
|
|
45
|
+
|
|
46
|
+
const date = this.getTimestamp();
|
|
47
|
+
const locale = this.getLocale() || 'en';
|
|
48
|
+
|
|
49
|
+
// Format using a default representation if we can't perfectly mimic GAS.
|
|
50
|
+
return date.toLocaleDateString(locale, {
|
|
51
|
+
year: 'numeric',
|
|
52
|
+
month: 'short',
|
|
53
|
+
day: 'numeric',
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Returns the date's locale used for the display value.
|
|
59
|
+
* @returns {string} The locale of the date.
|
|
60
|
+
*/
|
|
61
|
+
getLocale() {
|
|
62
|
+
const { nargs, matchThrow } = signatureArgs(arguments, 'Date.getLocale');
|
|
63
|
+
if (nargs !== 0) matchThrow();
|
|
64
|
+
|
|
65
|
+
// The API doesn't expose a per-date locale.
|
|
66
|
+
// It's likely inherited from the document.
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Returns the timestamp associated with the date.
|
|
72
|
+
* @returns {Date} The timestamp.
|
|
73
|
+
*/
|
|
74
|
+
getTimestamp() {
|
|
75
|
+
const { nargs, matchThrow } = signatureArgs(arguments, 'Date.getTimestamp');
|
|
76
|
+
if (nargs !== 0) matchThrow();
|
|
77
|
+
|
|
78
|
+
const item = this.__elementMapItem;
|
|
79
|
+
const dateResource = item.date;
|
|
80
|
+
if (!dateResource || !dateResource.timestamp) {
|
|
81
|
+
throw new Error('Date element missing timestamp.');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return new Date(dateResource.timestamp.seconds * 1000);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
toString() {
|
|
88
|
+
return 'Date';
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
registerElement('DATE', newFakeDate);
|
|
@@ -8,6 +8,8 @@ import { newFakeBody } from './fakebody.js';
|
|
|
8
8
|
import { newFakeRangeBuilder } from './fakerangebuilder.js';
|
|
9
9
|
import { newFakeHeaderSection } from './fakeheadersection.js';
|
|
10
10
|
import { newFakeFooterSection } from './fakefootersection.js';
|
|
11
|
+
import { newFakePosition } from './fakeposition.js';
|
|
12
|
+
import { newFakeBookmark } from './fakebookmark.js';
|
|
11
13
|
import { shadowPrefix } from './nrhelpers.js';
|
|
12
14
|
import { defaultDocumentStyleRequests } from './elementblasters.js';
|
|
13
15
|
|
|
@@ -343,6 +345,55 @@ class FakeDocument {
|
|
|
343
345
|
return newFakeRangeBuilder();
|
|
344
346
|
}
|
|
345
347
|
|
|
348
|
+
newPosition(element, offset) {
|
|
349
|
+
const { nargs, matchThrow } = signatureArgs(arguments, 'Document.newPosition');
|
|
350
|
+
if (nargs !== 2) matchThrow();
|
|
351
|
+
return newFakePosition(element, offset);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
addBookmark(position) {
|
|
355
|
+
const { nargs, matchThrow } = signatureArgs(arguments, 'Document.addBookmark');
|
|
356
|
+
if (nargs !== 1) matchThrow();
|
|
357
|
+
|
|
358
|
+
const shadow = this.__shadowDocument;
|
|
359
|
+
const element = position.getElement();
|
|
360
|
+
const offset = position.getOffset();
|
|
361
|
+
|
|
362
|
+
// We use a NamedRange to emulate the bookmark.
|
|
363
|
+
// Use the prefix 'kix.' as it's what FakeBookmark expects.
|
|
364
|
+
const name = 'kix.' + Utilities.getUuid();
|
|
365
|
+
|
|
366
|
+
const requests = [{
|
|
367
|
+
createNamedRange: {
|
|
368
|
+
name,
|
|
369
|
+
range: {
|
|
370
|
+
startIndex: element.__elementMapItem.startIndex + offset,
|
|
371
|
+
endIndex: element.__elementMapItem.startIndex + offset + 1,
|
|
372
|
+
segmentId: shadow.__segmentId,
|
|
373
|
+
tabId: shadow.__tabId
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}];
|
|
377
|
+
|
|
378
|
+
Docs.Documents.batchUpdate({ requests }, shadow.getId());
|
|
379
|
+
shadow.refresh();
|
|
380
|
+
|
|
381
|
+
return this.getBookmark(name.substring(4));
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
getBookmark(id) {
|
|
385
|
+
const { nargs, matchThrow } = signatureArgs(arguments, 'Document.getBookmark');
|
|
386
|
+
if (nargs !== 1) matchThrow();
|
|
387
|
+
|
|
388
|
+
const shadow = this.__shadowDocument;
|
|
389
|
+
const name = 'kix.' + id;
|
|
390
|
+
|
|
391
|
+
// Refresh to ensure we have the latest named ranges
|
|
392
|
+
const item = shadow.getElement(name);
|
|
393
|
+
if (!item) return null;
|
|
394
|
+
|
|
395
|
+
return newFakeBookmark(shadow, name);
|
|
396
|
+
}
|
|
346
397
|
|
|
347
398
|
// these are all actually preformed by the Drive api
|
|
348
399
|
addEditor(emailAddress) {
|
|
@@ -35,35 +35,19 @@ class FakeDocumentTab extends FakeElement {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
addBookmark(position) {
|
|
38
|
-
return
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
addFooter() {
|
|
42
|
-
return notYetImplemented('DocumentTab.addFooter()');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
addFooter() {
|
|
46
|
-
return this.__document.addFooter();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
addHeader() {
|
|
50
|
-
return this.__document.addHeader();
|
|
38
|
+
return this.__document.addBookmark(position);
|
|
51
39
|
}
|
|
52
40
|
|
|
53
41
|
addNamedRange(name, range) {
|
|
54
|
-
return
|
|
42
|
+
return this.__document.addNamedRange(name, range);
|
|
55
43
|
}
|
|
56
44
|
|
|
57
45
|
getBookmark(id) {
|
|
58
|
-
return
|
|
46
|
+
return this.__document.getBookmark(id);
|
|
59
47
|
}
|
|
60
48
|
|
|
61
49
|
getBookmarks() {
|
|
62
|
-
return
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
getFooter() {
|
|
66
|
-
return notYetImplemented('DocumentTab.getFooter()');
|
|
50
|
+
return this.__document.getBookmarks();
|
|
67
51
|
}
|
|
68
52
|
|
|
69
53
|
getFooter() {
|
|
@@ -71,7 +55,7 @@ class FakeDocumentTab extends FakeElement {
|
|
|
71
55
|
}
|
|
72
56
|
|
|
73
57
|
getFootnotes() {
|
|
74
|
-
return
|
|
58
|
+
return this.__document.getFootnotes();
|
|
75
59
|
}
|
|
76
60
|
|
|
77
61
|
getHeader() {
|
|
@@ -79,19 +63,19 @@ class FakeDocumentTab extends FakeElement {
|
|
|
79
63
|
}
|
|
80
64
|
|
|
81
65
|
getNamedRangeById(id) {
|
|
82
|
-
return
|
|
66
|
+
return this.__document.getNamedRangeById(id);
|
|
83
67
|
}
|
|
84
68
|
|
|
85
69
|
getNamedRanges() {
|
|
86
|
-
return
|
|
70
|
+
return this.__document.getNamedRanges();
|
|
87
71
|
}
|
|
88
72
|
|
|
89
73
|
newPosition(element, offset) {
|
|
90
|
-
return
|
|
74
|
+
return this.__document.newPosition(element, offset);
|
|
91
75
|
}
|
|
92
76
|
|
|
93
77
|
newRange() {
|
|
94
|
-
return
|
|
78
|
+
return this.__document.newRange();
|
|
95
79
|
}
|
|
96
80
|
|
|
97
81
|
|