mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-25 11:04:00 +00:00
Add util function getTimeStr and being testing
This commit is contained in:
parent
b11b6b916b
commit
f6df92fb29
4 changed files with 58 additions and 3 deletions
5
js/__tests__/.eslintrc
Normal file
5
js/__tests__/.eslintrc
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"env": {
|
||||
"jest": true
|
||||
}
|
||||
}
|
||||
34
js/__tests__/utils-test.js
Normal file
34
js/__tests__/utils-test.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
jest.unmock('../utils');
|
||||
|
||||
import {getTimeObj, getTimeStr} from '../utils';
|
||||
|
||||
describe('getTimeObj', () => {
|
||||
it('expresses seconds as an object', () => {
|
||||
const actual = getTimeObj(1234);
|
||||
const expected = {
|
||||
minutesFirstDigit: 2,
|
||||
minutesSecondDigit: 0,
|
||||
secondsFirstDigit: 3,
|
||||
secondsSecondDigit: 4
|
||||
};
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getTimeStr', () => {
|
||||
it('expresses seconds as string', () => {
|
||||
const actual = getTimeStr(1234);
|
||||
const expected = '20:34';
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
it('pads with zeros', () => {
|
||||
const actual = getTimeStr(5);
|
||||
const expected = '00:05';
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
it('truncates extra minutes', () => {
|
||||
const actual = getTimeStr(540000);
|
||||
const expected = '9000:00';
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
});
|
||||
16
js/utils.js
16
js/utils.js
|
|
@ -10,7 +10,19 @@ const getTimeObj = (time) => {
|
|||
};
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getTimeObj
|
||||
const getTimeStr = (time) => {
|
||||
const timeObj = getTimeObj(time);
|
||||
return [
|
||||
timeObj.minutesFirstDigit,
|
||||
timeObj.minutesSecondDigit,
|
||||
':',
|
||||
timeObj.secondsFirstDigit,
|
||||
timeObj.secondsSecondDigit
|
||||
].join('');
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getTimeObj,
|
||||
getTimeStr
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@
|
|||
"lint": "eslint js/*.js js/*.jsx",
|
||||
"build": "webpack --optimize-minimize",
|
||||
"serve": "webpack-dev-server",
|
||||
"weight": "npm run build && gzip-size built/winamp.js | pretty-bytes"
|
||||
"weight": "npm run build && gzip-size built/winamp.js | pretty-bytes",
|
||||
"test": "jest"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
@ -28,7 +29,9 @@
|
|||
"devDependencies": {
|
||||
"babel-cli": "^6.10.1",
|
||||
"babel-core": "^6.10.4",
|
||||
"babel-jest": "^13.2.2",
|
||||
"babel-loader": "^6.2.4",
|
||||
"babel-polyfill": "^6.9.1",
|
||||
"babel-preset-es2015": "^6.9.0",
|
||||
"babel-preset-react": "^6.11.1",
|
||||
"css-loader": "^0.23.1",
|
||||
|
|
@ -36,6 +39,7 @@
|
|||
"eslint-plugin-react": "^5.2.2",
|
||||
"file-loader": "^0.9.0",
|
||||
"gzip-size-cli": "^1.0.0",
|
||||
"jest-cli": "^13.2.3",
|
||||
"pretty-bytes-cli": "^1.0.0",
|
||||
"style-loader": "^0.13.1",
|
||||
"url-loader": "^0.5.7",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue