]> git.localhorst.tv Git - alttp.git/commitdiff
move js tests to separate dir
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sat, 24 Feb 2024 10:05:00 +0000 (11:05 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sat, 24 Feb 2024 10:05:00 +0000 (11:05 +0100)
package.json
resources/js/helpers/Result.js
resources/js/helpers/Result.test.js [deleted file]
tests/js/helpers/Result.test.js [new file with mode: 0644]

index 12a12552bac70baab680dc499443c44351a4dc78..78f545384302777447982bdba5985546d33c95af 100644 (file)
                 ],
                 "env": {
                     "jest": true
-                }
+                },
+                               "settings": {
+                                       "import/resolver": {
+                                               "node": {
+                                                       "paths": [
+                                                               "resources/js"
+                                                       ]
+                                               }
+                                       }
+                               }
             }
         ]
     },
     "jest": {
+               "moduleDirectories": [
+                       "node_modules",
+                       "resources/js"
+               ],
         "roots": [
-            "<rootDir>/resources/js"
+            "<rootDir>/resources/js",
+            "<rootDir>/tests/js"
         ],
         "setupFilesAfterEnv": [
             "<rootDir>/resources/js/setup-jest.js"
index b1fb3f90845e914e335113d3cd57b416b4ac1f54..329116d245515ffa0f3603d599a620388443156e 100644 (file)
@@ -71,7 +71,7 @@ export const getTime = (result, maySee) => {
 
 export const parseTime = str => {
        if (!str) return null;
-       return `${str}`.split(/[-.: ]+/).reduce((acc,time) => (60 * acc) + +time, 0);
+       return `${str}`.trim().split(/[-.: ]+/).reduce((acc,time) => (60 * acc) + +time, 0);
 };
 
 export default {
diff --git a/resources/js/helpers/Result.test.js b/resources/js/helpers/Result.test.js
deleted file mode 100644 (file)
index b6954be..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-import {
-       parseTime,
-} from './Result';
-
-describe('parseTime', () => {
-       test('null on empty', () => {
-               expect(parseTime()).toBeNull();
-       });
-});
diff --git a/tests/js/helpers/Result.test.js b/tests/js/helpers/Result.test.js
new file mode 100644 (file)
index 0000000..2d86f3f
--- /dev/null
@@ -0,0 +1,30 @@
+import {
+       parseTime,
+} from 'helpers/Result';
+
+describe('parseTime', () => {
+       test('null on empty', () => {
+               expect(parseTime()).toBeNull();
+       });
+       test('just numbers', () => {
+               expect(parseTime('1')).toEqual(1);
+               expect(parseTime('15')).toEqual(15);
+               expect(parseTime('60')).toEqual(60);
+               expect(parseTime('62')).toEqual(62);
+               expect(parseTime('500')).toEqual(500);
+       });
+       test('regular formats', () => {
+               expect(parseTime('1:00')).toEqual(60);
+               expect(parseTime('1:30')).toEqual(90);
+               expect(parseTime('0:70')).toEqual(70);
+               expect(parseTime('1:70')).toEqual(130);
+               expect(parseTime('01:20')).toEqual(80);
+               expect(parseTime('1:00:00')).toEqual(3600);
+               expect(parseTime('1:00:01')).toEqual(3601);
+       });
+       test('spaces', () => {
+               expect(parseTime(' 1:00')).toEqual(60);
+               expect(parseTime('1:00 ')).toEqual(60);
+               expect(parseTime('1 00')).toEqual(60);
+       });
+});