[gnome-maps/wip/mlundblad/redesign-opening-hours: 6/6] Add unit tests for the Translations module




commit 26c948d457f5c3ee0c3acecaa78ffab22d174884
Author: Marcus Lundblad <ml update uu se>
Date:   Fri Dec 18 23:04:40 2020 +0100

    Add unit tests for the Translations module

 tests/meson.build         |  4 +--
 tests/translationsTest.js | 66 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 2 deletions(-)
---
diff --git a/tests/meson.build b/tests/meson.build
index 8731e906..d5942bde 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -1,5 +1,5 @@
-tests = ['addressTest', 'colorTest', 'osmNamesTest', 'timeTest', 'utilsTest',
-         'urlsTest']
+tests = ['addressTest', 'colorTest', 'osmNamesTest', 'timeTest',
+         'translationsTest', 'utilsTest', 'urlsTest']
 
 foreach test : tests
   script_conf = configuration_data()
diff --git a/tests/translationsTest.js b/tests/translationsTest.js
new file mode 100644
index 00000000..068dfd2b
--- /dev/null
+++ b/tests/translationsTest.js
@@ -0,0 +1,66 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2020 Marcus Lundblad
+ *
+ * GNOME Maps is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * GNOME Maps is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with GNOME Maps; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Marcus Lundblad <ml update uu se>
+ */
+
+const JsUnit = imports.jsUnit;
+
+const Translations = imports.translations;
+
+// sample with 3 components, one day-range, two single days, single time ranges
+const SAMPLE1 = 'Mo-Fr 09:00-18:00; Sa 10:00-15:00; Su 12:00-15:00';
+// sample with 2 components, one day-range, one two day set, one with 2 time intervals
+const SAMPLE2 = 'Mo-Fr 09:00-12:00,13:00-18:00; Sa,Su 10:00-14:00';
+// sample with sunrise to sunset
+const SAMPLE3 = 'sunrise-sunset';
+
+pkg.initGettext();
+pkg.initFormat();
+
+function main() {
+  translateOpeningHoursTest();
+}
+
+function translateOpeningHoursTest() {
+    let translated = Translations.translateOpeningHours(SAMPLE1);
+    JsUnit.assertEquals(3, translated.length);
+    JsUnit.assertEquals(2, translated[0].length);
+    JsUnit.assertEquals('Mon-Fri', translated[0][0]);
+    JsUnit.assertEquals('09:00-18:00', translated[0][1]);
+    JsUnit.assertEquals(2, translated[1].length);
+    JsUnit.assertEquals('Sat', translated[1][0]);
+    JsUnit.assertEquals('10:00-15:00', translated[1][1]);
+    JsUnit.assertEquals(2, translated[2].length);
+    JsUnit.assertEquals('Sun', translated[2][0]);
+    JsUnit.assertEquals('12:00-15:00', translated[2][1]);
+
+    translated = Translations.translateOpeningHours(SAMPLE2);
+    JsUnit.assertEquals(2, translated.length);
+    JsUnit.assertEquals(2, translated[0].length);
+    JsUnit.assertEquals('Mon-Fri', translated[0][0]);
+    JsUnit.assertEquals('09:00-12:00, 13:00-18:00', translated[0][1]);
+    JsUnit.assertEquals(2, translated[1].length);
+    JsUnit.assertEquals('Sat,Sun', translated[1][0]);
+    JsUnit.assertEquals('10:00-14:00', translated[1][1]);
+
+    translated = Translations.translateOpeningHours(SAMPLE3);
+    JsUnit.assertEquals(1, translated.length);
+    JsUnit.assertEquals(1, translated[0].length);
+    JsUnit.assertEquals('From sunrise to sunset', translated[0][0]);
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]