UNPKG

@benshi.ai/js-sdk

Version:

Benshi SDK

75 lines (61 loc) 2.02 kB
/** * @jest-environment jsdom */ import Feed from "." import BsCore from "../../core/BsCore"; import { ContentBlock } from "../Navigation/typings"; import { FeedProperties, FeedType, PublicationAction, PublicationType } from "./typings"; import { FeedTypes } from "./typings"; let windowSpy let mockSender; let mockImpressionManager = {} describe('ELearning', () => { beforeAll(() => { mockSender = { add() { return false } } }) beforeEach(() => { windowSpy = jest.spyOn(window, "window", "get"); }) afterEach(() => { // to remove the singleton instance (BsCore as any).instance = null }) it('Should deliver a "Publication" event', () => { const senderSpy = jest.spyOn(mockSender, 'add') const bsCore = BsCore.createInstance(mockSender as any, mockImpressionManager as any, false, ContentBlock.Core,'device-id') const event = { action: PublicationAction.Like, type: PublicationType.Comment, id: '123', } Feed.logPublicationEvent(event) expect(senderSpy).toBeCalledWith( expect.anything(), expect.anything(), expect.objectContaining( { type: FeedTypes.Publication, props: event }), expect.anything()) }) it('Should deliver a "Feed" event', () => { const senderSpy = jest.spyOn(mockSender, 'add') const bsCore = BsCore.createInstance(mockSender as any, mockImpressionManager as any, false, ContentBlock.Core,'device-id') const event:FeedProperties = { type: FeedType.News } Feed.logFeedEvent(event) expect(senderSpy).toBeCalledWith( expect.anything(), expect.anything(), expect.objectContaining( { type: FeedTypes.Feed, props: event }), expect.anything()) }) })