util.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import test from 'ava';
  2. import {parseInfo} from 'd-fi-core';
  3. import {saveLayout, formatSecondsReadable, progressBar} from '../../src/lib/util';
  4. test.serial('SAVE LAYOUT 1', async (t) => {
  5. const {tracks, linkinfo} = await parseInfo('https://www.deezer.com/track/3135556');
  6. const layout = saveLayout({
  7. track: tracks[0],
  8. album: linkinfo,
  9. path: 'Music/{ALB_NAME}/{ART_NAME}/{SNG_TITLE}',
  10. minimumIntegerDigits: 2,
  11. trackNumber: true,
  12. });
  13. t.is(layout, 'Music/Daft Punk/04 - Harder, Better, Faster, Stronger');
  14. });
  15. test('SAVE LAYOUT 2', async (t) => {
  16. const {tracks, linkinfo} = await parseInfo('https://www.deezer.com/track/3135556');
  17. const layout = saveLayout({
  18. track: tracks[0],
  19. album: linkinfo,
  20. path: '{ALB_NAME}/{ART_NAME}/{TRACK_NUMBER} {SNG_TITLE}',
  21. minimumIntegerDigits: 2,
  22. trackNumber: true,
  23. });
  24. t.is(layout, 'Daft Punk/04 Harder, Better, Faster, Stronger');
  25. });
  26. test('SAVE LAYOUT 3', async (t) => {
  27. const {tracks, linkinfo} = await parseInfo('https://www.deezer.com/track/3135556');
  28. const layout = saveLayout({
  29. track: tracks[0],
  30. album: linkinfo,
  31. path: '{ALB_NAME}/{ART_NAME}/{NO_TRACK_NUMBER}{SNG_TITLE}',
  32. minimumIntegerDigits: 2,
  33. trackNumber: true,
  34. });
  35. t.is(layout, 'Daft Punk/Harder, Better, Faster, Stronger');
  36. });
  37. test('FORMAT SECONDS', (t) => {
  38. const time = formatSecondsReadable(96);
  39. t.is(time, '01m 36s');
  40. });
  41. test('PROGRESS BAR', (t) => {
  42. const bar = progressBar(1000, 40);
  43. t.is(typeof bar, 'function');
  44. const len = bar(500);
  45. t.is(len.length, 40);
  46. });