Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jest): 58% coverage for TextileFileSystem.ts #2300

Merged
merged 1 commit into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.