Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add event manager test #1045

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions ui/src/app/shared/service/event.service.spec.ts
Original file line number Diff line number Diff line change
@@ -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)
})
})
Loading