UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

327 lines (325 loc) • 10 kB
/** * DevExtreme (cjs/__internal/core/r1/utils/get_updated_options.test.js) * Version: 24.2.6 * Build date: Mon Mar 17 2025 * * Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ "use strict"; var _globals = require("@jest/globals"); var _get_updated_options = require("./get_updated_options"); function _extends() { return _extends = Object.assign ? Object.assign.bind() : function(n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) { ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]) } } return n }, _extends.apply(null, arguments) }(0, _globals.describe)("get_updated_options", (() => { class DummyDataSource { constructor() { this.dummy = true } }(0, _globals.it)("simple props changed", (() => { (0, _globals.expect)((0, _get_updated_options.getUpdatedOptions)({ visible: true }, { visible: false })).toEqual([{ path: "visible", value: false, previousValue: true }]) })); (0, _globals.it)("no props changed", (() => { (0, _globals.expect)((0, _get_updated_options.getUpdatedOptions)({ visible: true }, { visible: true })).toEqual([]) })); (0, _globals.it)("new props", (() => { (0, _globals.expect)((0, _get_updated_options.getUpdatedOptions)({ visible: true }, { visible: true, enabled: false })).toEqual([{ path: "enabled", value: false, previousValue: void 0 }]) })); (0, _globals.it)("old and new is undefined", (() => { (0, _globals.expect)((0, _get_updated_options.getUpdatedOptions)({ columns: void 0 }, { columns: void 0 })).toEqual([]) })); (0, _globals.it)("eventcallback props changed", (() => { const callback1 = () => {}; const callback2 = () => {}; (0, _globals.expect)((0, _get_updated_options.getUpdatedOptions)({ visible: true, onCellClick: callback1 }, { visible: true, onCellClick: callback2 })).toEqual([{ path: "onCellClick", value: callback2, previousValue: callback1 }]) })); (0, _globals.it)("nested props changed", (() => { (0, _globals.expect)((0, _get_updated_options.getUpdatedOptions)({ editing: { allowAdding: true } }, { editing: { allowAdding: false } })).toEqual([{ path: "editing.allowAdding", value: false, previousValue: true }]) })); (0, _globals.it)("nested props changed to empty", (() => { (0, _globals.expect)((0, _get_updated_options.getUpdatedOptions)({ visible: true, editing: { allowAdding: true } }, { visible: true })).toEqual([{ path: "editing", value: void 0, previousValue: { allowAdding: true } }]) })); (0, _globals.it)("type of value in props changed", (() => { (0, _globals.expect)((0, _get_updated_options.getUpdatedOptions)({ visible: true, filterValue: [] }, { visible: true, filterValue: "1" })).toEqual([{ path: "filterValue", value: "1", previousValue: [] }]) })); (0, _globals.it)("array item props changed", (() => { const oldColumns = [{ id: "field1", visible: true }, { id: "field2", visible: true }]; const columns = [oldColumns[0], _extends({}, oldColumns[1], { visible: false })]; (0, _globals.expect)((0, _get_updated_options.getUpdatedOptions)({ columns: oldColumns }, { columns: columns })).toEqual([{ path: "columns[1].visible", value: false, previousValue: true }]) })); (0, _globals.it)("array items count changed", (() => { const oldColumns = [{ id: "field1", visible: true }, { id: "field2", visible: true }]; const columns = [...oldColumns, { id: "field3", visible: true }]; (0, _globals.expect)((0, _get_updated_options.getUpdatedOptions)({ columns: oldColumns }, { columns: columns })).toEqual([{ path: "columns", value: columns, previousValue: oldColumns }]) })); (0, _globals.it)("ignore react props", (() => { (0, _globals.expect)((0, _get_updated_options.getUpdatedOptions)({ key: "grid1", ref: {}, children: [] }, { key: "grid2", ref: {}, children: [] })).toEqual([]) })); (0, _globals.it)("not to deep equal for equal object", (() => { const obj = { ref: null }; const refObj = { ref: obj }; obj.ref = refObj; const dataSource = [obj]; (0, _globals.expect)((0, _get_updated_options.getUpdatedOptions)({ dataSource: dataSource }, { dataSource: dataSource })).toEqual([]) })); (0, _globals.it)('use equal for compare array "dataSource"', (() => { (0, _globals.expect)((0, _get_updated_options.getUpdatedOptions)({ dataSource: [] }, { dataSource: [] })).toEqual([{ path: "dataSource", value: [], previousValue: [] }]) })); (0, _globals.it)("prevProps is undefined", (() => { (0, _globals.expect)((0, _get_updated_options.getUpdatedOptions)({ focusedRowKey: null }, { focusedRowKey: 0 })).toEqual([{ path: "focusedRowKey", value: 0, previousValue: null }]) })); (0, _globals.it)("deep diff if plain object", (() => { const diff = (0, _get_updated_options.getUpdatedOptions)({ items: [{ location: "before" }] }, { items: [{ location: "after" }] }); (0, _globals.expect)(diff).toEqual([{ path: "items[0].location", value: "after", previousValue: "before" }]) })); (0, _globals.it)("deep diff only for plain object", (() => { const oldObj = { dataSource: new DummyDataSource }; const obj = { dataSource: new DummyDataSource }; (0, _globals.expect)((0, _get_updated_options.getUpdatedOptions)(oldObj, obj)).toEqual([{ path: "dataSource", value: obj.dataSource, previousValue: oldObj.dataSource }]) })); (0, _globals.it)("using notDeepDiffArrays param", (() => { (0, _globals.expect)((0, _get_updated_options.getUpdatedOptions)({ toolbar: { items: [{ value: 1 }] } }, { toolbar: { items: [{ value: 2 }] } }, ["toolbar.items"])).toEqual([{ path: "toolbar.items", value: [{ value: 2 }], previousValue: [{ value: 1 }] }]) })); (0, _globals.it)("using defaultNotDeepDiffArrays", (() => { (0, _globals.expect)((0, _get_updated_options.getUpdatedOptions)({ toolbar: { dataSource: [{ value: 1 }] } }, { toolbar: { dataSource: [{ value: 2 }] } })).toEqual([{ path: "toolbar.dataSource", value: [{ value: 2 }], previousValue: [{ value: 1 }] }]) })); (0, _globals.it)("integration options are ignored", (() => { (0, _globals.expect)((0, _get_updated_options.getUpdatedOptions)({ visible: true, integrationOptions: true }, { visible: false, integrationOptions: void 0 })).toEqual([{ path: "visible", value: false, previousValue: true }]) })); (0, _globals.it)("integration options in child props are ignored", (() => { (0, _globals.expect)((0, _get_updated_options.getUpdatedOptions)({ visible: true, items: { integrationOptions: true, disabled: true } }, { visible: false, items: { integrationOptions: void 0, disabled: false } })).toEqual([{ path: "visible", value: false, previousValue: true }, { path: "items.disabled", value: false, previousValue: true }]) })) }));