1
0
Fork 0
toolkit/packages/cache/__tests__/uploadUtils.test.ts

59 lines
2.2 KiB
TypeScript
Raw Normal View History

2024-12-02 11:35:20 +00:00
import * as uploadUtils from '../src/internal/uploadUtils'
2024-12-02 12:24:17 +00:00
import {TransferProgressEvent} from '@azure/ms-rest-js'
2024-12-02 10:33:27 +00:00
test('upload progress tracked correctly', () => {
2024-12-02 11:35:20 +00:00
const progress = new uploadUtils.UploadProgress(1000)
2024-12-02 10:33:27 +00:00
expect(progress.contentLength).toBe(1000)
expect(progress.sentBytes).toBe(0)
expect(progress.displayedComplete).toBe(false)
expect(progress.timeoutHandle).toBeUndefined()
expect(progress.getTransferredBytes()).toBe(0)
expect(progress.isDone()).toBe(false)
2024-12-02 12:24:17 +00:00
progress.onProgress()({loadedBytes: 0} as TransferProgressEvent)
2024-12-02 10:33:27 +00:00
expect(progress.contentLength).toBe(1000)
expect(progress.sentBytes).toBe(0)
expect(progress.displayedComplete).toBe(false)
expect(progress.timeoutHandle).toBeUndefined()
expect(progress.getTransferredBytes()).toBe(0)
expect(progress.isDone()).toBe(false)
2024-12-02 12:24:17 +00:00
progress.onProgress()({loadedBytes: 250} as TransferProgressEvent)
2024-12-02 10:33:27 +00:00
expect(progress.contentLength).toBe(1000)
expect(progress.sentBytes).toBe(250)
expect(progress.displayedComplete).toBe(false)
expect(progress.timeoutHandle).toBeUndefined()
expect(progress.getTransferredBytes()).toBe(250)
expect(progress.isDone()).toBe(false)
2024-12-02 12:24:17 +00:00
progress.onProgress()({loadedBytes: 500} as TransferProgressEvent)
2024-12-02 10:33:27 +00:00
expect(progress.contentLength).toBe(1000)
expect(progress.sentBytes).toBe(500)
expect(progress.displayedComplete).toBe(false)
expect(progress.timeoutHandle).toBeUndefined()
expect(progress.getTransferredBytes()).toBe(500)
expect(progress.isDone()).toBe(false)
2024-12-02 12:24:17 +00:00
progress.onProgress()({loadedBytes: 750} as TransferProgressEvent)
2024-12-02 10:33:27 +00:00
expect(progress.contentLength).toBe(1000)
expect(progress.sentBytes).toBe(750)
expect(progress.displayedComplete).toBe(false)
expect(progress.timeoutHandle).toBeUndefined()
expect(progress.getTransferredBytes()).toBe(750)
expect(progress.isDone()).toBe(false)
2024-12-02 12:24:17 +00:00
progress.onProgress()({loadedBytes: 1000} as TransferProgressEvent)
2024-12-02 10:33:27 +00:00
expect(progress.contentLength).toBe(1000)
expect(progress.sentBytes).toBe(1000)
expect(progress.displayedComplete).toBe(false)
expect(progress.timeoutHandle).toBeUndefined()
expect(progress.getTransferredBytes()).toBe(1000)
expect(progress.isDone()).toBe(true)
})