Skip to content

Commit

Permalink
fix(stream): correct typing issue when detecting DebounceRenderStrategy
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbe812 committed Apr 12, 2023
1 parent 63b4690 commit 20c0a4e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion libs/stream/src/lib/types/render-strategies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export interface DebounceRenderStrategy extends RenderStrategy {
debounceInMs: number;
}

export type RenderStrategies = DefaultRenderStategy | ViewportRenderStrategy | ThrottleRenderStrategy;
export type RenderStrategies = DefaultRenderStategy | ViewportRenderStrategy | ThrottleRenderStrategy | DebounceRenderStrategy;

/**
* @description
Expand Down
45 changes: 45 additions & 0 deletions libs/stream/src/lib/util/setup-operator.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {setupOperator$} from "./setup-operator";
import {debounceTime, Observable, of, pipe, throttleTime} from "rxjs";
import {RenderStrategies} from "../types/render-strategies";
import {subscribeSpyTo} from "@hirez_io/observer-spy";

describe(`${setupOperator$.name}`, () => {
it('should emit throttleTime-operator for ThrottleStrategy', () => {
const renderStrategy$: Observable<RenderStrategies> = of({type: 'throttle', throttleInMs: 1000});

const operator$ = setupOperator$(renderStrategy$);

const result = subscribeSpyTo(operator$);

expect(result.getLastValue()).toEqual(throttleTime(1000));
})
it('should emit debounce-operator for DebounceStrategy', () => {
const renderStrategy$: Observable<RenderStrategies> = of({type: 'debounce', debounceInMs: 1000});

const operator$ = setupOperator$(renderStrategy$);

const result = subscribeSpyTo(operator$);

expect(result.getLastValue()).toEqual(debounceTime(1000));
})

it('should emit empty-operator for DefaultStrategy', () => {
const renderStrategy$: Observable<RenderStrategies> = of({type: 'default'});

const operator$ = setupOperator$(renderStrategy$);

const result = subscribeSpyTo(operator$);

expect(result.getLastValue()).toEqual(pipe());
});

it('should emit empty-operator when no strategy matches', () => {
const renderStrategy$: Observable<RenderStrategies> = of(null as unknown as RenderStrategies);

const operator$ = setupOperator$(renderStrategy$);

const result = subscribeSpyTo(operator$);

expect(result.getLastValue()).toEqual(pipe());
});
});
1 change: 0 additions & 1 deletion libs/stream/src/lib/util/setup-operator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export function setupOperator$(renderStrategy$$: Observable<RenderStrategies>) {
}

if (isDebounceRenderStrategy(strategy)) {
// @ts-ignore todo fix typing issue
return of(debounceTime(strategy.debounceInMs));
}

Expand Down

0 comments on commit 20c0a4e

Please sign in to comment.