koel/resources/assets/js/tests/services/utilsTest.js

35 lines
1,018 B
JavaScript
Raw Normal View History

2015-12-13 04:42:28 +00:00
require('chai').should();
2016-04-10 09:51:06 +00:00
import { secondsToHis, parseValidationError } from '../../services/utils';
2015-12-13 04:42:28 +00:00
describe('services/utils', () => {
describe('#secondsToHis', () => {
it('correctly formats a duration to H:i:s', () => {
2016-04-10 09:51:06 +00:00
secondsToHis(7547).should.equal('02:05:47');
2015-12-13 04:42:28 +00:00
});
it('ommits hours from short duration when formats to H:i:s', () => {
2016-04-10 09:51:06 +00:00
secondsToHis(314).should.equal('05:14');
2015-12-13 04:42:28 +00:00
});
});
describe('#parseValidationError', () => {
it('correctly parses single-level validation error', () => {
2016-03-28 13:38:14 +00:00
const error = {
err_1: ['Foo'],
};
2016-04-10 09:51:06 +00:00
parseValidationError(error).should.eql(['Foo']);
});
it('correctly parses multi-level validation error', () => {
2016-03-28 13:38:14 +00:00
const error = {
err_1: ['Foo', 'Bar'],
err_2: ['Baz', 'Qux'],
};
2016-04-10 09:51:06 +00:00
parseValidationError(error).should.eql(['Foo', 'Bar', 'Baz', 'Qux']);
});
});
2015-12-13 04:42:28 +00:00
});