aboutsummaryrefslogtreecommitdiff
path: root/Timeline/ClientApp/src/app/test-utilities
diff options
context:
space:
mode:
Diffstat (limited to 'Timeline/ClientApp/src/app/test-utilities')
-rw-r--r--Timeline/ClientApp/src/app/test-utilities/activated-route.mock.ts4
-rw-r--r--Timeline/ClientApp/src/app/test-utilities/mock.ts7
-rw-r--r--Timeline/ClientApp/src/app/test-utilities/storage.mock.ts28
3 files changed, 36 insertions, 3 deletions
diff --git a/Timeline/ClientApp/src/app/test-utilities/activated-route.mock.ts b/Timeline/ClientApp/src/app/test-utilities/activated-route.mock.ts
index 72707c5e..40484387 100644
--- a/Timeline/ClientApp/src/app/test-utilities/activated-route.mock.ts
+++ b/Timeline/ClientApp/src/app/test-utilities/activated-route.mock.ts
@@ -3,9 +3,7 @@ import { ParamMap, ActivatedRouteSnapshot, ActivatedRoute } from '@angular/route
import { Observable, BehaviorSubject } from 'rxjs';
import { map } from 'rxjs/operators';
-export type PartialMock<T> = {
- [P in keyof T]?: T[P] | PartialMock<T[P]>;
-};
+import { PartialMock } from './mock';
export interface ParamMapCreator { [name: string]: string | string[]; }
diff --git a/Timeline/ClientApp/src/app/test-utilities/mock.ts b/Timeline/ClientApp/src/app/test-utilities/mock.ts
new file mode 100644
index 00000000..c3e368f0
--- /dev/null
+++ b/Timeline/ClientApp/src/app/test-utilities/mock.ts
@@ -0,0 +1,7 @@
+export type Mock<T> = {
+ [P in keyof T]: T[P] extends Function ? T[P] : T[P] | Mock<T[P]>;
+};
+
+export type PartialMock<T> = {
+ [P in keyof T]?: T[P] extends Function ? T[P] : T[P] | PartialMock<T[P]> | Mock<T[P]>;
+};
diff --git a/Timeline/ClientApp/src/app/test-utilities/storage.mock.ts b/Timeline/ClientApp/src/app/test-utilities/storage.mock.ts
new file mode 100644
index 00000000..0ba5aa35
--- /dev/null
+++ b/Timeline/ClientApp/src/app/test-utilities/storage.mock.ts
@@ -0,0 +1,28 @@
+import { Mock } from './mock';
+import { nullIfUndefined } from '../utilities/language-untilities';
+
+export function createMockStorage(): Mock<Storage> {
+ const map: { [key: string]: string } = {};
+ return {
+ get length(): number {
+ return Object.keys(map).length;
+ },
+ key(index: number): string | null {
+ const keys = Object.keys(map);
+ if (index >= keys.length) { return null; }
+ return keys[index];
+ },
+ clear() {
+ Object.keys(map).forEach(key => delete map.key);
+ },
+ getItem(key: string): string | null {
+ return nullIfUndefined(map[key]);
+ },
+ setItem(key: string, value: string) {
+ map[key] = value;
+ },
+ removeItem(key: string) {
+ delete map[key];
+ }
+ };
+}