Entry.test.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import Entry from '../../../src/lib/Entry';
  2. import trailingSlash from '../../../src/lib/trailingSlash';
  3. describe('Entry', () => {
  4. const directory = new Entry({
  5. directory: true,
  6. fullPath: '/path/to/',
  7. modified: Date.now(),
  8. }),
  9. file = new Entry({
  10. fullPath: '/path/to/file.txt',
  11. modified: Date.now(),
  12. size: 54321,
  13. mimeType: 'text/plain',
  14. }),
  15. atFile = new Entry({
  16. fullPath: '/%40',
  17. modified: Date.now(),
  18. size: 54321,
  19. mimeType: 'text/plain',
  20. });
  21. // directory
  22. it('should strip the trailing slash for directories', () => {
  23. expect(directory.path).toBe('/path');
  24. expect(directory.name).toBe('to');
  25. });
  26. it('should return an empty size for directories', () => {
  27. expect(directory.directory).toBe(true);
  28. });
  29. it('should return an empty size for directories', () => {
  30. expect(directory.displaySize).toBe('');
  31. });
  32. it('should return a new object on update', () => {
  33. expect(directory.update()).not.toBe(directory);
  34. });
  35. it('should create the expected parent object', () => {
  36. const parent = directory.createParentEntry();
  37. expect(parent.fullPath).toBe(trailingSlash(directory.path));
  38. expect(parent.title).toBe('←');
  39. });
  40. it('should be possible to change the placeholder status', () => {
  41. expect(file.placeholder).toBe(false);
  42. file.placeholder = true;
  43. expect(file.placeholder).toBe(true);
  44. });
  45. // file
  46. it('should return the expected path', () => {
  47. expect(file.path).toBe('/path/to');
  48. });
  49. it('should return the expected filename', () => {
  50. expect(file.name).toBe('file.txt');
  51. });
  52. it('should return the expected extension', () => {
  53. expect(file.extension).toBe('txt');
  54. });
  55. it('should return the expected type', () => {
  56. expect(file.type).toBe('text');
  57. });
  58. it('should return the expected size string', () => {
  59. expect(file.displaySize).toBe('53.05 KiB');
  60. });
  61. // atFile
  62. it('should correctly decode filenames', () => {
  63. expect(atFile.name).toBe('%40');
  64. expect(atFile.title).toBe('@');
  65. });
  66. });