Skip to content

Commit

Permalink
feat(jest): 81% coverage for FilSystem.test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
drepram authored and stavares843 committed Mar 21, 2022
1 parent 855b65c commit 052e0c3
Show file tree
Hide file tree
Showing 2 changed files with 312 additions and 1 deletion.
13 changes: 12 additions & 1 deletion libraries/Files/test/FilSystem.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { v4 as uuidv4 } from 'uuid'
import { Directory } from '../Directory'
import { FileSystemErrors } from '../errors/Errors'
import { Fil } from '../Fil'
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',
Expand Down Expand Up @@ -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`, () =>
Expand Down
300 changes: 300 additions & 0 deletions libraries/Files/test/__snapshots__/FilSystem.test.ts.snap
Original file line number Diff line number Diff line change
@@ -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",
},
]
`;

0 comments on commit 052e0c3

Please sign in to comment.