|
| 1 | +import {setupOperator$} from "./setup-operator"; |
| 2 | +import {debounceTime, Observable, of, pipe, throttleTime} from "rxjs"; |
| 3 | +import {RenderStrategies} from "../types/render-strategies"; |
| 4 | +import {subscribeSpyTo} from "@hirez_io/observer-spy"; |
| 5 | + |
| 6 | +describe(`${setupOperator$.name}`, () => { |
| 7 | + it('should emit throttleTime-operator for ThrottleStrategy', () => { |
| 8 | + const renderStrategy$: Observable<RenderStrategies> = of({type: 'throttle', throttleInMs: 1000}); |
| 9 | + |
| 10 | + const operator$ = setupOperator$(renderStrategy$); |
| 11 | + |
| 12 | + const result = subscribeSpyTo(operator$); |
| 13 | + |
| 14 | + expect(result.getLastValue()).toEqual(throttleTime(1000)); |
| 15 | + }) |
| 16 | + it('should emit debounce-operator for DebounceStrategy', () => { |
| 17 | + const renderStrategy$: Observable<RenderStrategies> = of({type: 'debounce', debounceInMs: 1000}); |
| 18 | + |
| 19 | + const operator$ = setupOperator$(renderStrategy$); |
| 20 | + |
| 21 | + const result = subscribeSpyTo(operator$); |
| 22 | + |
| 23 | + expect(result.getLastValue()).toEqual(debounceTime(1000)); |
| 24 | + }) |
| 25 | + |
| 26 | + it('should emit empty-operator for DefaultStrategy', () => { |
| 27 | + const renderStrategy$: Observable<RenderStrategies> = of({type: 'default'}); |
| 28 | + |
| 29 | + const operator$ = setupOperator$(renderStrategy$); |
| 30 | + |
| 31 | + const result = subscribeSpyTo(operator$); |
| 32 | + |
| 33 | + expect(result.getLastValue()).toEqual(pipe()); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should emit empty-operator when no strategy matches', () => { |
| 37 | + const renderStrategy$: Observable<RenderStrategies> = of(null as unknown as RenderStrategies); |
| 38 | + |
| 39 | + const operator$ = setupOperator$(renderStrategy$); |
| 40 | + |
| 41 | + const result = subscribeSpyTo(operator$); |
| 42 | + |
| 43 | + expect(result.getLastValue()).toEqual(pipe()); |
| 44 | + }); |
| 45 | +}); |
0 commit comments