From f55c1cae9a9dd2179945c01f32475abe6d9def74 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Thu, 26 Oct 2023 19:50:28 +0300 Subject: [PATCH] Create event.service.spec.ts --- .../app/shared/service/event.service.spec.ts | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 ui/src/app/shared/service/event.service.spec.ts diff --git a/ui/src/app/shared/service/event.service.spec.ts b/ui/src/app/shared/service/event.service.spec.ts new file mode 100644 index 000000000..a9e1fdc96 --- /dev/null +++ b/ui/src/app/shared/service/event.service.spec.ts @@ -0,0 +1,49 @@ +import { EventType } from 'src/app/app.constants' +import { EventService } from './event.service' +import { Event } from '../model/event.model' + +describe('EventService', () => { + let eventService: EventService + + beforeEach(() => { + eventService = new EventService() + }) + + it('should be created', () => { + expect(eventService).toBeTruthy() + }) + + it('should broadcast events', () => { + const event: Event = { + type: EventType.LOG_IN_SUCCESS, + payload: 'Login successful', + } + let receivedEvent: Event | undefined + + eventService.on(EventType.LOG_IN_SUCCESS).subscribe((e) => { + receivedEvent = e + }) + + eventService.broadcast(event) + + expect(receivedEvent).toEqual(event) + }) + + it('should filter events by type', () => { + const event1: Event = { type: EventType.LOG_IN_SUCCESS, payload: 'data 1' } + const event2: Event = { + type: EventType.AFFILIATION_CREATED, + payload: 'data 2', + } + let receivedEvent: Event | undefined + + eventService.on(EventType.LOG_IN_SUCCESS).subscribe((e) => { + receivedEvent = e + }) + + eventService.broadcast(event1) + eventService.broadcast(event2) + + expect(receivedEvent).toEqual(event1) + }) +})