Entry.test.js 1.9 KB

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