;; 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.jobs-progress-test "How a job milestone is written: the stage and its counter." (:require [app.main.ui.jobs.progress :as jp] [app.util.i18n :as i18n] [cljs.test :as t :include-macros true] [frontend-tests.helpers.mock :as mock])) (def ^:private stub-tr (mock/stub (fn [k] (str "TR:" k)))) (t/deftest a-counter-milestone-writes-its-stage-and-counter (with-redefs [i18n/tr stub-tr] (t/is (= "TR:jobs.progress.stage.pages 3/8" (jp/milestone-text {:stage :pages :counters {:pages {:current 3 :total 8}}}))) (t/testing "a counter with no total writes the bare current" (t/is (= "TR:jobs.progress.stage.pages 3" (jp/milestone-text {:stage :pages :counters {:pages {:current 3}}})))))) (t/deftest the-upload-milestone-writes-the-percentage-of-the-file (with-redefs [i18n/tr stub-tr] (t/testing "the chunks sent become a whole percentage" (t/is (= "TR:jobs.progress.stage.upload (33%)" (jp/milestone-text {:stage :upload :counters {:upload {:current 1 :total 3}}}))) (t/is (= "TR:jobs.progress.stage.upload (100%)" (jp/milestone-text {:stage :upload :counters {:upload {:current 9 :total 9}}})))) (t/testing "an upload with no total keeps the bare label" (t/is (= "TR:jobs.progress.stage.upload" (jp/milestone-text {:stage :upload :counters {:upload {:current 1}}})))))) (t/deftest the-milestone-in-course-is-the-one-of-the-files-that-report-it (with-redefs [i18n/tr stub-tr] (t/testing "the files of a container share their milestone, so one is enough" (t/is (= "TR:jobs.progress.stage.pages 4/5" (jp/current-milestone-text [{:status :import-queued} {:progress {:stage :pages :counters {:pages {:current 4 :total 5}}}} {:progress {:stage :pages :counters {:pages {:current 4 :total 5}}}}])))) (t/testing "a file with nothing to report says nothing" (t/is (nil? (jp/current-milestone-text [{:status :import-ready} {:status :import-queued}]))) (t/is (nil? (jp/current-milestone-text [])))))) (t/deftest a-milestone-without-a-stage-writes-nothing (with-redefs [i18n/tr stub-tr] (t/is (nil? (jp/milestone-text nil))) (t/is (nil? (jp/milestone-text {})))))