@wise/dynamic-flow-client 0.2.0 → 0.2.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/build/flow/DynamicFlow.d.ts +1 -0
- package/build/flow/DynamicFlow.js +15 -5
- package/build/flow/DynamicFlowStep.d.ts +1 -0
- package/build/flow/errorBoundary/ErrorBoundaryAlert.d.ts +1 -0
- package/build/flow/fixtures/components/alert.d.ts +2 -2
- package/build/flow/fixtures/components/box.d.ts +2 -2
- package/build/flow/fixtures/components/button.d.ts +2 -2
- package/build/flow/fixtures/components/columns.d.ts +2 -2
- package/build/flow/fixtures/components/copyable.d.ts +2 -2
- package/build/flow/fixtures/components/decision.d.ts +2 -2
- package/build/flow/fixtures/components/heading.d.ts +2 -2
- package/build/flow/fixtures/components/image.d.ts +3 -2
- package/build/flow/fixtures/components/image.js +22 -3
- package/build/flow/fixtures/components/info.d.ts +2 -2
- package/build/flow/fixtures/components/list.d.ts +2 -2
- package/build/flow/fixtures/components/loading-indicator.d.ts +2 -2
- package/build/flow/fixtures/components/paragraph.d.ts +2 -2
- package/build/flow/fixtures/components/review.d.ts +2 -2
- package/build/flow/fixtures/examples/camera-capture.d.ts +2 -2
- package/build/flow/fixtures/examples/recipient-update.d.ts +2 -2
- package/build/flow/fixtures/examples/recipient-update.js +2 -2
- package/build/flow/fixtures/examples/recipient.d.ts +2 -2
- package/build/flow/fixtures/examples/single-file-upload.d.ts +2 -2
- package/build/flow/fixtures/examples/single-file-upload.js +32 -30
- package/build/flow/fixtures/examples/step-validation-errors.d.ts +2 -2
- package/build/flow/fixtures/features/action-response.d.ts +2 -2
- package/build/flow/fixtures/features/external.d.ts +2 -2
- package/build/flow/fixtures/features/persist-async.d.ts +2 -2
- package/build/flow/fixtures/features/polling.d.ts +2 -2
- package/build/flow/fixtures/features/validation-async.d.ts +3 -0
- package/build/flow/fixtures/features/validation-async.js +38 -0
- package/build/flow/fixtures/index.d.ts +34 -28
- package/build/flow/fixtures/index.js +8 -1
- package/build/flow/fixtures/responses/action-response-final.d.ts +2 -2
- package/build/flow/fixtures/responses/recipient-update-final.d.ts +2 -2
- package/build/flow/fixtures/schemas/basic-form.d.ts +2 -2
- package/build/flow/fixtures/schemas/number-and-integer.d.ts +2 -2
- package/build/flow/fixtures/schemas/one-of.d.ts +2 -2
- package/build/flow/fixtures/schemas/string-formats.d.ts +2 -2
- package/build/flow/fixtures/schemas/string-formats.js +6 -2
- package/build/flow/stories/DynamicFlow.story.d.ts +1 -0
- package/build/flow/stories/DynamicFlow.story.js +30 -0
- package/build/flow/stories/EditableDynamicFlow.d.ts +1 -0
- package/build/flow/stories/EditableDynamicFlow.js +2 -1
- package/build/flow/stories/fixtureFetcher.d.ts +2 -0
- package/build/flow/stories/fixtureFetcher.js +114 -0
- package/build/jsonSchemaForm/JsonSchemaForm.d.ts +1 -0
- package/build/jsonSchemaForm/allOfSchema/AllOfSchema.d.ts +1 -0
- package/build/jsonSchemaForm/arrayTypeSchema/ArraySchema.d.ts +1 -0
- package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/ArrayListSchema.d.ts +1 -0
- package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/MultipleFileUploadSchema.d.ts +1 -0
- package/build/jsonSchemaForm/basicTypeSchema/BasicTypeSchema.d.ts +1 -0
- package/build/jsonSchemaForm/controlFeedback/ControlFeedback.d.ts +1 -0
- package/build/jsonSchemaForm/genericSchema/GenericSchema.d.ts +1 -0
- package/build/jsonSchemaForm/help/Help.d.ts +1 -0
- package/build/jsonSchemaForm/objectSchema/ObjectSchema.d.ts +1 -0
- package/build/jsonSchemaForm/oneOfSchema/OneOfSchema.d.ts +1 -0
- package/build/jsonSchemaForm/persistAsyncSchema/PersistAsyncSchema.d.ts +1 -0
- package/build/jsonSchemaForm/persistAsyncSchema/basic/PersistAsyncBasicSchema.d.ts +1 -0
- package/build/jsonSchemaForm/persistAsyncSchema/blob/PersistAsyncBlobSchema.d.ts +1 -0
- package/build/jsonSchemaForm/persistAsyncSchema/blob/UploadInputAdapter.d.ts +1 -0
- package/build/jsonSchemaForm/promotedOneOfSchema/PromotedOneOfSchema.d.ts +1 -0
- package/build/jsonSchemaForm/promotedOneOfSchema/control/PromotedOneOfCheckboxControl.d.ts +1 -0
- package/build/jsonSchemaForm/promotedOneOfSchema/control/PromotedOneOfRadioControl.d.ts +1 -0
- package/build/jsonSchemaForm/readOnlySchema/ReadOnlySchema.d.ts +1 -0
- package/build/jsonSchemaForm/schemaFormControl/SchemaFormControl.d.ts +2 -1
- package/build/jsonSchemaForm/schemaFormControl/optionMapper.d.ts +7 -11
- package/build/jsonSchemaForm/schemaFormControl/optionMapper.js +12 -6
- package/build/jsonSchemaForm/validationAsyncSchema/ValidationAsyncSchema.d.ts +1 -0
- package/build/layout/DynamicLayout.d.ts +1 -0
- package/build/layout/alert/index.d.ts +1 -0
- package/build/layout/box/index.d.ts +1 -0
- package/build/layout/button/index.d.ts +1 -0
- package/build/layout/columns/index.d.ts +1 -0
- package/build/layout/decision/index.d.ts +1 -0
- package/build/layout/divider/index.d.ts +1 -0
- package/build/layout/external/DynamicExternal.d.ts +1 -0
- package/build/layout/form/index.d.ts +1 -0
- package/build/layout/heading/index.d.ts +1 -0
- package/build/layout/icon/index.d.ts +1 -0
- package/build/layout/image/index.d.ts +4 -2
- package/build/layout/image/index.js +17 -38
- package/build/layout/info/index.d.ts +1 -0
- package/build/layout/list/index.d.ts +1 -0
- package/build/layout/loading-indicator/index.d.ts +1 -0
- package/build/layout/paragraph/DynamicParagraph.d.ts +1 -0
- package/build/layout/review/index.d.ts +1 -0
- package/build/main.css +45 -0
- package/build/step/cameraStep/CameraStep.d.ts +1 -0
- package/build/step/cameraStep/cameraCapture/CameraCapture.d.ts +1 -0
- package/build/step/cameraStep/cameraCapture/components/index.d.ts +1 -0
- package/build/step/cameraStep/cameraCapture/overlay/Overlay.d.ts +1 -0
- package/build/step/cameraStep/cameraCapture/screens/CameraNotSupported/CameraNotSupported.d.ts +1 -0
- package/build/step/cameraStep/cameraCapture/screens/NoCameraAccess/NoCameraAccess.d.ts +1 -0
- package/build/step/externalConfirmationStep/ExternalConfirmationStep.d.ts +1 -0
- package/build/step/layoutStep/LayoutStep.d.ts +1 -0
- package/package.json +7 -5
- package/build/common/hooks/useDebouncedFunction.test.d.ts +0 -1
- package/build/common/hooks/useDebouncedFunction.test.js +0 -59
- package/build/common/logging/spec.d.ts +0 -1
- package/build/common/logging/spec.js +0 -45
- package/build/common/tracking/spec.d.ts +0 -1
- package/build/common/tracking/spec.js +0 -49
- package/build/common/utils/generate-random-id.test.d.ts +0 -1
- package/build/common/utils/generate-random-id.test.js +0 -12
- package/build/common/validation/rule-validators/spec.d.ts +0 -1
- package/build/common/validation/rule-validators/spec.js +0 -145
- package/build/common/validation/schema-validators/spec.d.ts +0 -1
- package/build/common/validation/schema-validators/spec.js +0 -137
- package/build/common/validation/valid-model/spec.d.ts +0 -1
- package/build/common/validation/valid-model/spec.js +0 -605
- package/build/common/validation/validation-failures/spec.d.ts +0 -1
- package/build/common/validation/validation-failures/spec.js +0 -185
- package/build/flow/response-parsers/spec.d.ts +0 -1
- package/build/flow/response-parsers/spec.js +0 -263
- package/build/layout/loading-indicator/spec.d.ts +0 -1
- package/build/layout/loading-indicator/spec.js +0 -11
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import { getValidationFailures } from '.';
|
|
2
|
-
describe('Given a library for identifying validation failures', function () {
|
|
3
|
-
var schema;
|
|
4
|
-
describe('when value is null and schema required', function () {
|
|
5
|
-
beforeEach(function () {
|
|
6
|
-
schema = {
|
|
7
|
-
type: 'string',
|
|
8
|
-
minLength: 3,
|
|
9
|
-
maxLength: 10,
|
|
10
|
-
pattern: '^[a-z]+$'
|
|
11
|
-
};
|
|
12
|
-
});
|
|
13
|
-
it('should return only required', function () {
|
|
14
|
-
expect(getValidationFailures(null, schema, true)).toStrictEqual(['required']);
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
describe('when validating a string schema', function () {
|
|
18
|
-
beforeEach(function () {
|
|
19
|
-
schema = {
|
|
20
|
-
type: 'string',
|
|
21
|
-
minLength: 3,
|
|
22
|
-
maxLength: 6,
|
|
23
|
-
pattern: '^[a-z]+$'
|
|
24
|
-
};
|
|
25
|
-
});
|
|
26
|
-
it('should return an empty array for valid string', function () {
|
|
27
|
-
expect(getValidationFailures('string', schema, false)).toStrictEqual([]);
|
|
28
|
-
});
|
|
29
|
-
it('should return an empty array for null if not required', function () {
|
|
30
|
-
expect(getValidationFailures(null, schema, false)).toStrictEqual([]);
|
|
31
|
-
});
|
|
32
|
-
it('should return minLength when too short', function () {
|
|
33
|
-
expect(getValidationFailures('st', schema, false)).toStrictEqual(['minLength']);
|
|
34
|
-
});
|
|
35
|
-
it('should return [maxLength] when too long', function () {
|
|
36
|
-
expect(getValidationFailures('strings', schema, false)).toStrictEqual(['maxLength']);
|
|
37
|
-
});
|
|
38
|
-
it('should return [pattern] when does not pass regex', function () {
|
|
39
|
-
expect(getValidationFailures('STRING', schema, false)).toStrictEqual(['pattern']);
|
|
40
|
-
});
|
|
41
|
-
it('should return [type] when incorrect data type', function () {
|
|
42
|
-
expect(getValidationFailures(1234, schema, false)).toStrictEqual(['type']);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
describe('when validating a string date', function () {
|
|
46
|
-
beforeEach(function () {
|
|
47
|
-
schema = {
|
|
48
|
-
type: 'string',
|
|
49
|
-
minimum: '2000-01-01T00:00:00Z',
|
|
50
|
-
maximum: '2010-01-01T00:00:00Z'
|
|
51
|
-
};
|
|
52
|
-
});
|
|
53
|
-
it('should return an empty array for valid date', function () {
|
|
54
|
-
expect(getValidationFailures('2005-01-01T00:00:00Z', schema, false)).toStrictEqual([]);
|
|
55
|
-
});
|
|
56
|
-
it('should return [min] when date is too early', function () {
|
|
57
|
-
expect(getValidationFailures('1999-01-01T00:00:00Z', schema, false)).toStrictEqual([
|
|
58
|
-
'minimum',
|
|
59
|
-
]);
|
|
60
|
-
});
|
|
61
|
-
it('should return [max] when date is too late', function () {
|
|
62
|
-
expect(getValidationFailures('2011-01-01T00:00:00Z', schema, false)).toStrictEqual([
|
|
63
|
-
'maximum',
|
|
64
|
-
]);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
describe('when validating a number schema', function () {
|
|
68
|
-
beforeEach(function () {
|
|
69
|
-
schema = {
|
|
70
|
-
type: 'number',
|
|
71
|
-
minimum: 0,
|
|
72
|
-
maximum: 20
|
|
73
|
-
};
|
|
74
|
-
});
|
|
75
|
-
it('should return an empty array for an integer in range', function () {
|
|
76
|
-
expect(getValidationFailures(10, schema, false)).toStrictEqual([]);
|
|
77
|
-
});
|
|
78
|
-
it('should return an empty array for a float in range', function () {
|
|
79
|
-
expect(getValidationFailures(12.34, schema, false)).toStrictEqual([]);
|
|
80
|
-
});
|
|
81
|
-
it('should return an empty array for a number that matches our min', function () {
|
|
82
|
-
expect(getValidationFailures(0, schema, false)).toStrictEqual([]);
|
|
83
|
-
});
|
|
84
|
-
it('should return an empty array for a number that matches our max', function () {
|
|
85
|
-
expect(getValidationFailures(20, schema, false)).toStrictEqual([]);
|
|
86
|
-
});
|
|
87
|
-
it('should return [min] when number is too low', function () {
|
|
88
|
-
expect(getValidationFailures(-1, schema, false)).toStrictEqual(['minimum']);
|
|
89
|
-
});
|
|
90
|
-
it('should return [max] when number is too high', function () {
|
|
91
|
-
expect(getValidationFailures(21, schema, false)).toStrictEqual(['maximum']);
|
|
92
|
-
});
|
|
93
|
-
it('should return [type] when incorrect data type', function () {
|
|
94
|
-
expect(getValidationFailures('string', schema, false)).toStrictEqual(['type']);
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
describe('when validating an integer schema', function () {
|
|
98
|
-
beforeEach(function () {
|
|
99
|
-
schema = { type: 'integer' };
|
|
100
|
-
});
|
|
101
|
-
it('should return an empty array for valid integer', function () {
|
|
102
|
-
expect(getValidationFailures(15, schema, false)).toStrictEqual([]);
|
|
103
|
-
});
|
|
104
|
-
it('should return [type] when a number is not an integer', function () {
|
|
105
|
-
expect(getValidationFailures(12.34, schema, false)).toStrictEqual(['type']);
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
describe('when validating a boolean schema', function () {
|
|
109
|
-
beforeEach(function () {
|
|
110
|
-
schema = { type: 'boolean' };
|
|
111
|
-
});
|
|
112
|
-
it('should return an empty array for valid boolean', function () {
|
|
113
|
-
expect(getValidationFailures(true, schema, false)).toStrictEqual([]);
|
|
114
|
-
expect(getValidationFailures(false, schema, false)).toStrictEqual([]);
|
|
115
|
-
});
|
|
116
|
-
it('should return [type] when incorrect data type', function () {
|
|
117
|
-
expect(getValidationFailures(1, schema, false)).toStrictEqual(['type']);
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
describe('when validating a const schema', function () {
|
|
121
|
-
beforeEach(function () {
|
|
122
|
-
schema = { "const": 'abcd' };
|
|
123
|
-
});
|
|
124
|
-
it('should return an empty array when the const matches', function () {
|
|
125
|
-
expect(getValidationFailures('abcd', schema, false)).toStrictEqual([]);
|
|
126
|
-
});
|
|
127
|
-
it("should return ['const'] when the const does not match", function () {
|
|
128
|
-
expect(getValidationFailures('1234', schema, false)).toStrictEqual(['const']);
|
|
129
|
-
});
|
|
130
|
-
it("should return ['const'] when null", function () {
|
|
131
|
-
expect(getValidationFailures(null, schema, false)).toStrictEqual(['const']);
|
|
132
|
-
});
|
|
133
|
-
it("should return ['const'] when undefined", function () {
|
|
134
|
-
expect(getValidationFailures(undefined, schema, false)) //
|
|
135
|
-
.toStrictEqual(['const']);
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
describe('when validating an array schema', function () {
|
|
139
|
-
beforeEach(function () {
|
|
140
|
-
schema = {
|
|
141
|
-
type: 'array',
|
|
142
|
-
items: {
|
|
143
|
-
type: 'number'
|
|
144
|
-
},
|
|
145
|
-
minItems: 2,
|
|
146
|
-
maxItems: 2
|
|
147
|
-
};
|
|
148
|
-
});
|
|
149
|
-
it('should return an empty array for a valid array', function () {
|
|
150
|
-
expect(getValidationFailures([1, 2], schema, false)).toStrictEqual([]);
|
|
151
|
-
});
|
|
152
|
-
it('should return [minItems] when the array is too small', function () {
|
|
153
|
-
expect(getValidationFailures([1], schema, false)).toStrictEqual(['minItems']);
|
|
154
|
-
});
|
|
155
|
-
it('should return [maxItems] when the array is too big', function () {
|
|
156
|
-
expect(getValidationFailures([1, 2, 3], schema, false)).toStrictEqual(['maxItems']);
|
|
157
|
-
});
|
|
158
|
-
it('should return [type] when incorrect data type', function () {
|
|
159
|
-
expect(getValidationFailures({ a: 1 }, schema, false)).toStrictEqual(['type']);
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
describe('when validating an object schema', function () {
|
|
163
|
-
beforeEach(function () {
|
|
164
|
-
schema = {
|
|
165
|
-
type: 'object',
|
|
166
|
-
properties: {
|
|
167
|
-
a: {
|
|
168
|
-
type: 'number'
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
|
-
required: ['a'],
|
|
172
|
-
displayOrder: ['a']
|
|
173
|
-
};
|
|
174
|
-
});
|
|
175
|
-
it('should return an empty array for a valid object', function () {
|
|
176
|
-
expect(getValidationFailures({ a: 1 }, schema, false)).toStrictEqual([]);
|
|
177
|
-
});
|
|
178
|
-
it('should return [required] when required properties are missing', function () {
|
|
179
|
-
expect(getValidationFailures({}, schema, false)).toStrictEqual(['required']);
|
|
180
|
-
});
|
|
181
|
-
it('should return [type] when incorrect data type', function () {
|
|
182
|
-
expect(getValidationFailures([1], schema, false)).toStrictEqual(['type']);
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
-
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;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
import { parseErrorResponse, parseExitResponse, parseFetchResponse } from '.';
|
|
38
|
-
describe('parseFetchResponse', function () {
|
|
39
|
-
describe('when response contains the X-DF-Exit header', function () {
|
|
40
|
-
var headers = { 'X-Df-Exit': 'true' };
|
|
41
|
-
describe('and response body can be json-parsed as an object', function () {
|
|
42
|
-
it('should return exit result', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
43
|
-
var response, parsedBody;
|
|
44
|
-
return __generator(this, function (_a) {
|
|
45
|
-
switch (_a.label) {
|
|
46
|
-
case 0:
|
|
47
|
-
response = new Response("{ \"exitResult\": \"exit result\" }", { headers: headers });
|
|
48
|
-
return [4 /*yield*/, parseFetchResponse(response)];
|
|
49
|
-
case 1:
|
|
50
|
-
parsedBody = _a.sent();
|
|
51
|
-
expect(parsedBody).toStrictEqual({
|
|
52
|
-
type: 'exit',
|
|
53
|
-
result: { exitResult: 'exit result' }
|
|
54
|
-
});
|
|
55
|
-
return [2 /*return*/];
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}); });
|
|
59
|
-
});
|
|
60
|
-
describe('but response body cannot be json-parsed as an object', function () {
|
|
61
|
-
getNonObjectBodyCases().forEach(function (_a) {
|
|
62
|
-
var description = _a[0], body = _a[1];
|
|
63
|
-
describe("when the body is ".concat(description), function () {
|
|
64
|
-
it("returns exit result with null", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
65
|
-
var parsedBody;
|
|
66
|
-
return __generator(this, function (_a) {
|
|
67
|
-
switch (_a.label) {
|
|
68
|
-
case 0: return [4 /*yield*/, parseFetchResponse(new Response(body, { headers: headers }))];
|
|
69
|
-
case 1:
|
|
70
|
-
parsedBody = _a.sent();
|
|
71
|
-
expect(parsedBody).toStrictEqual({ type: 'exit', result: null });
|
|
72
|
-
return [2 /*return*/];
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}); });
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
describe('when response does not contain the X-DF-Exit header', function () {
|
|
81
|
-
var headers = { etag: 'etag' };
|
|
82
|
-
describe('and response body can be json-parsed as an object', function () {
|
|
83
|
-
describe('and it contains an action property', function () {
|
|
84
|
-
describe('and the action property is an object', function () {
|
|
85
|
-
it('assumes the action property is of type Action, and returns type action and the action', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
86
|
-
var parsedBody;
|
|
87
|
-
return __generator(this, function (_a) {
|
|
88
|
-
switch (_a.label) {
|
|
89
|
-
case 0: return [4 /*yield*/, parseFetchResponse(new Response('{ "action": { "url": "/path", "method": "POST" } }'))];
|
|
90
|
-
case 1:
|
|
91
|
-
parsedBody = _a.sent();
|
|
92
|
-
expect(parsedBody).toStrictEqual({
|
|
93
|
-
type: 'action',
|
|
94
|
-
action: { url: '/path', method: 'POST' }
|
|
95
|
-
});
|
|
96
|
-
return [2 /*return*/];
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}); });
|
|
100
|
-
it('assumes the action property is of type Action, even if its NOT', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
101
|
-
var parsedBody;
|
|
102
|
-
return __generator(this, function (_a) {
|
|
103
|
-
switch (_a.label) {
|
|
104
|
-
case 0: return [4 /*yield*/, parseFetchResponse(new Response('{ "action": { "random": "property" } }'))];
|
|
105
|
-
case 1:
|
|
106
|
-
parsedBody = _a.sent();
|
|
107
|
-
expect(parsedBody).toStrictEqual({ type: 'action', action: { random: 'property' } });
|
|
108
|
-
return [2 /*return*/];
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}); });
|
|
112
|
-
});
|
|
113
|
-
describe('and the action property is NOT an object', function () {
|
|
114
|
-
it('throws an error', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
115
|
-
return __generator(this, function (_a) {
|
|
116
|
-
switch (_a.label) {
|
|
117
|
-
case 0: return [4 /*yield*/, expect(parseFetchResponse(new Response('{ "action": 123 }'))).rejects.toThrow('Incorrect response body in action response. Expected an object satisfying the type { action: Action }.')];
|
|
118
|
-
case 1:
|
|
119
|
-
_a.sent();
|
|
120
|
-
return [2 /*return*/];
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
}); });
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
describe('when the body is NOT an object with an action property', function () {
|
|
127
|
-
it('assumes the response is a step and returns step and etag', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
128
|
-
var response, parsedBody;
|
|
129
|
-
return __generator(this, function (_a) {
|
|
130
|
-
switch (_a.label) {
|
|
131
|
-
case 0:
|
|
132
|
-
response = new Response("{ \"stepResult\": \"step result\" }", { headers: headers });
|
|
133
|
-
return [4 /*yield*/, parseFetchResponse(response)];
|
|
134
|
-
case 1:
|
|
135
|
-
parsedBody = _a.sent();
|
|
136
|
-
expect(parsedBody).toStrictEqual({
|
|
137
|
-
type: 'step',
|
|
138
|
-
step: { stepResult: 'step result' },
|
|
139
|
-
etag: 'etag'
|
|
140
|
-
});
|
|
141
|
-
return [2 /*return*/];
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
}); });
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
describe('but response body cannot be json-parsed as an object', function () {
|
|
148
|
-
getNonObjectBodyCases().forEach(function (_a) {
|
|
149
|
-
var description = _a[0], body = _a[1];
|
|
150
|
-
describe("when the body is ".concat(description), function () {
|
|
151
|
-
it("throws an error", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
152
|
-
return __generator(this, function (_a) {
|
|
153
|
-
switch (_a.label) {
|
|
154
|
-
case 0: return [4 /*yield*/, expect(parseFetchResponse(new Response(body))).rejects.toThrow('Incorrect response body in response. Expected an object.')];
|
|
155
|
-
case 1:
|
|
156
|
-
_a.sent();
|
|
157
|
-
return [2 /*return*/];
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
}); });
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
describe('parseErrorResponse', function () {
|
|
167
|
-
describe('when response body can be json-parsed as an object', function () {
|
|
168
|
-
it('returns the response body', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
169
|
-
var response, parsedBody;
|
|
170
|
-
return __generator(this, function (_a) {
|
|
171
|
-
switch (_a.label) {
|
|
172
|
-
case 0:
|
|
173
|
-
response = new Response(JSON.stringify({
|
|
174
|
-
error: 'This is a global error',
|
|
175
|
-
validation: { field: 'This is a field error' }
|
|
176
|
-
}), { status: 422 });
|
|
177
|
-
return [4 /*yield*/, parseErrorResponse(response)];
|
|
178
|
-
case 1:
|
|
179
|
-
parsedBody = _a.sent();
|
|
180
|
-
expect(parsedBody).toStrictEqual({
|
|
181
|
-
error: 'This is a global error',
|
|
182
|
-
validation: { field: 'This is a field error' }
|
|
183
|
-
});
|
|
184
|
-
return [2 /*return*/];
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
}); });
|
|
188
|
-
});
|
|
189
|
-
describe('when response body CANNOT be json-parsed as an object', function () {
|
|
190
|
-
getNonObjectBodyCases().forEach(function (_a) {
|
|
191
|
-
var description = _a[0], body = _a[1];
|
|
192
|
-
describe("when the body is ".concat(description), function () {
|
|
193
|
-
it("throws an error", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
194
|
-
return __generator(this, function (_a) {
|
|
195
|
-
switch (_a.label) {
|
|
196
|
-
case 0: return [4 /*yield*/, expect(parseErrorResponse(new Response(body))).rejects.toThrow('Incorrect response body in error response. Expected an object.')];
|
|
197
|
-
case 1:
|
|
198
|
-
_a.sent();
|
|
199
|
-
return [2 /*return*/];
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
}); });
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
describe('parseExitResponse', function () {
|
|
208
|
-
describe('when response body can be json-parsed as an object', function () {
|
|
209
|
-
it('returns the parsed response body', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
210
|
-
var response;
|
|
211
|
-
return __generator(this, function (_a) {
|
|
212
|
-
switch (_a.label) {
|
|
213
|
-
case 0:
|
|
214
|
-
response = new Response("{ \"exitResult\": \"exit result\" }");
|
|
215
|
-
return [4 /*yield*/, expect(parseExitResponse(response)).resolves.toStrictEqual({
|
|
216
|
-
exitResult: 'exit result'
|
|
217
|
-
})];
|
|
218
|
-
case 1:
|
|
219
|
-
_a.sent();
|
|
220
|
-
return [2 /*return*/];
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
}); });
|
|
224
|
-
});
|
|
225
|
-
describe('when response body CANNOT be json-parsed as an object', function () {
|
|
226
|
-
getNonObjectBodyCases().forEach(function (_a) {
|
|
227
|
-
var description = _a[0], body = _a[1];
|
|
228
|
-
describe("when the body is ".concat(description), function () {
|
|
229
|
-
it("returns null", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
230
|
-
var parsedBody;
|
|
231
|
-
return __generator(this, function (_a) {
|
|
232
|
-
switch (_a.label) {
|
|
233
|
-
case 0: return [4 /*yield*/, parseExitResponse(new Response(body))];
|
|
234
|
-
case 1:
|
|
235
|
-
parsedBody = _a.sent();
|
|
236
|
-
expect(parsedBody).toBeNull();
|
|
237
|
-
return [2 /*return*/];
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
}); });
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
});
|
|
245
|
-
function getNonObjectBodyCases() {
|
|
246
|
-
return [
|
|
247
|
-
['parseable as number', '1234'],
|
|
248
|
-
['parseable as a string', '"json string"'],
|
|
249
|
-
['parseable as an empty string', '""'],
|
|
250
|
-
['parseable as an array', '[]'],
|
|
251
|
-
['parseable as true', 'true'],
|
|
252
|
-
['parseable as false', 'false'],
|
|
253
|
-
['parseable as null', 'null'],
|
|
254
|
-
['an empty string', ''],
|
|
255
|
-
['non-json parseable string', 'non-json string'],
|
|
256
|
-
['a number', 1234],
|
|
257
|
-
['NaN', NaN],
|
|
258
|
-
['undefined', undefined],
|
|
259
|
-
['a Blob instance', new Blob()],
|
|
260
|
-
['a FormData instance', new FormData()],
|
|
261
|
-
['a URLSearchParams instance', new URLSearchParams('foo=bar')],
|
|
262
|
-
];
|
|
263
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
3
|
-
import { DynamicLoadingIndicator } from '.';
|
|
4
|
-
describe('Given a component for dynamically rendering a loading indicator', function () {
|
|
5
|
-
describe('when initialised without any properties', function () {
|
|
6
|
-
it('renders a loading indicator of the default "md" size', function () {
|
|
7
|
-
var baseElement = render(_jsx(DynamicLoadingIndicator, { component: { type: 'loading-indicator' } })).baseElement;
|
|
8
|
-
expect(baseElement).toMatchInlineSnapshot("\n<body>\n <div>\n <div\n class=\"tw-loader m-x-auto tw-loader--md\"\n >\n <div\n class=\"tw-loader__stripe\"\n />\n <div\n class=\"tw-loader__stripe\"\n />\n <div\n class=\"tw-loader__stripe\"\n />\n <div\n class=\"tw-loader__stripe\"\n />\n <div\n class=\"tw-loader__stripe\"\n />\n </div>\n </div>\n</body>\n");
|
|
9
|
-
});
|
|
10
|
-
});
|
|
11
|
-
});
|