1
1
import { createFactory } from "@src/createFactory" ;
2
2
import { EntityRefHierarchy } from "@src/EntityRefHierarchy" ;
3
3
4
+ import { assert , IsExact } from "conditional-type-checks" ;
5
+
4
6
describe ( 'EntityRefHierarchy' , ( ) => {
5
7
6
8
const factoryWorkspace = createFactory ( 'workspace' , ( id : number ) => id ) ;
@@ -22,7 +24,7 @@ describe('EntityRefHierarchy', () => {
22
24
23
25
24
26
describe ( 'simple hierarchy' , ( ) => {
25
- const hierarchy = new EntityRefHierarchy ( [ REF_WORKSPACE , REF_PROJECT , REF_COLLECTION ] ) ;
27
+ const hierarchy = new EntityRefHierarchy ( [ REF_WORKSPACE , REF_PROJECT , REF_COLLECTION ] as const ) ;
26
28
27
29
it ( 'getting root and leaf refs' , ( ) => {
28
30
expect ( hierarchy . root )
@@ -40,6 +42,17 @@ describe('EntityRefHierarchy', () => {
40
42
. toEqual ( REF_COLLECTION ) ;
41
43
} ) ;
42
44
45
+
46
+ it ( 'types test' , ( ) => {
47
+ const workspaceRef = hierarchy . getRef ( 'workspace' ) ;
48
+ const projectRef = hierarchy . getRef ( 'project' ) ;
49
+ const collectionRef = hierarchy . getRef ( 'collection' ) ;
50
+
51
+ assert < IsExact < typeof workspaceRef , ReturnType < typeof factoryWorkspace > > > ( true ) ;
52
+ assert < IsExact < typeof projectRef , ReturnType < typeof factoryProject > > > ( true ) ;
53
+ assert < IsExact < typeof collectionRef , ReturnType < typeof factoryCollection > > > ( true ) ;
54
+ } ) ;
55
+
43
56
it ( 'iterating' , ( ) => {
44
57
expect ( [ ...hierarchy ] )
45
58
. toEqual ( [ REF_WORKSPACE , REF_PROJECT , REF_COLLECTION ] ) ;
@@ -51,7 +64,7 @@ describe('EntityRefHierarchy', () => {
51
64
undefined as ReturnType < typeof factoryWorkspace > | undefined ,
52
65
REF_PROJECT ,
53
66
REF_COLLECTION
54
- ] ) ;
67
+ ] as const ) ;
55
68
56
69
it ( 'getting root and leaf refs' , ( ) => {
57
70
expect ( hierarchy . root )
@@ -69,6 +82,16 @@ describe('EntityRefHierarchy', () => {
69
82
. toEqual ( REF_COLLECTION ) ;
70
83
} ) ;
71
84
85
+ it ( 'types test' , ( ) => {
86
+ const workspaceRef = hierarchy . getRef ( 'workspace' ) ;
87
+ const projectRef = hierarchy . getRef ( 'project' ) ;
88
+ const collectionRef = hierarchy . getRef ( 'collection' ) ;
89
+
90
+ assert < IsExact < typeof workspaceRef , ReturnType < typeof factoryWorkspace > | undefined > > ( true ) ;
91
+ assert < IsExact < typeof projectRef , ReturnType < typeof factoryProject > > > ( true ) ;
92
+ assert < IsExact < typeof collectionRef , ReturnType < typeof factoryCollection > > > ( true ) ;
93
+ } ) ;
94
+
72
95
it ( 'iterating' , ( ) => {
73
96
expect ( [ ...hierarchy ] )
74
97
. toEqual ( [ REF_PROJECT , REF_COLLECTION ] ) ;
0 commit comments