Skip to content

Commit

Permalink
feat(jest): 100% coverage for Directory.ts (#2314)
Browse files Browse the repository at this point in the history
  • Loading branch information
drepram authored Mar 15, 2022
1 parent 14d001b commit ab1b585
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions libraries/Files/test/Directory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { Fil } from '../Fil'
import { DIRECTORY_TYPE } from '../types/directory'
import { FileSystemErrors } from '../errors/Errors'

Date.now = jest.fn(() => 1645617999076)
const dateNow = Date.now()

describe('Test FileSystem Directory', () => {
const mockFileData = {
name: 'TestFile.png',
Expand Down Expand Up @@ -33,6 +36,20 @@ describe('Test FileSystem Directory', () => {
const child = directory.getChild(file.name)
expect(child.id).toEqual(file.id)
})
it('Correctly retrieves directory size after adding a child file/folder', () => {
expect(directory.size).toEqual(4235)
})
it('Correctly retrieves directory last modified timestamp after adding a child file/folder', () => {
expect(directory.modified).toEqual(dateNow)
})
it('Incorrectly adds duplicate file to directory', () => {
try {
directory.addChild(file)
} catch (error) {
expect(error).toBeInstanceOf(Error)
expect(error).toHaveProperty('message', FileSystemErrors.DUPLICATE_NAME)
}
})
it('Incorrectly adds directory as a child of itself', () => {
try {
directory.addChild(directory)
Expand All @@ -57,6 +74,18 @@ describe('Test FileSystem Directory', () => {
)
}
})

it('Correctly retrieves imported modified value', () => {
const mockDirTwo = {
name: 'Test Directory',
liked: false,
shared: false,
type: DIRECTORY_TYPE.DEFAULT,
modified: 1647250139467,
}
const directoryTwo = new Directory(mockDirTwo)
expect(directoryTwo.modified).toEqual(1647250139467)
})
it('Correctly displays content', () => {
const content = directory.content
expect(content).not.toEqual(null)
Expand Down

0 comments on commit ab1b585

Please sign in to comment.