UNPKG

@applicaster/zapp-react-native-utils

Version:

Applicaster Zapp React Native utilities package

109 lines (91 loc) 2.87 kB
const { isWeb } = require("@applicaster/zapp-react-native-utils/reactUtils"); import { ANALYTICS_CORE_EVENTS } from "../events"; jest.mock("@applicaster/zapp-react-native-utils/reactUtils", () => ({ isWeb: jest.fn(), })); const mock_postAnalyticEvent = jest.fn(); const mock_startAnalyticsTimedEvent = jest.fn(); const mock_endAnalyticsTimedEvent = jest.fn(); jest.mock("../manager", () => ({ postAnalyticEvent: mock_postAnalyticEvent, startAnalyticsTimedEvent: mock_startAnalyticsTimedEvent, endAnalyticsTimedEvent: mock_endAnalyticsTimedEvent, })); const analyticsUtils = require("../index"); const item = { title: "title", id: "A1234", content: { src: "http://stream.com/url.m3u8" }, type: { value: "video" }, extensions: {}, }; const component = { id: "component_1", component_type: "horizontal_list", styles: { cell_style: [], cell_plugin_configuration_id: "cell-id", family: "FAMILY_1", header: "HEADER_STYLE", }, data: { source: { url: "applicaster://fetchData?type=feed&url=url" }, type: "feed", }, rules: {}, }; const RESULT = { sendSelectCellEvent: { item_type: "video", item_name: "title", item_id: "A1234", item_number: 2, component_id: "component_1", component_type: "horizontal_list", cell_style: "cell-id", header_name: "title", component_source: { url: "applicaster://fetchData?type=feed&url=url" }, }, }; const headerTitle = item.title; const itemIndex = 1; function clearAllMocks() { mock_postAnalyticEvent.mockClear(); mock_startAnalyticsTimedEvent.mockClear(); mock_endAnalyticsTimedEvent.mockClear(); } describe("analyticsUtils", () => { beforeEach(clearAllMocks); describe("sendSelectCellEvent", () => { it("sends the tap_cell event", () => { analyticsUtils.sendSelectCellEvent( item, component, headerTitle, itemIndex ); expect(mock_postAnalyticEvent).toHaveBeenCalled(); const call = mock_postAnalyticEvent.mock.calls[0]; const eventArg = call[0]; const eventPayload = call[1]; expect(eventArg).toBe(ANALYTICS_CORE_EVENTS.TAP_CELL); expect(eventPayload).toEqual(RESULT.sendSelectCellEvent); }); }); describe("sendLaunchEvent", () => { beforeEach(clearAllMocks); it("sends launch event when isWeb is true", () => { isWeb.mockReturnValue(true); analyticsUtils.sendLaunchEvent(); expect(mock_postAnalyticEvent).toHaveBeenCalled(); const call = mock_postAnalyticEvent.mock.calls[0]; const eventArg = call[0]; expect(eventArg).toBe(ANALYTICS_CORE_EVENTS.LAUNCH_APP); }); it("does not send launch event when isWeb is false", () => { isWeb.mockReturnValue(false); analyticsUtils.sendLaunchEvent(); expect(mock_postAnalyticEvent).not.toHaveBeenCalled(); }); }); });