],
"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"
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 {
+++ /dev/null
-import {
- parseTime,
-} from './Result';
-
-describe('parseTime', () => {
- test('null on empty', () => {
- expect(parseTime()).toBeNull();
- });
-});
--- /dev/null
+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);
+ });
+});