mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-04-05 18:00:13 +00:00
test: increase coverage of constructor tests
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
2f59869e12
commit
b199cdba67
1 changed files with 18 additions and 2 deletions
|
@ -36,9 +36,15 @@ describe('websocket connection', () => {
|
|||
let mockedUser: User;
|
||||
let mockedMessageTransporter: MessageTransporter;
|
||||
|
||||
const mockedUserName = 'mockedUserName';
|
||||
const mockedDisplayName = 'mockedDisplayName';
|
||||
|
||||
beforeEach(() => {
|
||||
mockedRealtimeNote = new RealtimeNote(Mock.of<Note>({}), '');
|
||||
mockedUser = Mock.of<User>({});
|
||||
mockedUser = Mock.of<User>({
|
||||
username: mockedUserName,
|
||||
displayName: mockedDisplayName,
|
||||
});
|
||||
|
||||
mockedMessageTransporter = new MockedBackendMessageTransporter('');
|
||||
});
|
||||
|
@ -72,10 +78,15 @@ describe('websocket connection', () => {
|
|||
'returns the correct realtime user status with acceptEdits %s',
|
||||
(acceptEdits) => {
|
||||
const realtimeUserStatus = Mock.of<RealtimeUserStatusAdapter>();
|
||||
let usedConnection: RealtimeConnection | undefined = undefined;
|
||||
|
||||
jest
|
||||
.spyOn(RealtimeUserStatusModule, 'RealtimeUserStatusAdapter')
|
||||
.mockImplementation(
|
||||
(username, displayName, connection, acceptCursorUpdateProvider) => {
|
||||
expect(username).toBe(mockedUserName);
|
||||
expect(displayName).toBe(mockedDisplayName);
|
||||
usedConnection = connection;
|
||||
expect(acceptCursorUpdateProvider()).toBe(acceptEdits);
|
||||
return realtimeUserStatus;
|
||||
},
|
||||
|
@ -88,6 +99,7 @@ describe('websocket connection', () => {
|
|||
acceptEdits,
|
||||
);
|
||||
|
||||
expect(usedConnection).toBe(sut);
|
||||
expect(sut.getRealtimeUserStateAdapter()).toBe(realtimeUserStatus);
|
||||
},
|
||||
);
|
||||
|
@ -99,7 +111,9 @@ describe('websocket connection', () => {
|
|||
jest
|
||||
.spyOn(HedgeDocCommonsModule, 'YDocSyncServerAdapter')
|
||||
.mockImplementation((messageTransporter, doc, acceptEditsProvider) => {
|
||||
expect(messageTransporter).toBe(mockedMessageTransporter);
|
||||
expect(acceptEditsProvider()).toBe(acceptEdits);
|
||||
expect(doc).toBe(mockedRealtimeNote.getRealtimeDoc());
|
||||
return yDocSyncServerAdapter;
|
||||
});
|
||||
|
||||
|
@ -153,13 +167,15 @@ describe('websocket connection', () => {
|
|||
expect(sut.getDisplayName()).toBe('MockUser');
|
||||
});
|
||||
|
||||
it('returns a fallback if no username has been set', () => {
|
||||
it('returns a random fallback display name if the provided user has no display name', () => {
|
||||
const randomName = 'I am a random name';
|
||||
|
||||
jest
|
||||
.spyOn(NameRandomizerModule, 'generateRandomName')
|
||||
.mockReturnValue(randomName);
|
||||
|
||||
mockedUser = Mock.of<User>({});
|
||||
|
||||
const sut = new RealtimeConnection(
|
||||
mockedMessageTransporter,
|
||||
mockedUser,
|
||||
|
|
Loading…
Reference in a new issue