From: Daniel Karbach Date: Sat, 24 Feb 2024 10:05:00 +0000 (+0100) Subject: move js tests to separate dir X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=a1f2759cc827baaa49f1869b88f676d4dc39bf10;p=alttp.git move js tests to separate dir --- diff --git a/package.json b/package.json index 12a1255..78f5453 100644 --- a/package.json +++ b/package.json @@ -66,13 +66,27 @@ ], "env": { "jest": true - } + }, + "settings": { + "import/resolver": { + "node": { + "paths": [ + "resources/js" + ] + } + } + } } ] }, "jest": { + "moduleDirectories": [ + "node_modules", + "resources/js" + ], "roots": [ - "/resources/js" + "/resources/js", + "/tests/js" ], "setupFilesAfterEnv": [ "/resources/js/setup-jest.js" diff --git a/resources/js/helpers/Result.js b/resources/js/helpers/Result.js index b1fb3f9..329116d 100644 --- a/resources/js/helpers/Result.js +++ b/resources/js/helpers/Result.js @@ -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 index b6954be..0000000 --- a/resources/js/helpers/Result.test.js +++ /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 index 0000000..2d86f3f --- /dev/null +++ b/tests/js/helpers/Result.test.js @@ -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); + }); +});