Skip to content

Commit

Permalink
feat(jest): 58% coverage for TextileFileSystem.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
drepram committed Mar 11, 2022
1 parent 4b547f9 commit 63b690f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 32 deletions.
81 changes: 49 additions & 32 deletions libraries/Files/test/TextileFileSystem.test.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,60 @@
import fs from 'fs'
import Vue from 'vue'
import * as TFS from '../TextileFileSystem'
import { Fil } from '../Fil'
import TextileManager from '~/libraries/Textile/TextileManager'
// Vue.prototype.$TextileManager = new TextileManager()
Vue.prototype.$TextileManager = new TextileManager()

describe('', () => {
// const TFSConstructor = new TFS.TextileFileSystem()
// const inst = TFSConstructor
// const state = inst.bucket
const TFSConstructor = new TFS.TextileFileSystem()
const inst = TFSConstructor
const state = inst.bucket

test('get bucket TFS', () => {
expect('').toEqual('')
// const result: any = inst.bucket
// expect(result).toEqual(state)
const result: any = inst.bucket
expect(result).toEqual(state)
})
test('upload file TFS', async () => {
const TMConstructor = Vue.prototype.$TextileManager
TMConstructor.bucket = jest.fn()
TMConstructor.bucket.pushFile = jest.fn()
TMConstructor.bucket.pushFile.mockReturnValueOnce({
path: {
path: '0x0aef',
},
})
const testFile = new File(['hello'], 'test_fil.txt', {
type: 'text/plain',
})
const file = new Fil(testFile)
await inst.uploadFile(file)
expect(TMConstructor.bucket.pushFile).toHaveBeenCalled()
})
test('remove file TFS', async () => {
const TMConstructor = Vue.prototype.$TextileManager
TMConstructor.bucket = jest.fn()
TMConstructor.bucket.removeFile = jest.fn()
await inst.removeFile('TestFile.png')
expect(TMConstructor.bucket.removeFile).toHaveBeenCalled()
})
test.skip('upload file TFS svg', async () => {
const TMConstructor = Vue.prototype.$TextileManager
TMConstructor.bucket = jest.fn()
TMConstructor.bucket.pushFile = jest.fn()
TMConstructor.bucket.pushFile.mockReturnValueOnce({
path: {
path: '0x0aef',
},
})
const fileBuffer = fs.readFileSync('utilities/assets/svg-image.svg', {
flag: 'r',
})
const testFile = new File([fileBuffer as BlobPart], 'svg-image.svg', {
type: 'image/svg',
})
const file = new Fil(testFile)
await inst.uploadFile(file)
expect(TMConstructor.bucket.pushFile).toHaveBeenCalled()
})
// test('upload file TFS', async () => {
// const TMConstructor = Vue.prototype.$TextileManager
// TMConstructor.bucket = jest.fn()
// TMConstructor.bucket.pushFile = jest.fn()
// TMConstructor.bucket.pushFile.mockReturnValueOnce({
// path: {
// path: '0x0aef',
// },
// })
// const mockFileData = {
// name: 'TestFile.png',
// hash: '0x0aef',
// size: 42345,
// description: 'Test file description',
// }
// const file = new Fil(mockFileData)
// await inst.uploadFile(file)
// expect(TMConstructor.bucket.pushFile).toHaveBeenCalled()
// })
// test('remove file TFS', async () => {
// const TMConstructor = Vue.prototype.$TextileManager
// TMConstructor.bucket = jest.fn()
// TMConstructor.bucket.removeFile = jest.fn()
// await inst.removeFile('TestFile.png')
// expect(TMConstructor.bucket.removeFile).toHaveBeenCalled()
// })
})
5 changes: 5 additions & 0 deletions utilities/assets/svg-image.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 63b690f

Please sign in to comment.