af7be83b235d9237362187a6366e542a2d0460e0
[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) { return string };
84
85     // handle html entities, "Zurück" => "Zurück"
86     var M = function (string) {
87             return string;
88         };
89
90     function check_translation(list, text) {
91         expect(list.length).toBe(text.length);
92
93         for (var i = 0; i < text.length; i++) {
94             expect($(list[i]).text().match(M(text[i]))).not.toBeNull();
95         }
96     }
97
98
99     var locale_lang = {
100         "de": {
101       "Authors": "Autoren",
102       "Subjects": "Schlagw&ouml;rter",
103       "Sources": "Daten und Quellen",
104       "source": "datenquelle",
105       "Facets": "Termlisten",
106       "Next": "Weiter",
107       "Prev": "Zur&uuml;ck",
108       "Search": "Suche",
109       "Sort by": "Sortieren nach",
110       "and show": "und zeige",
111       "per page": "pro Seite",
112       "Displaying": "Zeige",
113       "to": "von",
114       "of": "aus",
115       "found": "gefunden",
116       "Title": "Titel",
117       "Author": "Autor",
118       "author": "autor",
119       "Date": "Datum",
120       "Subject": "Schlagwort",
121       "subject": "schlagwort",
122       "Location": "Ort",
123       "Records": "Datens&auml;tze",
124       "Targets": "Datenbanken",
125       "relevance": "Relevanz",
126       "title": "Titel",
127       "newest": "Neueste",
128       "oldest": "&Auml;lteste",
129
130       "dummy": "dummy"
131         }};
132
133     function check_translation_list(keywords, list) {
134         var errors = [];
135         for (var i = 0; i < keywords.length; i++) {
136              if ($(list[i]).match("^" + M(keywords[i]) + ": ") ) {
137                 debug("found: " + list[i] + " :: " + keywords[i]);
138              } else {
139                 debug("NOT found: " + list[i] + " :: " + keywords[i]);
140                 errors.push(keywords[i])
141              }
142         }
143         expect(errors.length).not.toBeGreaterThan(1);
144     }
145
146
147     it("record details", function () {
148         var keywords = ["Title", "Date", "Author"]; // , "Subject", "Locations"];
149         var list = ["Title: foo", "Date: bar", "Author: wolfram", "Location: bla"];
150         var list_de = ["Titel: foo", "Datum: bar", "Autor: wolfram", "Location: bla"];
151         var keywords_de = [];
152
153         check_translation_list(keywords, list);
154
155         for(var i = 0; i < keywords.length; i++ ) {
156                 keywords_de.push(locale_lang["de"][keywords[i]]);
157         }
158         debug(keywords_de);
159         check_translation_list(keywords_de, list_de);
160     });
161
162 });
163
164 /* done */
165 describe("All tests are done", function () {
166     it(">>> hooray <<<", function () {
167         mkws.jasmine_done = true;
168         debug(">>> hooray <<<");
169     });
170 });