-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jest): 58% coverage for TextileFileSystem.ts (#2300)
- Loading branch information
Showing
2 changed files
with
54 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
// }) | ||
}) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.