1
0
mirror of https://github.com/pavlobu/deskreen.git synced 2025-05-18 08:20:10 -07:00
deskreen/app/server/RoomIDService/RoomIDService.spec.ts
Pavlo Buidenkov b925803d9f better client UI code
huge work done on sharing desktop session
2020-11-22 17:07:01 +02:00

56 lines
1.7 KiB
TypeScript

import RoomIDService from '.';
jest.useFakeTimers();
describe('SharingSessionService unit tests', () => {
let roomIDService: RoomIDService;
beforeEach(() => {
roomIDService = new RoomIDService();
});
afterEach(() => {
jest.clearAllMocks();
});
describe('when new RoomIDService() is created', () => {
it('should have empty takenRoomIDs Set', () => {
expect(roomIDService.takenRoomIDs.size).toBe(0);
});
});
describe('when getShortIDStringOfAvailableRoom() is called', () => {
it('should resolve with non empty string', async () => {
const gotShortStringID = await roomIDService.getShortIDStringOfAvailableRoom();
expect(gotShortStringID).toBeTruthy();
});
});
describe('when getSimpleAvailableRoomID() is called', () => {
it('should resolve with non empty string of nextAvailableRoomIDNumber property', async () => {
const gotRoomID = await roomIDService.getSimpleAvailableRoomID();
expect(gotRoomID).not.toBe('');
});
});
describe('when markRoomIDAsTaken(id: string) is called', () => {
it('should add passed id: string argument to takenRoomIDs Set', () => {
const testRoomID = '1';
roomIDService.markRoomIDAsTaken(testRoomID);
expect(roomIDService.takenRoomIDs.has(testRoomID)).toBe(true);
});
});
describe('when unmarkRoomIDAsTaken(id: string) is called', () => {
it('should remove passed id: string argument to takenRoomIDs Set', () => {
const testRoomID = '1';
roomIDService.markRoomIDAsTaken(testRoomID);
roomIDService.unmarkRoomIDAsTaken(testRoomID);
expect(roomIDService.takenRoomIDs.has(testRoomID)).toBe(false);
});
});
});