diff --git a/frontend/src/app/main/ui/dashboard/import.cljs b/frontend/src/app/main/ui/dashboard/import.cljs index 048c0d7e73..5db2d5e6fe 100644 --- a/frontend/src/app/main/ui/dashboard/import.cljs +++ b/frontend/src/app/main/ui/dashboard/import.cljs @@ -669,6 +669,24 @@ :style (when (some? pct) #js {:width (str pct "%")})}]])]))) +(defn import-error-detail + "The text that explains why an entry could not be imported." + [err] + (cond + (= err (tr "dashboard.import.components-v1-error")) + err + + (and (string? err) + (str/includes? (str/lower err) "check error")) + (tr "dashboard.import.import-error.check-error") + + (and (string? err) + (str/includes? (str/lower err) "corrupt")) + (tr "dashboard.import.import-error.corrupt-file") + + :else + (tr "dashboard.import.import-error.unknown-error"))) + (mf/defc import-files-stage* {::mf/private true} [{:keys [entries template status step errors? import-success-total auto-linked-count @@ -715,17 +733,7 @@ [:div (:name entry)] (when-let [err (:error entry)] [:div {:class (stl/css :import-error-detail)} - (cond - (and (string? err) - (str/includes? (str/lower err) "check error")) - (tr "dashboard.import.import-error.check-error") - - (and (string? err) - (str/includes? (str/lower err) "corrupt")) - (tr "dashboard.import.import-error.corrupt-file") - - :else - (tr "dashboard.import.import-error.unknown-error"))])]))] + (import-error-detail err)])]))] [:div (tr "dashboard.import.import-error.message2")]] (imp/awaiting-analysis? status errors?) diff --git a/frontend/test/frontend_tests/runner.cljs b/frontend/test/frontend_tests/runner.cljs index a4c9e6fed0..f7fc1a5877 100644 --- a/frontend/test/frontend_tests/runner.cljs +++ b/frontend/test/frontend_tests/runner.cljs @@ -188,6 +188,7 @@ [frontend-tests.ui.comments-clustering-test] [frontend-tests.ui.comments-position-modifier-test] [frontend-tests.ui.context-menu-prototype-test] + [frontend-tests.ui.dashboard-import-errors-test] [frontend-tests.ui.dashboard-import-linking-test] [frontend-tests.ui.drawarea-test] [frontend-tests.ui.ds-controls-numeric-input-test] @@ -445,6 +446,7 @@ 'frontend-tests.ui.comments-clustering-test 'frontend-tests.ui.comments-position-modifier-test 'frontend-tests.ui.context-menu-prototype-test + 'frontend-tests.ui.dashboard-import-errors-test 'frontend-tests.ui.dashboard-import-linking-test 'frontend-tests.ui.drawarea-test 'frontend-tests.ui.ds-controls-numeric-input-test diff --git a/frontend/test/frontend_tests/ui/dashboard_import_errors_test.cljs b/frontend/test/frontend_tests/ui/dashboard_import_errors_test.cljs new file mode 100644 index 0000000000..be782843c8 --- /dev/null +++ b/frontend/test/frontend_tests/ui/dashboard_import_errors_test.cljs @@ -0,0 +1,28 @@ +;; This Source Code Form is subject to the terms of the Mozilla Public +;; License, v. 2.0. If a copy of the MPL was not distributed with this +;; file, You can obtain one at http://mozilla.org/MPL/2.0/. +;; +;; Copyright (c) KALEIDOS SUBSIDIARY SL + +(ns frontend-tests.ui.dashboard-import-errors-test + "The text the import wizard shows under an entry that failed." + (:require + [app.main.ui.dashboard.import :as import] + [app.util.i18n :refer [tr]] + [cljs.test :as t :include-macros true])) + +(t/deftest a-components-v1-file-shows-why-it-cannot-be-imported + (let [err (tr "dashboard.import.components-v1-error")] + (t/is (= err (import/import-error-detail err))))) + +(t/deftest known-failures-show-their-own-explanation + (t/is (= (tr "dashboard.import.import-error.check-error") + (import/import-error-detail "Check error: invalid shape"))) + (t/is (= (tr "dashboard.import.import-error.corrupt-file") + (import/import-error-detail "The file is corrupt")))) + +(t/deftest other-failures-show-the-generic-explanation + (t/is (= (tr "dashboard.import.import-error.unknown-error") + (import/import-error-detail "some server hint"))) + (t/is (= (tr "dashboard.import.import-error.unknown-error") + (import/import-error-detail nil))))