-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5909312
commit 11e1404
Showing
2 changed files
with
97 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright (c) Jupyter Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||
|
||
import { ICollaborativeDrive } from '@jupyter/collaborative-drive'; | ||
import { | ||
ForkManager, | ||
JUPYTER_COLLABORATION_FORK_EVENTS_URI | ||
} from '../forkManager'; | ||
import { Event } from '@jupyterlab/services'; | ||
import { Signal } from '@lumino/signaling'; | ||
import { requestAPI } from '../requests'; | ||
jest.mock('../requests'); | ||
|
||
const driveMock = { | ||
name: 'rtc', | ||
providers: new Map() | ||
} as ICollaborativeDrive; | ||
const stream = new Signal({}); | ||
const eventManagerMock = { | ||
stream: stream as any | ||
} as Event.IManager; | ||
|
||
describe('@jupyter/docprovider', () => { | ||
let manager: ForkManager; | ||
beforeEach(() => { | ||
manager = new ForkManager({ | ||
drive: driveMock, | ||
eventManager: eventManagerMock | ||
}); | ||
}); | ||
describe('forkManager', () => { | ||
it('should have a type', () => { | ||
expect(ForkManager).not.toBeUndefined(); | ||
}); | ||
it('should be able to create instance', () => { | ||
expect(manager).toBeInstanceOf(ForkManager); | ||
}); | ||
it('should be able to create new fork', async () => { | ||
await manager.createFork({ | ||
rootId: 'root-uuid', | ||
synchronize: true, | ||
label: 'my fork label', | ||
description: 'my fork description' | ||
}); | ||
expect(requestAPI).toHaveBeenCalledWith( | ||
'api/collaboration/fork/root-uuid', | ||
{ | ||
method: 'PUT', | ||
body: JSON.stringify({ | ||
label: 'my fork label', | ||
description: 'my fork description', | ||
synchronize: true | ||
}) | ||
} | ||
); | ||
}); | ||
it('should be able to get all forks', async () => { | ||
await manager.getAllForks('root-uuid'); | ||
expect(requestAPI).toHaveBeenCalledWith( | ||
'api/collaboration/fork/root-uuid', | ||
{ | ||
method: 'GET' | ||
} | ||
); | ||
}); | ||
it('should be able to get delete forks', async () => { | ||
await manager.deleteFork({ forkId: 'fork-uuid', merge: true }); | ||
expect(requestAPI).toHaveBeenCalledWith( | ||
'api/collaboration/fork/fork-uuid?merge=true', | ||
{ | ||
method: 'DELETE' | ||
} | ||
); | ||
}); | ||
it('should be able to emit fork added signal', async () => { | ||
const listener = jest.fn(); | ||
manager.forkAdded.connect(listener); | ||
const data = { | ||
schema_id: JUPYTER_COLLABORATION_FORK_EVENTS_URI, | ||
action: 'create' | ||
}; | ||
stream.emit(data); | ||
expect(listener).toHaveBeenCalledWith(manager, data); | ||
}); | ||
it('should be able to emit fork deleted signal', async () => { | ||
const listener = jest.fn(); | ||
manager.forkDeleted.connect(listener); | ||
const data = { | ||
schema_id: JUPYTER_COLLABORATION_FORK_EVENTS_URI, | ||
action: 'delete' | ||
}; | ||
stream.emit(data); | ||
expect(listener).toHaveBeenCalledWith(manager, data); | ||
}); | ||
}); | ||
}); |
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