@baselift/blocks-testing 0.0.1
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 +177 -0
- package/dist/cjs/error_utils.js +56 -0
- package/dist/cjs/index.js +24 -0
- package/dist/cjs/inject_mock_airtable_interface.js +6 -0
- package/dist/cjs/mock_airtable_interface.js +851 -0
- package/dist/cjs/private_utils.js +78 -0
- package/dist/cjs/test_driver.js +658 -0
- package/dist/cjs/test_mutations.js +37 -0
- package/dist/cjs/vacant_airtable_interface.js +367 -0
- package/dist/types/src/error_utils.d.ts +11 -0
- package/dist/types/src/error_utils.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +4 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/inject_mock_airtable_interface.d.ts +2 -0
- package/dist/types/src/inject_mock_airtable_interface.d.ts.map +1 -0
- package/dist/types/src/mock_airtable_interface.d.ts +237 -0
- package/dist/types/src/mock_airtable_interface.d.ts.map +1 -0
- package/dist/types/src/private_utils.d.ts +33 -0
- package/dist/types/src/private_utils.d.ts.map +1 -0
- package/dist/types/src/test_driver.d.ts +450 -0
- package/dist/types/src/test_driver.d.ts.map +1 -0
- package/dist/types/src/test_mutations.d.ts +43 -0
- package/dist/types/src/test_mutations.d.ts.map +1 -0
- package/dist/types/src/vacant_airtable_interface.d.ts +2 -0
- package/dist/types/src/vacant_airtable_interface.d.ts.map +1 -0
- package/dist/types/test/index_compatible.test.d.ts +8 -0
- package/dist/types/test/index_compatible.test.d.ts.map +1 -0
- package/dist/types/test/index_incompatible.test.d.ts +2 -0
- package/dist/types/test/index_incompatible.test.d.ts.map +1 -0
- package/dist/types/test/mock_airtable_interface.test.d.ts +2 -0
- package/dist/types/test/mock_airtable_interface.test.d.ts.map +1 -0
- package/dist/types/test/mutation_types.test.d.ts +2 -0
- package/dist/types/test/mutation_types.test.d.ts.map +1 -0
- package/dist/types/test/package_json.test.d.ts +2 -0
- package/dist/types/test/package_json.test.d.ts.map +1 -0
- package/dist/types/test/test_driver.test.d.ts +2 -0
- package/dist/types/test/test_driver.test.d.ts.map +1 -0
- package/dist/types/test/untestable_bindings.test.d.ts +2 -0
- package/dist/types/test/untestable_bindings.test.d.ts.map +1 -0
- package/package.json +120 -0
- package/types/globals.d.ts +6 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/es.symbol.js");
|
|
4
|
+
require("core-js/modules/es.array.filter.js");
|
|
5
|
+
require("core-js/modules/es.object.get-own-property-descriptors.js");
|
|
6
|
+
require("core-js/modules/es.object.to-string.js");
|
|
7
|
+
require("core-js/modules/web.dom-collections.for-each.js");
|
|
8
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
9
|
+
Object.defineProperty(exports, "__esModule", {
|
|
10
|
+
value: true
|
|
11
|
+
});
|
|
12
|
+
exports.TestMutationTypes = void 0;
|
|
13
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
14
|
+
var _unstable_testing_utils = require("@baselift/blocks/unstable_testing_utils");
|
|
15
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
17
|
+
/**
|
|
18
|
+
* Get the type of all the values of an object.
|
|
19
|
+
*
|
|
20
|
+
* Same as the legacy Flow `$Values<T>` type.
|
|
21
|
+
*
|
|
22
|
+
* @hidden
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/** @hidden */
|
|
26
|
+
var TestMutationTypes = exports.TestMutationTypes = Object.freeze(_objectSpread(_objectSpread({}, _unstable_testing_utils.MutationTypes), {}, {
|
|
27
|
+
DELETE_SINGLE_FIELD: 'deleteSingleField',
|
|
28
|
+
DELETE_SINGLE_VIEW: 'deleteSingleView'
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
/** @hidden */
|
|
32
|
+
|
|
33
|
+
/** @hidden */
|
|
34
|
+
|
|
35
|
+
/** @hidden */
|
|
36
|
+
|
|
37
|
+
/** @hidden */
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
12
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
13
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
14
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
15
|
+
var _unstable_testing_utils = require("@baselift/blocks/unstable_testing_utils");
|
|
16
|
+
var _error_utils = require("./error_utils");
|
|
17
|
+
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
|
|
18
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
19
|
+
var cannotSimulateErrorMessage = 'Unable to simulate behavior' + '\n\n' + 'Extensions which retrieve model references using JavaScript `import` ' + 'declarations cannot be tested. To resolve this, replace `import` ' + "declaration in your Extension's source code with corresponding React " + 'Hooks. For instance, replace' + '\n\n' + ' import {base} from "@baselift/blocks";' + '\n\n' + 'with' + '\n\n' + ' const base = useBase();';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* An implementation of the MockAirtableInterface designed to satisfy the SDK's
|
|
23
|
+
* requirement for an instance at the moment of initial module evaluation. This
|
|
24
|
+
* instance (like the SDK features it enables) is fundamentally untestable both
|
|
25
|
+
* because the consumer cannot control its initial state and because it is
|
|
26
|
+
* shared by every Extension created in the testing environment.
|
|
27
|
+
*
|
|
28
|
+
* For some features of the SDK, Extension developers can avoid reliance on the
|
|
29
|
+
* VacantAirtableInterface by refactoring their code to use more testable
|
|
30
|
+
* patterns. This instance informs test authors of such cases by immediately
|
|
31
|
+
* throwing an error (intentionally discouraging its use).
|
|
32
|
+
*
|
|
33
|
+
* For other features of the SDK, the only way to use the feature is via an
|
|
34
|
+
* untestable pattern. In these cases, Extension developers have no alternative but
|
|
35
|
+
* to rely on the VacantAirtableInterface. This instance informs test authors
|
|
36
|
+
* of such cases by issuing a warning (allowing Extension code to be partially
|
|
37
|
+
* validated).
|
|
38
|
+
*
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
var VacantAirtableInterface = exports.default = /*#__PURE__*/function (_AbstractMockAirtable) {
|
|
42
|
+
function VacantAirtableInterface() {
|
|
43
|
+
(0, _classCallCheck2.default)(this, VacantAirtableInterface);
|
|
44
|
+
return _callSuper(this, VacantAirtableInterface, [{
|
|
45
|
+
isDevelopmentMode: false,
|
|
46
|
+
blockInstallationId: '',
|
|
47
|
+
isFirstRun: false,
|
|
48
|
+
isFullscreen: false,
|
|
49
|
+
initialKvValuesByKey: {},
|
|
50
|
+
runContext: {
|
|
51
|
+
type: _unstable_testing_utils.BlockRunContextType.DASHBOARD_APP
|
|
52
|
+
},
|
|
53
|
+
baseData: {
|
|
54
|
+
id: '',
|
|
55
|
+
name: '',
|
|
56
|
+
color: '',
|
|
57
|
+
activeTableId: '',
|
|
58
|
+
tableOrder: [],
|
|
59
|
+
tablesById: {},
|
|
60
|
+
permissionLevel: 'create',
|
|
61
|
+
currentUserId: '',
|
|
62
|
+
enabledFeatureNames: [],
|
|
63
|
+
collaboratorsById: {},
|
|
64
|
+
activeCollaboratorIds: [],
|
|
65
|
+
cursorData: null,
|
|
66
|
+
billingPlanGrouping: 'pro',
|
|
67
|
+
appInterface: {},
|
|
68
|
+
isBlockDevelopmentRestrictionEnabled: false,
|
|
69
|
+
workspaceId: ''
|
|
70
|
+
},
|
|
71
|
+
intentData: null
|
|
72
|
+
}]);
|
|
73
|
+
}
|
|
74
|
+
(0, _inherits2.default)(VacantAirtableInterface, _AbstractMockAirtable);
|
|
75
|
+
return (0, _createClass2.default)(VacantAirtableInterface, [{
|
|
76
|
+
key: "applyMutationAsync",
|
|
77
|
+
value: function () {
|
|
78
|
+
var _applyMutationAsync = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee(mutation, opts) {
|
|
79
|
+
return _regenerator.default.wrap(function (_context) {
|
|
80
|
+
while (1) switch (_context.prev = _context.next) {
|
|
81
|
+
case 0:
|
|
82
|
+
throw (0, _error_utils.spawnError)(cannotSimulateErrorMessage);
|
|
83
|
+
case 1:
|
|
84
|
+
case "end":
|
|
85
|
+
return _context.stop();
|
|
86
|
+
}
|
|
87
|
+
}, _callee);
|
|
88
|
+
}));
|
|
89
|
+
function applyMutationAsync(_x, _x2) {
|
|
90
|
+
return _applyMutationAsync.apply(this, arguments);
|
|
91
|
+
}
|
|
92
|
+
return applyMutationAsync;
|
|
93
|
+
}()
|
|
94
|
+
}, {
|
|
95
|
+
key: "checkPermissionsForMutation",
|
|
96
|
+
value: function checkPermissionsForMutation(mutation) {
|
|
97
|
+
throw (0, _error_utils.spawnError)(cannotSimulateErrorMessage);
|
|
98
|
+
}
|
|
99
|
+
}, {
|
|
100
|
+
key: "globalConfigHelpers",
|
|
101
|
+
get: function get() {
|
|
102
|
+
throw (0, _error_utils.spawnError)(cannotSimulateErrorMessage);
|
|
103
|
+
}
|
|
104
|
+
}, {
|
|
105
|
+
key: "expandRecord",
|
|
106
|
+
value: function expandRecord(tableId, recordId, recordIds) {
|
|
107
|
+
throw (0, _error_utils.spawnError)(cannotSimulateErrorMessage);
|
|
108
|
+
}
|
|
109
|
+
}, {
|
|
110
|
+
key: "fieldTypeProvider",
|
|
111
|
+
get: function get() {
|
|
112
|
+
throw (0, _error_utils.spawnError)(cannotSimulateErrorMessage);
|
|
113
|
+
}
|
|
114
|
+
}, {
|
|
115
|
+
key: "fetchAndSubscribeToCellValuesInFieldsAsync",
|
|
116
|
+
value: function () {
|
|
117
|
+
var _fetchAndSubscribeToCellValuesInFieldsAsync = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee2(tableId, fieldIds) {
|
|
118
|
+
return _regenerator.default.wrap(function (_context2) {
|
|
119
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
120
|
+
case 0:
|
|
121
|
+
throw (0, _error_utils.spawnError)(cannotSimulateErrorMessage);
|
|
122
|
+
case 1:
|
|
123
|
+
case "end":
|
|
124
|
+
return _context2.stop();
|
|
125
|
+
}
|
|
126
|
+
}, _callee2);
|
|
127
|
+
}));
|
|
128
|
+
function fetchAndSubscribeToCellValuesInFieldsAsync(_x3, _x4) {
|
|
129
|
+
return _fetchAndSubscribeToCellValuesInFieldsAsync.apply(this, arguments);
|
|
130
|
+
}
|
|
131
|
+
return fetchAndSubscribeToCellValuesInFieldsAsync;
|
|
132
|
+
}()
|
|
133
|
+
}, {
|
|
134
|
+
key: "fetchAndSubscribeToCursorDataAsync",
|
|
135
|
+
value: function () {
|
|
136
|
+
var _fetchAndSubscribeToCursorDataAsync = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee3() {
|
|
137
|
+
return _regenerator.default.wrap(function (_context3) {
|
|
138
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
139
|
+
case 0:
|
|
140
|
+
throw (0, _error_utils.spawnError)(cannotSimulateErrorMessage);
|
|
141
|
+
case 1:
|
|
142
|
+
case "end":
|
|
143
|
+
return _context3.stop();
|
|
144
|
+
}
|
|
145
|
+
}, _callee3);
|
|
146
|
+
}));
|
|
147
|
+
function fetchAndSubscribeToCursorDataAsync() {
|
|
148
|
+
return _fetchAndSubscribeToCursorDataAsync.apply(this, arguments);
|
|
149
|
+
}
|
|
150
|
+
return fetchAndSubscribeToCursorDataAsync;
|
|
151
|
+
}()
|
|
152
|
+
}, {
|
|
153
|
+
key: "fetchAndSubscribeToTableDataAsync",
|
|
154
|
+
value: function () {
|
|
155
|
+
var _fetchAndSubscribeToTableDataAsync = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee4(tableId) {
|
|
156
|
+
return _regenerator.default.wrap(function (_context4) {
|
|
157
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
158
|
+
case 0:
|
|
159
|
+
throw (0, _error_utils.spawnError)(cannotSimulateErrorMessage);
|
|
160
|
+
case 1:
|
|
161
|
+
case "end":
|
|
162
|
+
return _context4.stop();
|
|
163
|
+
}
|
|
164
|
+
}, _callee4);
|
|
165
|
+
}));
|
|
166
|
+
function fetchAndSubscribeToTableDataAsync(_x5) {
|
|
167
|
+
return _fetchAndSubscribeToTableDataAsync.apply(this, arguments);
|
|
168
|
+
}
|
|
169
|
+
return fetchAndSubscribeToTableDataAsync;
|
|
170
|
+
}()
|
|
171
|
+
}, {
|
|
172
|
+
key: "fetchAndSubscribeToViewDataAsync",
|
|
173
|
+
value: function () {
|
|
174
|
+
var _fetchAndSubscribeToViewDataAsync = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee5(tableId, viewId) {
|
|
175
|
+
return _regenerator.default.wrap(function (_context5) {
|
|
176
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
177
|
+
case 0:
|
|
178
|
+
throw (0, _error_utils.spawnError)(cannotSimulateErrorMessage);
|
|
179
|
+
case 1:
|
|
180
|
+
case "end":
|
|
181
|
+
return _context5.stop();
|
|
182
|
+
}
|
|
183
|
+
}, _callee5);
|
|
184
|
+
}));
|
|
185
|
+
function fetchAndSubscribeToViewDataAsync(_x6, _x7) {
|
|
186
|
+
return _fetchAndSubscribeToViewDataAsync.apply(this, arguments);
|
|
187
|
+
}
|
|
188
|
+
return fetchAndSubscribeToViewDataAsync;
|
|
189
|
+
}()
|
|
190
|
+
}, {
|
|
191
|
+
key: "hasRecord",
|
|
192
|
+
value: function hasRecord(tableId, recordId) {
|
|
193
|
+
throw (0, _error_utils.spawnError)(cannotSimulateErrorMessage);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// get idGenerator(): never {
|
|
197
|
+
// throw spawnError(cannotSimulateErrorMessage);
|
|
198
|
+
// }
|
|
199
|
+
}, {
|
|
200
|
+
key: "setFullscreenMaxSize",
|
|
201
|
+
value: function setFullscreenMaxSize() {
|
|
202
|
+
throw (0, _error_utils.spawnError)(cannotSimulateErrorMessage);
|
|
203
|
+
}
|
|
204
|
+
}, {
|
|
205
|
+
key: "performBackendFetchAsync",
|
|
206
|
+
value: function () {
|
|
207
|
+
var _performBackendFetchAsync = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee6(requestJson) {
|
|
208
|
+
return _regenerator.default.wrap(function (_context6) {
|
|
209
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
210
|
+
case 0:
|
|
211
|
+
throw (0, _error_utils.spawnError)(cannotSimulateErrorMessage);
|
|
212
|
+
case 1:
|
|
213
|
+
case "end":
|
|
214
|
+
return _context6.stop();
|
|
215
|
+
}
|
|
216
|
+
}, _callee6);
|
|
217
|
+
}));
|
|
218
|
+
function performBackendFetchAsync(_x8) {
|
|
219
|
+
return _performBackendFetchAsync.apply(this, arguments);
|
|
220
|
+
}
|
|
221
|
+
return performBackendFetchAsync;
|
|
222
|
+
}()
|
|
223
|
+
}, {
|
|
224
|
+
key: "fetchDefaultCellValuesByFieldIdAsync",
|
|
225
|
+
value: function () {
|
|
226
|
+
var _fetchDefaultCellValuesByFieldIdAsync = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee7() {
|
|
227
|
+
return _regenerator.default.wrap(function (_context7) {
|
|
228
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
229
|
+
case 0:
|
|
230
|
+
throw (0, _error_utils.spawnError)(cannotSimulateErrorMessage);
|
|
231
|
+
case 1:
|
|
232
|
+
case "end":
|
|
233
|
+
return _context7.stop();
|
|
234
|
+
}
|
|
235
|
+
}, _callee7);
|
|
236
|
+
}));
|
|
237
|
+
function fetchDefaultCellValuesByFieldIdAsync() {
|
|
238
|
+
return _fetchDefaultCellValuesByFieldIdAsync.apply(this, arguments);
|
|
239
|
+
}
|
|
240
|
+
return fetchDefaultCellValuesByFieldIdAsync;
|
|
241
|
+
}()
|
|
242
|
+
}, {
|
|
243
|
+
key: "expandRecordList",
|
|
244
|
+
value: function expandRecordList() {
|
|
245
|
+
throw (0, _error_utils.spawnError)(cannotSimulateErrorMessage);
|
|
246
|
+
}
|
|
247
|
+
}, {
|
|
248
|
+
key: "expandRecordPickerAsync",
|
|
249
|
+
value: function () {
|
|
250
|
+
var _expandRecordPickerAsync = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee8() {
|
|
251
|
+
return _regenerator.default.wrap(function (_context8) {
|
|
252
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
253
|
+
case 0:
|
|
254
|
+
throw (0, _error_utils.spawnError)(cannotSimulateErrorMessage);
|
|
255
|
+
case 1:
|
|
256
|
+
case "end":
|
|
257
|
+
return _context8.stop();
|
|
258
|
+
}
|
|
259
|
+
}, _callee8);
|
|
260
|
+
}));
|
|
261
|
+
function expandRecordPickerAsync() {
|
|
262
|
+
return _expandRecordPickerAsync.apply(this, arguments);
|
|
263
|
+
}
|
|
264
|
+
return expandRecordPickerAsync;
|
|
265
|
+
}()
|
|
266
|
+
/**
|
|
267
|
+
* `reload` is made available to Extensions through an undocumented binding
|
|
268
|
+
* exported by the SDK's main entry point. That reference is associated
|
|
269
|
+
* with the singleton instance of the `Sdk` class and therefore cannot be
|
|
270
|
+
* controlled in the testing environment.
|
|
271
|
+
*/
|
|
272
|
+
}, {
|
|
273
|
+
key: "reloadFrame",
|
|
274
|
+
value: function reloadFrame() {
|
|
275
|
+
// eslint-disable-next-line no-console
|
|
276
|
+
console.warn('Frame reloading cannot be simulated in the Extension testing environment.');
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* An Extension can only retrieve a reference to the `SettingsButton` singleton
|
|
281
|
+
* via a JavaScript `import` declaration. The SDK does not offer a testable
|
|
282
|
+
* pattern for explicitly controlling the visibility of the settings button
|
|
283
|
+
*/
|
|
284
|
+
}, {
|
|
285
|
+
key: "setSettingsButtonVisibility",
|
|
286
|
+
value: function setSettingsButtonVisibility() {
|
|
287
|
+
// eslint-disable-next-line no-console
|
|
288
|
+
console.warn('The Settings button cannot be simulated in the Extension testing environment.');
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* `undoRedo` is made available to Extensions through an undocumented binding
|
|
293
|
+
* exported by the SDK's main entry point. That reference is associated
|
|
294
|
+
* with the singleton instance of the `Sdk` class and therefore cannot be
|
|
295
|
+
* controlled in the testing environment.
|
|
296
|
+
*/
|
|
297
|
+
}, {
|
|
298
|
+
key: "setUndoRedoMode",
|
|
299
|
+
value: function setUndoRedoMode() {
|
|
300
|
+
// eslint-disable-next-line no-console
|
|
301
|
+
console.warn('The `undoRedo` feature cannot be simulated in the Extension testing environment.');
|
|
302
|
+
}
|
|
303
|
+
}, {
|
|
304
|
+
key: "enterFullscreen",
|
|
305
|
+
value: function enterFullscreen() {
|
|
306
|
+
throw (0, _error_utils.spawnError)(cannotSimulateErrorMessage);
|
|
307
|
+
}
|
|
308
|
+
}, {
|
|
309
|
+
key: "exitFullscreen",
|
|
310
|
+
value: function exitFullscreen() {
|
|
311
|
+
throw (0, _error_utils.spawnError)(cannotSimulateErrorMessage);
|
|
312
|
+
}
|
|
313
|
+
}, {
|
|
314
|
+
key: "fetchAndSubscribeToPerformRecordActionAsync",
|
|
315
|
+
value: function () {
|
|
316
|
+
var _fetchAndSubscribeToPerformRecordActionAsync = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee9() {
|
|
317
|
+
return _regenerator.default.wrap(function (_context9) {
|
|
318
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
319
|
+
case 0:
|
|
320
|
+
throw (0, _error_utils.spawnError)(cannotSimulateErrorMessage);
|
|
321
|
+
case 1:
|
|
322
|
+
case "end":
|
|
323
|
+
return _context9.stop();
|
|
324
|
+
}
|
|
325
|
+
}, _callee9);
|
|
326
|
+
}));
|
|
327
|
+
function fetchAndSubscribeToPerformRecordActionAsync() {
|
|
328
|
+
return _fetchAndSubscribeToPerformRecordActionAsync.apply(this, arguments);
|
|
329
|
+
}
|
|
330
|
+
return fetchAndSubscribeToPerformRecordActionAsync;
|
|
331
|
+
}()
|
|
332
|
+
/**
|
|
333
|
+
* `trackEvent` is made available to internal Extensions through the
|
|
334
|
+
* `unstable_private_utils` module. That reference is not associated with
|
|
335
|
+
* any instance of the `Sdk` class.
|
|
336
|
+
*/
|
|
337
|
+
}, {
|
|
338
|
+
key: "trackEvent",
|
|
339
|
+
value: function trackEvent() {
|
|
340
|
+
// eslint-disable-next-line no-console
|
|
341
|
+
console.warn('Event tracking signals cannot be observed in the Extension testing environment.');
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* `trackExposure` cannot be invoked by any Extensions (neither those authored by
|
|
346
|
+
* Airtable nor by other Extension developers). It should be implemented to
|
|
347
|
+
* satisfy the AirtableInterface contract, but the implementation should
|
|
348
|
+
* not throw (since it must be successful for Extensions to function), nor should
|
|
349
|
+
* it emit an event (since test authors have no need to track its usage).
|
|
350
|
+
*/
|
|
351
|
+
}, {
|
|
352
|
+
key: "trackExposure",
|
|
353
|
+
value: function trackExposure() {}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* `blockStats` is made available to internal Extensions through the
|
|
357
|
+
* `unstable_private_utils` module. That reference is not associated with
|
|
358
|
+
* any instance of the `Sdk` class.
|
|
359
|
+
*/
|
|
360
|
+
}, {
|
|
361
|
+
key: "sendStat",
|
|
362
|
+
value: function sendStat() {
|
|
363
|
+
// eslint-disable-next-line no-console
|
|
364
|
+
console.warn('Statistic tracking signals cannot be observed in the Extension testing environment.');
|
|
365
|
+
}
|
|
366
|
+
}]);
|
|
367
|
+
}(_unstable_testing_utils.AbstractMockAirtableInterface);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hidden
|
|
3
|
+
*/
|
|
4
|
+
export declare function spawnError(errorMessageFormat: string, ...errorMessageArgs: ReadonlyArray<unknown>): Error;
|
|
5
|
+
/**
|
|
6
|
+
* An alternative to facebook's invariant that's safe to use with base data
|
|
7
|
+
*
|
|
8
|
+
* @hidden
|
|
9
|
+
*/
|
|
10
|
+
export declare function invariant(condition: unknown, errorMessageFormat: string, ...errorMessageArgs: Array<unknown>): asserts condition;
|
|
11
|
+
//# sourceMappingURL=error_utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error_utils.d.ts","sourceRoot":"","sources":["../../../src/error_utils.ts"],"names":[],"mappings":"AAgCA;;GAEG;AACH,wBAAgB,UAAU,CACtB,kBAAkB,EAAE,MAAM,EAC1B,GAAG,gBAAgB,EAAE,aAAa,CAAC,OAAO,CAAC,SAO9C;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CACrB,SAAS,EAAE,OAAO,EAClB,kBAAkB,EAAE,MAAM,EAC1B,GAAG,gBAAgB,EAAE,KAAK,CAAC,OAAO,CAAC,GACpC,OAAO,CAAC,SAAS,CAQnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,kCAAkC,CAAC;AAG1C,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAC;AACtC,OAAO,EAAC,aAAa,EAAC,MAAM,yCAAyC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject_mock_airtable_interface.d.ts","sourceRoot":"","sources":["../../../src/inject_mock_airtable_interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { BaseId, CollaboratorData, Color, FieldId, PermissionCheckResult, RecordActionData, RecordId, TableId, ViewId } from '@baselift/blocks/types';
|
|
2
|
+
import { AbstractMockAirtableInterface, CursorData, GlobalConfigData, FieldType, Mutation, PartialViewData, RecordData, RequestJson, ResponseJson, ViewportSizeConstraint, ViewType } from '@baselift/blocks/unstable_testing_utils';
|
|
3
|
+
import { TestMutation } from './test_mutations';
|
|
4
|
+
import { ObjectMap } from './private_utils';
|
|
5
|
+
/**
|
|
6
|
+
* A mapping relating the names of event subscriptions available on
|
|
7
|
+
* {@link TestDriver} instances to the arguments that are provided when one of
|
|
8
|
+
* those events is triggered.
|
|
9
|
+
*/
|
|
10
|
+
export interface WatchableKeysAndArgs {
|
|
11
|
+
/**
|
|
12
|
+
* Triggered whenever the SDK has been induced to persist a change to the
|
|
13
|
+
* Base.
|
|
14
|
+
*/
|
|
15
|
+
mutation: Mutation;
|
|
16
|
+
/**
|
|
17
|
+
* Triggered when the SDK has been induced to expand a Record in the user
|
|
18
|
+
* interface
|
|
19
|
+
*/
|
|
20
|
+
expandRecord: {
|
|
21
|
+
recordId: RecordId;
|
|
22
|
+
recordIds: Array<RecordId> | null;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Triggered when the SDK has been induced to enter full screen mode.
|
|
26
|
+
*/
|
|
27
|
+
enterFullscreen: null;
|
|
28
|
+
/**
|
|
29
|
+
* Triggered when the SDK has been induced to exit full screen mode.
|
|
30
|
+
*/
|
|
31
|
+
exitFullscreen: null;
|
|
32
|
+
/**
|
|
33
|
+
* Triggered when the maximum full screen size is modified.
|
|
34
|
+
*/
|
|
35
|
+
setFullscreenMaxSize: ViewportSizeConstraint;
|
|
36
|
+
/**
|
|
37
|
+
* Triggered when the SDK has been induced to expand a list of Records in
|
|
38
|
+
* the user interface.
|
|
39
|
+
*/
|
|
40
|
+
expandRecordList: {
|
|
41
|
+
tableId: string;
|
|
42
|
+
recordIds: Array<string>;
|
|
43
|
+
fieldIds: Array<string> | null;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A complete set of information necessary to initialize a simulated Airtable
|
|
48
|
+
* Base in automated test environments.
|
|
49
|
+
*/
|
|
50
|
+
export interface FixtureData {
|
|
51
|
+
/**
|
|
52
|
+
* An optional object describing the initial state of the globalConfig
|
|
53
|
+
* which is associated with the simulated Base. If omitted, the Base's
|
|
54
|
+
* globalConfig will be initially empty.
|
|
55
|
+
*/
|
|
56
|
+
globalConfig?: GlobalConfigData;
|
|
57
|
+
/** A representation of the state of an Airtable Base */
|
|
58
|
+
base: {
|
|
59
|
+
id: BaseId;
|
|
60
|
+
name: string;
|
|
61
|
+
color?: string;
|
|
62
|
+
tables: Array<TableFixtureData>;
|
|
63
|
+
collaborators: Array<CollaboratorData & {
|
|
64
|
+
isActive: boolean;
|
|
65
|
+
}>;
|
|
66
|
+
workspaceId: string;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** A representation of the state of a Table */
|
|
70
|
+
interface TableFixtureData {
|
|
71
|
+
/** A unique identifier for the simulated Tbale */
|
|
72
|
+
id: TableId;
|
|
73
|
+
/** The name to assign to the simulated Table */
|
|
74
|
+
name: string;
|
|
75
|
+
/** The description to assign to the simulated Table */
|
|
76
|
+
description: string | null;
|
|
77
|
+
/**
|
|
78
|
+
* Fixture data for the simulated Fields that should be present in the
|
|
79
|
+
* simulated Table when it is initialized.
|
|
80
|
+
*/
|
|
81
|
+
fields: Array<FieldFixtureData>;
|
|
82
|
+
/**
|
|
83
|
+
* Fixture data for the simulated Views that should be present in the
|
|
84
|
+
* simulated Table when it is initialized.
|
|
85
|
+
*/
|
|
86
|
+
views: Array<ViewFixtureData>;
|
|
87
|
+
/**
|
|
88
|
+
* Fixture data for the simulated Records that should be present in the
|
|
89
|
+
* simulated Table when it is initialized.
|
|
90
|
+
*/
|
|
91
|
+
records: Array<RecordFixtureData>;
|
|
92
|
+
}
|
|
93
|
+
/** A representation of the state of a Field */
|
|
94
|
+
interface FieldFixtureData {
|
|
95
|
+
/** A unique identifier for the simulated Field */
|
|
96
|
+
id: FieldId;
|
|
97
|
+
/** The name to assign to the simulated Field */
|
|
98
|
+
name: string;
|
|
99
|
+
/** The description to assign to the simulated Field */
|
|
100
|
+
description: string | null;
|
|
101
|
+
/** The type of the simulated Field */
|
|
102
|
+
type: FieldType;
|
|
103
|
+
/** Options associated with the simulated Field */
|
|
104
|
+
options: null | {
|
|
105
|
+
[key: string]: unknown;
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/** A representation of the state of a View */
|
|
109
|
+
interface ViewFixtureData {
|
|
110
|
+
/** A unique identifier for the simulated View */
|
|
111
|
+
id: ViewId;
|
|
112
|
+
/** The name to assign to the simulated View */
|
|
113
|
+
name: string;
|
|
114
|
+
/** The type of the simulated view */
|
|
115
|
+
type: ViewType;
|
|
116
|
+
/**
|
|
117
|
+
* A description of how simulated Fields should be sequenced within the
|
|
118
|
+
* simulated View
|
|
119
|
+
*/
|
|
120
|
+
fieldOrder: {
|
|
121
|
+
fieldIds: Array<FieldId>;
|
|
122
|
+
visibleFieldCount: number;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* A set of references to Records contained within the simulated view. This
|
|
126
|
+
* is distinct from the complete fixture data for the simulated Records.
|
|
127
|
+
*/
|
|
128
|
+
records: Array<ViewRecordFixtureData>;
|
|
129
|
+
/**
|
|
130
|
+
* A boolean determining if a view is locked
|
|
131
|
+
*/
|
|
132
|
+
isLockedView: boolean;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* A reference to Record contained within a simulated view. This is distinct
|
|
136
|
+
* from the complete fixture data for the simulated Record.
|
|
137
|
+
*/
|
|
138
|
+
interface ViewRecordFixtureData {
|
|
139
|
+
/** A value which uniquely identifies a Record within a base. */
|
|
140
|
+
id: RecordId;
|
|
141
|
+
/** The color associated with a Record's membership in a View. */
|
|
142
|
+
color: Color | null;
|
|
143
|
+
}
|
|
144
|
+
/** A representation of the state of a Record */
|
|
145
|
+
interface RecordFixtureData {
|
|
146
|
+
/** A unique identifier for the simulated Record */
|
|
147
|
+
id: RecordId;
|
|
148
|
+
/** The number of comments to assign to the simulated record */
|
|
149
|
+
commentCount: number;
|
|
150
|
+
/** The time the simulated record should appear to have been created */
|
|
151
|
+
createdTime: string;
|
|
152
|
+
/** A mapping of field identifiers to cell values */
|
|
153
|
+
cellValuesByFieldId: ObjectMap<FieldId, unknown>;
|
|
154
|
+
}
|
|
155
|
+
/** @hidden */
|
|
156
|
+
interface RecordDataStore {
|
|
157
|
+
tables: {
|
|
158
|
+
[key: string]: {
|
|
159
|
+
[key: string]: RecordFixtureData;
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
views: {
|
|
163
|
+
[key: string]: {
|
|
164
|
+
[key: string]: Pick<ViewFixtureData, 'fieldOrder' | 'records'>;
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* A callback function allowing tests to simulate user interaction with the
|
|
170
|
+
* expanded record picker UI. The testing library will invoke this function
|
|
171
|
+
* whenever the Extension under test uses the {@link expandRecordPickerAsync}
|
|
172
|
+
* function, and the return value of this function will be provided to the Extension
|
|
173
|
+
* under test as the {@link Record} that the simulated user selected.
|
|
174
|
+
*/
|
|
175
|
+
export type PickRecord = (tableId: string, recordIds: Array<string>, fieldIds: Array<string> | null, shouldAllowCreatingRecord: boolean) => RecordId | null;
|
|
176
|
+
/**
|
|
177
|
+
* An implementation of the MockAirtableInterface designed for use in automated
|
|
178
|
+
* test suites for Airtable Blocks maintained externally. Provides a more
|
|
179
|
+
* high-level constructor for specifying test fixture data and implements some
|
|
180
|
+
* features which approximate interactions with Hyperbase in production.
|
|
181
|
+
*
|
|
182
|
+
* @hidden
|
|
183
|
+
*/
|
|
184
|
+
export default class MockAirtableInterface extends AbstractMockAirtableInterface {
|
|
185
|
+
_recordDataStore: RecordDataStore;
|
|
186
|
+
_userPermissionCheck?: (mutation: Mutation) => boolean;
|
|
187
|
+
_pickRecord?: PickRecord;
|
|
188
|
+
constructor(unsafeFixtureData: FixtureData);
|
|
189
|
+
applyMutationAsync(mutation: TestMutation, opts?: {
|
|
190
|
+
holdForMs?: number;
|
|
191
|
+
}): Promise<void>;
|
|
192
|
+
checkPermissionsForMutation(mutation: Mutation): PermissionCheckResult;
|
|
193
|
+
get globalConfigHelpers(): import("@baselift/blocks/dist/types/src/types/airtable_interface").GlobalConfigHelpers;
|
|
194
|
+
emit<Key extends keyof WatchableKeysAndArgs>(key: Key, data: WatchableKeysAndArgs[Key]): void;
|
|
195
|
+
expandRecord(tableId: string, recordId: string, recordIds: Array<string> | null): void;
|
|
196
|
+
expandRecordList(tableId: string, recordIds: Array<string>, fieldIds: Array<string> | null): void;
|
|
197
|
+
expandRecordPickerAsync(tableId: string, recordIds: Array<string>, fieldIds: Array<string> | null, shouldAllowCreatingRecord: boolean): Promise<string | null>;
|
|
198
|
+
get fieldTypeProvider(): import("@baselift/blocks/dist/types/src/types/airtable_interface").FieldTypeProvider;
|
|
199
|
+
fetchAndSubscribeToCellValuesInFieldsAsync(tableId: TableId, fieldIds: Array<FieldId>): Promise<any>;
|
|
200
|
+
fetchAndSubscribeToCursorDataAsync(): Promise<CursorData>;
|
|
201
|
+
fetchAndSubscribeToTableDataAsync(tableId: string): Promise<{
|
|
202
|
+
recordsById: {
|
|
203
|
+
[recordId: string]: RecordData;
|
|
204
|
+
};
|
|
205
|
+
}>;
|
|
206
|
+
fetchAndSubscribeToViewDataAsync(tableId: string, viewId: string): Promise<PartialViewData>;
|
|
207
|
+
hasRecord(tableId: TableId, recordId: RecordId): boolean;
|
|
208
|
+
get idGenerator(): import("@baselift/blocks/dist/types/src/types/airtable_interface").IdGenerator;
|
|
209
|
+
on<Key extends keyof WatchableKeysAndArgs>(key: Key, fn: (data: WatchableKeysAndArgs[Key]) => void): void;
|
|
210
|
+
off<Key extends keyof WatchableKeysAndArgs>(key: Key, fn: (data: WatchableKeysAndArgs[Key]) => void): void;
|
|
211
|
+
setFullscreenMaxSize(maxFullscreenSize: ViewportSizeConstraint): void;
|
|
212
|
+
setPickRecord(pickRecord: PickRecord): void;
|
|
213
|
+
setUserPermissionCheck(check: (mutation: Mutation) => boolean): void;
|
|
214
|
+
performBackendFetchAsync(requestJson: RequestJson): Promise<ResponseJson>;
|
|
215
|
+
fetchDefaultCellValuesByFieldIdAsync(): Promise<{
|
|
216
|
+
[key: string]: unknown;
|
|
217
|
+
}>;
|
|
218
|
+
reloadFrame(): void;
|
|
219
|
+
setSettingsButtonVisibility(): void;
|
|
220
|
+
setUndoRedoMode(): void;
|
|
221
|
+
enterFullscreen(): void;
|
|
222
|
+
exitFullscreen(): void;
|
|
223
|
+
fetchAndSubscribeToPerformRecordActionAsync(): Promise<RecordActionData | null>;
|
|
224
|
+
trackEvent(): void;
|
|
225
|
+
/**
|
|
226
|
+
* `trackExposure` cannot be invoked by any Extensions (neither those authored by
|
|
227
|
+
* Airtable nor by other Extension developers). It should be implemented to
|
|
228
|
+
* satisfy the AirtableInterface contract, but the implementation should
|
|
229
|
+
* not throw because it must be successful for Extensions to function. Likewise,
|
|
230
|
+
* it should not emit an event because test authors have no need to track
|
|
231
|
+
* its usage.
|
|
232
|
+
*/
|
|
233
|
+
trackExposure(): void;
|
|
234
|
+
sendStat(): void;
|
|
235
|
+
}
|
|
236
|
+
export {};
|
|
237
|
+
//# sourceMappingURL=mock_airtable_interface.d.ts.map
|