update German translation
[mkws-moved-to-github.git] / test / spec-dev / translate.spec.js
1 /* Copyright (c) 2013-2015 Index Data ApS. http://indexdata.com
2  *
3  * perform papzpar2 / pz2.js search & retrieve request in the browser
4  *
5  */
6
7 var mkws = {};
8 var document = {};
9
10 // get references from mkws.js, lazy evaluation
11 var debug = function (text) {
12         // use a debug function with time stamps
13         console.log("Jasmine: " + text);
14
15         //mkws.log("Jasmine: " + text)
16     }
17
18     // Define empty jasmine_config for simple applications that don't define it.
19 if (jasmine_config == null || typeof jasmine_config != 'object') {
20     var jasmine_config = {};
21 }
22
23 var jasmine_status = {
24     source_click: 0
25 };
26
27 /* check config for jasmine test
28  *
29  * you can override the default values in the config
30  * object: jasmine_config = {};
31  *
32  */
33 function init_jasmine_config() {
34
35     var jasmine_config_default = {
36         // tune parameter for batch testing
37         batch_tuning: true,
38
39         search_query: "freebsd",
40         max_time: 17,
41         // in seconds
42         expected_hits: 80,
43         // at least expected hit counter
44         second: 1000,
45         // miliseconds to seconds
46         show_record_url: true,
47         // check for valid URL in records
48         check_motd: true,
49
50         // check sort by and per page menu
51         check_sortby: false,
52
53         dummy: false
54     };
55
56     // use default values for undefined values
57     for (var key in jasmine_config_default) {
58         if (!jasmine_config.hasOwnProperty(key)) {
59             jasmine_config[key] = jasmine_config_default[key];
60         }
61         debug("jasmine config: " + key + " => " + jasmine_config[key]);
62     }
63
64
65     mkws.jasmine_done = false;
66 };
67
68 /******************************************************************************/
69 describe("Init jasmine config", function () {
70     it("jasmine was successfully initialized", function () {
71         init_jasmine_config();
72
73         expect(jasmine_config.search_query).toMatch(/\w/);
74         expect(jasmine_config.second).toBeGreaterThan(100);
75         expect(jasmine_config.max_time).toBeGreaterThan(1);
76         expect(jasmine_config.expected_hits).toBeGreaterThan(1);
77     });
78 });
79
80
81 // temporary disabled due records without an author, MKWS-400
82 describe("Check translations", function () {
83     var $ = function (string) {
84             return string
85         };
86
87     // handle html entities, "Zurück" => "Zurück"
88     var M = function (string) {
89             return string;
90         };
91
92     function check_translation(list, text) {
93         expect(list.length).toBe(text.length);
94
95         for (var i = 0; i < text.length; i++) {
96             expect($(list[i]).text().match(M(text[i]))).not.toBeNull();
97         }
98     }
99
100
101     var locale_lang = {
102         "de": {
103             "Authors": "Autoren",
104             "Subjects": "Schlagw&ouml;rter",
105             "Sources": "Daten und Quellen",
106             "source": "datenquelle",
107             "Facets": "Termlisten",
108             "Next": "Weiter",
109             "Prev": "Zur&uuml;ck",
110             "Search": "Suche",
111             "Sort by": "Sortieren nach",
112             "and show": "und zeige",
113             "per page": "pro Seite",
114             "Displaying": "Zeige",
115             "to": "von",
116             "of": "aus",
117             "found": "gefunden",
118             "Title": "Titel",
119             "Author": "Autor",
120             "author": "autor",
121             "Date": "Datum",
122             "Subject": "Schlagwort",
123             "subject": "schlagwort",
124             "Location": "Bestand",
125             "Locations": "Bestand",
126             "Records": "Datens&auml;tze",
127             "Targets": "Datenbanken",
128             "relevance": "Relevanz",
129             "title": "Titel",
130             "newest": "Neueste",
131             "oldest": "&Auml;lteste",
132
133             "dummy": "dummy"
134         }
135     };
136
137     function check_translation_list(keywords, list) {
138         var errors = [];
139         for (var i = 0; i < keywords.length; i++) {
140             if ($(list[i]).match("^" + M(keywords[i]) + ": ")) {
141                 debug("found: " + list[i] + " :: " + keywords[i]);
142             } else {
143                 debug("NOT found: " + list[i] + " :: " + keywords[i]);
144                 errors.push(keywords[i])
145             }
146         }
147         expect(errors.length).not.toBeGreaterThan(1);
148     }
149
150
151     it("record details", function () {
152         var keywords = ["Title", "Date", "Author"]; // , "Subject", "Locations"];
153         var list = ["Title: foo", "Date: bar", "Author: wolfram", "Location: bla"];
154         var list_de = ["Titel: foo", "Datum: bar", "Autor: wolfram", "Location: bla"];
155         var keywords_de = [];
156
157         check_translation_list(keywords, list);
158
159         for (var i = 0; i < keywords.length; i++) {
160             keywords_de.push(locale_lang["de"][keywords[i]]);
161         }
162         debug(keywords_de);
163         check_translation_list(keywords_de, list_de);
164     });
165
166 });
167
168 /* done */
169 describe("All tests are done", function () {
170     it(">>> hooray <<<", function () {
171         mkws.jasmine_done = true;
172         debug(">>> hooray <<<");
173     });
174 });