@jskit-ai/uploads-image-web 0.1.222 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/locales/en.json +22 -0
- package/package.json +5 -3
- package/src/client/composables/createImageUploadRuntime.js +5 -1
- package/src/client/composables/createManagedImageAssetRuntime.js +36 -27
- package/src/client/i18n.js +6 -0
- package/test/exportsContract.test.js +3 -1
- package/test/i18nCatalog.test.js +16 -0
- package/test/imageUploadTexts.test.js +123 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0 - 2026-10-29
|
|
4
|
+
|
|
5
|
+
- Translation ready: every user-visible text is a message key with its English in `locales/en.json`, so an app translates it by supplying translation files only. With no translations, texts and behaviour are unchanged. See the guide "Translating a JSKIT app".
|
|
6
|
+
|
|
7
|
+
### New message keys (12)
|
|
8
|
+
|
|
9
|
+
All keys in `locales/en.json` (exported as `./locales/en.json`) are new in this version.
|
|
10
|
+
|
|
11
|
+
<details><summary>Key list</summary>
|
|
12
|
+
|
|
13
|
+
- `jskit.uploads.imageUpload.note`
|
|
14
|
+
- `jskit.uploads.imageAsset.endpointUnavailable`
|
|
15
|
+
- `jskit.uploads.imageAsset.uploadSuccess`
|
|
16
|
+
- `jskit.uploads.imageAsset.uploadInvalidResponse`
|
|
17
|
+
- `jskit.uploads.imageAsset.uploadError`
|
|
18
|
+
- `jskit.uploads.imageAsset.uploadRestriction`
|
|
19
|
+
- `jskit.uploads.imageAsset.editorUnavailable`
|
|
20
|
+
- `jskit.uploads.imageAsset.deleteSuccess`
|
|
21
|
+
- `jskit.uploads.imageAsset.deleteError`
|
|
22
|
+
- `jskit.uploads.imageAsset.deleteUnavailable`
|
|
23
|
+
- `jskit.uploads.imageAsset.deleteRequestFailed`
|
|
24
|
+
- `jskit.uploads.imageAsset.changeError`
|
|
25
|
+
|
|
26
|
+
</details>
|
package/locales/en.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"jskit": {
|
|
3
|
+
"uploads": {
|
|
4
|
+
"imageUpload": {
|
|
5
|
+
"note": "Accepted: {types}, max {maxMb}MB"
|
|
6
|
+
},
|
|
7
|
+
"imageAsset": {
|
|
8
|
+
"endpointUnavailable": "Image endpoint is unavailable.",
|
|
9
|
+
"uploadSuccess": "Image uploaded.",
|
|
10
|
+
"uploadInvalidResponse": "Image uploaded, but the response payload was invalid.",
|
|
11
|
+
"uploadError": "Unable to upload image.",
|
|
12
|
+
"uploadRestriction": "Selected image does not meet upload restrictions.",
|
|
13
|
+
"editorUnavailable": "Image editor is unavailable in this environment.",
|
|
14
|
+
"deleteSuccess": "Image removed.",
|
|
15
|
+
"deleteError": "Unable to remove image.",
|
|
16
|
+
"deleteUnavailable": "Image removal is unavailable.",
|
|
17
|
+
"deleteRequestFailed": "Image delete request failed.",
|
|
18
|
+
"changeError": "Image updated, but the page could not refresh."
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/uploads-image-web",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node --test --test-concurrency=1"
|
|
@@ -10,10 +10,11 @@
|
|
|
10
10
|
"./client/composables/createImageUploadRuntime": "./src/client/composables/createImageUploadRuntime.js",
|
|
11
11
|
"./client/composables/createManagedImageAssetRuntime": "./src/client/composables/createManagedImageAssetRuntime.js",
|
|
12
12
|
"./client/styles": "./src/client/styles/index.js",
|
|
13
|
-
"./shared": "./src/shared/index.js"
|
|
13
|
+
"./shared": "./src/shared/index.js",
|
|
14
|
+
"./locales/en.json": "./locales/en.json"
|
|
14
15
|
},
|
|
15
16
|
"dependencies": {
|
|
16
|
-
"@jskit-ai/uploads-runtime": "0.
|
|
17
|
+
"@jskit-ai/uploads-runtime": "0.2.0",
|
|
17
18
|
"@uppy/compressor": "^3.1.0",
|
|
18
19
|
"@uppy/core": "^5.2.0",
|
|
19
20
|
"@uppy/dashboard": "^5.1.1",
|
|
@@ -21,6 +22,7 @@
|
|
|
21
22
|
"@uppy/xhr-upload": "^5.1.1"
|
|
22
23
|
},
|
|
23
24
|
"peerDependencies": {
|
|
25
|
+
"@jskit-ai/kernel": "0.2.0",
|
|
24
26
|
"vue": "^3.5.13"
|
|
25
27
|
},
|
|
26
28
|
"description": "Reusable client-side image upload runtime with pre-upload image editing.",
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
} from "../../shared/imageUploadDefaults.js";
|
|
13
13
|
import { parseUploadResponse } from "../support/parseUploadResponse.js";
|
|
14
14
|
import { stopImageEditor } from "../support/stopImageEditor.js";
|
|
15
|
+
import { useJskitText } from "../i18n.js";
|
|
15
16
|
|
|
16
17
|
function normalizeObject(value) {
|
|
17
18
|
return value && typeof value === "object" ? value : {};
|
|
@@ -57,7 +58,10 @@ function createImageUploadRuntime({
|
|
|
57
58
|
const normalizedMethod = String(method || "POST").trim().toUpperCase() || "POST";
|
|
58
59
|
const dashboardNote =
|
|
59
60
|
String(note || "").trim() ||
|
|
60
|
-
|
|
61
|
+
useJskitText().t("jskit.uploads.imageUpload.note", {
|
|
62
|
+
types: normalizedAllowedMimeTypes.join(", "),
|
|
63
|
+
maxMb: Math.floor(normalizedMaxUploadBytes / (1024 * 1024))
|
|
64
|
+
});
|
|
61
65
|
|
|
62
66
|
function emitSelectedFileName(fileName) {
|
|
63
67
|
if (typeof onSelectedFileNameChanged === "function") {
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { computed, ref, unref } from "vue";
|
|
2
2
|
import { createImageUploadRuntime } from "./createImageUploadRuntime.js";
|
|
3
|
+
import { useJskitText } from "../i18n.js";
|
|
3
4
|
|
|
5
|
+
// Message keys; a caller's messages may be keys or plain text, rendered with
|
|
6
|
+
// useJskitText().text() when shown.
|
|
4
7
|
const DEFAULT_MANAGED_IMAGE_ASSET_MESSAGES = Object.freeze({
|
|
5
|
-
endpointUnavailable: "
|
|
6
|
-
uploadSuccess: "
|
|
7
|
-
uploadInvalidResponse: "
|
|
8
|
-
uploadError: "
|
|
9
|
-
uploadRestriction: "
|
|
10
|
-
editorUnavailable: "
|
|
11
|
-
deleteSuccess: "
|
|
12
|
-
deleteError: "
|
|
13
|
-
deleteUnavailable: "
|
|
14
|
-
changeError: "
|
|
8
|
+
endpointUnavailable: "jskit.uploads.imageAsset.endpointUnavailable",
|
|
9
|
+
uploadSuccess: "jskit.uploads.imageAsset.uploadSuccess",
|
|
10
|
+
uploadInvalidResponse: "jskit.uploads.imageAsset.uploadInvalidResponse",
|
|
11
|
+
uploadError: "jskit.uploads.imageAsset.uploadError",
|
|
12
|
+
uploadRestriction: "jskit.uploads.imageAsset.uploadRestriction",
|
|
13
|
+
editorUnavailable: "jskit.uploads.imageAsset.editorUnavailable",
|
|
14
|
+
deleteSuccess: "jskit.uploads.imageAsset.deleteSuccess",
|
|
15
|
+
deleteError: "jskit.uploads.imageAsset.deleteError",
|
|
16
|
+
deleteUnavailable: "jskit.uploads.imageAsset.deleteUnavailable",
|
|
17
|
+
changeError: "jskit.uploads.imageAsset.changeError"
|
|
15
18
|
});
|
|
16
19
|
|
|
17
20
|
function normalizeText(value) {
|
|
@@ -57,14 +60,18 @@ function resolveMessage(value, fallback) {
|
|
|
57
60
|
return normalizedValue || fallback;
|
|
58
61
|
}
|
|
59
62
|
|
|
63
|
+
// The server's error in the user's language when JSKIT knows its code.
|
|
64
|
+
function resolveBodyErrorMessage(body) {
|
|
65
|
+
const source = body && typeof body === "object" ? body : {};
|
|
66
|
+
return source.error ? useJskitText().serverMessage({ ...source, message: source.error }) : "";
|
|
67
|
+
}
|
|
68
|
+
|
|
60
69
|
function resolveUploadErrorFallback({ error, response, fallbackMessage }) {
|
|
61
|
-
|
|
62
|
-
return resolveMessage(body?.error || error?.message, fallbackMessage);
|
|
70
|
+
return resolveMessage(resolveBodyErrorMessage(response?.body) || error?.message, fallbackMessage);
|
|
63
71
|
}
|
|
64
72
|
|
|
65
73
|
function resolveDeleteErrorFallback({ error, body, fallbackMessage }) {
|
|
66
|
-
|
|
67
|
-
return resolveMessage(normalizedBody?.error || error?.message, fallbackMessage);
|
|
74
|
+
return resolveMessage(resolveBodyErrorMessage(body) || error?.message, fallbackMessage);
|
|
68
75
|
}
|
|
69
76
|
|
|
70
77
|
function normalizeDeleteResult(result) {
|
|
@@ -102,12 +109,14 @@ function createManagedImageAssetRuntime({
|
|
|
102
109
|
source = "uploads-image-web.managed-image-asset",
|
|
103
110
|
dependencies = {}
|
|
104
111
|
} = {}) {
|
|
112
|
+
const { t, text } = useJskitText();
|
|
105
113
|
const createImageUploadRuntimeFactory = dependencies.createImageUploadRuntimeFactory || createImageUploadRuntime;
|
|
106
114
|
const fetchImpl = dependencies.fetchImpl || globalThis.fetch?.bind(globalThis);
|
|
107
115
|
const normalizedMessages = {
|
|
108
116
|
...DEFAULT_MANAGED_IMAGE_ASSET_MESSAGES,
|
|
109
117
|
...normalizeObject(messages)
|
|
110
118
|
};
|
|
119
|
+
const messageText = (name) => text(normalizedMessages[name]);
|
|
111
120
|
const selectedFileNameRef = normalizeWritableRef(selectedFileName);
|
|
112
121
|
const isDeleting = ref(false);
|
|
113
122
|
const normalizedFieldName = normalizeText(fieldName || "file") || "file";
|
|
@@ -192,7 +201,7 @@ function createManagedImageAssetRuntime({
|
|
|
192
201
|
await Promise.resolve(handler(payload));
|
|
193
202
|
} catch (error) {
|
|
194
203
|
report({
|
|
195
|
-
message: resolveMessage(error?.message,
|
|
204
|
+
message: resolveMessage(error?.message, messageText("changeError")),
|
|
196
205
|
severity: "error",
|
|
197
206
|
channel: "banner",
|
|
198
207
|
dedupeKey: `${source}:change-error`
|
|
@@ -204,7 +213,7 @@ function createManagedImageAssetRuntime({
|
|
|
204
213
|
const fallbackMessage = resolveUploadErrorFallback({
|
|
205
214
|
error,
|
|
206
215
|
response,
|
|
207
|
-
fallbackMessage:
|
|
216
|
+
fallbackMessage: messageText("uploadError")
|
|
208
217
|
});
|
|
209
218
|
if (typeof resolveUploadErrorMessage !== "function") {
|
|
210
219
|
return fallbackMessage;
|
|
@@ -225,7 +234,7 @@ function createManagedImageAssetRuntime({
|
|
|
225
234
|
const fallbackMessage = resolveDeleteErrorFallback({
|
|
226
235
|
error,
|
|
227
236
|
body,
|
|
228
|
-
fallbackMessage:
|
|
237
|
+
fallbackMessage: messageText("deleteError")
|
|
229
238
|
});
|
|
230
239
|
if (typeof resolveDeleteErrorMessage !== "function") {
|
|
231
240
|
return fallbackMessage;
|
|
@@ -276,7 +285,7 @@ function createManagedImageAssetRuntime({
|
|
|
276
285
|
closeDashboard(payload?.uppy);
|
|
277
286
|
updateSelectedFileName("");
|
|
278
287
|
report({
|
|
279
|
-
message:
|
|
288
|
+
message: messageText("uploadSuccess"),
|
|
280
289
|
severity: "success",
|
|
281
290
|
channel: "snackbar",
|
|
282
291
|
dedupeKey: `${source}:upload-success`
|
|
@@ -285,7 +294,7 @@ function createManagedImageAssetRuntime({
|
|
|
285
294
|
},
|
|
286
295
|
onInvalidResponse: () => {
|
|
287
296
|
report({
|
|
288
|
-
message:
|
|
297
|
+
message: messageText("uploadInvalidResponse"),
|
|
289
298
|
severity: "error",
|
|
290
299
|
channel: "banner",
|
|
291
300
|
dedupeKey: `${source}:upload-invalid-response`
|
|
@@ -301,7 +310,7 @@ function createManagedImageAssetRuntime({
|
|
|
301
310
|
},
|
|
302
311
|
onRestrictionFailed: ({ error }) => {
|
|
303
312
|
report({
|
|
304
|
-
message: resolveMessage(error?.message,
|
|
313
|
+
message: resolveMessage(error?.message, messageText("uploadRestriction")),
|
|
305
314
|
severity: "error",
|
|
306
315
|
channel: "banner",
|
|
307
316
|
dedupeKey: `${source}:upload-restriction`
|
|
@@ -309,7 +318,7 @@ function createManagedImageAssetRuntime({
|
|
|
309
318
|
},
|
|
310
319
|
onUnavailable: () => {
|
|
311
320
|
report({
|
|
312
|
-
message:
|
|
321
|
+
message: messageText("editorUnavailable"),
|
|
313
322
|
severity: "error",
|
|
314
323
|
channel: "banner",
|
|
315
324
|
dedupeKey: `${source}:editor-unavailable`
|
|
@@ -330,7 +339,7 @@ function createManagedImageAssetRuntime({
|
|
|
330
339
|
const runtime = ensureUploadRuntime();
|
|
331
340
|
if (!runtime) {
|
|
332
341
|
report({
|
|
333
|
-
message:
|
|
342
|
+
message: messageText("endpointUnavailable"),
|
|
334
343
|
severity: "error",
|
|
335
344
|
channel: "banner",
|
|
336
345
|
dedupeKey: `${source}:endpoint-unavailable`
|
|
@@ -349,7 +358,7 @@ function createManagedImageAssetRuntime({
|
|
|
349
358
|
const endpoint = normalizedDeleteEndpoint.value;
|
|
350
359
|
if (!endpoint) {
|
|
351
360
|
report({
|
|
352
|
-
message:
|
|
361
|
+
message: messageText("deleteUnavailable"),
|
|
353
362
|
severity: "error",
|
|
354
363
|
channel: "banner",
|
|
355
364
|
dedupeKey: `${source}:delete-unavailable`
|
|
@@ -359,7 +368,7 @@ function createManagedImageAssetRuntime({
|
|
|
359
368
|
|
|
360
369
|
if (typeof deleteRequest !== "function" && typeof fetchImpl !== "function") {
|
|
361
370
|
report({
|
|
362
|
-
message:
|
|
371
|
+
message: messageText("deleteUnavailable"),
|
|
363
372
|
severity: "error",
|
|
364
373
|
channel: "banner",
|
|
365
374
|
dedupeKey: `${source}:delete-unavailable`
|
|
@@ -389,7 +398,7 @@ function createManagedImageAssetRuntime({
|
|
|
389
398
|
response = deleteResult.response;
|
|
390
399
|
body = deleteResult.body;
|
|
391
400
|
if (response && response.ok === false) {
|
|
392
|
-
const requestError = new Error("
|
|
401
|
+
const requestError = new Error(t("jskit.uploads.imageAsset.deleteRequestFailed"));
|
|
393
402
|
requestError.response = response;
|
|
394
403
|
requestError.body = body;
|
|
395
404
|
throw requestError;
|
|
@@ -403,13 +412,13 @@ function createManagedImageAssetRuntime({
|
|
|
403
412
|
body = await readJsonResponse(response);
|
|
404
413
|
|
|
405
414
|
if (!response.ok) {
|
|
406
|
-
throw new Error("
|
|
415
|
+
throw new Error(t("jskit.uploads.imageAsset.deleteRequestFailed"));
|
|
407
416
|
}
|
|
408
417
|
}
|
|
409
418
|
|
|
410
419
|
updateSelectedFileName("");
|
|
411
420
|
report({
|
|
412
|
-
message:
|
|
421
|
+
message: messageText("deleteSuccess"),
|
|
413
422
|
severity: "success",
|
|
414
423
|
channel: "snackbar",
|
|
415
424
|
dedupeKey: `${source}:delete-success`
|
|
@@ -17,7 +17,9 @@ test("uploads-image-web exports are explicit and aligned with usage", () => {
|
|
|
17
17
|
"./client",
|
|
18
18
|
"./client/composables/createImageUploadRuntime",
|
|
19
19
|
"./client/composables/createManagedImageAssetRuntime",
|
|
20
|
-
"./shared"
|
|
20
|
+
"./shared",
|
|
21
|
+
// The generated client bootstrap registers the package's English catalog.
|
|
22
|
+
"./locales/en.json"
|
|
21
23
|
]
|
|
22
24
|
});
|
|
23
25
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import test from "node:test";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { evaluateI18nCatalogContract } from "../../../tooling/test-support/i18nCatalogContract.mjs";
|
|
6
|
+
|
|
7
|
+
const TEST_DIRECTORY = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const REPO_ROOT = path.resolve(TEST_DIRECTORY, "..", "..", "..");
|
|
9
|
+
|
|
10
|
+
test("uploads-image-web English catalog matches its source", () => {
|
|
11
|
+
const { problems } = evaluateI18nCatalogContract({
|
|
12
|
+
repoRoot: REPO_ROOT,
|
|
13
|
+
packageDir: path.join(REPO_ROOT, "packages", "uploads-image-web")
|
|
14
|
+
});
|
|
15
|
+
assert.deepEqual(problems, []);
|
|
16
|
+
});
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { createI18n } from "vue-i18n";
|
|
4
|
+
import { setJskitI18n } from "@jskit-ai/kernel/client";
|
|
5
|
+
import { createImageUploadRuntime } from "../src/client/composables/createImageUploadRuntime.js";
|
|
6
|
+
import { createManagedImageAssetRuntime } from "../src/client/composables/createManagedImageAssetRuntime.js";
|
|
7
|
+
|
|
8
|
+
function captureDashboardNote(options = {}) {
|
|
9
|
+
const previousWindow = globalThis.window;
|
|
10
|
+
globalThis.window = {};
|
|
11
|
+
let note = "";
|
|
12
|
+
try {
|
|
13
|
+
createImageUploadRuntime({
|
|
14
|
+
...options,
|
|
15
|
+
endpoint: "/api/upload",
|
|
16
|
+
dependencies: {
|
|
17
|
+
UppyClass: class {
|
|
18
|
+
use(plugin, pluginOptions) {
|
|
19
|
+
if (plugin.name === "Dashboard") note = pluginOptions.note;
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
on() {
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
DashboardPlugin: { name: "Dashboard" },
|
|
27
|
+
ImageEditorPlugin: { name: "ImageEditor" },
|
|
28
|
+
CompressorPlugin: { name: "Compressor" },
|
|
29
|
+
XHRUploadPlugin: { name: "XHRUpload" }
|
|
30
|
+
}
|
|
31
|
+
}).setup();
|
|
32
|
+
} finally {
|
|
33
|
+
if (previousWindow === undefined) {
|
|
34
|
+
delete globalThis.window;
|
|
35
|
+
} else {
|
|
36
|
+
globalThis.window = previousWindow;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return note;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function createManagedRuntime(feedbackEvents, options = {}) {
|
|
43
|
+
return createManagedImageAssetRuntime({
|
|
44
|
+
reportFeedback: (payload) => feedbackEvents.push(payload.message),
|
|
45
|
+
dependencies: {
|
|
46
|
+
createImageUploadRuntimeFactory: (runtimeOptions) => ({
|
|
47
|
+
options: runtimeOptions,
|
|
48
|
+
destroy() {},
|
|
49
|
+
openEditor() {},
|
|
50
|
+
setup() {}
|
|
51
|
+
})
|
|
52
|
+
},
|
|
53
|
+
...options
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
test("the upload dashboard note keeps its English", () => {
|
|
58
|
+
assert.equal(
|
|
59
|
+
captureDashboardNote({ allowedMimeTypes: ["image/png", "image/jpeg"], maxUploadBytes: 2 * 1024 * 1024 }),
|
|
60
|
+
"Accepted: image/png, image/jpeg, max 2MB"
|
|
61
|
+
);
|
|
62
|
+
assert.equal(captureDashboardNote({ note: "Square photos only." }), "Square photos only.");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("managed image feedback keeps its English and accepts message keys", async () => {
|
|
66
|
+
const feedbackEvents = [];
|
|
67
|
+
createManagedRuntime(feedbackEvents).openEditor();
|
|
68
|
+
createManagedRuntime(feedbackEvents, {
|
|
69
|
+
uploadEndpoint: "/api/photo",
|
|
70
|
+
deleteRequest: async () => ({ body: null, response: { ok: false } })
|
|
71
|
+
}).deleteAsset();
|
|
72
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
73
|
+
createManagedRuntime(feedbackEvents, { messages: { endpointUnavailable: "jskit.uploads.imageAsset.deleteUnavailable" } }).openEditor();
|
|
74
|
+
|
|
75
|
+
assert.deepEqual(feedbackEvents, [
|
|
76
|
+
"Image endpoint is unavailable.",
|
|
77
|
+
"Image delete request failed.",
|
|
78
|
+
"Image removal is unavailable."
|
|
79
|
+
]);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("managed image upload errors show a coded server error in the app's language", () => {
|
|
83
|
+
setJskitI18n(createI18n({
|
|
84
|
+
legacy: false,
|
|
85
|
+
locale: "it",
|
|
86
|
+
messages: {
|
|
87
|
+
it: {
|
|
88
|
+
jskit: {
|
|
89
|
+
errors: { validation_failed: "Convalida non riuscita." },
|
|
90
|
+
uploads: { imageAsset: { uploadSuccess: "Immagine caricata." } }
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}));
|
|
95
|
+
try {
|
|
96
|
+
const feedbackEvents = [];
|
|
97
|
+
const created = [];
|
|
98
|
+
const runtime = createManagedRuntime(feedbackEvents, {
|
|
99
|
+
uploadEndpoint: "/api/photo",
|
|
100
|
+
dependencies: {
|
|
101
|
+
createImageUploadRuntimeFactory: (runtimeOptions) => {
|
|
102
|
+
const fake = { options: runtimeOptions, destroy() {}, openEditor() {}, setup() {} };
|
|
103
|
+
created.push(fake);
|
|
104
|
+
return fake;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
runtime.openEditor();
|
|
109
|
+
created[0].options.onUploadError({
|
|
110
|
+
error: { message: "Request failed." },
|
|
111
|
+
response: { body: { error: "Validation failed.", code: "validation_failed", params: {} } }
|
|
112
|
+
});
|
|
113
|
+
created[0].options.onUploadError({
|
|
114
|
+
error: { message: "Request failed." },
|
|
115
|
+
response: { body: { error: "Photo is blurry.", code: "validation_failed", params: {} } }
|
|
116
|
+
});
|
|
117
|
+
created[0].options.onUploadSuccess({ data: {} });
|
|
118
|
+
|
|
119
|
+
assert.deepEqual(feedbackEvents, ["Convalida non riuscita.", "Photo is blurry.", "Immagine caricata."]);
|
|
120
|
+
} finally {
|
|
121
|
+
setJskitI18n(null);
|
|
122
|
+
}
|
|
123
|
+
});
|