blob: 0c1afa5b96b47df8128ff17fd5c7dfc7df3ccd30 [file] [log] [blame]
Akron0c4cd222019-07-19 16:33:34 +02001define(['util'], function () {
2 describe('KorAP.util', function () {
3
4 it('should quote', function () {
5 expect('Baum'.quote()).toEqual('"Baum"');
6 expect('B"a"um'.quote()).toEqual('"B\\"a\\"um"');
7 });
8
9 it('should escape regex', function () {
10 expect('aaa/bbb\/ccc'.escapeRegex()).toEqual('aaa\\/bbb\\/ccc');
11 });
12
13 it('should slugify', function () {
14 expect('/korap/test'.slugify()).toEqual('koraptest');
15 expect('korap test'.slugify()).toEqual('korap-test');
16 expect('Korap Test'.slugify()).toEqual('korap-test');
17 });
Akron1cfde272021-06-14 18:32:39 +020018 });
19
20 describe('KorAP.util.initTogllePwdVisibility', function () {
21 it('should toggle', function () {
22 const div = document.createElement('div');
23 let input = div.addE('input');
24 input.setAttribute('type', 'password');
25 input.setAttribute('class', 'show-pwd');
26
27 expect(div.children.length).toEqual(1);
28 initTogglePwdVisibility(div);
29 expect(div.children.length).toEqual(2);
30 expect(div.lastChild.tagName).toEqual("A");
31 expect(div.lastChild.classList.contains("hide")).toBeFalsy();
32 expect(input.getAttribute("type")).toEqual("password");
33
34 div.lastChild.click();
35
36 expect(input.getAttribute("type")).toEqual("text");
37 expect(div.lastChild.classList.contains("hide")).toBeTruthy();
38 });
39 });
Akrona9c55802021-06-15 11:41:29 +020040
41 describe('KorAP.util.initCopyToClipboard', function () {
42 it('should be initializable', function () {
43 const div = document.createElement('div');
44 let input = div.addE('input');
45 input.value = "abcde";
46 input.setAttribute('type', 'text');
47 input.setAttribute('class', 'copy-to-clipboard');
48 expect(div.children.length).toEqual(1);
49 initCopyToClipboard(div);
50 expect(div.children.length).toEqual(2);
51 expect(div.lastChild.tagName).toEqual("A");
52 });
53
54 // document.execCommand() can't be tested without user
55 // intervention.
56 });
Akron0c4cd222019-07-19 16:33:34 +020057});