diff --git a/libraries/Files/test/FilSystem.test.ts b/libraries/Files/test/FilSystem.test.ts index d221097591..c44ab532a3 100644 --- a/libraries/Files/test/FilSystem.test.ts +++ b/libraries/Files/test/FilSystem.test.ts @@ -1,3 +1,4 @@ +import { v4 as uuidv4 } from 'uuid' import { Directory } from '../Directory' import { FileSystemErrors } from '../errors/Errors' import { Fil } from '../Fil' @@ -5,6 +6,10 @@ import { FilSystem } from '../FilSystem' import { DIRECTORY_TYPE } from '../types/directory' import { FILESYSTEM_TYPE } from '../types/filesystem' +Date.now = jest.fn(() => 1645617999076) +jest.mock('uuid') +uuidv4.mockImplementation(() => 'testid') + const mockFileData = { name: 'TestFile.png', hash: '0x0aef', @@ -60,9 +65,15 @@ describe('Test FilSystem', () => { } it(`Correctly returns filesystem parent`, () => expect(filesystem.parent).toBe(null)) + it(`Correctly returns filesystem content`, () => + expect(filesystem.content).toMatchSnapshot()) + it(`Correctly returns filesystem totalSize`, () => + expect(filesystem.totalSize).toBe(17349948)) + it(`Correctly returns filesystem percentStorageUsed`, () => + expect(filesystem.percentStorageUsed).toBe(0.4337487)) it(`Correctly exports filesystem`, () => expect(filesystem.export).toMatchObject({ - version: 1, + version: 3, type: FILESYSTEM_TYPE.DEFAULT, })) it(`Correctly copies entire filesystem`, () => diff --git a/libraries/Files/test/__snapshots__/FilSystem.test.ts.snap b/libraries/Files/test/__snapshots__/FilSystem.test.ts.snap new file mode 100644 index 0000000000..f34ef42ff6 --- /dev/null +++ b/libraries/Files/test/__snapshots__/FilSystem.test.ts.snap @@ -0,0 +1,300 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Test FilSystem Correctly returns filesystem content 1`] = ` +Array [ + Directory { + "_children": Map {}, + "_id": "testid", + "_liked": false, + "_modified": 1645617999076, + "_name": "Test Directory", + "_parent": Directory { + "_children": Map { + "Test Directory" => [Circular], + "Test Directory copy" => Directory { + "_children": Map {}, + "_id": "testid", + "_liked": false, + "_modified": 1645617999076, + "_name": "Test Directory copy", + "_parent": [Circular], + "_shared": false, + "_type": "DEFAULT", + }, + "second dir" => Directory { + "_children": Map { + "TestFile.png" => Fil { + "_description": "Test file description", + "_file": undefined, + "_hash": "0x0aef", + "_id": "testid", + "_liked": false, + "_modified": 1645617999076, + "_name": "TestFile.png", + "_parent": [Circular], + "_shared": false, + "_size": 4337487, + "_thumbnail": "", + "_type": "generic", + }, + "testPng2.png" => Fil { + "_description": "Test file description", + "_file": undefined, + "_hash": "0x0aef", + "_id": "testid", + "_liked": false, + "_modified": 1645617999076, + "_name": "testPng2.png", + "_parent": [Circular], + "_shared": false, + "_size": 4337487, + "_thumbnail": "", + "_type": "generic", + }, + "abc.png" => Fil { + "_description": "Test file description", + "_file": undefined, + "_hash": "0x0aef", + "_id": "testid", + "_liked": false, + "_modified": 1645617999076, + "_name": "abc.png", + "_parent": [Circular], + "_shared": false, + "_size": 4337487, + "_thumbnail": "", + "_type": "generic", + }, + "cc123.png" => Fil { + "_description": "Test file description", + "_file": undefined, + "_hash": "0x0aef", + "_id": "testid", + "_liked": false, + "_modified": 1645617999076, + "_name": "cc123.png", + "_parent": [Circular], + "_shared": false, + "_size": 4337487, + "_thumbnail": "", + "_type": "generic", + }, + }, + "_id": "testid", + "_liked": false, + "_modified": 1645617999076, + "_name": "second dir", + "_parent": [Circular], + "_shared": false, + "_type": "DEFAULT", + }, + }, + "_id": "testid", + "_liked": false, + "_modified": 1645617999076, + "_name": "root", + "_parent": null, + "_shared": false, + "_type": "DEFAULT", + }, + "_shared": false, + "_type": "DEFAULT", + }, + Directory { + "_children": Map {}, + "_id": "testid", + "_liked": false, + "_modified": 1645617999076, + "_name": "Test Directory copy", + "_parent": Directory { + "_children": Map { + "Test Directory" => Directory { + "_children": Map {}, + "_id": "testid", + "_liked": false, + "_modified": 1645617999076, + "_name": "Test Directory", + "_parent": [Circular], + "_shared": false, + "_type": "DEFAULT", + }, + "Test Directory copy" => [Circular], + "second dir" => Directory { + "_children": Map { + "TestFile.png" => Fil { + "_description": "Test file description", + "_file": undefined, + "_hash": "0x0aef", + "_id": "testid", + "_liked": false, + "_modified": 1645617999076, + "_name": "TestFile.png", + "_parent": [Circular], + "_shared": false, + "_size": 4337487, + "_thumbnail": "", + "_type": "generic", + }, + "testPng2.png" => Fil { + "_description": "Test file description", + "_file": undefined, + "_hash": "0x0aef", + "_id": "testid", + "_liked": false, + "_modified": 1645617999076, + "_name": "testPng2.png", + "_parent": [Circular], + "_shared": false, + "_size": 4337487, + "_thumbnail": "", + "_type": "generic", + }, + "abc.png" => Fil { + "_description": "Test file description", + "_file": undefined, + "_hash": "0x0aef", + "_id": "testid", + "_liked": false, + "_modified": 1645617999076, + "_name": "abc.png", + "_parent": [Circular], + "_shared": false, + "_size": 4337487, + "_thumbnail": "", + "_type": "generic", + }, + "cc123.png" => Fil { + "_description": "Test file description", + "_file": undefined, + "_hash": "0x0aef", + "_id": "testid", + "_liked": false, + "_modified": 1645617999076, + "_name": "cc123.png", + "_parent": [Circular], + "_shared": false, + "_size": 4337487, + "_thumbnail": "", + "_type": "generic", + }, + }, + "_id": "testid", + "_liked": false, + "_modified": 1645617999076, + "_name": "second dir", + "_parent": [Circular], + "_shared": false, + "_type": "DEFAULT", + }, + }, + "_id": "testid", + "_liked": false, + "_modified": 1645617999076, + "_name": "root", + "_parent": null, + "_shared": false, + "_type": "DEFAULT", + }, + "_shared": false, + "_type": "DEFAULT", + }, + Directory { + "_children": Map { + "TestFile.png" => Fil { + "_description": "Test file description", + "_file": undefined, + "_hash": "0x0aef", + "_id": "testid", + "_liked": false, + "_modified": 1645617999076, + "_name": "TestFile.png", + "_parent": [Circular], + "_shared": false, + "_size": 4337487, + "_thumbnail": "", + "_type": "generic", + }, + "testPng2.png" => Fil { + "_description": "Test file description", + "_file": undefined, + "_hash": "0x0aef", + "_id": "testid", + "_liked": false, + "_modified": 1645617999076, + "_name": "testPng2.png", + "_parent": [Circular], + "_shared": false, + "_size": 4337487, + "_thumbnail": "", + "_type": "generic", + }, + "abc.png" => Fil { + "_description": "Test file description", + "_file": undefined, + "_hash": "0x0aef", + "_id": "testid", + "_liked": false, + "_modified": 1645617999076, + "_name": "abc.png", + "_parent": [Circular], + "_shared": false, + "_size": 4337487, + "_thumbnail": "", + "_type": "generic", + }, + "cc123.png" => Fil { + "_description": "Test file description", + "_file": undefined, + "_hash": "0x0aef", + "_id": "testid", + "_liked": false, + "_modified": 1645617999076, + "_name": "cc123.png", + "_parent": [Circular], + "_shared": false, + "_size": 4337487, + "_thumbnail": "", + "_type": "generic", + }, + }, + "_id": "testid", + "_liked": false, + "_modified": 1645617999076, + "_name": "second dir", + "_parent": Directory { + "_children": Map { + "Test Directory" => Directory { + "_children": Map {}, + "_id": "testid", + "_liked": false, + "_modified": 1645617999076, + "_name": "Test Directory", + "_parent": [Circular], + "_shared": false, + "_type": "DEFAULT", + }, + "Test Directory copy" => Directory { + "_children": Map {}, + "_id": "testid", + "_liked": false, + "_modified": 1645617999076, + "_name": "Test Directory copy", + "_parent": [Circular], + "_shared": false, + "_type": "DEFAULT", + }, + "second dir" => [Circular], + }, + "_id": "testid", + "_liked": false, + "_modified": 1645617999076, + "_name": "root", + "_parent": null, + "_shared": false, + "_type": "DEFAULT", + }, + "_shared": false, + "_type": "DEFAULT", + }, +] +`;