5
5
import { enableMobxBindings } from "@syncedstore/yjs-reactive-bindings" ;
6
6
import * as mobx from "mobx" ;
7
7
import { beforeEach , describe , expect , it } from "vitest" ;
8
- import { uri } from "vscode-lib" ;
8
+ import { async , uri } from "vscode-lib" ;
9
9
import * as Y from "yjs" ;
10
10
import { Identifier } from "../identifiers/Identifier" ;
11
11
import {
@@ -76,7 +76,7 @@ function createDocAndAllowAccess(forUsers: User[], docId: DocId) {
76
76
const resourceAsInbox = inboxBaseResource . getSpecificType < InboxResource > (
77
77
InboxResource as any
78
78
) ;
79
- resourceAsInbox . inboxTarget = docId ;
79
+ resourceAsInbox . inboxTarget = "test:test/" + docId ;
80
80
user . docs [ docId + "-inbox" ] = {
81
81
resourceAsInbox,
82
82
resource : inboxBaseResource ,
@@ -86,24 +86,27 @@ function createDocAndAllowAccess(forUsers: User[], docId: DocId) {
86
86
87
87
// create main doc
88
88
const ydoc = new Y . Doc ( ) ;
89
- const resource = new BaseResource ( ydoc , new TestIdentifier ( docId ) , {
90
- ...UnimplementedBaseResourceExternalManager ,
91
- loadInboxResource : async ( id ) => {
92
- const testIdentifier = new TestIdentifier ( id . toString ( ) ) ;
93
- const inbox = user . docs [ testIdentifier . id + "-inbox" ] . resourceAsInbox ;
89
+ const manager : any = {
90
+ loadInboxResource : async ( id : TestIdentifier ) => {
91
+ // const testIdentifier = new TestIdentifier(id.toString());
92
+ const inbox = user . docs [ id . id + "-inbox" ] . resourceAsInbox ;
94
93
if ( ! inbox ) {
95
94
throw new Error ( "can't resolve inbox id " + id ) ;
96
95
}
97
96
return inbox ;
98
97
} ,
99
- } ) ;
98
+ } ;
99
+ manager . prototype = UnimplementedBaseResourceExternalManager ;
100
+ const resource = new BaseResource ( ydoc , new TestIdentifier ( docId ) , manager ) ;
100
101
101
102
const validator = new InboxValidator (
102
103
resourceAsInbox ! ,
103
104
ChildReference ,
104
- async ( identifier ) => {
105
- const testIdentifier = identifier . uri . path . substring ( 1 ) ;
106
- return user . docs [ testIdentifier ] . resource ;
105
+ async ( idStr ) => {
106
+ // hacky
107
+ const testIdentifier = uri . URI . parse ( idStr . replace ( "test:" , "test://" ) ) ;
108
+ const docId = testIdentifier . path . substring ( 1 ) ;
109
+ return user . docs [ docId ] . resource ;
107
110
}
108
111
) ;
109
112
@@ -158,7 +161,7 @@ describe("links", () => {
158
161
expect ( user2 . docs . doc1 . ydoc . getMap ( "test" ) . get ( "hello" ) ) . toBeUndefined ( ) ;
159
162
} ) ;
160
163
161
- it . only ( "adds a ref" , async ( ) => {
164
+ it ( "adds a ref" , async ( ) => {
162
165
createDocAndAllowAccess ( [ user1 , user2 ] , "doc1" ) ;
163
166
createDocAndAllowAccess ( [ user1 , user2 ] , "doc2" ) ;
164
167
@@ -174,6 +177,8 @@ describe("links", () => {
174
177
175
178
await new Promise ( ( resolve ) => setImmediate ( resolve ) ) ; // allow autorun to fire
176
179
180
+ await async . timeout ( 100 ) ;
181
+
177
182
expect ( user1 . docs . doc2 . validator ! . validRefMessages . length ) . toBe ( 1 ) ;
178
183
expect ( user2 . docs . doc2 . validator ! . validRefMessages . length ) . toBe ( 0 ) ;
179
184
0 commit comments