@@ -9,63 +9,69 @@ type ClientJS = org.modelix.model.client2.ClientJS;
9
9
type ChangeJS = org . modelix . model . client2 . ChangeJS ;
10
10
const { loadModelsFromJson } = org . modelix . model . client2 ;
11
11
12
- const root = {
13
- root : { } ,
14
- } ;
15
-
16
- function getClient ( _url : string ) : Promise < ClientJS > {
17
- return Promise . resolve ( new TestClientJS ( ) as unknown as ClientJS ) ;
18
- }
12
+ test ( "test branch connects" , ( done ) => {
13
+ class SuccessfulBranchJS {
14
+ public rootNode : INodeJS ;
19
15
20
- class TestBranchJS implements BranchJS {
21
- public disposed = false ;
22
- public rootNode : INodeJS ;
16
+ constructor ( branchId : string , changeCallback : ( change : ChangeJS ) => void ) {
17
+ const root = {
18
+ root : { } ,
19
+ } ;
23
20
24
- constructor ( branchId : string , changeCallback : ( change : ChangeJS ) => void ) {
25
- this . rootNode = loadModelsFromJson ( [ JSON . stringify ( root ) ] , changeCallback ) ;
26
- this . rootNode . setPropertyValue ( "branchId" , branchId ) ;
21
+ this . rootNode = loadModelsFromJson (
22
+ [ JSON . stringify ( root ) ] ,
23
+ changeCallback ,
24
+ ) ;
25
+ this . rootNode . setPropertyValue ( "branchId" , branchId ) ;
26
+ }
27
27
}
28
28
29
- dispose ( ) : void {
30
- this . disposed = true ;
29
+ class SuccessfulClientJS {
30
+ connectBranch (
31
+ _repositoryId : string ,
32
+ branchId : string ,
33
+ changeCallback : ( change : ChangeJS ) => void ,
34
+ ) : Promise < BranchJS > {
35
+ return Promise . resolve (
36
+ new SuccessfulBranchJS ( branchId , changeCallback ) as BranchJS ,
37
+ ) ;
38
+ }
31
39
}
32
40
33
- // @ts -ignore It is fine to be undefined, because we do not pass it back to Kotlin code.
34
- __doNotUseOrImplementIt : undefined ;
35
- }
41
+ const { client } = useModelClient ( "anURL" , ( ) =>
42
+ Promise . resolve ( new SuccessfulClientJS ( ) as ClientJS ) ,
43
+ ) ;
36
44
37
- class TestClientJS implements ClientJS {
38
- public disposed = false ;
45
+ const { rootNode } = useRootNode ( client , "aRepository" , "aBranch" ) ;
39
46
40
- dispose ( ) : void {
41
- this . disposed = true ;
42
- }
43
- connectBranch (
44
- _repositoryId : string ,
45
- branchId : string ,
46
- changeCallback : ( change : ChangeJS ) => void ,
47
- ) : Promise < BranchJS > {
48
- return Promise . resolve (
49
- new TestBranchJS ( branchId , changeCallback ) as unknown as BranchJS ,
50
- ) ;
51
- }
52
- fetchBranches ( _repositoryId : string ) : Promise < string [ ] > {
53
- throw new Error ( "Method not implemented." ) ;
54
- }
55
- fetchRepositories ( ) : Promise < string [ ] > {
56
- throw new Error ( "Method not implemented." ) ;
47
+ watchEffect ( ( ) => {
48
+ if ( rootNode . value !== null ) {
49
+ expect ( rootNode . value . getPropertyValue ( "branchId" ) ) . toBe ( "aBranch" ) ;
50
+ done ( ) ;
51
+ }
52
+ } ) ;
53
+ } ) ;
54
+
55
+ test ( "test branch connection error is exposed" , ( done ) => {
56
+ class FailingClientJS {
57
+ connectBranch (
58
+ _repositoryId : string ,
59
+ _branchId : string ,
60
+ _changeCallback : ( change : ChangeJS ) => void ,
61
+ ) : Promise < BranchJS > {
62
+ return Promise . reject ( "Could not connect branch." ) ;
63
+ }
57
64
}
58
65
59
- // @ts -ignore It is fine to be undefined, because we do not pass it back to Kotlin code.
60
- __doNotUseOrImplementIt : undefined ;
61
- }
66
+ const { client } = useModelClient ( "anURL" , ( ) =>
67
+ Promise . resolve ( new FailingClientJS ( ) as ClientJS ) ,
68
+ ) ;
69
+
70
+ const { error } = useRootNode ( client , "aRepository" , "aBranch" ) ;
62
71
63
- test ( "test branch connects" , ( done ) => {
64
- const { client } = useModelClient ( "anURL" , getClient ) ;
65
- const { rootNode } = useRootNode ( client , "aRepository" , "aBranch" ) ;
66
72
watchEffect ( ( ) => {
67
- if ( rootNode . value !== null ) {
68
- expect ( rootNode . value . getPropertyValue ( "branchId" ) ) . toBe ( "aBranch " ) ;
73
+ if ( error . value !== null ) {
74
+ expect ( error . value ) . toBe ( "Could not connect branch. " ) ;
69
75
done ( ) ;
70
76
}
71
77
} ) ;
0 commit comments