file-tree-limit.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. const FILE_PER_FOLDER = 2
  2. const DOC_PER_FOLDER = 3
  3. const FOLDER_PER_FOLDER = 2
  4. const MAX_DEPTH = 7
  5. function fakeId() {
  6. return Math.random().toString(16).replace(/0\./, 'random-test-id-')
  7. }
  8. function makeFileRefs(path) {
  9. const fileRefs = []
  10. for (let index = 0; index < FILE_PER_FOLDER; index++) {
  11. fileRefs.push({ _id: fakeId(), name: `${path}-file-${index}.jpg` })
  12. }
  13. return fileRefs
  14. }
  15. function makeDocs(path) {
  16. const docs = []
  17. for (let index = 0; index < DOC_PER_FOLDER; index++) {
  18. docs.push({ _id: fakeId(), name: `${path}-doc-${index}.tex` })
  19. }
  20. return docs
  21. }
  22. function makeFolders(path, depth = 0) {
  23. const folders = []
  24. for (let index = 0; index < FOLDER_PER_FOLDER; index++) {
  25. const folderPath = `${path}-folder-${index}`
  26. folders.push({
  27. _id: fakeId(),
  28. name: folderPath,
  29. folders: depth < MAX_DEPTH ? makeFolders(folderPath, depth + 1) : [],
  30. fileRefs: makeFileRefs(folderPath),
  31. docs: makeDocs(folderPath),
  32. })
  33. }
  34. return folders
  35. }
  36. export const rootFolderLimit = [
  37. {
  38. _id: fakeId(),
  39. name: 'rootFolder',
  40. folders: makeFolders('root'),
  41. fileRefs: makeFileRefs('root'),
  42. docs: makeDocs('root'),
  43. },
  44. ]