-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into NAS-131036
- Loading branch information
Showing
279 changed files
with
6,243 additions
and
2,656 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { | ||
Injectable, | ||
Type, | ||
ExistingProvider, | ||
FactoryProvider, | ||
forwardRef, | ||
} from '@angular/core'; | ||
import { Observable, of } from 'rxjs'; | ||
import { MockGlobalStoreResponses } from 'app/core/testing/interfaces/mock-global-store-responses.interface'; | ||
import { | ||
ApiCallAndSubscribeMethod, | ||
ApiCallAndSubscribeResponse, | ||
} from 'app/interfaces/api/api-call-and-subscribe-directory.interface'; | ||
import { | ||
ApiCallMethod, | ||
ApiCallResponse, | ||
} from 'app/interfaces/api/api-call-directory.interface'; | ||
import { ApiEventMethod, ApiEventTyped } from 'app/interfaces/api-message.interface'; | ||
import { | ||
GlobalStoreMembers, | ||
} from 'app/services/global-store/global-store.service'; | ||
|
||
export function mockGlobalStore< | ||
M1 extends ApiCallMethod, | ||
M2 extends ApiEventMethod, | ||
M3 extends ApiCallAndSubscribeMethod, | ||
>( | ||
stores: [ | ||
store: Type<GlobalStoreMembers<M1, M2, M3>>, | ||
mockResponses?: MockGlobalStoreResponses<M1, M2, M3>, | ||
][], | ||
): (FactoryProvider | ExistingProvider)[] { | ||
return stores.map((store) => { | ||
const mockStoreService = new (mockGlobalStoreService(store[1]))(); | ||
return [ | ||
{ | ||
provide: store[0], | ||
useFactory: () => mockStoreService, | ||
}, | ||
{ | ||
provide: mockStoreService, | ||
useExisting: forwardRef(() => store[0]), | ||
}, | ||
]; | ||
}).flat(); | ||
} | ||
|
||
function mockGlobalStoreService< | ||
M1 extends ApiCallMethod, | ||
M2 extends ApiEventMethod, | ||
M3 extends ApiCallAndSubscribeMethod, | ||
>( | ||
mockResponses?: MockGlobalStoreResponses<M1, M2, M3>, | ||
): Type<GlobalStoreMembers<M1, M2, M3>> { | ||
@Injectable({ providedIn: 'root' }) | ||
class MockGlobalStore implements GlobalStoreMembers<M1, M2, M3> { | ||
get call(): Observable<ApiCallResponse<M1>> { | ||
return this.getResponse(mockResponses?.call); | ||
} | ||
|
||
get subscribe(): Observable<ApiEventTyped<M2>> { | ||
return this.getResponse(mockResponses?.subscribe); | ||
} | ||
|
||
get callAndSubscribe(): Observable<ApiCallAndSubscribeResponse<M3>[]> { | ||
return this.getResponse(mockResponses?.callAndSubscribe); | ||
} | ||
|
||
invalidate(): void {} | ||
|
||
private getResponse<R>(mockResponse: R): Observable<R> { | ||
if (mockResponse === undefined) { | ||
throw Error('Unmocked global store response'); | ||
} | ||
return of(mockResponse); | ||
} | ||
} | ||
return MockGlobalStore; | ||
} |
22 changes: 22 additions & 0 deletions
22
src/app/core/testing/interfaces/mock-global-store-responses.interface.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,22 @@ | ||
import { | ||
ApiCallAndSubscribeMethod, | ||
ApiCallAndSubscribeResponse, | ||
} from 'app/interfaces/api/api-call-and-subscribe-directory.interface'; | ||
import { | ||
ApiCallMethod, | ||
ApiCallResponse, | ||
} from 'app/interfaces/api/api-call-directory.interface'; | ||
import { | ||
ApiEventMethod, | ||
ApiEventTyped, | ||
} from 'app/interfaces/api-message.interface'; | ||
|
||
export interface MockGlobalStoreResponses< | ||
M1 extends ApiCallMethod, | ||
M2 extends ApiEventMethod, | ||
M3 extends ApiCallAndSubscribeMethod, | ||
> { | ||
call?: ApiCallResponse<M1>; | ||
subscribe?: ApiEventTyped<M2>; | ||
callAndSubscribe?: ApiCallAndSubscribeResponse<M3>[]; | ||
} |
Oops, something went wrong.