-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(unit-test): updated operator tests
- Loading branch information
1 parent
8c666a7
commit 05ab39b
Showing
14 changed files
with
337 additions
and
69 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
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
Binary file not shown.
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
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,23 +1,117 @@ | ||
import { describe, test } from 'vitest'; | ||
import { mockBlob } from '#mocks/blob.js'; | ||
import fs from 'node:fs'; | ||
import { map } from 'rxjs'; | ||
import { TestScheduler } from 'rxjs/testing'; | ||
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'; | ||
|
||
describe('blob', () => { | ||
test('blob to text', () => { | ||
// | ||
let testScheduler; | ||
|
||
beforeEach(() => { | ||
vi.spyOn(global, 'Blob').mockImplementation(mockBlob()); | ||
testScheduler = new TestScheduler((actual, expected) => expect(actual).deep.equal(expected)); | ||
}); | ||
|
||
test('blob to json', () => { | ||
// | ||
afterEach(() => { | ||
vi.restoreAllMocks(); | ||
}); | ||
|
||
test('blob to xml', () => { | ||
// | ||
test('blob to text', async () => { | ||
const { blobToText } = await import('./blob.js'); | ||
|
||
const expectedVal = { | ||
a: 'hello world', | ||
b: 'foo bar' | ||
}; | ||
|
||
const triggerVal = { | ||
a: new Blob([new TextEncoder().encode(expectedVal.a)], 'text/plain'), | ||
b: new Blob([new TextEncoder().encode(expectedVal.b)], 'text/plain') | ||
}; | ||
|
||
testScheduler.run(({ cold, expectObservable }) => { | ||
expectObservable(cold('a-b|', triggerVal).pipe(blobToText())).toBe('a-b|', expectedVal); | ||
}); | ||
}); | ||
|
||
test('blob to video', () => { | ||
// | ||
test('blob to json', async () => { | ||
const { blobToJSON } = await import('./blob.js'); | ||
|
||
const expectedVal = { | ||
a: { hello: 'world' }, | ||
b: { foo: 'bar' } | ||
}; | ||
|
||
const triggerVal = { | ||
a: new Blob([new TextEncoder().encode(JSON.stringify(expectedVal.a))], 'application/json'), | ||
b: new Blob([new TextEncoder().encode(JSON.stringify(expectedVal.b))], 'application/json') | ||
}; | ||
|
||
testScheduler.run(({ cold, expectObservable }) => { | ||
expectObservable(cold('a-b|', triggerVal).pipe(blobToJSON())).toBe('a-b|', expectedVal); | ||
}); | ||
}); | ||
|
||
test('blob to (auto detect)', () => { | ||
// | ||
test('blob to xml', async () => { | ||
const { blobToXML } = await import('./blob.js'); | ||
|
||
const expectedVal = { | ||
a: new DOMParser().parseFromString('<xml></xml>', 'text/xml'), | ||
b: new DOMParser().parseFromString('<xml><a></a></xml>', 'text/xml') | ||
}; | ||
|
||
const triggerVal = { | ||
a: new Blob([new TextEncoder().encode('<xml></xml>')], 'text/xml'), | ||
b: new Blob([new TextEncoder().encode('<xml><a></a></xml>')], 'text/xml') | ||
}; | ||
|
||
testScheduler.run(({ cold, expectObservable }) => { | ||
expectObservable(cold('a-b|', triggerVal).pipe(blobToXML())).toBe('a-b|', expectedVal); | ||
}); | ||
}); | ||
|
||
test('blob to url', async () => { | ||
vi.restoreAllMocks(); | ||
|
||
const { blobToURL } = await import('./blob.js'); | ||
|
||
const triggerVal = { | ||
a: new Blob([fs.readFileSync(`${__dirname}/../fixtures/videos/demo.mp4`)], 'video/mp4') | ||
}; | ||
|
||
const expectedVal = { | ||
a: 'blob:nodedata:' | ||
}; | ||
|
||
testScheduler.run(({ cold, expectObservable }) => { | ||
expectObservable( | ||
cold('a|', triggerVal).pipe( | ||
blobToURL(), | ||
map(v => v.replace(/([a-z0-9-]+)$/, '')) | ||
) | ||
).toBe('a|', expectedVal); | ||
}); | ||
}); | ||
|
||
test('blob to (auto detect)', async () => { | ||
const { blobTo } = await import('./blob.js'); | ||
|
||
const expectedVal = { | ||
a: 'hello world', | ||
b: { foo: 'bar' }, | ||
c: new DOMParser().parseFromString('<xml><a></a></xml>', 'text/xml'), | ||
d: new Blob([new TextEncoder().encode('aha')], 'x-text/plain') | ||
}; | ||
|
||
const triggerVal = { | ||
a: new Blob([new TextEncoder().encode('hello world')], 'text/plain'), | ||
b: new Blob([new TextEncoder().encode(JSON.stringify({ foo: 'bar' }))], 'application/json'), | ||
c: new Blob([new TextEncoder().encode('<xml><a></a></xml>')], 'text/xml'), | ||
d: expectedVal.d | ||
}; | ||
|
||
testScheduler.run(({ cold, expectObservable }) => { | ||
expectObservable(cold('a-b-c-d|', triggerVal).pipe(blobTo())).toBe('a-b-c-d|', expectedVal); | ||
}); | ||
}); | ||
}); |
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
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
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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { tap } from 'rxjs'; | ||
import { TestScheduler } from 'rxjs/testing'; | ||
import { beforeEach, describe, expect, test } from 'vitest'; | ||
|
||
import EstimateTime from './EstimateTime'; | ||
import { SECOND } from './utils'; | ||
|
||
describe('EstimateTime', () => { | ||
let testScheduler; | ||
|
||
beforeEach(() => { | ||
testScheduler = new TestScheduler((actual, expected) => expect(actual).deep.equal(expected)); | ||
}); | ||
|
||
test('calc estimate time - millisecond', async () => { | ||
const triggerVal = { | ||
a: { value: new TextEncoder().encode('abc'), total: 26, period: 1 }, | ||
b: { value: new TextEncoder().encode('def'), total: 26, period: 2 }, | ||
c: { value: new TextEncoder().encode('ghi'), total: 26, period: 3 }, | ||
d: { value: new TextEncoder().encode('jkl'), total: 26, period: 4 }, | ||
e: { value: new TextEncoder().encode('mno'), total: 26, period: 5 }, | ||
f: { value: new TextEncoder().encode('pqr'), total: 26, period: 6 }, | ||
g: { value: new TextEncoder().encode('stu'), total: 26, period: 7 }, | ||
h: { value: new TextEncoder().encode('vwx'), total: 26, period: 8 }, | ||
i: { value: new TextEncoder().encode('yz'), total: 26, period: 9 } | ||
}; | ||
|
||
const expectedVal = { | ||
a: 8, | ||
b: 7, | ||
c: 6, | ||
d: 5, | ||
e: 4, | ||
f: 3, | ||
g: 2, | ||
h: 1, | ||
i: 0 | ||
}; | ||
|
||
const estimateTime = EstimateTime.create(); | ||
|
||
testScheduler.run(({ cold, expectObservable }) => { | ||
expectObservable(estimateTime).toBe('a-b-c-d-e-f-g-h-i', expectedVal); | ||
expectObservable( | ||
cold('a-b-c-d-e-f-g-h-i|', triggerVal).pipe(tap(val => estimateTime.next(val))) | ||
); | ||
}); | ||
}); | ||
|
||
test('calc estimate time - second', async () => { | ||
const triggerVal = { | ||
a: { value: new TextEncoder().encode('abc'), total: 26, period: 1 }, | ||
b: { value: new TextEncoder().encode('def'), total: 26, period: 2 }, | ||
c: { value: new TextEncoder().encode('ghi'), total: 26, period: 3 }, | ||
d: { value: new TextEncoder().encode('jkl'), total: 26, period: 4 }, | ||
e: { value: new TextEncoder().encode('mno'), total: 26, period: 5 }, | ||
f: { value: new TextEncoder().encode('pqr'), total: 26, period: 6 }, | ||
g: { value: new TextEncoder().encode('stu'), total: 26, period: 7 }, | ||
h: { value: new TextEncoder().encode('vwx'), total: 26, period: 8 }, | ||
i: { value: new TextEncoder().encode('yz'), total: 26, period: 9 } | ||
}; | ||
|
||
const expectedVal = { | ||
a: 0.008, | ||
b: 0.007, | ||
c: 0.006, | ||
d: 0.005, | ||
e: 0.004, | ||
f: 0.003, | ||
g: 0.002, | ||
h: 0.001, | ||
i: 0 | ||
}; | ||
|
||
const estimateTimeSecond = EstimateTime.create(SECOND); | ||
|
||
testScheduler.run(({ cold, expectObservable }) => { | ||
expectObservable(estimateTimeSecond).toBe('a-b-c-d-e-f-g-h-i', expectedVal); | ||
expectObservable( | ||
cold('a-b-c-d-e-f-g-h-i|', triggerVal).pipe(tap(val => estimateTimeSecond.next(val))) | ||
); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.