UNPKG

@roderickhsiao/react-i13n

Version:

[Experiment] React I13n provides a performant and scalable solution to application instrumentation.

127 lines (119 loc) 4.1 kB
"use strict"; var _ReactI13n = _interopRequireDefault(require("../ReactI13n")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } /** * Copyright 2020, Yahoo! Inc. * Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms. */ describe('ReactI13n', function () { it('should be created correctly', function () { var reactI13n = new _ReactI13n["default"]({ isViewportEnabled: true }); expect(reactI13n.isViewportEnabled()).toEqual(true); }); it('should be able to update options', function () { var reactI13n = new _ReactI13n["default"]({ isViewportEnabled: true }); expect(reactI13n.isViewportEnabled()).toEqual(true); reactI13n.updateOptions({ isViewportEnabled: false }); expect(reactI13n.isViewportEnabled()).toEqual(false); }); it('should be able to generate root i13n node', function () { var rootModelData = { foo: 'bar' }; var mockReactI13nClass = jest.fn(); mockReactI13nClass.prototype.getMergedModel = function () { return rootModelData; }; mockReactI13nClass.prototype.setDOMNode = function () {}; var reactI13n = new _ReactI13n["default"]({ rootModelData: rootModelData, i13nNodeClass: mockReactI13nClass }); reactI13n.createRootI13nNode(); expect(reactI13n.getRootI13nNode().getMergedModel()).toEqual(rootModelData); }); it('should be able to setup plugin and execute event', function (done) { var mockPlugin1 = { name: 'test1', eventHandlers: { click: function click(payload, callback) { expect(payload).toEqual({}); callback(); } } }; var mockPlugin2 = { name: 'test2', eventHandlers: { click: function click(payload, callback) { expect(payload).toEqual({}); callback(); } } }; var reactI13n = new _ReactI13n["default"]({}); reactI13n.plug(mockPlugin1); reactI13n.plug(mockPlugin2); // two plugin should be executed correctly then call the custom callback reactI13n.execute('click', {}, function () { expect(true).toEqual(true); done(); }); }); it('should be able to execute event without modifying payload', function (done) { var mockPlugin1 = { name: 'test1', eventHandlers: { click: function click(payload, callback) { expect(payload).toEqual({}); callback(); } } }; var payload = { foo: 'bar' }; var reactI13n = new _ReactI13n["default"]({}); reactI13n.plug(mockPlugin1); reactI13n.execute('click', payload, function () { // should only have one attribute as 'foo', which means payload is not modified inside reactI13n.execute expect(payload).toEqual({ foo: 'bar' }); done(); }); }); it('should have a global timeout if event handler does not finish in time', function (done) { var mockPlugin1 = { name: 'test1', eventHandlers: { click: function click() {// do nothing, without callback, simulate if event handler does not execute correctly or timeout } } }; var reactI13n = new _ReactI13n["default"]({}); reactI13n.plug(mockPlugin1); // two plugin should be executed correctly then call the custom callback reactI13n.execute('click', {}, function () { // should still have callback due to the global timeout expect(true).toEqual(true); done(); }); }); it('should be able to set a scrollableContainerId', function () { var reactI13n = new _ReactI13n["default"]({ scrollableContainerId: 'scrollable-test' }); expect(reactI13n.getScrollableContainerId()).toEqual('scrollable-test'); }); it('should have an undefined scrollableContainerDOMNode if the scrollableContainerId is undefined', function () { var reactI13n = new _ReactI13n["default"]({ isViewportEnabled: true }); expect(reactI13n.getScrollableContainerDOMNode()).toEqual(undefined); }); });