UNPKG

@benshi.ai/js-sdk

Version:

Benshi SDK

107 lines (88 loc) 2.84 kB
/** * @jest-environment jsdom */ import ELearning from ".."; import BsCore from "../../../core/BsCore" import Navigation from "../../Navigation" import { ContentBlock } from "../../Navigation/typings"; import { ModuleAction , ExamAction, ExamProperties} from "../typings"; import { ELearningTypes, QuestionAction } 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 "Module" event', () => { const senderSpy = jest.spyOn(mockSender, 'add') const bsCore = BsCore.createInstance(mockSender as any, mockImpressionManager as any, false, ContentBlock.Core,'device-id') const event = { id: 'id', progress: 78, action: ModuleAction.View } ELearning.logModuleEvent(event) expect(senderSpy).toBeCalledWith( expect.anything(), expect.anything(), expect.objectContaining( { type: ELearningTypes.Module, props: event }), expect.anything()) }) it('Should deliver a "Exam" event', () => { const senderSpy = jest.spyOn(mockSender, 'add') const bsCore = BsCore.createInstance(mockSender as any, mockImpressionManager as any, false, ContentBlock.Core, 'device-id') const event = { id: 'id', action: ExamAction.Start, } ELearning.logExamEvent(event as ExamProperties) expect(senderSpy).toBeCalledWith( expect.anything(), expect.anything(), expect.objectContaining( { type: ELearningTypes.Exam, props: event }), expect.anything()) }) it('Should deliver a "Question" event', () => { const senderSpy = jest.spyOn(mockSender, 'add') const bsCore = BsCore.createInstance(mockSender as any, mockImpressionManager as any, false, ContentBlock.Core, 'device-id') const event = { id: 'id', exam_id: '123', answer_id: 'id2', action:QuestionAction.Answer } ELearning.logQuestionEvent(event) expect(senderSpy).toBeCalledWith( expect.anything(), expect.anything(), expect.objectContaining( { type: ELearningTypes.Question, props: event }), expect.anything()) }) })