-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added dbxFirebaseDocumentWithParentStore
- added LockSet tests - added other tests
- Loading branch information
Showing
20 changed files
with
570 additions
and
124 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
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
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
81 changes: 81 additions & 0 deletions
81
packages/dbx-firebase/src/lib/model/store/store.subcollection.document.spec.ts
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,81 @@ | ||
/** | ||
* @jest-environment node | ||
*/ | ||
// use the node environment, as the jsdom environment breaks for tests that use the firestore. | ||
|
||
import { MockItemSubItem, MockItemSubItemDocument, authorizedTestWithMockItemCollection, MockItem, MockItemDocument, MockItemFirestoreCollection, MockItemSubItemFirestoreCollectionFactory } from "@dereekb/firebase"; | ||
import { SubscriptionObject } from "@dereekb/rxjs"; | ||
import { filter, first, of, timeout } from "rxjs"; | ||
import { AbstractDbxFirebaseDocumentStore } from "./store.document"; | ||
import { AbstractDbxFirebaseDocumentWithParentStore } from './store.subcollection.document'; | ||
|
||
export class TestDbxFirebaseDocumentStore extends AbstractDbxFirebaseDocumentStore<MockItem, MockItemDocument> { | ||
|
||
constructor(firestoreCollection: MockItemFirestoreCollection) { | ||
super({ firestoreCollection }) | ||
} | ||
|
||
} | ||
|
||
export class TestDbxFirebaseDocumentWithParentStore extends AbstractDbxFirebaseDocumentWithParentStore<MockItemSubItem, MockItem, MockItemSubItemDocument, MockItemDocument> { | ||
|
||
constructor(collectionFactory: MockItemSubItemFirestoreCollectionFactory) { | ||
super({ collectionFactory }) | ||
} | ||
|
||
} | ||
|
||
describe('AbstractDbxFirebaseCollectionWithParentStore', () => { | ||
|
||
authorizedTestWithMockItemCollection((f) => { | ||
|
||
let sub: SubscriptionObject; | ||
let parentStore: TestDbxFirebaseDocumentStore; | ||
let store: TestDbxFirebaseDocumentWithParentStore; | ||
|
||
beforeEach(() => { | ||
const firestoreCollection = f.instance.firestoreCollection; | ||
parentStore = new TestDbxFirebaseDocumentStore(firestoreCollection); | ||
store = new TestDbxFirebaseDocumentWithParentStore(f.instance.mockItemSubItemCollection); | ||
sub = new SubscriptionObject(); | ||
}); | ||
|
||
afterEach(() => { | ||
parentStore.ngOnDestroy(); | ||
store.ngOnDestroy(); | ||
sub.destroy(); | ||
}); | ||
|
||
describe('with parent store', () => { | ||
|
||
beforeEach(() => { | ||
store.setParentStore(parentStore); | ||
}); | ||
|
||
it('should not load while a parent is not set.', (done) => { | ||
sub.subscription = store.document$.pipe(timeout({ first: 500, with: () => of(false) }), first()).subscribe((result) => { | ||
expect(result).toBe(false); | ||
done(); | ||
}); | ||
}); | ||
|
||
describe('with parent loaded', () => { | ||
|
||
beforeEach(() => { | ||
parentStore.setId('test'); | ||
}); | ||
|
||
it('should load the document.', (done) => { | ||
sub.subscription = store.document$.pipe(first()).subscribe((iteration) => { | ||
expect(iteration).toBeDefined(); | ||
done(); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); |
58 changes: 58 additions & 0 deletions
58
packages/dbx-firebase/src/lib/model/store/store.subcollection.document.ts
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,58 @@ | ||
import { filterMaybe } from '@dereekb/rxjs'; | ||
import { Injectable } from '@angular/core'; | ||
import { Observable, shareReplay, distinctUntilChanged, map } from 'rxjs'; | ||
import { FirestoreDocument, FirestoreCollectionWithParentFactory } from '@dereekb/firebase'; | ||
import { Maybe } from '@dereekb/util'; | ||
import { AbstractDbxFirebaseDocumentStore, DbxFirebaseDocumentStore, DbxFirebaseDocumentStoreContextState } from './store.document'; | ||
import { DbxFirebaseComponentStoreWithParentSetParentEffectFunction, setParentEffect, DbxFirebaseComponentStoreWithParentSetParentStoreEffectFunction, setParentStoreEffect, DbxFirebaseComponentStoreWithParent, DbxFirebaseComponentStoreWithParentContextState } from './store.subcollection.rxjs'; | ||
|
||
export interface DbxFirebaseDocumentWithParentStore<T, PT, D extends FirestoreDocument<T> = FirestoreDocument<T>, PD extends FirestoreDocument<PT> = FirestoreDocument<PT>> | ||
extends DbxFirebaseDocumentStore<T, D>, DbxFirebaseComponentStoreWithParent<T, PT, D, PD> { } | ||
|
||
export interface DbxFirebaseDocumentWithParentStoreContextState<T, PT, D extends FirestoreDocument<T> = FirestoreDocument<T>, PD extends FirestoreDocument<PT> = FirestoreDocument<PT>> | ||
extends DbxFirebaseDocumentStoreContextState<T, D>, DbxFirebaseComponentStoreWithParentContextState<T, PT, D, PD> { } | ||
|
||
/** | ||
* Abstract DbxFirebaseDocumentStore that has a parent document from which is derives it's FiresbaseCollection from. | ||
*/ | ||
@Injectable() | ||
export class AbstractDbxFirebaseDocumentWithParentStore<T, PT, D extends FirestoreDocument<T> = FirestoreDocument<T>, PD extends FirestoreDocument<PT> = FirestoreDocument<PT>, C extends DbxFirebaseDocumentWithParentStoreContextState<T, PT, D, PD> = DbxFirebaseDocumentWithParentStoreContextState<T, PT, D, PD>> | ||
extends AbstractDbxFirebaseDocumentStore<T, D, C> implements DbxFirebaseDocumentWithParentStore<T, PT, D, PD> { | ||
|
||
// MARK: Effects | ||
readonly setParent: DbxFirebaseComponentStoreWithParentSetParentEffectFunction<PD> = setParentEffect(this); | ||
readonly setParentStore: DbxFirebaseComponentStoreWithParentSetParentStoreEffectFunction<PT, PD> = setParentStoreEffect(this); | ||
|
||
// MARK: Accessors | ||
readonly currentParent$: Observable<Maybe<PD>> = this.state$.pipe( | ||
map(x => x.parent), | ||
distinctUntilChanged(), | ||
shareReplay(1) | ||
); | ||
|
||
readonly parent$: Observable<PD> = this.currentParent$.pipe( | ||
filterMaybe() | ||
); | ||
|
||
readonly currentCollectionFactory$: Observable<Maybe<FirestoreCollectionWithParentFactory<T, PT, D, PD>>> = this.state$.pipe( | ||
map(x => x.collectionFactory), | ||
distinctUntilChanged(), | ||
shareReplay(1) | ||
); | ||
|
||
readonly collectionFactory$: Observable<FirestoreCollectionWithParentFactory<T, PT, D, PD>> = this.currentCollectionFactory$.pipe( | ||
filterMaybe() | ||
); | ||
|
||
// MARK: State Changes | ||
/** | ||
* Sets the collection factory function to use. | ||
*/ | ||
readonly setCollectionFactory = this.updater((state, collectionFactory: FirestoreCollectionWithParentFactory<T, PT, D, PD>) => ({ ...state, collectionFactory })); | ||
|
||
/** | ||
* Sets the parent on the current state. | ||
*/ | ||
readonly _setParentDocument = this.updater((state, parent: Maybe<PD>) => ({ ...state, parent })); | ||
|
||
} |
Oops, something went wrong.