Skip to content
This repository has been archived by the owner on May 26, 2023. It is now read-only.

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
waterplea committed Apr 9, 2020
1 parent 1123073 commit e4ccf0c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import {Attribute, Directive, Inject, Output} from '@angular/core';
import {Observable} from 'rxjs';
import {IntersectionObserverService} from '../services/intersection-observer.service';
import {INTERSECTION_ROOT_MARGIN} from '../tokens/intersection-root-margin';
import {INTERSECTION_THRESHOLD} from '../tokens/intersection-threshold';
import {
INTERSECTION_ROOT_MARGIN,
INTERSECTION_ROOT_MARGIN_DEFAULT,
} from '../tokens/intersection-root-margin';
import {
INTERSECTION_THRESHOLD,
INTERSECTION_THRESHOLD_DEFAULT,
} from '../tokens/intersection-threshold';

export function rootMarginFactory(rootMargin: string | null): string | null {
return rootMargin;
export function rootMarginFactory(rootMargin: string | null): string {
return rootMargin || INTERSECTION_ROOT_MARGIN_DEFAULT;
}

export function thresholdFactory(threshold: string | null): number[] | null {
return threshold ? threshold.split(',').map(parseFloat) : null;
export function thresholdFactory(threshold: string | null): number | number[] {
return threshold
? threshold.split(',').map(parseFloat)
: INTERSECTION_THRESHOLD_DEFAULT;
}

@Directive({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {Component} from '@angular/core';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {IntersectionObserverModule} from '../../module';
import {INTERSECTION_ROOT_MARGIN} from '../../tokens/intersection-root-margin';
import {INTERSECTION_THRESHOLD} from '../../tokens/intersection-threshold';

describe('IntersectionObserverDirective', () => {
@Component({
Expand Down Expand Up @@ -60,4 +62,10 @@ describe('IntersectionObserverDirective', () => {
done();
}, 100);
});

it('Default options', () => {
// https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/IntersectionObserver
expect(TestBed.get(INTERSECTION_ROOT_MARGIN)).toBe('0px 0px 0px 0px');
expect(TestBed.get(INTERSECTION_THRESHOLD)).toBe(0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ describe('IntersectionObserverService', () => {
nativeElement: document.createElement('DIV'),
},
false,
null,
null,
'0px 0px 0px 0px',
0,
null,
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {InjectionToken} from '@angular/core';

export const INTERSECTION_ROOT_MARGIN_DEFAULT = '0px 0px 0px 0px';
export const INTERSECTION_ROOT_MARGIN = new InjectionToken<string>(
'rootMargin for IntersectionObserver',
{
providedIn: 'root',
factory: () => '0px 0px 0px 0px',
factory: () => INTERSECTION_ROOT_MARGIN_DEFAULT,
},
);
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {InjectionToken} from '@angular/core';

export const INTERSECTION_THRESHOLD_DEFAULT = 0;
export const INTERSECTION_THRESHOLD = new InjectionToken<number | number[]>(
'threshold for IntersectionObserver',
{
providedIn: 'root',
factory: () => 0,
factory: () => INTERSECTION_THRESHOLD_DEFAULT,
},
);

0 comments on commit e4ccf0c

Please sign in to comment.